From 923ec4e42583f37a9f86b5840f49d0f93aa7b166 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 31 May 2015 19:54:10 -0500 Subject: [PATCH] Transform (v)fork calls to use GNO's fork2 call. --- telnet/commands.c | 71 ++++++++++++++++++++++++++++++++-------------- telnetd/sys_term.c | 34 ++++++++++++++++++---- 2 files changed, 78 insertions(+), 27 deletions(-) diff --git a/telnet/commands.c b/telnet/commands.c index 9d47c17..c37e2e9 100644 --- a/telnet/commands.c +++ b/telnet/commands.c @@ -1350,42 +1350,69 @@ suspend(void) 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 shell(int argc, char **argv __unused) { long oldrows, oldcols, newrows, newcols, err_; + int result; setcommandmode(); 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: perror("Fork failed\n"); break; case 0: - { - /* - * 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); - } + child_shell(argc); 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 && (err_ || ((oldrows != newrows) || (oldcols != newcols)))) { diff --git a/telnetd/sys_term.c b/telnetd/sys_term.c index 15b6b39..74ed516 100644 --- a/telnetd/sys_term.c +++ b/telnetd/sys_term.c @@ -921,6 +921,20 @@ cleanopen(char *li) 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) * @@ -944,14 +958,24 @@ startslave(char *host, int autologin, char *autoname) } #endif - - if ((i = fork()) < 0) +#ifndef __GNO__ + 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"); if (i) { +#ifdef __GNO__ + do { + errno = 0; + (void)wait(NULL); + } while (errno == EINTR); +#endif } else { - getptyslave(); - start_login(host, autologin, autoname); - /*NOTREACHED*/ + slaveproc(host, autologin, autoname); } }