/* dboot.c - program for inittab to execute and start processes
                for the test station.  Arguments are:
      tty to use for console
      program to run (most likly login)
      [any program args]
example:
c1:respawn:/usr/local/dboot tty1 login -f adams
will startup user 'adams' on console 1
*/
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
int main(int ac, char **av)
{
   char  cdev[50];
   char  buf[50];
   int   fd;
   pid_t pid;
   strcpy(cdev,"/dev/");
   strcat(cdev,av[1]);  /* Console device */
   if (-1 == (fd = open(cdev,O_RDWR))) {
      perror("open");
      exit(0);
   }
   close(0);
   if (-1 == (dup(fd))) {
      perror("dup 0");
      exit(0);
   }
   close(1);
   if (-1 == (dup(fd))) {
      perror("dup 1");
      exit(0);
   }
   close(2);
   if (-1 == (dup(fd))) {
      perror("dup 2");
      exit(0);
   }
   if (-1 == execvp(av[2],&av[2])) {
      perror("execvp");
      exit(0);
   }
}
  
  
  
  
  
  
  
  
  
    Copyright © 1994 - 2018 Linux Journal.  All rights reserved.