[3119] in Athena Bugs
Resend: 6.0C: bug in toehold
daemon@ATHENA.MIT.EDU (John Carr)
Wed Sep 6 22:02:32 1989
To: bugs@ATHENA.MIT.EDU
In-Reply-To: [966]
Date: Wed, 06 Sep 89 22:02:15 EDT
From: John Carr <jfc@ATHENA.MIT.EDU>
As the first anniversary of this bug report approaches with no fix in
sight, I resubmit it for consideration. This time, I will include a
patch to be ignored along with the bug report.
*** /paris/source/4.3/etc.athena/toehold.c Mon Jul 17 17:49:19 1989
--- toehold.c Wed Sep 6 21:56:58 1989
***************
*** 12,17 ****
--- 12,18 ----
#include <sys/file.h>
#include <signal.h>
#include <sys/ioctl.h>
+ #include <fcntl.h>
#include <sgtty.h>
#include <utmp.h>
#include <sys/types.h>
***************
*** 200,206 ****
/* Start up X */
wpid = fork();
if(!wpid) {
! fclose(stderr); /* this forces X to open it's own logfile */
sigsetmask(0);
prog = *xargv;
*xargv = "-";
--- 201,210 ----
/* Start up X */
wpid = fork();
if(!wpid) {
! /* Since stderr is unbuffered, close-on-exec will do the right
! thing with the stdio library */
! if(fcntl(fileno(stderr), F_SETFD, 1) == -1)
! fclose(stderr);
sigsetmask(0);
prog = *xargv;
*xargv = "-";
Here is the original message:
Subject: 6.0C: bug in toehold
To: bugs@ATHENA.MIT.EDU
Date: Sat, 17 Sep 88 22:19:55 EDT
From: John Carr <jfc@ATHENA.MIT.EDU>
After toehold exec()s the X server, it does a perror() to catch a failed
exec. This will fail because stderr was closed before the exec.
source/4.3/etc.athena/toehold.c
180 fclose(stderr); /* this forces X to open it's own logfile */
...
184 execv(prog, xargv);
185 perror("executing X server");
...
It is possible to recover stderr by dup(2) before the exec, and dup() and
fdopen() after (you have to save and restore errno to do this correctly).
Alternatively, X could me modified to add a flag to the X server to open
a logfile regardless of the state of stderr.
--John Carr