]> git.pond.sub.org Git - empserver/commitdiff
Fix crash dump not to mess up streams
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 9 Mar 2009 20:10:44 +0000 (21:10 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 9 Mar 2009 20:25:46 +0000 (21:25 +0100)
Crash dump forks a child to call abort().  abort() may flush or close
streams.  This is unwelcome, because it can mess up streams in the
parent.  Observed with the journal.  Could theoretically also affect
commands info, read, turn, and wire; announcement expiry, and reading
of econfig and schedule.

Fix by using SIGABRT instead.

Note that flushing streams before fork() is not a sufficient fix,
because closing a stream can still move the file descriptor's file
position.  Do it anyway, to ensure any buffered output is visible to
post_crash_dump_hook.

src/server/main.c

index 36d046e3ff71d401e1ffe65f94af99853529c1bd..b619fb20826267a71934b81726a39466e6aa9f89 100644 (file)
@@ -324,13 +324,14 @@ crash_dump(void)
     pid_t pid;
     int status;
 
+    fflush(NULL);
     pid = fork();
     if (pid < 0) {
        logerror("Can't fork for crash dump (%s)", strerror(errno));
        return;
     }
     if (pid == 0)
-       abort();                /* child */
+       raise(SIGABRT);         /* child */
 
     /* parent */
     while (waitpid(pid, &status, 0) < 0) {