/[baselayout]/trunk/src/rc.c
Gentoo

Contents of /trunk/src/rc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2889 - (show annotations) (download) (as text)
Tue Sep 18 15:43:19 2007 UTC (6 years, 9 months ago) by uberlord
File MIME type: text/x-csrc
File size: 36015 byte(s)
Don't be an ass - don't free the 2nd list. Instead just empty it.
1 /*
2 rc.c
3 rc - manager for init scripts which control the startup, shutdown
4 and the running of daemons on a Gentoo system.
5
6 Also a multicall binary for various commands that can be used in shell
7 scripts to query service state, mark service state and provide the
8 Gentoo einfo family of informational functions.
9
10 Copyright 2007 Gentoo Foundation
11 Released under the GPLv2
12 */
13
14 #define APPLET "rc"
15
16 #define SYSLOG_NAMES
17
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 #include <sys/utsname.h>
21 #include <sys/wait.h>
22 #include <errno.h>
23 #include <ctype.h>
24 #include <getopt.h>
25 #include <libgen.h>
26 #include <limits.h>
27 #include <stdbool.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <signal.h>
31 #include <string.h>
32 #include <syslog.h>
33 #include <termios.h>
34 #include <unistd.h>
35
36 #include "builtins.h"
37 #include "einfo.h"
38 #include "rc.h"
39 #include "rc-misc.h"
40 #include "rc-plugin.h"
41 #include "strlist.h"
42
43 #define INITSH RC_LIBDIR "/sh/init.sh"
44 #define INITEARLYSH RC_LIBDIR "/sh/init-early.sh"
45 #define HALTSH RC_INITDIR "/halt.sh"
46
47 #define SHUTDOWN "/sbin/shutdown"
48 #define SULOGIN "/sbin/sulogin"
49
50 #define INTERACTIVE RC_SVCDIR "/interactive"
51
52 #define DEVBOOT "/dev/.rcboot"
53
54 /* Cleanup anything in main */
55 #define CHAR_FREE(_item) if (_item) { \
56 free (_item); \
57 _item = NULL; \
58 }
59
60 extern char **environ;
61
62 static char *RUNLEVEL = NULL;
63 static char *PREVLEVEL = NULL;
64
65 static char *applet = NULL;
66 static char **env = NULL;
67 static char **newenv = NULL;
68 static char **coldplugged_services = NULL;
69 static char **stop_services = NULL;
70 static char **start_services = NULL;
71 static rc_depinfo_t *deptree = NULL;
72 static char **types = NULL;
73 static char *tmp = NULL;
74
75 struct termios *termios_orig = NULL;
76
77 typedef struct pidlist
78 {
79 pid_t pid;
80 struct pidlist *next;
81 } pidlist_t;
82 static pidlist_t *service_pids = NULL;
83
84 static void cleanup (void)
85 {
86 if (applet && strcmp (applet, "rc") == 0) {
87 pidlist_t *pl = service_pids;
88
89 rc_plugin_unload ();
90
91 if (! rc_in_plugin && termios_orig) {
92 tcsetattr (fileno (stdin), TCSANOW, termios_orig);
93 free (termios_orig);
94 }
95
96 while (pl) {
97 pidlist_t *p = pl->next;
98 free (pl);
99 pl = p;
100 }
101
102 rc_strlist_free (env);
103 rc_strlist_free (newenv);
104 rc_strlist_free (coldplugged_services);
105 rc_strlist_free (stop_services);
106 rc_strlist_free (start_services);
107 rc_free_deptree (deptree);
108 rc_strlist_free (types);
109
110 /* Clean runlevel start, stop markers */
111 if (! rc_in_plugin) {
112 if (rc_is_dir (RC_STARTING))
113 rc_rm_dir (RC_STARTING, true);
114 if (rc_is_dir (RC_STOPPING))
115 rc_rm_dir (RC_STOPPING, true);
116 }
117 }
118
119 free (applet);
120 }
121
122 static int syslog_decode (char *name, CODE *codetab)
123 {
124 CODE *c;
125
126 if (isdigit (*name))
127 return (atoi (name));
128
129 for (c = codetab; c->c_name; c++)
130 if (! strcasecmp (name, c->c_name))
131 return (c->c_val);
132
133 return (-1);
134 }
135
136 static int do_e (int argc, char **argv)
137 {
138 int retval = EXIT_SUCCESS;
139 int i;
140 int l = 0;
141 char *message = NULL;
142 char *p;
143 char *fmt = NULL;
144 int level = 0;
145
146 if (strcmp (applet, "eval_ecolors") == 0) {
147 printf ("GOOD='%s'\nWARN='%s'\nBAD='%s'\nHILITE='%s'\nBRACKET='%s'\nNORMAL='%s'\n",
148 ecolor (ecolor_good),
149 ecolor (ecolor_warn),
150 ecolor (ecolor_bad),
151 ecolor (ecolor_hilite),
152 ecolor (ecolor_bracket),
153 ecolor (ecolor_normal));
154 exit (EXIT_SUCCESS);
155 }
156
157 if (argc > 0) {
158
159 if (strcmp (applet, "eend") == 0 ||
160 strcmp (applet, "ewend") == 0 ||
161 strcmp (applet, "veend") == 0 ||
162 strcmp (applet, "vweend") == 0)
163 {
164 errno = 0;
165 retval = strtol (argv[0], NULL, 0);
166 if (errno != 0)
167 retval = EXIT_FAILURE;
168 else {
169 argc--;
170 argv++;
171 }
172 } else if (strcmp (applet, "esyslog") == 0 ||
173 strcmp (applet, "elog") == 0) {
174 char *dot = strchr (argv[0], '.');
175 if ((level = syslog_decode (dot + 1, prioritynames)) == -1)
176 eerrorx ("%s: invalid log level `%s'", applet, argv[0]);
177
178 if (argc < 3)
179 eerrorx ("%s: not enough arguments", applet);
180
181 unsetenv ("RC_ELOG");
182 setenv ("RC_ELOG", argv[1], 1);
183
184 argc -= 2;
185 argv += 2;
186 }
187 }
188
189 if (argc > 0) {
190 for (i = 0; i < argc; i++)
191 l += strlen (argv[i]) + 1;
192
193 message = rc_xmalloc (l);
194 p = message;
195
196 for (i = 0; i < argc; i++) {
197 if (i > 0)
198 *p++ = ' ';
199 memcpy (p, argv[i], strlen (argv[i]));
200 p += strlen (argv[i]);
201 }
202 *p = 0;
203 }
204
205 if (message)
206 fmt = rc_xstrdup ("%s");
207
208 if (strcmp (applet, "einfo") == 0)
209 einfo (fmt, message);
210 else if (strcmp (applet, "einfon") == 0)
211 einfon (fmt, message);
212 else if (strcmp (applet, "ewarn") == 0)
213 ewarn (fmt, message);
214 else if (strcmp (applet, "ewarnn") == 0)
215 ewarnn (fmt, message);
216 else if (strcmp (applet, "eerror") == 0) {
217 eerror (fmt, message);
218 retval = 1;
219 } else if (strcmp (applet, "eerrorn") == 0) {
220 eerrorn (fmt, message);
221 retval = 1;
222 } else if (strcmp (applet, "ebegin") == 0)
223 ebegin (fmt, message);
224 else if (strcmp (applet, "eend") == 0)
225 eend (retval, fmt, message);
226 else if (strcmp (applet, "ewend") == 0)
227 ewend (retval, fmt, message);
228 else if (strcmp (applet, "esyslog") == 0)
229 elog (level, fmt, message);
230 else if (strcmp (applet, "veinfo") == 0)
231 einfov (fmt, message);
232 else if (strcmp (applet, "veinfon") == 0)
233 einfovn (fmt, message);
234 else if (strcmp (applet, "vewarn") == 0)
235 ewarnv (fmt, message);
236 else if (strcmp (applet, "vewarnn") == 0)
237 ewarnvn (fmt, message);
238 else if (strcmp (applet, "vebegin") == 0)
239 ebeginv (fmt, message);
240 else if (strcmp (applet, "veend") == 0)
241 eendv (retval, fmt, message);
242 else if (strcmp (applet, "vewend") == 0)
243 ewendv (retval, fmt, message);
244 else if (strcmp (applet, "eindent") == 0)
245 eindent ();
246 else if (strcmp (applet, "eoutdent") == 0)
247 eoutdent ();
248 else if (strcmp (applet, "veindent") == 0)
249 eindentv ();
250 else if (strcmp (applet, "veoutdent") == 0)
251 eoutdentv ();
252 else {
253 eerror ("%s: unknown applet", applet);
254 retval = EXIT_FAILURE;
255 }
256
257 if (fmt)
258 free (fmt);
259 if (message)
260 free (message);
261 return (retval);
262 }
263
264 static int do_service (int argc, char **argv)
265 {
266 bool ok = false;
267
268 if (argc < 1 || ! argv[0] || strlen (argv[0]) == 0)
269 eerrorx ("%s: no service specified", applet);
270
271 if (strcmp (applet, "service_started") == 0)
272 ok = rc_service_state (argv[0], rc_service_started);
273 else if (strcmp (applet, "service_stopped") == 0)
274 ok = rc_service_state (argv[0], rc_service_stopped);
275 else if (strcmp (applet, "service_inactive") == 0)
276 ok = rc_service_state (argv[0], rc_service_inactive);
277 else if (strcmp (applet, "service_starting") == 0)
278 ok = rc_service_state (argv[0], rc_service_starting);
279 else if (strcmp (applet, "service_stopping") == 0)
280 ok = rc_service_state (argv[0], rc_service_stopping);
281 else if (strcmp (applet, "service_coldplugged") == 0)
282 ok = rc_service_state (argv[0], rc_service_coldplugged);
283 else if (strcmp (applet, "service_wasinactive") == 0)
284 ok = rc_service_state (argv[0], rc_service_wasinactive);
285 else if (strcmp (applet, "service_started_daemon") == 0) {
286 int idx = 0;
287 if (argc > 2)
288 sscanf (argv[2], "%d", &idx);
289 exit (rc_service_started_daemon (argv[0], argv[1], idx)
290 ? 0 : 1);
291 } else
292 eerrorx ("%s: unknown applet", applet);
293
294 return (ok ? EXIT_SUCCESS : EXIT_FAILURE);
295 }
296
297 static int do_mark_service (int argc, char **argv)
298 {
299 bool ok = false;
300 char *svcname = getenv ("SVCNAME");
301
302 if (argc < 1 || ! argv[0] || strlen (argv[0]) == 0)
303 eerrorx ("%s: no service specified", applet);
304
305 if (strcmp (applet, "mark_service_started") == 0)
306 ok = rc_mark_service (argv[0], rc_service_started);
307 else if (strcmp (applet, "mark_service_stopped") == 0)
308 ok = rc_mark_service (argv[0], rc_service_stopped);
309 else if (strcmp (applet, "mark_service_inactive") == 0)
310 ok = rc_mark_service (argv[0], rc_service_inactive);
311 else if (strcmp (applet, "mark_service_starting") == 0)
312 ok = rc_mark_service (argv[0], rc_service_starting);
313 else if (strcmp (applet, "mark_service_stopping") == 0)
314 ok = rc_mark_service (argv[0], rc_service_stopping);
315 else if (strcmp (applet, "mark_service_coldplugged") == 0)
316 ok = rc_mark_service (argv[0], rc_service_coldplugged);
317 else
318 eerrorx ("%s: unknown applet", applet);
319
320 /* If we're marking ourselves then we need to inform our parent runscript
321 process so they do not mark us based on our exit code */
322 if (ok && svcname && strcmp (svcname, argv[0]) == 0) {
323 char *runscript_pid = getenv ("RC_RUNSCRIPT_PID");
324 char *mtime;
325 pid_t pid = 0;
326 int l;
327
328 if (runscript_pid && sscanf (runscript_pid, "%d", &pid) == 1)
329 if (kill (pid, SIGHUP) != 0)
330 eerror ("%s: failed to signal parent %d: %s",
331 applet, pid, strerror (errno));
332
333 /* Remove the exclsive time test. This ensures that it's not
334 in control as well */
335 l = strlen (RC_SVCDIR "exclusive") +
336 strlen (svcname) +
337 strlen (runscript_pid) +
338 4;
339 mtime = rc_xmalloc (l);
340 snprintf (mtime, l, RC_SVCDIR "exclusive/%s.%s",
341 svcname, runscript_pid);
342 if (rc_exists (mtime) && unlink (mtime) != 0)
343 eerror ("%s: unlink: %s", applet, strerror (errno));
344 free (mtime);
345 }
346
347 return (ok ? EXIT_SUCCESS : EXIT_FAILURE);
348 }
349
350 static int do_options (int argc, char **argv)
351 {
352 bool ok = false;
353 char *service = getenv ("SVCNAME");
354
355 if (! service)
356 eerrorx ("%s: no service specified", applet);
357
358 if (argc < 1 || ! argv[0] || strlen (argv[0]) == 0)
359 eerrorx ("%s: no option specified", applet);
360
361 if (strcmp (applet, "get_options") == 0) {
362 char buffer[1024];
363 memset (buffer, 0, 1024);
364 ok = rc_get_service_option (service, argv[0], buffer);
365 if (ok)
366 printf ("%s", buffer);
367 } else if (strcmp (applet, "save_options") == 0)
368 ok = rc_set_service_option (service, argv[0], argv[1]);
369 else
370 eerrorx ("%s: unknown applet", applet);
371
372 return (ok ? EXIT_SUCCESS : EXIT_FAILURE);
373 }
374
375 #ifdef __linux__
376 static char *proc_getent (const char *ent)
377 {
378 FILE *fp;
379 char buffer[RC_LINEBUFFER];
380 char *p;
381 char *value = NULL;
382 int i;
383
384 if (! rc_exists ("/proc/cmdline"))
385 return (NULL);
386
387 if (! (fp = fopen ("/proc/cmdline", "r"))) {
388 eerror ("failed to open `/proc/cmdline': %s", strerror (errno));
389 return (NULL);
390 }
391
392 memset (buffer, 0, sizeof (buffer));
393 if (fgets (buffer, RC_LINEBUFFER, fp) &&
394 (p = strstr (buffer, ent)))
395 {
396 i = p - buffer;
397 if (i == '\0' || buffer[i - 1] == ' ') {
398 /* Trim the trailing carriage return if present */
399 i = strlen (buffer) - 1;
400 if (buffer[i] == '\n')
401 buffer[i] = 0;
402
403 p += strlen (ent);
404 if (*p == '=')
405 p++;
406 value = strdup (strsep (&p, " "));
407 }
408 } else
409 errno = ENOENT;
410 fclose (fp);
411
412 return (value);
413 }
414 #endif
415
416 static char read_key (bool block)
417 {
418 struct termios termios;
419 char c = 0;
420 int fd = fileno (stdin);
421
422 if (! isatty (fd))
423 return (false);
424
425 /* Now save our terminal settings. We need to restore them at exit as we
426 will be changing it for non-blocking reads for Interactive */
427 if (! termios_orig) {
428 termios_orig = rc_xmalloc (sizeof (struct termios));
429 tcgetattr (fd, termios_orig);
430 }
431
432 tcgetattr (fd, &termios);
433 termios.c_lflag &= ~(ICANON | ECHO);
434 if (block)
435 termios.c_cc[VMIN] = 1;
436 else {
437 termios.c_cc[VMIN] = 0;
438 termios.c_cc[VTIME] = 0;
439 }
440 tcsetattr (fd, TCSANOW, &termios);
441
442 read (fd, &c, 1);
443
444 tcsetattr (fd, TCSANOW, termios_orig);
445
446 return (c);
447 }
448
449 static bool want_interactive (void)
450 {
451 char c;
452
453 if (PREVLEVEL &&
454 strcmp (PREVLEVEL, "N") != 0 &&
455 strcmp (PREVLEVEL, "S") != 0 &&
456 strcmp (PREVLEVEL, "1") != 0)
457 return (false);
458
459 if (! rc_is_env ("RC_INTERACTIVE", "yes"))
460 return (false);
461
462 c = read_key (false);
463 return ((c == 'I' || c == 'i') ? true : false);
464 }
465
466 static void mark_interactive (void)
467 {
468 FILE *fp = fopen (INTERACTIVE, "w");
469 if (fp)
470 fclose (fp);
471 }
472
473 static void sulogin (bool cont)
474 {
475 #ifdef __linux__
476 char *e = getenv ("RC_SYS");
477
478 /* VPS systems cannot do an sulogin */
479 if (e && strcmp (e, "VPS") == 0) {
480 execl ("/sbin/halt", "/sbin/halt", "-f", (char *) NULL);
481 eerrorx ("%s: unable to exec `/sbin/halt': %s", applet, strerror (errno));
482 }
483 #endif
484
485 newenv = rc_filter_env ();
486
487 if (cont) {
488 int status = 0;
489 #ifdef __linux__
490 char *tty = ttyname (fileno (stdout));
491 #endif
492
493 pid_t pid = vfork ();
494
495 if (pid == -1)
496 eerrorx ("%s: vfork: %s", applet, strerror (errno));
497 if (pid == 0) {
498 #ifdef __linux__
499 if (tty)
500 execle (SULOGIN, SULOGIN, tty, (char *) NULL, newenv);
501 else
502 execle (SULOGIN, SULOGIN, (char *) NULL, newenv);
503
504 eerror ("%s: unable to exec `%s': %s", applet, SULOGIN,
505 strerror (errno));
506 #else
507 execle ("/bin/sh", "/bin/sh", (char *) NULL, newenv);
508 eerror ("%s: unable to exec `/bin/sh': %s", applet,
509 strerror (errno));
510 #endif
511 _exit (EXIT_FAILURE);
512 }
513 waitpid (pid, &status, 0);
514 } else {
515 #ifdef __linux__
516 execle ("/sbin/sulogin", "/sbin/sulogin", (char *) NULL, newenv);
517 eerrorx ("%s: unable to exec `/sbin/sulogin': %s", applet, strerror (errno));
518 #else
519 exit (EXIT_SUCCESS);
520 #endif
521 }
522 }
523
524 static void single_user (void)
525 {
526 #ifdef __linux__
527 execl ("/sbin/telinit", "/sbin/telinit", "S", (char *) NULL);
528 eerrorx ("%s: unable to exec `/sbin/telinit': %s",
529 applet, strerror (errno));
530 #else
531 if (kill (1, SIGTERM) != 0)
532 eerrorx ("%s: unable to send SIGTERM to init (pid 1): %s",
533 applet, strerror (errno));
534 exit (EXIT_SUCCESS);
535 #endif
536 }
537
538 static void set_ksoftlevel (const char *runlevel)
539 {
540 FILE *fp;
541
542 if (! runlevel ||
543 strcmp (runlevel, getenv ("RC_BOOTLEVEL")) == 0 ||
544 strcmp (runlevel, RC_LEVEL_SINGLE) == 0 ||
545 strcmp (runlevel, RC_LEVEL_SYSINIT) == 0)
546 {
547 if (rc_exists (RC_KSOFTLEVEL) &&
548 unlink (RC_KSOFTLEVEL) != 0)
549 eerror ("unlink `%s': %s", RC_KSOFTLEVEL, strerror (errno));
550 return;
551 }
552
553 if (! (fp = fopen (RC_KSOFTLEVEL, "w"))) {
554 eerror ("fopen `%s': %s", RC_KSOFTLEVEL, strerror (errno));
555 return;
556 }
557
558 fprintf (fp, "%s", runlevel);
559 fclose (fp);
560 }
561
562 static int get_ksoftlevel (char *buffer, int buffer_len)
563 {
564 FILE *fp;
565 int i = 0;
566
567 if (! rc_exists (RC_KSOFTLEVEL))
568 return (0);
569
570 if (! (fp = fopen (RC_KSOFTLEVEL, "r"))) {
571 eerror ("fopen `%s': %s", RC_KSOFTLEVEL, strerror (errno));
572 return (-1);
573 }
574
575 if (fgets (buffer, buffer_len, fp)) {
576 i = strlen (buffer) - 1;
577 if (buffer[i] == '\n')
578 buffer[i] = 0;
579 }
580
581 fclose (fp);
582 return (i);
583 }
584
585 static void wait_for_services ()
586 {
587 int status = 0;
588 while (wait (&status) != -1);
589 }
590
591 static void add_pid (pid_t pid)
592 {
593 pidlist_t *sp = service_pids;
594 if (sp) {
595 while (sp->next)
596 sp = sp->next;
597 sp->next = rc_xmalloc (sizeof (pidlist_t));
598 sp = sp->next;
599 } else
600 sp = service_pids = rc_xmalloc (sizeof (pidlist_t));
601 memset (sp, 0, sizeof (pidlist_t));
602 sp->pid = pid;
603 }
604
605 static void remove_pid (pid_t pid)
606 {
607 pidlist_t *last = NULL;
608 pidlist_t *pl;
609
610 for (pl = service_pids; pl; pl = pl->next) {
611 if (pl->pid == pid) {
612 if (last)
613 last->next = pl->next;
614 else
615 service_pids = pl->next;
616 free (pl);
617 break;
618 }
619 last = pl;
620 }
621 }
622
623 static void handle_signal (int sig)
624 {
625 int serrno = errno;
626 char signame[10] = { '\0' };
627 pidlist_t *pl;
628 pid_t pid;
629 int status = 0;
630
631 switch (sig) {
632 case SIGCHLD:
633 do {
634 pid = waitpid (-1, &status, WNOHANG);
635 if (pid < 0) {
636 if (errno != ECHILD)
637 eerror ("waitpid: %s", strerror (errno));
638 return;
639 }
640 } while (! WIFEXITED (status) && ! WIFSIGNALED (status));
641
642 /* Remove that pid from our list */
643 if (pid > 0)
644 remove_pid (pid);
645 break;
646
647 case SIGINT:
648 if (! signame[0])
649 snprintf (signame, sizeof (signame), "SIGINT");
650 case SIGTERM:
651 if (! signame[0])
652 snprintf (signame, sizeof (signame), "SIGTERM");
653 case SIGQUIT:
654 if (! signame[0])
655 snprintf (signame, sizeof (signame), "SIGQUIT");
656 eerrorx ("%s: caught %s, aborting", applet, signame);
657 case SIGUSR1:
658 eerror ("rc: Aborting!");
659 /* Kill any running services we have started */
660
661 signal (SIGCHLD, SIG_IGN);
662 for (pl = service_pids; pl; pl = pl->next)
663 kill (pl->pid, SIGTERM);
664
665 /* Notify plugins we are aborting */
666 rc_plugin_run (rc_hook_abort, NULL);
667
668 /* Only drop into single user mode if we're booting */
669 if ((PREVLEVEL &&
670 (strcmp (PREVLEVEL, "S") == 0 ||
671 strcmp (PREVLEVEL, "1") == 0)) ||
672 (RUNLEVEL &&
673 (strcmp (RUNLEVEL, "S") == 0 ||
674 strcmp (RUNLEVEL, "1") == 0)))
675 single_user ();
676
677 exit (EXIT_FAILURE);
678 break;
679
680 default:
681 eerror ("%s: caught unknown signal %d", applet, sig);
682 }
683
684 /* Restore errno */
685 errno = serrno;
686 }
687
688 static void run_script (const char *script) {
689 int status = 0;
690 pid_t pid = vfork ();
691
692 if (pid < 0)
693 eerrorx ("%s: vfork: %s", applet, strerror (errno));
694 else if (pid == 0) {
695 execl (script, script, (char *) NULL);
696 eerror ("%s: unable to exec `%s': %s",
697 script, applet, strerror (errno));
698 _exit (EXIT_FAILURE);
699 }
700
701 do {
702 pid_t wpid = waitpid (pid, &status, 0);
703 if (wpid < 1)
704 eerror ("waitpid: %s", strerror (errno));
705 } while (! WIFEXITED (status) && ! WIFSIGNALED (status));
706
707 if (! WIFEXITED (status) || ! WEXITSTATUS (status) == 0)
708 eerrorx ("%s: failed to exec `%s'", applet, script);
709 }
710
711 #include "_usage.h"
712 #define getoptstring getoptstring_COMMON
713 static struct option longopts[] = {
714 longopts_COMMON
715 { NULL, 0, NULL, 0}
716 };
717 #include "_usage.c"
718
719 int main (int argc, char **argv)
720 {
721 char *runlevel = NULL;
722 const char *bootlevel = NULL;
723 char *newlevel = NULL;
724 char *service = NULL;
725 char **deporder = NULL;
726 char **tmplist;
727 int i = 0;
728 int j = 0;
729 bool going_down = false;
730 bool interactive = false;
731 int depoptions = RC_DEP_STRICT | RC_DEP_TRACE;
732 char ksoftbuffer [PATH_MAX];
733 char pidstr[6];
734 int opt;
735
736 atexit (cleanup);
737 if (argv[0])
738 applet = rc_xstrdup (basename (argv[0]));
739
740 if (! applet)
741 eerrorx ("arguments required");
742
743 /* These used to be programs in their own right, so we shouldn't
744 * touch argc or argv for them */
745 if (strcmp (applet, "env-update") == 0)
746 exit (env_update (argc, argv));
747 else if (strcmp (applet, "fstabinfo") == 0)
748 exit (fstabinfo (argc, argv));
749 else if (strcmp (applet, "mountinfo") == 0)
750 exit (mountinfo (argc, argv));
751 else if (strcmp (applet, "rc-depend") == 0)
752 exit (rc_depend (argc, argv));
753 else if (strcmp (applet, "rc-status") == 0)
754 exit (rc_status (argc, argv));
755 else if (strcmp (applet, "rc-update") == 0 ||
756 strcmp (applet, "update-rc") == 0)
757 exit (rc_update (argc, argv));
758 else if (strcmp (applet, "runscript") == 0)
759 exit (runscript (argc, argv));
760 else if (strcmp (applet, "start-stop-daemon") == 0)
761 exit (start_stop_daemon (argc, argv));
762
763 argc--;
764 argv++;
765
766 /* Handle multicall stuff */
767 if (applet[0] == 'e' || (applet[0] == 'v' && applet[1] == 'e'))
768 exit (do_e (argc, argv));
769
770 if (strncmp (applet, "service_", strlen ("service_")) == 0)
771 exit (do_service (argc, argv));
772
773 if (strcmp (applet, "get_options") == 0 ||
774 strcmp (applet, "save_options") == 0)
775 exit (do_options (argc, argv));
776
777 if (strncmp (applet, "mark_service_", strlen ("mark_service_")) == 0)
778 exit (do_mark_service (argc, argv));
779
780 if (strcmp (applet, "is_runlevel_start") == 0)
781 exit (rc_runlevel_starting () ? 0 : 1);
782 else if (strcmp (applet, "is_runlevel_stop") == 0)
783 exit (rc_runlevel_stopping () ? 0 : 1);
784
785 if (strcmp (applet, "rc-abort") == 0) {
786 char *p = getenv ("RC_PID");
787 pid_t pid = 0;
788
789 if (p && sscanf (p, "%d", &pid) == 1) {
790 if (kill (pid, SIGUSR1) != 0)
791 eerrorx ("rc-abort: failed to signal parent %d: %s",
792 pid, strerror (errno));
793 exit (EXIT_SUCCESS);
794 }
795 exit (EXIT_FAILURE);
796 }
797
798 if (strcmp (applet, "rc" ) != 0)
799 eerrorx ("%s: unknown applet", applet);
800
801 /* Change dir to / to ensure all scripts don't use stuff in pwd */
802 chdir ("/");
803
804 /* RUNLEVEL is set by sysvinit as is a magic number
805 RC_SOFTLEVEL is set by us and is the name for this magic number
806 even though all our userland documentation refers to runlevel */
807 RUNLEVEL = getenv ("RUNLEVEL");
808 PREVLEVEL = getenv ("PREVLEVEL");
809
810 /* Setup a signal handler */
811 signal (SIGINT, handle_signal);
812 signal (SIGQUIT, handle_signal);
813 signal (SIGTERM, handle_signal);
814 signal (SIGUSR1, handle_signal);
815
816 /* Ensure our environment is pure
817 Also, add our configuration to it */
818 env = rc_filter_env ();
819 tmplist = rc_make_env ();
820 rc_strlist_join (&env, tmplist);
821 rc_strlist_free (tmplist);
822
823 if (env) {
824 char *p;
825
826 #ifdef __linux__
827 /* clearenv isn't portable, but there's no harm in using it
828 if we have it */
829 clearenv ();
830 #else
831 char *var;
832 /* No clearenv present here then.
833 We could manipulate environ directly ourselves, but it seems that
834 some kernels bitch about this according to the environ man pages
835 so we walk though environ and call unsetenv for each value. */
836 while (environ[0]) {
837 tmp = rc_xstrdup (environ[0]);
838 p = tmp;
839 var = strsep (&p, "=");
840 unsetenv (var);
841 free (tmp);
842 }
843 tmp = NULL;
844 #endif
845
846 STRLIST_FOREACH (env, p, i)
847 if (strcmp (p, "RC_SOFTLEVEL") != 0 && strcmp (p, "SOFTLEVEL") != 0)
848 putenv (p);
849
850 /* We don't free our list as that would be null in environ */
851 }
852
853 argc++;
854 argv--;
855 while ((opt = getopt_long (argc, argv, getoptstring,
856 longopts, (int *) 0)) != -1)
857 {
858 switch (opt) {
859 case_RC_COMMON_GETOPT
860 }
861 }
862
863 newlevel = argv[optind++];
864
865 /* OK, so we really are the main RC process
866 Only root should be able to run us */
867 if (geteuid () != 0)
868 eerrorx ("%s: root access required", applet);
869
870 /* Enable logging */
871 setenv ("RC_ELOG", "rc", 1);
872
873 /* Export our PID */
874 snprintf (pidstr, sizeof (pidstr), "%d", getpid ());
875 setenv ("RC_PID", pidstr, 1);
876
877 interactive = rc_exists (INTERACTIVE);
878 rc_plugin_load ();
879
880 /* Load current softlevel */
881 bootlevel = getenv ("RC_BOOTLEVEL");
882 runlevel = rc_get_runlevel ();
883
884 /* Check we're in the runlevel requested, ie from
885 rc single
886 rc shutdown
887 rc reboot
888 */
889 if (newlevel) {
890 if (strcmp (newlevel, RC_LEVEL_SYSINIT) == 0 &&
891 RUNLEVEL &&
892 (strcmp (RUNLEVEL, "S") == 0 ||
893 strcmp (RUNLEVEL, "1") == 0))
894 {
895 /* OK, we're either in runlevel 1 or single user mode */
896 struct utsname uts;
897 #ifdef __linux__
898 char *cmd;
899 #endif
900
901 /* exec init-early.sh if it exists
902 * This should just setup the console to use the correct
903 * font. Maybe it should setup the keyboard too? */
904 if (rc_exists (INITEARLYSH))
905 run_script (INITEARLYSH);
906
907 uname (&uts);
908
909 printf ("\n");
910 printf (" %sGentoo/%s; %shttp://www.gentoo.org/%s"
911 "\n Copyright 1999-2007 Gentoo Foundation; "
912 "Distributed under the GPLv2\n\n",
913 ecolor (ecolor_good), uts.sysname, ecolor (ecolor_bracket),
914 ecolor (ecolor_normal));
915
916 if (rc_is_env ("RC_INTERACTIVE", "yes"))
917 printf ("Press %sI%s to enter interactive boot mode\n\n",
918 ecolor (ecolor_good), ecolor (ecolor_normal));
919
920 setenv ("RC_SOFTLEVEL", newlevel, 1);
921 rc_plugin_run (rc_hook_runlevel_start_in, newlevel);
922 run_script (INITSH);
923
924 #ifdef __linux__
925 /* If we requested a softlevel, save it now */
926 set_ksoftlevel (NULL);
927 if ((cmd = proc_getent ("softlevel"))) {
928 set_ksoftlevel (cmd);
929 free (cmd);
930 }
931
932 #endif
933 rc_plugin_run (rc_hook_runlevel_start_out, newlevel);
934
935 if (want_interactive ())
936 mark_interactive ();
937
938 exit (EXIT_SUCCESS);
939 } else if (strcmp (newlevel, RC_LEVEL_SINGLE) == 0) {
940 if (! RUNLEVEL ||
941 (strcmp (RUNLEVEL, "S") != 0 &&
942 strcmp (RUNLEVEL, "1") != 0))
943 {
944 /* Remember the current runlevel for when we come back */
945 set_ksoftlevel (runlevel);
946 single_user ();
947 }
948 } else if (strcmp (newlevel, RC_LEVEL_REBOOT) == 0) {
949 if (! RUNLEVEL ||
950 strcmp (RUNLEVEL, "6") != 0)
951 {
952 execl (SHUTDOWN, SHUTDOWN, "-r", "now", (char *) NULL);
953 eerrorx ("%s: unable to exec `" SHUTDOWN "': %s",
954 applet, strerror (errno));
955 }
956 } else if (strcmp (newlevel, RC_LEVEL_SHUTDOWN) == 0) {
957 if (! RUNLEVEL ||
958 strcmp (RUNLEVEL, "0") != 0)
959 {
960 execl (SHUTDOWN, SHUTDOWN,
961 #ifdef __linux__
962 "-h",
963 #else
964 "-p",
965 #endif
966 "now", (char *) NULL);
967 eerrorx ("%s: unable to exec `" SHUTDOWN "': %s",
968 applet, strerror (errno));
969 }
970 }
971 }
972
973 /* Now we start handling our children */
974 signal (SIGCHLD, handle_signal);
975
976 /* We should only use ksoftlevel if we were in single user mode
977 If not, we need to erase ksoftlevel now. */
978 if (PREVLEVEL &&
979 (strcmp (PREVLEVEL, "1") == 0 ||
980 strcmp (PREVLEVEL, "S") == 0 ||
981 strcmp (PREVLEVEL, "N") == 0))
982 {
983 /* Try not to join boot and ksoftlevels together */
984 if (! newlevel ||
985 strcmp (newlevel, getenv ("RC_BOOTLEVEL")) != 0)
986 if (get_ksoftlevel (ksoftbuffer, sizeof (ksoftbuffer)))
987 newlevel = ksoftbuffer;
988 } else if (! RUNLEVEL ||
989 (strcmp (RUNLEVEL, "1") != 0 &&
990 strcmp (RUNLEVEL, "S") != 0 &&
991 strcmp (RUNLEVEL, "N") != 0))
992 {
993 set_ksoftlevel (NULL);
994 }
995
996 if (newlevel &&
997 (strcmp (newlevel, RC_LEVEL_REBOOT) == 0 ||
998 strcmp (newlevel, RC_LEVEL_SHUTDOWN) == 0 ||
999 strcmp (newlevel, RC_LEVEL_SINGLE) == 0))
1000 {
1001 going_down = true;
1002 rc_set_runlevel (newlevel);
1003 setenv ("RC_SOFTLEVEL", newlevel, 1);
1004 rc_plugin_run (rc_hook_runlevel_stop_in, newlevel);
1005 } else {
1006 rc_plugin_run (rc_hook_runlevel_stop_in, runlevel);
1007 }
1008
1009 /* Check if runlevel is valid if we're changing */
1010 if (newlevel && strcmp (runlevel, newlevel) != 0 && ! going_down) {
1011 tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel, (char *) NULL);
1012 if (! rc_is_dir (tmp))
1013 eerrorx ("%s: is not a valid runlevel", newlevel);
1014 CHAR_FREE (tmp);
1015 }
1016
1017 /* Load our deptree now */
1018 if ((deptree = rc_load_deptree ()) == NULL)
1019 eerrorx ("failed to load deptree");
1020
1021 /* Clean the failed services state dir now */
1022 if (rc_is_dir (RC_SVCDIR "/failed"))
1023 rc_rm_dir (RC_SVCDIR "/failed", false);
1024
1025 mkdir (RC_STOPPING, 0755);
1026
1027 #ifdef __linux__
1028 /* udev likes to start services before we're ready when it does
1029 its coldplugging thing. runscript knows when we're not ready so it
1030 stores a list of coldplugged services in DEVBOOT for us to pick up
1031 here when we are ready for them */
1032 if (rc_is_dir (DEVBOOT)) {
1033 start_services = rc_ls_dir (DEVBOOT, RC_LS_INITD);
1034 rc_rm_dir (DEVBOOT, true);
1035
1036 STRLIST_FOREACH (start_services, service, i)
1037 if (rc_allow_plug (service))
1038 rc_mark_service (service, rc_service_coldplugged);
1039 /* We need to dump this list now.
1040 This may seem redunant, but only Linux needs this and saves on
1041 code bloat. */
1042 rc_strlist_free (start_services);
1043 start_services = NULL;
1044 }
1045 #else
1046 /* BSD's on the other hand populate /dev automagically and use devd.
1047 The only downside of this approach and ours is that we have to hard code
1048 the device node to the init script to simulate the coldplug into
1049 runlevel for our dependency tree to work. */
1050 if (newlevel && strcmp (newlevel, bootlevel) == 0 &&
1051 (strcmp (runlevel, RC_LEVEL_SINGLE) == 0 ||
1052 strcmp (runlevel, RC_LEVEL_SYSINIT) == 0) &&
1053 rc_is_env ("RC_COLDPLUG", "yes"))
1054 {
1055 #if defined(__DragonFly__) || defined(__FreeBSD__)
1056 /* The net interfaces are easy - they're all in net /dev/net :) */
1057 start_services = rc_ls_dir ("/dev/net", 0);
1058 STRLIST_FOREACH (start_services, service, i) {
1059 j = (strlen ("net.") + strlen (service) + 1);
1060 tmp = rc_xmalloc (sizeof (char *) * j);
1061 snprintf (tmp, j, "net.%s", service);
1062 if (rc_service_exists (tmp) && rc_allow_plug (tmp))
1063 rc_mark_service (tmp, rc_service_coldplugged);
1064 CHAR_FREE (tmp);
1065 }
1066 rc_strlist_free (start_services);
1067 #endif
1068
1069 /* The mice are a little more tricky.
1070 If we coldplug anything else, we'll probably do it here. */
1071 start_services = rc_ls_dir ("/dev", 0);
1072 STRLIST_FOREACH (start_services, service, i) {
1073 if (strncmp (service, "psm", 3) == 0 ||
1074 strncmp (service, "ums", 3) == 0)
1075 {
1076 char *p = service + 3;
1077 if (p && isdigit (*p)) {
1078 j = (strlen ("moused.") + strlen (service) + 1);
1079 tmp = rc_xmalloc (sizeof (char *) * j);
1080 snprintf (tmp, j, "moused.%s", service);
1081 if (rc_service_exists (tmp) && rc_allow_plug (tmp))
1082 rc_mark_service (tmp, rc_service_coldplugged);
1083 CHAR_FREE (tmp);
1084 }
1085 }
1086 }
1087 rc_strlist_free (start_services);
1088 start_services = NULL;
1089 }
1090 #endif
1091
1092 /* Build a list of all services to stop and then work out the
1093 correct order for stopping them */
1094 stop_services = rc_ls_dir (RC_SVCDIR_STARTING, RC_LS_INITD);
1095
1096 tmplist = rc_ls_dir (RC_SVCDIR_INACTIVE, RC_LS_INITD);
1097 rc_strlist_join (&stop_services, tmplist);
1098 rc_strlist_free (tmplist);
1099
1100 tmplist = rc_ls_dir (RC_SVCDIR_STARTED, RC_LS_INITD);
1101 rc_strlist_join (&stop_services, tmplist);
1102 rc_strlist_free (tmplist);
1103
1104 types = NULL;
1105 rc_strlist_add (&types, "ineed");
1106 rc_strlist_add (&types, "iuse");
1107 rc_strlist_add (&types, "iafter");
1108
1109 deporder = rc_get_depends (deptree, types, stop_services,
1110 runlevel, depoptions | RC_DEP_STOP);
1111
1112 rc_strlist_free (stop_services);
1113 rc_strlist_free (types);
1114 types = NULL;
1115 stop_services = deporder;
1116 deporder = NULL;
1117 rc_strlist_reverse (stop_services);
1118
1119 /* Load our list of coldplugged services */
1120 coldplugged_services = rc_ls_dir (RC_SVCDIR_COLDPLUGGED, RC_LS_INITD);
1121
1122 /* Load our start services now.
1123 We have different rules dependent on runlevel. */
1124 if (newlevel && strcmp (newlevel, bootlevel) == 0) {
1125 if (coldplugged_services) {
1126 einfon ("Device initiated services:");
1127 STRLIST_FOREACH (coldplugged_services, service, i) {
1128 printf (" %s", service);
1129 rc_strlist_add (&start_services, service);
1130 }
1131 printf ("\n");
1132 }
1133 tmp = rc_strcatpaths (RC_RUNLEVELDIR, newlevel ? newlevel : runlevel,
1134 (char *) NULL);
1135 tmplist = rc_ls_dir (tmp, RC_LS_INITD);
1136 rc_strlist_join (&start_services, tmplist);
1137 rc_strlist_free (tmplist);
1138 CHAR_FREE (tmp);
1139 } else {
1140 /* Store our list of coldplugged services */
1141 rc_strlist_join (&coldplugged_services,
1142 rc_ls_dir (RC_SVCDIR_COLDPLUGGED, RC_LS_INITD));
1143 if (strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SINGLE) != 0 &&
1144 strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_SHUTDOWN) != 0 &&
1145 strcmp (newlevel ? newlevel : runlevel, RC_LEVEL_REBOOT) != 0)
1146 {
1147 /* We need to include the boot runlevel services if we're not in it */
1148 tmplist = rc_services_in_runlevel (bootlevel);
1149 rc_strlist_join (&start_services, tmplist);
1150 rc_strlist_free (tmplist);
1151 tmplist = rc_services_in_runlevel (newlevel ? newlevel : runlevel);
1152 rc_strlist_join (&start_services, tmplist);
1153 rc_strlist_free (tmplist);
1154
1155 STRLIST_FOREACH (coldplugged_services, service, i)
1156 rc_strlist_add (&start_services, service);
1157
1158 }
1159 }
1160
1161 /* Save out softlevel now */
1162 if (going_down)
1163 rc_set_runlevel (newlevel);
1164
1165 types = NULL;
1166 rc_strlist_add (&types, "needsme");
1167 /* Now stop the services that shouldn't be running */
1168 STRLIST_FOREACH (stop_services, service, i) {
1169 bool found = false;
1170 char *conf = NULL;
1171 char **stopdeps = NULL;
1172 char *svc1 = NULL;
1173 char *svc2 = NULL;
1174 int k;
1175
1176 if (rc_service_state (service, rc_service_stopped))
1177 continue;
1178
1179 /* We always stop the service when in these runlevels */
1180 if (going_down) {
1181 pid_t pid = rc_stop_service (service);
1182 if (pid > 0 && ! rc_is_env ("RC_PARALLEL", "yes"))
1183 rc_waitpid (pid);
1184 continue;
1185 }
1186
1187 /* If we're in the start list then don't bother stopping us */
1188 STRLIST_FOREACH (start_services, svc1, j)
1189 if (strcmp (svc1, service) == 0) {
1190 found = true;
1191 break;
1192 }
1193
1194 /* Unless we would use a different config file */
1195 if (found) {
1196 int len;
1197 if (! newlevel)
1198 continue;
1199
1200 len = strlen (service) + strlen (runlevel) + 2;
1201 tmp = rc_xmalloc (sizeof (char *) * len);
1202 snprintf (tmp, len, "%s.%s", service, runlevel);
1203 conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
1204 found = rc_exists (conf);
1205 CHAR_FREE (conf);
1206 CHAR_FREE (tmp);
1207 if (! found) {
1208 len = strlen (service) + strlen (newlevel) + 2;
1209 tmp = rc_xmalloc (sizeof (char *) * len);
1210 snprintf (tmp, len, "%s.%s", service, newlevel);
1211 conf = rc_strcatpaths (RC_CONFDIR, tmp, (char *) NULL);
1212 found = rc_exists (conf);
1213 CHAR_FREE (conf);
1214 CHAR_FREE (tmp);
1215 if (!found)
1216 continue;
1217 }
1218 } else {
1219 /* Allow coldplugged services not to be in the runlevels list */
1220 if (rc_service_state (service, rc_service_coldplugged))
1221 continue;
1222 }
1223
1224 /* We got this far! Or last check is to see if any any service that
1225 going to be started depends on us */
1226 rc_strlist_add (&stopdeps, service);
1227 deporder = rc_get_depends (deptree, types, stopdeps,
1228 runlevel, RC_DEP_STRICT);
1229 rc_strlist_free (stopdeps);
1230 stopdeps = NULL;
1231 found = false;
1232 STRLIST_FOREACH (deporder, svc1, j) {
1233 STRLIST_FOREACH (start_services, svc2, k)
1234 if (strcmp (svc1, svc2) == 0) {
1235 found = true;
1236 break;
1237 }
1238 if (found)
1239 break;
1240 }
1241 rc_strlist_free (deporder);
1242 deporder = NULL;
1243
1244 /* After all that we can finally stop the blighter! */
1245 if (! found) {
1246 pid_t pid = rc_stop_service (service);
1247 if (pid > 0 && ! rc_is_env ("RC_PARALLEL", "yes"))
1248 rc_waitpid (pid);
1249 }
1250 }
1251 rc_strlist_free (types);
1252 types = NULL;
1253
1254 /* Wait for our services to finish */
1255 wait_for_services ();
1256
1257 /* Notify the plugins we have finished */
1258 rc_plugin_run (rc_hook_runlevel_stop_out, runlevel);
1259
1260 rmdir (RC_STOPPING);
1261
1262 /* Store the new runlevel */
1263 if (newlevel) {
1264 rc_set_runlevel (newlevel);
1265 runlevel = newlevel;
1266 setenv ("RC_SOFTLEVEL", runlevel, 1);
1267 }
1268
1269 /* Run the halt script if needed */
1270 if (strcmp (runlevel, RC_LEVEL_SHUTDOWN) == 0 ||
1271 strcmp (runlevel, RC_LEVEL_REBOOT) == 0)
1272 {
1273 execl (HALTSH, HALTSH, runlevel, (char *) NULL);
1274 eerrorx ("%s: unable to exec `%s': %s",
1275 applet, HALTSH, strerror (errno));
1276 }
1277
1278 /* Single user is done now */
1279 if (strcmp (runlevel, RC_LEVEL_SINGLE) == 0) {
1280 if (rc_exists (INTERACTIVE))
1281 unlink (INTERACTIVE);
1282 sulogin (false);
1283 }
1284
1285 mkdir (RC_STARTING, 0755);
1286 rc_plugin_run (rc_hook_runlevel_start_in, runlevel);
1287
1288 /* Re-add our coldplugged services if they stopped */
1289 STRLIST_FOREACH (coldplugged_services, service, i)
1290 rc_mark_service (service, rc_service_coldplugged);
1291
1292 /* Order the services to start */
1293 rc_strlist_add (&types, "ineed");
1294 rc_strlist_add (&types, "iuse");
1295 rc_strlist_add (&types, "iafter");
1296 deporder = rc_get_depends (deptree, types, start_services,
1297 runlevel, depoptions | RC_DEP_START);
1298 rc_strlist_free (types);
1299 types = NULL;
1300 rc_strlist_free (start_services);
1301 start_services = deporder;
1302 deporder = NULL;
1303
1304 #ifdef __linux__
1305 /* mark any services skipped as started */
1306 if (PREVLEVEL && strcmp (PREVLEVEL, "N") == 0) {
1307 if ((service = proc_getent ("noinitd"))) {
1308 char *p = service;
1309 char *token;
1310
1311 while ((token = strsep (&p, ",")))
1312 rc_mark_service (token, rc_service_started);
1313 free (service);
1314 }
1315 }
1316 #endif
1317
1318
1319 STRLIST_FOREACH (start_services, service, i) {
1320 if (rc_service_state (service, rc_service_stopped)) {
1321 pid_t pid;
1322
1323 if (! interactive)
1324 interactive = want_interactive ();
1325
1326 if (interactive) {
1327 interactive_retry:
1328 printf ("\n");
1329 einfo ("About to start the service %s", service);
1330 eindent ();
1331 einfo ("1) Start the service\t\t2) Skip the service");
1332 einfo ("3) Continue boot process\t\t4) Exit to shell");
1333 eoutdent ();
1334 interactive_option:
1335 switch (read_key (true)) {
1336 case '1': break;
1337 case '2': continue;
1338 case '3': interactive = false; break;
1339 case '4': sulogin (true); goto interactive_retry;
1340 default: goto interactive_option;
1341 }
1342 }
1343
1344 /* Remember the pid if we're running in parallel */
1345 if ((pid = rc_start_service (service)))
1346 add_pid (pid);
1347
1348 if (! rc_is_env ("RC_PARALLEL", "yes")) {
1349 rc_waitpid (pid);
1350 remove_pid (pid);
1351 }
1352 }
1353 }
1354
1355 /* Wait for our services to finish */
1356 wait_for_services ();
1357
1358 rc_plugin_run (rc_hook_runlevel_start_out, runlevel);
1359
1360 #ifdef __linux__
1361 /* mark any services skipped as stopped */
1362 if (PREVLEVEL && strcmp (PREVLEVEL, "N") == 0) {
1363 if ((service = proc_getent ("noinitd"))) {
1364 char *p = service;
1365 char *token;
1366
1367 while ((token = strsep (&p, ",")))
1368 rc_mark_service (token, rc_service_stopped);
1369 free (service);
1370 }
1371 }
1372 #endif
1373
1374 /* Store our interactive status for boot */
1375 if (interactive && strcmp (runlevel, bootlevel) == 0)
1376 mark_interactive ();
1377 else {
1378 if (rc_exists (INTERACTIVE))
1379 unlink (INTERACTIVE);
1380 }
1381
1382 return (EXIT_SUCCESS);
1383 }

  ViewVC Help
Powered by ViewVC 1.1.20