18888: Philippe Troin: allow clone to acquire a controlling tty

This commit is contained in:
Peter Stephenson 2003-07-23 09:27:56 +00:00
parent ef8d5c7214
commit 93141e6960
2 changed files with 35 additions and 17 deletions

View file

@ -1,3 +1,8 @@
2003-07-23 Peter Stephenson <pws@csr.com>
* 18888: Philippe Troin: Src/Modules/clone.c: Allow clone to
acquire a controlling tty so that the clone can use job control.
2003-07-22 Peter Stephenson <pws@csr.com>
* 18880: Src/Modules/parameter.c: Don't return unset variables

View file

@ -43,7 +43,7 @@
static int
bin_clone(char *nam, char **args, Options ops, int func)
{
int ttyfd, pid;
int ttyfd, pid, cttyfd;
unmetafy(*args, NULL);
ttyfd = open(*args, O_RDWR|O_NOCTTY);
@ -57,29 +57,42 @@ bin_clone(char *nam, char **args, Options ops, int func)
ppid = getppid();
mypid = getpid();
#ifdef HAVE_SETSID
if (setsid() != mypid) {
if (setsid() != mypid)
zwarnnam(nam, "failed to create new session: %e", NULL, errno);
#endif
#ifdef TIOCNOTTY
#elif defined(TIOCNOTTY)
if (ioctl(SHTTY, TIOCNOTTY, 0))
zwarnnam(nam, "%e", NULL, errno);
zwarnnam(*args, "%e", NULL, errno);
setpgrp(0L, mypid);
#endif
#ifdef HAVE_SETSID
}
#endif
if (ttyfd) {
close(0);
dup(ttyfd);
} else
ttyfd = -1;
close(1);
close(2);
dup(0);
dup(0);
dup2(ttyfd,0);
dup2(ttyfd,1);
dup2(ttyfd,2);
if (ttyfd > 2)
close(ttyfd);
closem(0);
close(coprocin);
close(coprocout);
/* Acquire a controlling terminal */
cttyfd = open(*args, O_RDWR);
if (cttyfd == -1)
zwarnnam(nam, "%e", NULL, errno);
else {
#ifdef TIOCSCTTY
ioctl(cttyfd, TIOCSCTTY, 0);
#endif
close(cttyfd);
}
/* check if we acquired the tty successfully */
cttyfd = open("/dev/tty", O_RDWR);
if (cttyfd == -1)
zwarnnam(nam, "could not make %s my controlling tty, job control "
"disabled", *args, 0);
else
close(cttyfd);
/* Clear mygrp so that acquire_pgrp() gets the new process group.
* (acquire_pgrp() is called from init_io()) */
mypgrp = 0;
init_io();
setsparam("TTY", ztrdup(ttystrname));
}