/[nova]/nova/init/init.c
ViewVC logotype

Diff of /nova/init/init.c

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

revision 1.1.1.1 by jrydberg, Tue Feb 12 19:28:15 2002 UTC revision 1.2 by jrydberg, Wed Mar 27 23:21:54 2002 UTC
# Line 1  Line 1 
1  /* ???  /* /sbin/init for Nova.
2     Copyright 2002 Johan Rydberg, jrydberg@rtmk.org.     Copyright 2002 Johan Rydberg, jrydberg@rtmk.org.
3    
4  This program is free software; you can redistribute it and/or modify  This program is free software; you can redistribute it and/or modify
# Line 15  You should have received a copy of the G Line 15  You should have received a copy of the G
15  along with this program; if not, write to the Free Software  along with this program; if not, write to the Free Software
16  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
17    
18    #include <sys/utsname.h>
19    #include <stdio.h>
20    #include <stdlib.h>
21    #include <argp.h>
22    #include <error.h>
23    
24    #undef  VERSION
25    #define VERSION "0.0"
26    
27    /* If we should boot the system in single-user mode.  */
28    int single_user_p = 0;
29    
30    /* If we should initialize the system.  */
31    int init_system_p = 0;
32    
33    /* Runlevel that we should start at.  */
34    int initial_runlevel = -1;
35    
36    const char *argp_program_version = "0.0";
37    const char *argp_program_bug_address = "nova-discuss@mail.freesoftware.fsf.org";
38    
39    static struct argp_option options[] =
40    {
41      {"single-user",       's', 0,         0, "Startup system in single-user mode"},
42      {"initialize-system", 'i', 0,         0, "Initialize system"},
43      {0}
44    };
45    
46    static char doc[] = "Process control initialization";
47    
48    static int
49    parse_opt (int key, char *arg, struct argp_state *state)
50    {
51      switch (key)
52        {
53        case ARGP_KEY_ARG: initial_runlevel = atoi (arg); break;
54        case 's': single_user_p = 1; break;
55        case 'i': init_system_p = 1; break;
56        default: return ARGP_ERR_UNKNOWN;
57        }
58      return 0;
59    }
60    
61    /* Singel-user shell locations.  */
62    char *shell_paths [] = { "/bin/sh", "/bin/rc", 0 };
63    
64  int  int
65  main (void)  main (int argc, char **argv)
66  {  {
67      struct argp argp = { options, parse_opt, 0, doc };
68      struct utsname utsname;
69      int err, pid, i;
70    
71      /* Parse the arguments.  We don't want the vector reordered,
72         we should pass on to our child the exact arguments we got
73         and just ignore any arguments that aren't flags for us.  */
74      argp_parse (&argp, argc, argv, ARGP_IN_ORDER, 0, 0);
75    
76      /* If we're not initializing the system and have not
77         specified a runlevel, default to runlevel 3.  */
78      if (init_system_p && initial_runlevel == -1)
79        initial_runlevel = 3;
80    
81      /* Special case for not initializing system.  */
82      if (! init_system_p)
83        {
84          if (initial_runlevel == -1)
85            error (1, 0, "Must specify runlevel");
86    
87          error (1, 0, "Should switch to level %d", initial_runlevel);
88        }
89    
90      /* Get name and information about kernel.  */
91      err = uname (&utsname);
92      if (err)
93        error (0, err, "uname");
94      printf ("init %s running on %s %s (%s)\n", VERSION,
95              utsname.sysname, utsname.release, utsname.machine);
96      fflush (stdout);
97    
98      /* As of now we only support single-user mode.  */
99      if (! single_user_p)
100        {
101          single_user_p = 1;
102          printf ("Multi-user mode not supported, falling back to single-user mode\n");
103          fflush (stdout);
104        }
105    
106      /* If we're in single-user mode we fork and try to run
107         /sbin/sh.  If we do not find /bin/sh, try other locations.  */
108      if ((pid = fork ()) == 0)
109        {
110          int i;
111          
112          for (i = 0; shell_paths [i]; i++)
113            {
114              printf ("trying to execute %s\n", shell_paths [i]);
115              fflush (stdout);
116              err = execl (shell_paths [i], shell_paths [i], NULL);
117              printf ("failed, err is %d\n", err);
118              fflush (stdout);
119            }
120          error (1, err, "Can not run single-user shell");
121        }
122      else
123        wait (&err);
124    
125      printf ("???\n");
126      fflush (stdout);
127    
128    for (;;)    for (;;)
129      ;      ;
130  }  }

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26