Skip to content

Commit 6799779

Browse files
author
git-core
committed
Wait until the child is really killed, ...
... so su can get its exit status
1 parent 40c3d17 commit 6799779

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

su.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,22 @@ static void socket_cleanup(struct su_context *ctx)
152152
static void kill_child(pid_t pid)
153153
{
154154
LOGD("killing child %d", pid);
155-
if (pid && kill(pid, SIGKILL))
156-
PLOGE("kill (%d)", pid);
155+
if (pid) {
156+
sigset_t set, old;
157+
158+
sigemptyset(&set);
159+
sigaddset(&set, SIGCHLD);
160+
if (sigprocmask(SIG_BLOCK, &set, &old)) {
161+
PLOGE("sigprocmask(SIG_BLOCK)");
162+
return;
163+
}
164+
if (kill(pid, SIGKILL))
165+
PLOGE("kill (%d)", pid);
166+
else if (sigsuspend(&old) && errno != EINTR)
167+
PLOGE("sigsuspend");
168+
if (sigprocmask(SIG_SETMASK, &old, NULL))
169+
PLOGE("sigprocmask(SIG_BLOCK)");
170+
}
157171
}
158172

159173
static void child_cleanup(struct su_context *ctx)
@@ -172,10 +186,14 @@ static void child_cleanup(struct su_context *ctx)
172186
exit(EXIT_FAILURE);
173187
}
174188
if (WIFEXITED(rc) && WEXITSTATUS(rc)) {
175-
LOGE("child %d terminated with error %d", pid, rc);
189+
LOGE("child %d terminated with error %d", pid, WEXITSTATUS(rc));
190+
exit(EXIT_FAILURE);
191+
}
192+
if (WIFSIGNALED(rc) && WTERMSIG(rc) != SIGKILL) {
193+
LOGE("child %d terminated with signal %d", pid, WTERMSIG(rc));
176194
exit(EXIT_FAILURE);
177195
}
178-
LOGE("child %d terminated, status %d", pid, rc);
196+
LOGD("child %d terminated, status %d", pid, rc);
179197

180198
if (ctx)
181199
ctx->child = 0;

0 commit comments

Comments
 (0)