Transform (v)fork calls to use GNO's fork2 call.
This commit is contained in:
parent
de9fad8d67
commit
923ec4e425
|
@ -1350,42 +1350,69 @@ suspend(void)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __ORCAC__
|
||||||
|
# pragma databank 1
|
||||||
|
#endif
|
||||||
|
static void
|
||||||
|
child_shell(int argc)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Fire up the shell in the child.
|
||||||
|
*/
|
||||||
|
const char *shellp, *shellname;
|
||||||
|
|
||||||
|
shellp = getenv("SHELL");
|
||||||
|
if (shellp == NULL) {
|
||||||
|
#ifndef __GNO__
|
||||||
|
shellp = "/bin/sh";
|
||||||
|
#else
|
||||||
|
shellp = "/bin/gsh";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if ((shellname = strrchr(shellp, '/')) == 0)
|
||||||
|
shellname = shellp;
|
||||||
|
else
|
||||||
|
shellname++;
|
||||||
|
if (argc > 1)
|
||||||
|
execl(shellp, shellname, "-c", &saveline[1], (char *)0);
|
||||||
|
else
|
||||||
|
execl(shellp, shellname, (char *)0);
|
||||||
|
perror("Execl");
|
||||||
|
#ifndef __GNO__
|
||||||
|
_exit(1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#ifdef __ORCAC__
|
||||||
|
# pragma databank 0
|
||||||
|
#endif
|
||||||
|
|
||||||
static int
|
static int
|
||||||
shell(int argc, char **argv __unused)
|
shell(int argc, char **argv __unused)
|
||||||
{
|
{
|
||||||
long oldrows, oldcols, newrows, newcols, err_;
|
long oldrows, oldcols, newrows, newcols, err_;
|
||||||
|
int result;
|
||||||
|
|
||||||
setcommandmode();
|
setcommandmode();
|
||||||
|
|
||||||
err_ = (TerminalWindowSize(&oldrows, &oldcols) == 0) ? 1 : 0;
|
err_ = (TerminalWindowSize(&oldrows, &oldcols) == 0) ? 1 : 0;
|
||||||
switch(vfork()) {
|
#ifndef __GNO__
|
||||||
|
result = vfork();
|
||||||
|
#else
|
||||||
|
result = fork2(child_shell, 1024, 0, "telnet subshell",
|
||||||
|
sizeof(argc)/2, argc);
|
||||||
|
#endif
|
||||||
|
switch(result) {
|
||||||
case -1:
|
case -1:
|
||||||
perror("Fork failed\n");
|
perror("Fork failed\n");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0:
|
case 0:
|
||||||
{
|
child_shell(argc);
|
||||||
/*
|
|
||||||
* Fire up the shell in the child.
|
|
||||||
*/
|
|
||||||
const char *shellp, *shellname;
|
|
||||||
|
|
||||||
shellp = getenv("SHELL");
|
|
||||||
if (shellp == NULL)
|
|
||||||
shellp = "/bin/sh";
|
|
||||||
if ((shellname = strrchr(shellp, '/')) == 0)
|
|
||||||
shellname = shellp;
|
|
||||||
else
|
|
||||||
shellname++;
|
|
||||||
if (argc > 1)
|
|
||||||
execl(shellp, shellname, "-c", &saveline[1], (char *)0);
|
|
||||||
else
|
|
||||||
execl(shellp, shellname, (char *)0);
|
|
||||||
perror("Execl");
|
|
||||||
_exit(1);
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
(void)wait(NULL); /* Wait for the shell to complete */
|
do {
|
||||||
|
errno = 0;
|
||||||
|
(void)wait(NULL); /* Wait for the shell to complete */
|
||||||
|
} while (errno == EINTR);
|
||||||
|
|
||||||
if (TerminalWindowSize(&newrows, &newcols) && connected &&
|
if (TerminalWindowSize(&newrows, &newcols) && connected &&
|
||||||
(err_ || ((oldrows != newrows) || (oldcols != newcols)))) {
|
(err_ || ((oldrows != newrows) || (oldcols != newcols)))) {
|
||||||
|
|
|
@ -921,6 +921,20 @@ cleanopen(char *li)
|
||||||
return(t);
|
return(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __ORCAC__
|
||||||
|
# pragma databank 1
|
||||||
|
#endif
|
||||||
|
static void
|
||||||
|
slaveproc(char *host, int autologin, char *autoname)
|
||||||
|
{
|
||||||
|
getptyslave();
|
||||||
|
start_login(host, autologin, autoname);
|
||||||
|
/*NOTREACHED*/
|
||||||
|
}
|
||||||
|
#ifdef __ORCAC__
|
||||||
|
# pragma databank 0
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* startslave(host)
|
* startslave(host)
|
||||||
*
|
*
|
||||||
|
@ -944,14 +958,24 @@ startslave(char *host, int autologin, char *autoname)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef __GNO__
|
||||||
if ((i = fork()) < 0)
|
i = fork();
|
||||||
|
#else
|
||||||
|
i = fork2(slaveproc, 1024, 0, "telnetd pty slave proc",
|
||||||
|
(sizeof(host) + sizeof(autologin) + sizeof(autoname))/2,
|
||||||
|
host, autologin, autoname);
|
||||||
|
#endif
|
||||||
|
if (i < 0)
|
||||||
fatalperror(net, "fork");
|
fatalperror(net, "fork");
|
||||||
if (i) {
|
if (i) {
|
||||||
|
#ifdef __GNO__
|
||||||
|
do {
|
||||||
|
errno = 0;
|
||||||
|
(void)wait(NULL);
|
||||||
|
} while (errno == EINTR);
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
getptyslave();
|
slaveproc(host, autologin, autoname);
|
||||||
start_login(host, autologin, autoname);
|
|
||||||
/*NOTREACHED*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue