[BACK]Return to init.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sbin / init

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sbin/init/init.c between version 1.27 and 1.28

version 1.27, 1997/07/19 19:00:44 version 1.28, 1997/07/30 03:43:21
Line 53  __RCSID("$NetBSD$");
Line 53  __RCSID("$NetBSD$");
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/sysctl.h>  #include <sys/sysctl.h>
 #include <sys/wait.h>  #include <sys/wait.h>
   #include <sys/mman.h>
   #include <sys/stat.h>
   #include <sys/mount.h>
   #ifdef DEBUG
   #include <sys/sysctl.h>
   #include <machine/cpu.h>
   #endif
   
 #include <db.h>  #include <db.h>
 #include <errno.h>  #include <errno.h>
Line 66  __RCSID("$NetBSD$");
Line 73  __RCSID("$NetBSD$");
 #include <ttyent.h>  #include <ttyent.h>
 #include <unistd.h>  #include <unistd.h>
 #include <util.h>  #include <util.h>
   #include <paths.h>
   #include <err.h>
   
 #ifdef __STDC__  #ifdef __STDC__
 #include <stdarg.h>  #include <stdarg.h>
Line 93  int main __P((int, char *[]));
Line 102  int main __P((int, char *[]));
 void handle __P((sig_t, ...));  void handle __P((sig_t, ...));
 void delset __P((sigset_t *, ...));  void delset __P((sigset_t *, ...));
   
 void stall __P((char *, ...));  void stall __P((const char *, ...))
 void warning __P((char *, ...));      __attribute__((__format__(__printf__,1,2)));
 void emergency __P((char *, ...));  void warning __P((const char *, ...))
       __attribute__((__format__(__printf__,1,2)));
   void emergency __P((const char *, ...))
       __attribute__((__format__(__printf__,1,2)));
 void disaster __P((int));  void disaster __P((int));
 void badsys __P((int));  void badsys __P((int));
   
Line 165  void del_session __P((session_t *));
Line 177  void del_session __P((session_t *));
 session_t *find_session __P((pid_t));  session_t *find_session __P((pid_t));
 DB *session_db;  DB *session_db;
   
   #ifdef MSDOSFS_ROOT
   static void msdosfs_root __P((void));
   #endif
   
 /*  /*
  * The mother of all processes.   * The mother of all processes.
  */   */
Line 180  main(argc, argv)
Line 196  main(argc, argv)
 #ifndef LETS_GET_SMALL  #ifndef LETS_GET_SMALL
         /* Dispose of random users. */          /* Dispose of random users. */
         if (getuid() != 0) {          if (getuid() != 0) {
                 (void)fprintf(stderr, "init: %s\n", strerror(EPERM));                  errno = EPERM;
                 exit (1);                  err(1, "%s", "");
         }          }
   
         /* System V users like to reexec init. */          /* System V users like to reexec init. */
         if (getpid() != 1) {          if (getpid() != 1)
                 (void)fprintf(stderr, "init: already running\n");                  errx(1, "already running");
                 exit (1);  #endif
         }  
   
         /*  
          * Note that this does NOT open a file...  
          * Does 'init' deserve its own facility number?  
          */  
         openlog("init", LOG_CONS|LOG_ODELAY, LOG_AUTH);  
 #endif /* LETS_GET_SMALL */  
   
         /*          /*
          * Create an initial session.           * Create an initial session.
          */           */
         if (setsid() < 0)          if (setsid() < 0)
                 warning("initial setsid() failed: %m");                  warn("initial setsid() failed");
   
         /*          /*
          * Establish an initial user so that programs running           * Establish an initial user so that programs running
          * single user do not freak out and die (like passwd).           * single user do not freak out and die (like passwd).
          */           */
         if (setlogin("root") < 0)          if (setlogin("root") < 0)
                 warning("setlogin() failed: %m");                  warn("setlogin() failed");
   
   
   #ifdef MSDOSFS_ROOT
           msdosfs_root();
   #endif
   
   #ifndef LETS_GET_SMALL
           /*
            * Note that this does NOT open a file...
            * Does 'init' deserve its own facility number?
            */
           openlog("init", LOG_CONS|LOG_ODELAY, LOG_AUTH);
   #endif /* LETS_GET_SMALL */
   
   
 #ifndef LETS_GET_SMALL  #ifndef LETS_GET_SMALL
         /*          /*
Line 341  delset(va_alist)
Line 363  delset(va_alist)
  */   */
 void  void
 #ifdef __STDC__  #ifdef __STDC__
 stall(char *message, ...)  stall(const char *message, ...)
 #else  #else
 stall(va_alist)  stall(va_alist)
         va_dcl          va_dcl
