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

Diff of /trunk/src/rc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2768 Revision 2769
56 _item = NULL; \ 56 _item = NULL; \
57} 57}
58 58
59extern char **environ; 59extern char **environ;
60 60
61static char *RUNLEVEL = NULL;
62static char *PREVLEVEL = NULL;
63
61static char *applet = NULL; 64static char *applet = NULL;
62static char **env = NULL; 65static char **env = NULL;
63static char **newenv = NULL; 66static char **newenv = NULL;
64static char **coldplugged_services = NULL; 67static char **coldplugged_services = NULL;
65static char **stop_services = NULL; 68static char **stop_services = NULL;
82 pidlist_t *pl = service_pids; 85 pidlist_t *pl = service_pids;
83 86
84 rc_plugin_unload (); 87 rc_plugin_unload ();
85 88
86 if (! rc_in_plugin && termios_orig) { 89 if (! rc_in_plugin && termios_orig) {
87 tcsetattr (STDIN_FILENO, TCSANOW, termios_orig); 90 tcsetattr (fileno (stdin), TCSANOW, termios_orig);
88 free (termios_orig); 91 free (termios_orig);
89 } 92 }
90 93
91 while (pl) { 94 while (pl) {
92 pidlist_t *p = pl->next; 95 pidlist_t *p = pl->next;
336 339
337static char read_key (bool block) 340static char read_key (bool block)
338{ 341{
339 struct termios termios; 342 struct termios termios;
340 char c = 0; 343 char c = 0;
341 344 int fd = fileno (stdin);
342 if (! isatty (STDIN_FILENO)) 345
346 if (! isatty (fd))
343 return (false); 347 return (false);
344 348
345 /* Now save our terminal settings. We need to restore them at exit as we 349 /* Now save our terminal settings. We need to restore them at exit as we
346 will be changing it for non-blocking reads for Interactive */ 350 will be changing it for non-blocking reads for Interactive */
347 if (! termios_orig) { 351 if (! termios_orig) {
348 termios_orig = rc_xmalloc (sizeof (struct termios)); 352 termios_orig = rc_xmalloc (sizeof (struct termios));
349 tcgetattr (STDIN_FILENO, termios_orig); 353 tcgetattr (fd, termios_orig);
350 } 354 }
351 355
352 tcgetattr (STDIN_FILENO, &termios); 356 tcgetattr (fd, &termios);
353 termios.c_lflag &= ~(ICANON | ECHO); 357 termios.c_lflag &= ~(ICANON | ECHO);
354 if (block) 358 if (block)
355 termios.c_cc[VMIN] = 1; 359 termios.c_cc[VMIN] = 1;
356 else { 360 else {
357 termios.c_cc[VMIN] = 0; 361 termios.c_cc[VMIN] = 0;
358 termios.c_cc[VTIME] = 0; 362 termios.c_cc[VTIME] = 0;
359 } 363 }
360 tcsetattr (STDIN_FILENO, TCSANOW, &termios); 364 tcsetattr (fd, TCSANOW, &termios);
361 365
362 read (STDIN_FILENO, &c, 1); 366 read (fd, &c, 1);
363 367
364 tcsetattr (STDIN_FILENO, TCSANOW, termios_orig); 368 tcsetattr (fd, TCSANOW, termios_orig);
365 369
366 return (c); 370 return (c);
367} 371}
368 372
369static bool want_interactive (void) 373static bool want_interactive (void)
370{ 374{
371 char c; 375 char c;
376
377 if (PREVLEVEL &&
378 strcmp (PREVLEVEL, "N") != 0 &&
379 strcmp (PREVLEVEL, "S") != 0 &&
380 strcmp (PREVLEVEL, "1") != 0)
381 return (false);
372 382
373 if (! rc_is_env ("RC_INTERACTIVE", "yes")) 383 if (! rc_is_env ("RC_INTERACTIVE", "yes"))
374 return (false); 384 return (false);
375 385
376 c = read_key (false); 386 c = read_key (false);
537 547
538static void handle_signal (int sig) 548static void handle_signal (int sig)
539{ 549{
540 int serrno = errno; 550 int serrno = errno;
541 char signame[10] = { '\0' }; 551 char signame[10] = { '\0' };
542 char *run;
543 char *prev;
544 pidlist_t *pl; 552 pidlist_t *pl;
545 pid_t pid; 553 pid_t pid;
546 int status = 0; 554 int status = 0;
547 555
548 switch (sig) { 556 switch (sig) {
581 589
582 /* Notify plugins we are aborting */ 590 /* Notify plugins we are aborting */
583 rc_plugin_run (rc_hook_abort, NULL); 591 rc_plugin_run (rc_hook_abort, NULL);
584 592
585 /* Only drop into single user mode if we're booting */ 593 /* Only drop into single user mode if we're booting */
586 run = getenv ("RUNLEVEL"); 594 if ((PREVLEVEL &&
587 prev = getenv ("PREVLEVEL");
588 if ((prev &&
589 (strcmp (prev, "S") == 0 || 595 (strcmp (PREVLEVEL, "S") == 0 ||
590 strcmp (prev, "1") == 0)) || 596 strcmp (PREVLEVEL, "1") == 0)) ||
591 (run && 597 (RUNLEVEL &&
592 (strcmp (run, "S") == 0 || 598 (strcmp (RUNLEVEL, "S") == 0 ||
593 strcmp (run, "1") == 0))) 599 strcmp (RUNLEVEL, "1") == 0)))
594 single_user (); 600 single_user ();
595 601
596 exit (EXIT_FAILURE); 602 exit (EXIT_FAILURE);
597 break; 603 break;
598 604
635}; 641};
636#include "_usage.c" 642#include "_usage.c"
637 643
638int main (int argc, char **argv) 644int main (int argc, char **argv)
639{ 645{
640 char *RUNLEVEL = NULL;
641 char *PREVLEVEL = NULL;
642 char *runlevel = NULL; 646 char *runlevel = NULL;
643 char *newlevel = NULL; 647 char *newlevel = NULL;
644 char *service = NULL; 648 char *service = NULL;
645 char **deporder = NULL; 649 char **deporder = NULL;
646 int i = 0; 650 int i = 0;
698 702
699 atexit (cleanup); 703 atexit (cleanup);
700 704
701 /* Change dir to / to ensure all scripts don't use stuff in pwd */ 705 /* Change dir to / to ensure all scripts don't use stuff in pwd */
702 chdir ("/"); 706 chdir ("/");
707
708 /* RUNLEVEL is set by sysvinit as is a magic number
709 RC_SOFTLEVEL is set by us and is the name for this magic number
710 even though all our userland documentation refers to runlevel */
711 RUNLEVEL = getenv ("RUNLEVEL");
712 PREVLEVEL = getenv ("PREVLEVEL");
703 713
704 /* Setup a signal handler */ 714 /* Setup a signal handler */
705 signal (SIGINT, handle_signal); 715 signal (SIGINT, handle_signal);
706 signal (SIGQUIT, handle_signal); 716 signal (SIGQUIT, handle_signal);
707 signal (SIGTERM, handle_signal); 717 signal (SIGTERM, handle_signal);
766 snprintf (pidstr, sizeof (pidstr), "%d", getpid ()); 776 snprintf (pidstr, sizeof (pidstr), "%d", getpid ());
767 setenv ("RC_PID", pidstr, 1); 777 setenv ("RC_PID", pidstr, 1);
768 778
769 interactive = rc_exists (INTERACTIVE); 779 interactive = rc_exists (INTERACTIVE);
770 rc_plugin_load (); 780 rc_plugin_load ();
771
772 /* RUNLEVEL is set by sysvinit as is a magic number
773 RC_SOFTLEVEL is set by us and is the name for this magic number
774 even though all our userland documentation refers to runlevel */
775 RUNLEVEL = getenv ("RUNLEVEL");
776 PREVLEVEL = getenv ("PREVLEVEL");
777
778 781
779 /* Load current softlevel */ 782 /* Load current softlevel */
780 runlevel = rc_get_runlevel (); 783 runlevel = rc_get_runlevel ();
781 784
782 /* Check we're in the runlevel requested, ie from 785 /* Check we're in the runlevel requested, ie from

Legend:
Removed from v.2768  
changed lines
  Added in v.2769

  ViewVC Help
Powered by ViewVC 1.1.20