runsv.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /*
  2. Copyright (c) 2001-2006, Gerrit Pape
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. 1. Redistributions of source code must retain the above copyright notice,
  7. this list of conditions and the following disclaimer.
  8. 2. Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. 3. The name of the author may not be used to endorse or promote products
  12. derived from this software without specific prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  14. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  15. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  16. EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  19. OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  20. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  21. OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  22. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. /* Busyboxed by Denys Vlasenko <vda.linux@googlemail.com> */
  25. /* TODO: depends on runit_lib.c - review and reduce/eliminate */
  26. #include <sys/poll.h>
  27. #include <sys/file.h>
  28. #include "libbb.h"
  29. #include "runit_lib.h"
  30. #if ENABLE_MONOTONIC_SYSCALL
  31. #include <sys/syscall.h>
  32. /* libc has incredibly messy way of doing this,
  33. * typically requiring -lrt. We just skip all this mess */
  34. static void gettimeofday_ns(struct timespec *ts)
  35. {
  36. syscall(__NR_clock_gettime, CLOCK_REALTIME, ts);
  37. }
  38. #else
  39. static void gettimeofday_ns(struct timespec *ts)
  40. {
  41. if (sizeof(struct timeval) == sizeof(struct timespec)
  42. && sizeof(((struct timeval*)ts)->tv_usec) == sizeof(ts->tv_nsec)
  43. ) {
  44. /* Cheat */
  45. gettimeofday((void*)ts, NULL);
  46. ts->tv_nsec *= 1000;
  47. } else {
  48. extern void BUG_need_to_implement_gettimeofday_ns(void);
  49. BUG_need_to_implement_gettimeofday_ns();
  50. }
  51. }
  52. #endif
  53. /* Compare possibly overflowing unsigned counters */
  54. #define LESS(a,b) ((int)((unsigned)(b) - (unsigned)(a)) > 0)
  55. /* state */
  56. #define S_DOWN 0
  57. #define S_RUN 1
  58. #define S_FINISH 2
  59. /* ctrl */
  60. #define C_NOOP 0
  61. #define C_TERM 1
  62. #define C_PAUSE 2
  63. /* want */
  64. #define W_UP 0
  65. #define W_DOWN 1
  66. #define W_EXIT 2
  67. struct svdir {
  68. int pid;
  69. smallint state;
  70. smallint ctrl;
  71. smallint want;
  72. smallint islog;
  73. struct timespec start;
  74. int fdlock;
  75. int fdcontrol;
  76. int fdcontrolwrite;
  77. };
  78. struct globals {
  79. smallint haslog;
  80. smallint sigterm;
  81. smallint pidchanged;
  82. struct fd_pair selfpipe;
  83. struct fd_pair logpipe;
  84. char *dir;
  85. struct svdir svd[2];
  86. };
  87. #define G (*(struct globals*)&bb_common_bufsiz1)
  88. #define haslog (G.haslog )
  89. #define sigterm (G.sigterm )
  90. #define pidchanged (G.pidchanged )
  91. #define selfpipe (G.selfpipe )
  92. #define logpipe (G.logpipe )
  93. #define dir (G.dir )
  94. #define svd (G.svd )
  95. #define INIT_G() do { \
  96. pidchanged = 1; \
  97. } while (0)
  98. static void fatal2_cannot(const char *m1, const char *m2)
  99. {
  100. bb_perror_msg_and_die("%s: fatal: cannot %s%s", dir, m1, m2);
  101. /* was exiting 111 */
  102. }
  103. static void fatal_cannot(const char *m)
  104. {
  105. fatal2_cannot(m, "");
  106. /* was exiting 111 */
  107. }
  108. static void fatal2x_cannot(const char *m1, const char *m2)
  109. {
  110. bb_error_msg_and_die("%s: fatal: cannot %s%s", dir, m1, m2);
  111. /* was exiting 111 */
  112. }
  113. static void warn_cannot(const char *m)
  114. {
  115. bb_perror_msg("%s: warning: cannot %s", dir, m);
  116. }
  117. static void s_child(int sig_no ATTRIBUTE_UNUSED)
  118. {
  119. write(selfpipe.wr, "", 1);
  120. }
  121. static void s_term(int sig_no ATTRIBUTE_UNUSED)
  122. {
  123. sigterm = 1;
  124. write(selfpipe.wr, "", 1); /* XXX */
  125. }
  126. static char *add_str(char *p, const char *to_add)
  127. {
  128. while ((*p = *to_add) != '\0') {
  129. p++;
  130. to_add++;
  131. }
  132. return p;
  133. }
  134. static int open_trunc_or_warn(const char *name)
  135. {
  136. int fd = open_trunc(name);
  137. if (fd < 0)
  138. bb_perror_msg("%s: warning: cannot open %s",
  139. dir, name);
  140. return fd;
  141. }
  142. static void update_status(struct svdir *s)
  143. {
  144. ssize_t sz;
  145. int fd;
  146. svstatus_t status;
  147. /* pid */
  148. if (pidchanged) {
  149. fd = open_trunc_or_warn("supervise/pid.new");
  150. if (fd < 0)
  151. return;
  152. if (s->pid) {
  153. char spid[sizeof(int)*3 + 2];
  154. int size = sprintf(spid, "%u\n", (unsigned)s->pid);
  155. write(fd, spid, size);
  156. }
  157. close(fd);
  158. if (rename_or_warn("supervise/pid.new",
  159. s->islog ? "log/supervise/pid" : "log/supervise/pid"+4))
  160. return;
  161. pidchanged = 0;
  162. }
  163. /* stat */
  164. fd = open_trunc_or_warn("supervise/stat.new");
  165. if (fd < -1)
  166. return;
  167. {
  168. char stat_buf[sizeof("finish, paused, got TERM, want down\n")];
  169. char *p = stat_buf;
  170. switch (s->state) {
  171. case S_DOWN:
  172. p = add_str(p, "down");
  173. break;
  174. case S_RUN:
  175. p = add_str(p, "run");
  176. break;
  177. case S_FINISH:
  178. p = add_str(p, "finish");
  179. break;
  180. }
  181. if (s->ctrl & C_PAUSE) p = add_str(p, ", paused");
  182. if (s->ctrl & C_TERM) p = add_str(p, ", got TERM");
  183. if (s->state != S_DOWN)
  184. switch (s->want) {
  185. case W_DOWN:
  186. p = add_str(p, ", want down");
  187. break;
  188. case W_EXIT:
  189. p = add_str(p, ", want exit");
  190. break;
  191. }
  192. *p++ = '\n';
  193. write(fd, stat_buf, p - stat_buf);
  194. close(fd);
  195. }
  196. rename_or_warn("supervise/stat.new",
  197. s->islog ? "log/supervise/stat" : "log/supervise/stat"+4);
  198. /* supervise compatibility */
  199. memset(&status, 0, sizeof(status));
  200. status.time_be64 = SWAP_BE64(s->start.tv_sec + 0x400000000000000aULL);
  201. status.time_nsec_be32 = SWAP_BE32(s->start.tv_nsec);
  202. status.pid_le32 = SWAP_LE32(s->pid);
  203. if (s->ctrl & C_PAUSE)
  204. status.paused = 1;
  205. if (s->want == W_UP)
  206. status.want = 'u';
  207. else
  208. status.want = 'd';
  209. if (s->ctrl & C_TERM)
  210. status.got_term = 1;
  211. status.run_or_finish = s->state;
  212. fd = open_trunc_or_warn("supervise/status.new");
  213. if (fd < 0)
  214. return;
  215. sz = write(fd, &status, sizeof(status));
  216. close(fd);
  217. if (sz != sizeof(status)) {
  218. warn_cannot("write supervise/status.new");
  219. unlink("supervise/status.new");
  220. return;
  221. }
  222. rename_or_warn("supervise/status.new",
  223. s->islog ? "log/supervise/status" : "log/supervise/status"+4);
  224. }
  225. static unsigned custom(struct svdir *s, char c)
  226. {
  227. int pid;
  228. int w;
  229. char a[10];
  230. struct stat st;
  231. char *prog[2];
  232. if (s->islog) return 0;
  233. strcpy(a, "control/?");
  234. a[8] = c; /* replace '?' */
  235. if (stat(a, &st) == 0) {
  236. if (st.st_mode & S_IXUSR) {
  237. pid = vfork();
  238. if (pid == -1) {
  239. warn_cannot("vfork for control/?");
  240. return 0;
  241. }
  242. if (!pid) {
  243. /* child */
  244. if (haslog && dup2(logpipe.wr, 1) == -1)
  245. warn_cannot("setup stdout for control/?");
  246. prog[0] = a;
  247. prog[1] = NULL;
  248. execv(a, prog);
  249. fatal_cannot("run control/?");
  250. }
  251. /* parent */
  252. while (safe_waitpid(pid, &w, 0) == -1) {
  253. warn_cannot("wait for child control/?");
  254. return 0;
  255. }
  256. return !wait_exitcode(w);
  257. }
  258. } else {
  259. if (errno != ENOENT)
  260. warn_cannot("stat control/?");
  261. }
  262. return 0;
  263. }
  264. static void stopservice(struct svdir *s)
  265. {
  266. if (s->pid && !custom(s, 't')) {
  267. kill(s->pid, SIGTERM);
  268. s->ctrl |= C_TERM;
  269. update_status(s);
  270. }
  271. if (s->want == W_DOWN) {
  272. kill(s->pid, SIGCONT);
  273. custom(s, 'd');
  274. return;
  275. }
  276. if (s->want == W_EXIT) {
  277. kill(s->pid, SIGCONT);
  278. custom(s, 'x');
  279. }
  280. }
  281. static void startservice(struct svdir *s)
  282. {
  283. int p;
  284. char *run[2];
  285. if (s->state == S_FINISH)
  286. run[0] = (char*)"./finish";
  287. else {
  288. run[0] = (char*)"./run";
  289. custom(s, 'u');
  290. }
  291. run[1] = NULL;
  292. if (s->pid != 0)
  293. stopservice(s); /* should never happen */
  294. while ((p = vfork()) == -1) {
  295. warn_cannot("vfork, sleeping");
  296. sleep(5);
  297. }
  298. if (p == 0) {
  299. /* child */
  300. if (haslog) {
  301. /* NB: bug alert! right order is close, then dup2 */
  302. if (s->islog) {
  303. xchdir("./log");
  304. close(logpipe.wr);
  305. xdup2(logpipe.rd, 0);
  306. } else {
  307. close(logpipe.rd);
  308. xdup2(logpipe.wr, 1);
  309. }
  310. }
  311. bb_signals(0
  312. + (1 << SIGCHLD)
  313. + (1 << SIGTERM)
  314. , SIG_DFL);
  315. sig_unblock(SIGCHLD);
  316. sig_unblock(SIGTERM);
  317. execvp(*run, run);
  318. fatal2_cannot(s->islog ? "start log/" : "start ", *run);
  319. }
  320. /* parent */
  321. if (s->state != S_FINISH) {
  322. gettimeofday_ns(&s->start);
  323. s->state = S_RUN;
  324. }
  325. s->pid = p;
  326. pidchanged = 1;
  327. s->ctrl = C_NOOP;
  328. update_status(s);
  329. }
  330. static int ctrl(struct svdir *s, char c)
  331. {
  332. int sig;
  333. switch (c) {
  334. case 'd': /* down */
  335. s->want = W_DOWN;
  336. update_status(s);
  337. if (s->pid && s->state != S_FINISH)
  338. stopservice(s);
  339. break;
  340. case 'u': /* up */
  341. s->want = W_UP;
  342. update_status(s);
  343. if (s->pid == 0)
  344. startservice(s);
  345. break;
  346. case 'x': /* exit */
  347. if (s->islog)
  348. break;
  349. s->want = W_EXIT;
  350. update_status(s);
  351. /* FALLTHROUGH */
  352. case 't': /* sig term */
  353. if (s->pid && s->state != S_FINISH)
  354. stopservice(s);
  355. break;
  356. case 'k': /* sig kill */
  357. if (s->pid && !custom(s, c))
  358. kill(s->pid, SIGKILL);
  359. s->state = S_DOWN;
  360. break;
  361. case 'p': /* sig pause */
  362. if (s->pid && !custom(s, c))
  363. kill(s->pid, SIGSTOP);
  364. s->ctrl |= C_PAUSE;
  365. update_status(s);
  366. break;
  367. case 'c': /* sig cont */
  368. if (s->pid && !custom(s, c))
  369. kill(s->pid, SIGCONT);
  370. if (s->ctrl & C_PAUSE)
  371. s->ctrl &= ~C_PAUSE;
  372. update_status(s);
  373. break;
  374. case 'o': /* once */
  375. s->want = W_DOWN;
  376. update_status(s);
  377. if (!s->pid)
  378. startservice(s);
  379. break;
  380. case 'a': /* sig alarm */
  381. sig = SIGALRM;
  382. goto sendsig;
  383. case 'h': /* sig hup */
  384. sig = SIGHUP;
  385. goto sendsig;
  386. case 'i': /* sig int */
  387. sig = SIGINT;
  388. goto sendsig;
  389. case 'q': /* sig quit */
  390. sig = SIGQUIT;
  391. goto sendsig;
  392. case '1': /* sig usr1 */
  393. sig = SIGUSR1;
  394. goto sendsig;
  395. case '2': /* sig usr2 */
  396. sig = SIGUSR2;
  397. goto sendsig;
  398. }
  399. return 1;
  400. sendsig:
  401. if (s->pid && !custom(s, c))
  402. kill(s->pid, sig);
  403. return 1;
  404. }
  405. int runsv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  406. int runsv_main(int argc ATTRIBUTE_UNUSED, char **argv)
  407. {
  408. struct stat s;
  409. int fd;
  410. int r;
  411. char buf[256];
  412. INIT_G();
  413. if (!argv[1] || argv[2])
  414. bb_show_usage();
  415. dir = argv[1];
  416. xpiped_pair(selfpipe);
  417. close_on_exec_on(selfpipe.rd);
  418. close_on_exec_on(selfpipe.wr);
  419. ndelay_on(selfpipe.rd);
  420. ndelay_on(selfpipe.wr);
  421. sig_block(SIGCHLD);
  422. bb_signals_recursive(1 << SIGCHLD, s_child);
  423. sig_block(SIGTERM);
  424. bb_signals_recursive(1 << SIGTERM, s_term);
  425. xchdir(dir);
  426. /* bss: svd[0].pid = 0; */
  427. if (S_DOWN) svd[0].state = S_DOWN; /* otherwise already 0 (bss) */
  428. if (C_NOOP) svd[0].ctrl = C_NOOP;
  429. if (W_UP) svd[0].want = W_UP;
  430. /* bss: svd[0].islog = 0; */
  431. /* bss: svd[1].pid = 0; */
  432. gettimeofday_ns(&svd[0].start);
  433. if (stat("down", &s) != -1) svd[0].want = W_DOWN;
  434. if (stat("log", &s) == -1) {
  435. if (errno != ENOENT)
  436. warn_cannot("stat ./log");
  437. } else {
  438. if (!S_ISDIR(s.st_mode)) {
  439. errno = 0;
  440. warn_cannot("stat log/down: log is not a directory");
  441. } else {
  442. haslog = 1;
  443. svd[1].state = S_DOWN;
  444. svd[1].ctrl = C_NOOP;
  445. svd[1].want = W_UP;
  446. svd[1].islog = 1;
  447. gettimeofday_ns(&svd[1].start);
  448. if (stat("log/down", &s) != -1)
  449. svd[1].want = W_DOWN;
  450. xpiped_pair(logpipe);
  451. close_on_exec_on(logpipe.rd);
  452. close_on_exec_on(logpipe.wr);
  453. }
  454. }
  455. if (mkdir("supervise", 0700) == -1) {
  456. r = readlink("supervise", buf, sizeof(buf));
  457. if (r != -1) {
  458. if (r == sizeof(buf))
  459. fatal2x_cannot("readlink ./supervise", ": name too long");
  460. buf[r] = 0;
  461. mkdir(buf, 0700);
  462. } else {
  463. if ((errno != ENOENT) && (errno != EINVAL))
  464. fatal_cannot("readlink ./supervise");
  465. }
  466. }
  467. svd[0].fdlock = xopen3("log/supervise/lock"+4,
  468. O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600);
  469. if (lock_exnb(svd[0].fdlock) == -1)
  470. fatal_cannot("lock supervise/lock");
  471. close_on_exec_on(svd[0].fdlock);
  472. if (haslog) {
  473. if (mkdir("log/supervise", 0700) == -1) {
  474. r = readlink("log/supervise", buf, 256);
  475. if (r != -1) {
  476. if (r == 256)
  477. fatal2x_cannot("readlink ./log/supervise", ": name too long");
  478. buf[r] = 0;
  479. fd = xopen(".", O_RDONLY|O_NDELAY);
  480. xchdir("./log");
  481. mkdir(buf, 0700);
  482. if (fchdir(fd) == -1)
  483. fatal_cannot("change back to service directory");
  484. close(fd);
  485. }
  486. else {
  487. if ((errno != ENOENT) && (errno != EINVAL))
  488. fatal_cannot("readlink ./log/supervise");
  489. }
  490. }
  491. svd[1].fdlock = xopen3("log/supervise/lock",
  492. O_WRONLY|O_NDELAY|O_APPEND|O_CREAT, 0600);
  493. if (lock_ex(svd[1].fdlock) == -1)
  494. fatal_cannot("lock log/supervise/lock");
  495. close_on_exec_on(svd[1].fdlock);
  496. }
  497. mkfifo("log/supervise/control"+4, 0600);
  498. svd[0].fdcontrol = xopen("log/supervise/control"+4, O_RDONLY|O_NDELAY);
  499. close_on_exec_on(svd[0].fdcontrol);
  500. svd[0].fdcontrolwrite = xopen("log/supervise/control"+4, O_WRONLY|O_NDELAY);
  501. close_on_exec_on(svd[0].fdcontrolwrite);
  502. update_status(&svd[0]);
  503. if (haslog) {
  504. mkfifo("log/supervise/control", 0600);
  505. svd[1].fdcontrol = xopen("log/supervise/control", O_RDONLY|O_NDELAY);
  506. close_on_exec_on(svd[1].fdcontrol);
  507. svd[1].fdcontrolwrite = xopen("log/supervise/control", O_WRONLY|O_NDELAY);
  508. close_on_exec_on(svd[1].fdcontrolwrite);
  509. update_status(&svd[1]);
  510. }
  511. mkfifo("log/supervise/ok"+4, 0600);
  512. fd = xopen("log/supervise/ok"+4, O_RDONLY|O_NDELAY);
  513. close_on_exec_on(fd);
  514. if (haslog) {
  515. mkfifo("log/supervise/ok", 0600);
  516. fd = xopen("log/supervise/ok", O_RDONLY|O_NDELAY);
  517. close_on_exec_on(fd);
  518. }
  519. for (;;) {
  520. struct pollfd x[3];
  521. unsigned deadline;
  522. char ch;
  523. if (haslog)
  524. if (!svd[1].pid && svd[1].want == W_UP)
  525. startservice(&svd[1]);
  526. if (!svd[0].pid)
  527. if (svd[0].want == W_UP || svd[0].state == S_FINISH)
  528. startservice(&svd[0]);
  529. x[0].fd = selfpipe.rd;
  530. x[0].events = POLLIN;
  531. x[1].fd = svd[0].fdcontrol;
  532. x[1].events = POLLIN;
  533. /* x[2] is used only if haslog == 1 */
  534. x[2].fd = svd[1].fdcontrol;
  535. x[2].events = POLLIN;
  536. sig_unblock(SIGTERM);
  537. sig_unblock(SIGCHLD);
  538. poll(x, 2 + haslog, 3600*1000);
  539. sig_block(SIGTERM);
  540. sig_block(SIGCHLD);
  541. while (read(selfpipe.rd, &ch, 1) == 1)
  542. continue;
  543. for (;;) {
  544. int child;
  545. int wstat;
  546. child = wait_any_nohang(&wstat);
  547. if (!child)
  548. break;
  549. if ((child == -1) && (errno != EINTR))
  550. break;
  551. if (child == svd[0].pid) {
  552. svd[0].pid = 0;
  553. pidchanged = 1;
  554. svd[0].ctrl &=~ C_TERM;
  555. if (svd[0].state != S_FINISH) {
  556. fd = open_read("finish");
  557. if (fd != -1) {
  558. close(fd);
  559. svd[0].state = S_FINISH;
  560. update_status(&svd[0]);
  561. continue;
  562. }
  563. }
  564. svd[0].state = S_DOWN;
  565. deadline = svd[0].start.tv_sec + 1;
  566. gettimeofday_ns(&svd[0].start);
  567. update_status(&svd[0]);
  568. if (LESS(svd[0].start.tv_sec, deadline))
  569. sleep(1);
  570. }
  571. if (haslog) {
  572. if (child == svd[1].pid) {
  573. svd[1].pid = 0;
  574. pidchanged = 1;
  575. svd[1].state = S_DOWN;
  576. svd[1].ctrl &= ~C_TERM;
  577. deadline = svd[1].start.tv_sec + 1;
  578. gettimeofday_ns(&svd[1].start);
  579. update_status(&svd[1]);
  580. if (LESS(svd[1].start.tv_sec, deadline))
  581. sleep(1);
  582. }
  583. }
  584. } /* for (;;) */
  585. if (read(svd[0].fdcontrol, &ch, 1) == 1)
  586. ctrl(&svd[0], ch);
  587. if (haslog)
  588. if (read(svd[1].fdcontrol, &ch, 1) == 1)
  589. ctrl(&svd[1], ch);
  590. if (sigterm) {
  591. ctrl(&svd[0], 'x');
  592. sigterm = 0;
  593. }
  594. if (svd[0].want == W_EXIT && svd[0].state == S_DOWN) {
  595. if (svd[1].pid == 0)
  596. _exit(EXIT_SUCCESS);
  597. if (svd[1].want != W_EXIT) {
  598. svd[1].want = W_EXIT;
  599. /* stopservice(&svd[1]); */
  600. update_status(&svd[1]);
  601. close(logpipe.wr);
  602. close(logpipe.rd);
  603. }
  604. }
  605. } /* for (;;) */
  606. /* not reached */
  607. return 0;
  608. }