[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ale] tcsetpgrp()






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();


?????????????? ?????????????? ?????????????? 


?????????????? 
}