Skip to content

Commit fb7c8d1

Browse files
author
git-core
committed
Mark child as volatile
It's shared between the SIGCHLD signal handler and normal flow. Its type is still pid_t, however, not sig_atomic_t.
1 parent 70a5e41 commit fb7c8d1

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

activity.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ int send_intent(struct su_context *ctx, allow_t allow, const char *action)
6464
__sighandler_t handler;
6565
pid_t pid;
6666

67-
if (ctx->child) {
68-
kill_child(ctx->child);
69-
if (ctx->child) {
70-
LOGE("child %d is still running", ctx->child);
67+
pid = ctx->child;
68+
if (pid) {
69+
kill_child(pid);
70+
pid = ctx->child;
71+
if (pid) {
72+
LOGE("child %d is still running", pid);
7173
return -1;
7274
}
7375
}

su.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,13 @@ static void socket_cleanup(struct su_context *ctx)
151151

152152
static void child_cleanup(struct su_context *ctx)
153153
{
154-
pid_t pid = (ctx && ctx->child) ? ctx->child : -1;
154+
pid_t pid = ctx->child;
155155
int rc;
156156

157-
if (!ctx)
158-
LOGE("no context present");
159-
if (!ctx->child)
157+
if (!pid) {
160158
LOGE("unexpected child");
161-
159+
pid = -1; /* pick up any child */
160+
}
162161
pid = waitpid(pid, &rc, WNOHANG);
163162
if (pid < 0) {
164163
PLOGE("waitpid");
@@ -173,9 +172,7 @@ static void child_cleanup(struct su_context *ctx)
173172
exit(EXIT_FAILURE);
174173
}
175174
LOGD("child %d terminated, status %d", pid, rc);
176-
177-
if (ctx)
178-
ctx->child = 0;
175+
ctx->child = 0;
179176
}
180177

181178
/*

su.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct su_context {
7070
struct su_initiator from;
7171
struct su_request to;
7272
mode_t umask;
73-
pid_t child;
73+
volatile pid_t child;
7474
char sock_path[PATH_MAX];
7575
};
7676

0 commit comments

Comments
 (0)