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

Claudio Fleiner claudio at fleiner.com
Tue Oct 1 09:22:03 UTC 2002


Well, this program/applet is not currently meant to
run from init and needs to be adapted a bit. Instead,
we use it to open shells on virtual terminals from
shell scripts (some of them as root, some of them
running with a user id). So of course it needs to be adapted
a bit to make it useful for init. My point was that instead
of changing init a new applet that can also be used
from shell scripts may be useful.

on Tue, 01 Oct 2002 12:25:28 +0400 "Vladimir N. Oleynik" <dzo at simtreas.ru> wrote:
VNO> Claudio,
VNO> 
VNO> >         if ((pid=fork())) {
VNO> >                 int status;
VNO> >                 do { waitpid(pid,&status,0); } while(kill(pid,0)==0);
VNO> >                 exit(0);
VNO> >         }
VNO> 
VNO> fork for respawn? Hmm, init waiting programms as respawn configured lines.
Obviously; could either be removed or made optional.

VNO> 
VNO> 
VNO> >         if (setsid() < 0) {
VNO> >                 perror_msg_and_die("setsid failed");
VNO> >         }
VNO> 
VNO> And not required ;)
This is required if running from a shell scrip.

VNO> 
VNO> >         if (chdir("/") < 0) {
VNO> >                 perror_msg_and_die("chdir failed");
VNO> >         }
VNO> 
VNO> Already from init ;)
This too. You probably even want to 'cd' to the home directory
of the user.

VNO> 
VNO> >         if((fd = open(argv[1], O_RDWR)) < 0) {
VNO> >                 perror_msg_and_die("open of %s failed", argv[1]);
VNO> >         }
VNO> >         if (ioctl(fd, TIOCSCTTY, 0) < 0) {
VNO> >                 perror_msg_and_die("ioctl failed");
VNO> >         }
VNO> 
VNO> WHY? :0
Why not? You do want to set the new terminal as the session
control terminal.

VNO> 
VNO> >         dup(fd);
VNO> >         dup(fd);
VNO> >         if (ioctl(fd, TIOCSCTTY, 1) < 0) {
VNO> >                 perror_msg_and_die("ioctl failed");
VNO> >         }
VNO> 
VNO> I think this 2 block must be remove.
which two blocks? This spawn applet also has the option of
setting uid/gid, so the following block is necessary. Should
probably be extended to also support string uid/gid. You also
have to set the tty structure as you don't know to what it
was set.
VNO> 
VNO> >         setregid(gid, gid);
VNO> >         setgroups(1, &gid);
VNO> >         setreuid(uid, uid);
VNO> > 
VNO> >         tcgetattr(0,&p);
VNO> >         p.c_lflag|= ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE | IEXTEN;
VNO> >         tcsetattr(0,TCSANOW,&p);
VNO> > 
VNO> >         /* one of these should work */
VNO> >         if (argc > 4) { /* user specified command line, with path search */
VNO> >                 execvp(argv[4], argv + 4);
VNO> >         }
VNO> >         execl("/bin/bash", "/bin/bash", NULL);
VNO> >         execl("/bin/ksh", "/bin/ksh", NULL);
VNO> 
VNO> Bad idea.
Agreed

VNO> 
VNO> >         execl("/bin/sh", "/bin/sh", NULL);
VNO> >         execl("/bin/ash", "/bin/ash", NULL);
VNO> 
VNO> Must perror_msg_and_die("Can`t start shell");
VNO> 
VNO> >         exit(1);
VNO> > }

----------------------------------------------------------------------------
Claudio Fleiner                                          claudio at fleiner.com





More information about the busybox mailing list