3

I'm running a Java program as a daemon on Linux using Apache commons-daemon's jsvc.

The daemon "randomly" crashes with only message:

jsvc.exec error: Service did not exit cleanly

This is the relevant part of the code in jsvc (in jsvc-unix.c line 1142):

while (waitpid(pid, &status, 0) != pid) {
    /* Waith for process */
}

/* The child must have exited cleanly */
if (WIFEXITED(status)) {
    status = WEXITSTATUS(status);

    // Clean exit code...
}
else {
    if (WIFSIGNALED(status)) {
        log_error("Service killed by signal %d", WTERMSIG(status));
        /* prevent looping */
        if (laststart + 60 > time(NULL)) {
            log_debug("Waiting 60 s to prevent looping");
            sleep(60);
        }
        continue;
    }
    log_error("Service did not exit cleanly", status);
    return 1;
}

In which case can WIFEXITED and WIFSIGNALED both be false ? Is it guaranteed that the process was not killed in this case (by a process or Linux OOM killer) ?

nicoulaj
  • 3,463
  • 4
  • 27
  • 32

1 Answers1

1

WIFSTOPPED exists too, but it's only possible if the parent is ptrace:ing the child process (or with different flags to waitpid).

I think your best bet is to print the status and the look at the bits in sys/wait.h. It's quite hard to get it right though. Much information is being stuffed into that int and it's hard to figure it out. It looks like the code you pasted already tries to do that, but forgot the %d in the format string.

Art
  • 19,807
  • 1
  • 34
  • 60