aboutsummaryrefslogtreecommitdiff
path: root/runit
diff options
context:
space:
mode:
Diffstat (limited to 'runit')
-rw-r--r--runit/runsv.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/runit/runsv.c b/runit/runsv.c
index 0da03e6b3..2ab034af6 100644
--- a/runit/runsv.c
+++ b/runit/runsv.c
@@ -256,15 +256,16 @@ static unsigned custom(struct svdir *s, char c)
256 256
257 if (s->islog) return 0; 257 if (s->islog) return 0;
258 strcpy(a, "control/?"); 258 strcpy(a, "control/?");
259 a[8] = c; 259 a[8] = c; /* replace '?' */
260 if (stat(a, &st) == 0) { 260 if (stat(a, &st) == 0) {
261 if (st.st_mode & S_IXUSR) { 261 if (st.st_mode & S_IXUSR) {
262 pid = fork(); 262 pid = vfork();
263 if (pid == -1) { 263 if (pid == -1) {
264 warn_cannot("fork for control/?"); 264 warn_cannot("vfork for control/?");
265 return 0; 265 return 0;
266 } 266 }
267 if (!pid) { 267 if (!pid) {
268 /* child */
268 if (haslog && dup2(logpipe.wr, 1) == -1) 269 if (haslog && dup2(logpipe.wr, 1) == -1)
269 warn_cannot("setup stdout for control/?"); 270 warn_cannot("setup stdout for control/?");
270 prog[0] = a; 271 prog[0] = a;
@@ -272,6 +273,7 @@ static unsigned custom(struct svdir *s, char c)
272 execv(a, prog); 273 execv(a, prog);
273 fatal_cannot("run control/?"); 274 fatal_cannot("run control/?");
274 } 275 }
276 /* parent */
275 while (safe_waitpid(pid, &w, 0) == -1) { 277 while (safe_waitpid(pid, &w, 0) == -1) {
276 warn_cannot("wait for child control/?"); 278 warn_cannot("wait for child control/?");
277 return 0; 279 return 0;
@@ -318,8 +320,8 @@ static void startservice(struct svdir *s)
318 320
319 if (s->pid != 0) 321 if (s->pid != 0)
320 stopservice(s); /* should never happen */ 322 stopservice(s); /* should never happen */
321 while ((p = fork()) == -1) { 323 while ((p = vfork()) == -1) {
322 warn_cannot("fork, sleeping"); 324 warn_cannot("vfork, sleeping");
323 sleep(5); 325 sleep(5);
324 } 326 }
325 if (p == 0) { 327 if (p == 0) {
@@ -344,6 +346,7 @@ static void startservice(struct svdir *s)
344 execvp(*run, run); 346 execvp(*run, run);
345 fatal2_cannot(s->islog ? "start log/" : "start ", *run); 347 fatal2_cannot(s->islog ? "start log/" : "start ", *run);
346 } 348 }
349 /* parent */
347 if (s->state != S_FINISH) { 350 if (s->state != S_FINISH) {
348 gettimeofday_ns(&s->start); 351 gettimeofday_ns(&s->start);
349 s->state = S_RUN; 352 s->state = S_RUN;