Gentoo Archives: gentoo-commits

From: Lars Wendler <polynomial-c@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: sys-apps/netplug/, sys-apps/netplug/files/
Date: Sat, 20 Apr 2019 23:07:09
Message-Id: 1555801577.ca3c5c6b52e60bea1eab05a2b5bc97942aa7dc66.polynomial-c@gentoo
1 commit: ca3c5c6b52e60bea1eab05a2b5bc97942aa7dc66
2 Author: Lars Wendler <polynomial-c <AT> gentoo <DOT> org>
3 AuthorDate: Sat Apr 20 23:02:50 2019 +0000
4 Commit: Lars Wendler <polynomial-c <AT> gentoo <DOT> org>
5 CommitDate: Sat Apr 20 23:06:17 2019 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ca3c5c6b
7
8 sys-apps/netplug: Attempt to fix zombie creation
9
10 Thanks-to: Lev Danilski <8o55kd+1v8xnjsby8b9k <AT> pokemail.net>
11 Closes: https://bugs.gentoo.org/631316
12 Package-Manager: Portage-2.3.64, Repoman-2.3.12
13 Signed-off-by: Lars Wendler <polynomial-c <AT> gentoo.org>
14
15 .../netplug-1.2.9.2-multi-waitpid-sigchld.patch | 65 +++++++++++++++++++
16 sys-apps/netplug/netplug-1.2.9.2-r3.ebuild | 73 ++++++++++++++++++++++
17 2 files changed, 138 insertions(+)
18
19 diff --git a/sys-apps/netplug/files/netplug-1.2.9.2-multi-waitpid-sigchld.patch b/sys-apps/netplug/files/netplug-1.2.9.2-multi-waitpid-sigchld.patch
20 new file mode 100644
21 index 00000000000..06e645c1dee
22 --- /dev/null
23 +++ b/sys-apps/netplug/files/netplug-1.2.9.2-multi-waitpid-sigchld.patch
24 @@ -0,0 +1,65 @@
25 +# Rework SIGCHLD handler to anticipate multiple children dying while the
26 +# handler is being executed.
27 +#
28 +# Without the patch if multiple SIGCHLD signals are received while the signal
29 +# handler is being executed, the first will be left in pending state and the
30 +# extra discarded. Due to the children processing logic in netplugd, the ones
31 +# which were missed will never be waited, left as zombies.
32 +#
33 +# Implementation of the signal handler is following suggested handling in
34 +# https://www.gnu.org/software/libc/manual/html_node/Merged-Signals.html
35 +#
36 +# The patch strives to change only the children wait logic in the signal
37 +# handler, it doesn't try to enhance write call error handling or the unsafe
38 +# call to exit/do_log. Also the formatting is left as it was in the original
39 +# code.
40 +
41 +--- a/main.c
42 ++++ b/main.c
43 +@@ -153,17 +153,29 @@ static int child_handler_pipe[2];
44 + static void
45 + child_handler(int sig, siginfo_t *info, void *v)
46 + {
47 +- struct child_exit ce;
48 +- int ret;
49 +- ssize_t s = 0;
50 ++ int old_errno = errno;
51 +
52 + assert(sig == SIGCHLD);
53 +
54 +- ce.pid = info->si_pid;
55 +- ret = waitpid(info->si_pid, &ce.status, 0);
56 +- if (ret == info->si_pid)
57 ++ while (1)
58 + {
59 +- s = write(child_handler_pipe[1], &ce, sizeof(ce));
60 ++ pid_t pid;
61 ++ int status;
62 ++
63 ++ do
64 ++ {
65 ++ errno = 0;
66 ++ pid = waitpid(WAIT_ANY, &status, WNOHANG);
67 ++ } while (pid <= 0 && errno == EINTR);
68 ++
69 ++ if (pid <= 0)
70 ++ {
71 ++ break;
72 ++ }
73 ++
74 ++ struct child_exit ce = { .pid = pid, .status = status };
75 ++
76 ++ ssize_t s = write(child_handler_pipe[1], &ce, sizeof(ce));
77 +
78 + if (s == -1)
79 + {
80 +@@ -171,6 +183,9 @@ child_handler(int sig, siginfo_t *info, void *v)
81 + exit(1);
82 + }
83 + }
84 ++
85 ++ errno = old_errno;
86 ++ return;
87 + }
88 +
89 + /* Poll the existing interface state, so we can catch any state
90
91 diff --git a/sys-apps/netplug/netplug-1.2.9.2-r3.ebuild b/sys-apps/netplug/netplug-1.2.9.2-r3.ebuild
92 new file mode 100644
93 index 00000000000..a452c1ad1c3
94 --- /dev/null
95 +++ b/sys-apps/netplug/netplug-1.2.9.2-r3.ebuild
96 @@ -0,0 +1,73 @@
97 +# Copyright 1999-2019 Gentoo Authors
98 +# Distributed under the terms of the GNU General Public License v2
99 +
100 +EAPI=7
101 +
102 +inherit toolchain-funcs
103 +
104 +DESCRIPTION="Brings up/down ethernet ports automatically with cable detection"
105 +HOMEPAGE="https://www.red-bean.com/~bos/"
106 +SRC_URI="https://www.red-bean.com/~bos/netplug/${P}.tar.bz2"
107 +
108 +LICENSE="GPL-2"
109 +SLOT="0"
110 +KEYWORDS="~amd64 ~arm ~mips ~ppc ~ppc64 ~sparc ~x86"
111 +IUSE="debug doc"
112 +
113 +DEPEND="doc? ( app-text/ghostscript-gpl
114 + media-gfx/graphviz )"
115 +RDEPEND=""
116 +
117 +PATCHES=(
118 + # Remove nested functions, #116140
119 + "${FILESDIR}/${PN}-1.2.9-remove-nest.patch"
120 +
121 + # Ignore wireless events
122 + "${FILESDIR}/${PN}-1.2.9-ignore-wireless.patch"
123 +
124 + # Fix DOWNANDOUT problem #599400
125 + "${FILESDIR}/${P}-downandout.patch"
126 +
127 + # Wait for multiple children in SIGCHLD handler #631316
128 + "${FILESDIR}/${P}-multi-waitpid-sigchld.patch"
129 +)
130 +
131 +src_prepare() {
132 + # Remove debug flags from CFLAGS
133 + if ! use debug ; then
134 + sed -i -e "s/ -ggdb3//" Makefile || die
135 + fi
136 +
137 + # Remove -O3 and -Werror from CFLAGS
138 + sed -i -e "s/ -O3//" -e "s/ -Werror//" Makefile || die
139 +
140 + default
141 +}
142 +
143 +src_compile() {
144 + tc-export CC
145 + emake CC="${CC}"
146 +
147 + if use doc ; then
148 + emake -C docs/
149 + fi
150 +}
151 +
152 +src_install() {
153 + into /
154 + dosbin netplugd
155 + doman man/man8/netplugd.8
156 +
157 + dodir /etc/netplug.d
158 + exeinto /etc/netplug.d
159 + newexe "${FILESDIR}/netplug-2" netplug
160 +
161 + dodir /etc/netplug
162 + echo "eth*" > "${ED}"/etc/netplug/netplugd.conf || die
163 +
164 + dodoc ChangeLog NEWS README TODO
165 +
166 + if use doc; then
167 + dodoc docs/state-machine.ps
168 + fi
169 +}