From 2d4768183b3eb0658f6effa4cdb0d3636400cf68 Mon Sep 17 00:00:00 2001 From: zodiac Date: Sat, 28 Feb 2009 07:57:46 +0000 Subject: [PATCH] Better error reporting if forkpty() fails. git-svn-id: https://shellinabox.googlecode.com/svn/trunk@74 0da03de8-d603-11dd-86c2-0f8696b7b6f9 --- config.h | 2 +- shellinabox/launcher.c | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/config.h b/config.h index 6d6ff7f..4820e85 100644 --- a/config.h +++ b/config.h @@ -95,7 +95,7 @@ #define STDC_HEADERS 1 /* Most recent revision number in the version control system */ -#define VCS_REVISION "73" +#define VCS_REVISION "69" /* Version number of package */ #define VERSION "2.4" diff --git a/shellinabox/launcher.c b/shellinabox/launcher.c index 82cc851..a722b53 100644 --- a/shellinabox/launcher.c +++ b/shellinabox/launcher.c @@ -574,7 +574,7 @@ static int forkPty(int *pty, int useLogin, struct Utmp **utmp, fname[9] = *ptr2; if ((*pty = NOINTR(open(fname, O_RDWR, 0))) < 0) { if (errno == ENOENT) { - goto failure; + continue; } } grantpt(*pty); @@ -590,7 +590,6 @@ static int forkPty(int *pty, int useLogin, struct Utmp **utmp, NOINTR(close(*pty)); } } - failure: *pty = -1; *utmp = NULL; return -1; @@ -1229,18 +1228,27 @@ static void launcherDaemon(int fd) { struct Utmp *utmp; if ((pid = forkPty(&pty, services[request.service]->useLogin, - &utmp, request.peerName)) < 0) { - } else if (pid == 0) { + &utmp, request.peerName)) == 0) { childProcess(services[request.service], request.width, request.height, utmp, request.peerName); _exit(1); } else { // Remember the utmp entry so that we can clean up when the child // terminates. - if (!childProcesses) { - childProcesses = newHashMap(destroyUtmpHashEntry, NULL); + if (pid > 0) { + if (!childProcesses) { + childProcesses = newHashMap(destroyUtmpHashEntry, NULL); + } + addToHashMap(childProcesses, utmp->pid, (char *)utmp); + } else { + int fds[2]; + if (!pipe(fds)) { + write(fds[1], "forkpty() failed\r\n", 18); + NOINTR(close(fds[1])); + pty = fds[0]; + pid = 0; + } } - addToHashMap(childProcesses, utmp->pid, (char *)utmp); // Send file handle and process id back to parent char cmsg_buf[CMSG_SPACE(sizeof(int))];