Index: esh-sys-utils.c =================================================================== RCS file: /home/courses/cs3214/admin/cvs/psh/src-solution/esh-sys-utils.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- esh-sys-utils.c 3 Sep 2014 18:59:25 -0000 1.5 +++ esh-sys-utils.c 4 Feb 2015 00:01:13 -0000 1.6 @@ -20,7 +20,7 @@ #include "esh-sys-utils.h" -static const char rcsid [] = "$Id: esh-sys-utils.c,v 1.5 2014/09/03 18:59:25 cs3214 Exp $"; +static const char rcsid [] = "$Id: esh-sys-utils.c,v 1.6 2015/02/04 00:01:13 cs3214 Exp $"; /* Utility function for esh_sys_fatal_error and esh_sys_error */ static void @@ -54,6 +54,18 @@ exit(EXIT_FAILURE); } + +/* Set the 'close-on-exec' flag on fd, return error indicator */ +int +esh_set_cloexec(int fd) +{ + int oldflags = fcntl (fd, F_GETFD, 0); + if (oldflags < 0) + return oldflags; + + return fcntl(fd, F_SETFD, oldflags | FD_CLOEXEC); +} + static int terminal_fd = -1; /* the controlling terminal */ static struct termios saved_tty_state; /* the state of the terminal when shell was started. */ @@ -69,6 +81,9 @@ if (terminal_fd == -1) esh_sys_fatal_error("opening controlling terminal %s failed: ", tty); + if (esh_set_cloexec(terminal_fd)) + esh_sys_fatal_error("cannot mark terminal fd FD_CLOEXEC"); + esh_sys_tty_save(&saved_tty_state); return &saved_tty_state; } Index: esh-sys-utils.h =================================================================== RCS file: /home/courses/cs3214/admin/cvs/psh/src-solution/esh-sys-utils.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- esh-sys-utils.h 26 Feb 2010 07:31:03 -0000 1.3 +++ esh-sys-utils.h 4 Feb 2015 00:01:13 -0000 1.4 @@ -15,6 +15,9 @@ void esh_sys_error(char *fmt, ...); void esh_sys_fatal_error(char *fmt, ...); +/* Set the 'close-on-exec' flag on fd, return error indicator */ +int esh_set_cloexec(int fd); + /* Get a file descriptor that refers to controlling terminal */ int esh_sys_tty_getfd(void); Index: eshoutput.py =================================================================== RCS file: /home/courses/cs3214/admin/cvs/psh/src-solution/eshoutput.py,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- eshoutput.py 29 Sep 2011 15:39:29 -0000 1.8 +++ eshoutput.py 4 Feb 2015 00:01:13 -0000 1.9 @@ -46,3 +46,8 @@ 'fg' : 'fg %s', 'bg' : 'bg %s' } + +# Uncomment this line if you like stdriver.py to keep a log of everything +# input and output to the pty in file 'log.txt' +# +# logfile=open("log.txt", "w")