X server crashes (was Re: wait crashes X (or worse))



I have read the earlier posts on this subject, but there's still
something wrong.  I admit I haven't tried rewriting the stuff I'm
trying to exec to use _exit() instead of exit(), but let's face it,
there will always be cases where that's not possible. 

I *have* tried closing everything in sight before exec-ing, in
accordance with my understanding of X's requirements, but the X
server still crashes.

My trace output looks like this:

Trying again, keeping stderr around

Forking ppp . . . Pid = 1611
There seem to be 256 open files
Closed file descriptor 0
Closed file descriptor 1
Closed file descriptor 3
Closed file descriptor 4
Closed file descriptor 5
Closed 5 files
Highest fd was 257
Forking killppp . . . Pid = 1647
Waiting for killppp (process 1647) to exit.
There seem to be 256 open files
Closed file descriptor 0
Closed file descriptor 1
Closed file descriptor 3
Closed file descriptor 4
Closed file descriptor 5
Closed 5 files
Highest fd was 257
cat: /var/run/ppp0.pid: No such file or directory
killppp has exited

Gdk-ERROR **: an x io error occurred
aborting...


And the relevant code in fork/exec looks like this:

pid_t
forkexec (char *procname)
{
  static pid_t pid = 0;
  pid_t p;
  int fd, i;
  struct rlimit *rlim;

  fprintf(stderr, "Forking %s . . . ", procname);
  if ((p = fork()) < 0) {
    fprintf(stderr, "Fork failed\n");
  } else {
    if (p == 0) { /* are we the child? */

      /*************************************************************
       *
       *   Trick needed here:  close all file descriptors to
       *   prevent subsequent crashes.  In particular, close the
       *   fd belonging to the X-server so when the exec'd proc
       *   exits, we don't lose the whole farm.
       *
       *************************************************************/

      rlim = g_malloc(sizeof(struct rlimit));
      getrlimit(RLIMIT_NOFILE, rlim);
      fprintf(stderr, "There seem to be %d open files\n", rlim->rlim_cur);
      for(i = fd = 0; i <= rlim->rlim_cur; i++) {
	if ((i != 2) && ((close(i) == 0))) {
	  fprintf(stderr, "Closed file descriptor %d\n", i);
	  fd++;  /* count successful closes */
	}
      }
      fprintf(stderr, "Closed %d files\nHighest fd was %d\n", fd, i);
      g_free(rlim);
      execlp (procname, procname, NULL);
      fprintf(stderr, "exec %s failed, %d\n", procname, errno);
      _exit(-1);
    }
  }
  pid = p;
  fprintf(stderr, "Pid = %d\n", pid);
  return pid;
}

This time was interesting, because it crashed without having
established a modem connection.  In the past, it's been able to
run killppp without crashing under these circs.

I must be missing something really obvious, but what???

All assistance greatly appreciated,

Jeff




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]