Line 356  stall(va_alist)
Line 378  stall(va_alist)
 #else  #else
         va_start(ap, message);          va_start(ap, message);
 #endif  #endif
   
         vsyslog(LOG_ALERT, message, ap);          vsyslog(LOG_ALERT, message, ap);
         va_end(ap);          va_end(ap);
         closelog();          closelog();
Line 370  stall(va_alist)
Line 391  stall(va_alist)
  */   */
 void  void
 #ifdef __STDC__  #ifdef __STDC__
 warning(char *message, ...)  warning(const char *message, ...)
 #else  #else
 warning(va_alist)  warning(va_alist)
         va_dcl          va_dcl
Line 397  warning(va_alist)
Line 418  warning(va_alist)
  */   */
 void  void
 #ifdef __STDC__  #ifdef __STDC__
 emergency(char *message, ...)  emergency(const char *message, ...)
 #else  #else
 emergency(va_alist)  emergency(va_alist)
         va_dcl          va_dcl
Line 1332  death()
Line 1353  death()
         return (state_func_t) single_user;          return (state_func_t) single_user;
 }  }
 #endif /* LETS_GET_SMALL */  #endif /* LETS_GET_SMALL */
   
   #ifdef MSDOSFS_ROOT
   
   static void
   msdosfs_root()
   {
           /*
            * We cannot print errors so we bail out silently...
            */
           int fd = -1;
           struct stat st;
           pid_t pid;
           int status, i;
           void *ptr;
           struct statfs sfs;
   
           if (statfs("/", &sfs) == -1)
                   return;
   
           if (strcmp(sfs.f_fstypename, MOUNT_MSDOS) != 0)
                   return;
   
           /* If we have devices, we cannot be on msdosfs */
           if (access(_PATH_CONSOLE, F_OK) != -1)
                   return;
   
           /* Grab the contents of MAKEDEV */
           if ((fd = open("/dev/MAKEDEV", O_RDONLY)) == -1)
                   return;
   
           if (fstat(fd, &st) == -1)
                   goto done;
   
           if ((ptr = mmap(0, st.st_size, PROT_READ, 0, fd, 0)) == (void *) -1)
                   goto done;
   
           (void) close(fd);
           fd = -1;
   
           /* Mount an mfs over /dev so we can create devices */
           switch ((pid = fork())) {
           case 0:
                   (void) execl("/sbin/mount_mfs", "mount_mfs", "-i", "18000",
                       "-s", "192", "-b", "4096", "-f", "512", "swap", "/dev",
                       NULL);
                   goto done;
   
           case -1:
                   goto done;
   
           default:
                   if (waitpid(pid, &status, 0) == -1)
                           goto done;
                   if (status != 0)
                           goto done;
                   break;
           }
   
           /* Make sure that the mfs is up and running */
           for (i = 0; i < 10; i++) {
                   if (access("/dev/MAKEDEV", F_OK) != 0)
                           break;
                   sleep(1);
           }
   
           if (i == 10)
                   return;
   
           /* Create a MAKEDEV script in /dev */
           if ((fd = open("/dev/MAKEDEV", O_WRONLY|O_CREAT|O_TRUNC, 0755)) == -1)
                   goto done;
   
           if (write(fd, ptr, st.st_size) != st.st_size)
                   goto done;
   
           (void) munmap(ptr, st.st_size);
   
           (void) close(fd);
           fd = -1;
   
   #ifdef DEBUG
           {
                   mode_t mode = 0666 | S_IFCHR;
                   dev_t dev;
   #ifdef CPU_CONSDEV
                   int s = sizeof(dev);
                   static int name[2] = { CTL_MACHDEP, CPU_CONSDEV };
   
                   if (sysctl(name, sizeof(name) / sizeof(name[0]), &dev, &s,
                       NULL, 0) == -1)
                           goto done;
   #else
                   dev = makedev(0, 0);
   #endif
   
                   /* Make a console for us, so we can see things happening */
                   if (mknod(_PATH_CONSOLE, mode, dev) == -1)
                           goto done;
           }
   #endif
   
           /* Run the makedev script to create devices */
           switch ((pid = fork())) {
           case 0:
                   if (chdir("/dev") == -1)
                           goto done;
                   (void) execl("/bin/sh", "sh", "./MAKEDEV", "all", NULL);
                   goto done;
   
           case -1:
                   goto done;
   
           default:
                   if (waitpid(pid, &status, 0) == -1)
                       goto done;
                   if (status != 0)
                           goto done;
                   break;
           }
   
   done:
           if (fd != -1)
                   (void) close(fd);
   }
   #endif

Legend:
Removed from v.1.27  
changed lines
  Added in v.1.28

CVSweb <webmaster@jp.NetBSD.org>