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

Diff of /trunk/src/rc.c

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

Revision 2733 Revision 2734
8 Gentoo einfo family of informational functions. 8 Gentoo einfo family of informational functions.
9 9
10 Copyright 2007 Gentoo Foundation 10 Copyright 2007 Gentoo Foundation
11 Released under the GPLv2 11 Released under the GPLv2
12 */ 12 */
13
14#define APPLET "rc"
13 15
14#include <sys/types.h> 16#include <sys/types.h>
15#include <sys/stat.h> 17#include <sys/stat.h>
16#include <sys/utsname.h> 18#include <sys/utsname.h>
17#include <sys/wait.h> 19#include <sys/wait.h>
18#include <errno.h> 20#include <errno.h>
19#include <ctype.h> 21#include <ctype.h>
22#include <getopt.h>
20#include <libgen.h> 23#include <libgen.h>
21#include <limits.h> 24#include <limits.h>
22#include <stdbool.h> 25#include <stdbool.h>
23#include <stdio.h> 26#include <stdio.h>
24#include <stdlib.h> 27#include <stdlib.h>
598 601
599 if (! WIFEXITED (status) || ! WEXITSTATUS (status) == 0) 602 if (! WIFEXITED (status) || ! WEXITSTATUS (status) == 0)
600 exit (EXIT_FAILURE); 603 exit (EXIT_FAILURE);
601} 604}
602 605
606#include "_usage.h"
607#define getoptstring getoptstring_COMMON
608static struct option longopts[] = {
609 longopts_COMMON
610 { NULL, 0, NULL, 0}
611};
612#include "_usage.c"
613
603int main (int argc, char **argv) 614int main (int argc, char **argv)
604{ 615{
605 char *RUNLEVEL = NULL; 616 char *RUNLEVEL = NULL;
606 char *PREVLEVEL = NULL; 617 char *PREVLEVEL = NULL;
607 char *runlevel = NULL; 618 char *runlevel = NULL;
613 bool going_down = false; 624 bool going_down = false;
614 bool interactive = false; 625 bool interactive = false;
615 int depoptions = RC_DEP_STRICT | RC_DEP_TRACE; 626 int depoptions = RC_DEP_STRICT | RC_DEP_TRACE;
616 char ksoftbuffer [PATH_MAX]; 627 char ksoftbuffer [PATH_MAX];
617 char pidstr[6]; 628 char pidstr[6];
629 int opt;
618 630
619 if (argv[0]) 631 if (argv[0])
620 applet = rc_xstrdup (basename (argv[0])); 632 applet = rc_xstrdup (basename (argv[0]));
621 633
622 if (! applet) 634 if (! applet)
658 } 670 }
659 671
660 if (strcmp (applet, "rc" ) != 0) 672 if (strcmp (applet, "rc" ) != 0)
661 eerrorx ("%s: unknown applet", applet); 673 eerrorx ("%s: unknown applet", applet);
662 674
663 /* OK, so we really are the main RC process
664 Only root should be able to run us */
665 if (geteuid () != 0)
666 eerrorx ("%s: root access required", applet);
667
668 atexit (cleanup); 675 atexit (cleanup);
669 newlevel = argv[0];
670 676
671 /* Change dir to / to ensure all scripts don't use stuff in pwd */ 677 /* Change dir to / to ensure all scripts don't use stuff in pwd */
672 chdir ("/"); 678 chdir ("/");
673 679
674 /* Setup a signal handler */ 680 /* Setup a signal handler */
709 if (strcmp (p, "RC_SOFTLEVEL") != 0 && strcmp (p, "SOFTLEVEL") != 0) 715 if (strcmp (p, "RC_SOFTLEVEL") != 0 && strcmp (p, "SOFTLEVEL") != 0)
710 putenv (p); 716 putenv (p);
711 717
712 /* We don't free our list as that would be null in environ */ 718 /* We don't free our list as that would be null in environ */
713 } 719 }
720
721 argc++;
722 argv--;
723 while ((opt = getopt_long (argc, argv, getoptstring,
724 longopts, (int *) 0)) != -1)
725 {
726 switch (opt) {
727 case_RC_COMMON_GETOPT
728 }
729 }
730
731 newlevel = argv[optind++];
732
733 /* OK, so we really are the main RC process
734 Only root should be able to run us */
735 if (geteuid () != 0)
736 eerrorx ("%s: root access required", applet);
714 737
715 /* Enable logging */ 738 /* Enable logging */
716 setenv ("RC_ELOG", "rc", 1); 739 setenv ("RC_ELOG", "rc", 1);
717 740
718 /* Export our PID */ 741 /* Export our PID */

Legend:
Removed from v.2733  
changed lines
  Added in v.2734

  ViewVC Help
Powered by ViewVC 1.1.20