[BusyBox] RFC: giving respawn init actions a controlling tty?

Vladimir N. Oleynik dzo at simtreas.ru
Tue Oct 1 02:26:03 UTC 2002


Claudio,

>         if ((pid=fork())) {
>                 int status;
>                 do { waitpid(pid,&status,0); } while(kill(pid,0)==0);
>                 exit(0);
>         }

fork for respawn? Hmm, init waiting programms as respawn configured lines.


>         if (setsid() < 0) {
>                 perror_msg_and_die("setsid failed");
>         }

And not required ;)

>         if (chdir("/") < 0) {
>                 perror_msg_and_die("chdir failed");
>         }

Already from init ;)

>         if((fd = open(argv[1], O_RDWR)) < 0) {
>                 perror_msg_and_die("open of %s failed", argv[1]);
>         }
>         if (ioctl(fd, TIOCSCTTY, 0) < 0) {
>                 perror_msg_and_die("ioctl failed");
>         }

WHY? :0

>         dup(fd);
>         dup(fd);
>         if (ioctl(fd, TIOCSCTTY, 1) < 0) {
>                 perror_msg_and_die("ioctl failed");
>         }

I think this 2 block must be remove.

>         setregid(gid, gid);
>         setgroups(1, &gid);
>         setreuid(uid, uid);
> 
>         tcgetattr(0,&p);
>         p.c_lflag|= ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN;
>         tcsetattr(0,TCSANOW,&p);
> 
>         /* one of these should work */
>         if (argc > 4) { /* user specified command line, with path search */
>                 execvp(argv[4], argv + 4);
>         }
>         execl("/bin/bash", "/bin/bash", NULL);
>         execl("/bin/ksh", "/bin/ksh", NULL);

Bad idea.

>         execl("/bin/sh", "/bin/sh", NULL);
>         execl("/bin/ash", "/bin/ash", NULL);

Must perror_msg_and_die("Can`t start shell");

>         exit(1);
> }


--w
vodz



More information about the busybox mailing list