[ale] tcsetpgrp()
Chris Fowler
ChrisF at computone.com
Wed May 2 16:19:17 EDT 2001
I made this little cheezy program to act as init for me on a floppy. It spawns the shell just find.
Problem is that everytime I enter a command on the CL, I get following error message:
tcsetpgrp: Inappropriate ioclt for device.
It seems that all through the shell code the tcsetpgrp is being placed on STDIN. So, Im thinking that in my efforts to
spawn a daemon, I might have forgot something simple.Â
Thanks,
Chris
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
int
init(int argc, char *argv[])
{
       int pid;
       int status;
       char *arguments[2];
                    Â
       setsid();
       setpgrp();
       umask(0);
       chroot("/");
       arguments[0] = "/bin/sh";     Â
       arguments[1] = 0;
       open("/dev/console", O_RDONLY);
       open("/dev/console", O_WRONLY);
       open("/dev/console", O_WRONLY);
      Â
       printf("Serial Test Starting\n");
       pid = fork();
       switch (pid) {
              case 0:Â
                     close(0);
                     close(1);
                     close(2);
                     open("/dev/tty1", O_RDONLY);
                     open("/dev/tty1", O_WRONLY);
                     open("/dev/tty1", O_WRONLY);
                    Â
                     setsid();
                     setpgrp();
                     setpgid(0,0);
                     umask(0);
                     chroot("/");
                     if(execvp(arguments[0],arguments) ==-1)
                            perror("init");
                     break;
              case -1:
                     perror("init");
                     exit(1);
                     break;
       }
       wait(&status);
       printf("Turn off computer!\n");
       printf("Or press Enter to restart");
       getchar();
       restart();
                    Â
      Â
}
More information about the Ale
mailing list