what_exited = "unknown";
}
if (who_exited >= 0) {
- if (WIFEXITED(status)) {
- fprintf(stderr, "ctdlvisor: %d (%s) exited, exitcode=%d\n", who_exited, what_exited, WEXITSTATUS(status));
- }
- else if (WIFSIGNALED(status)) {
- fprintf(stderr, "ctdlvisor: %d (%s) crashed, signal=%d\n", who_exited, what_exited, WTERMSIG(status));
- }
- else {
- fprintf(stderr, "ctdlvisor: %d (%s) ended, status=%d\n", who_exited, what_exited, status);
- }
+ fprintf(stderr, "ctdlvisor: %d (%s) ended, status=%d\n", who_exited, what_exited, status);
}
} while (who_exited >= 0);
ctdlvisor_exit(0);
pid_t start_citadel() {
char bin[1024];
+ char backtrace_filename[PATH_MAX];
sprintf(bin, "%s/usr/local/citadel/citserver", getenv("APPDIR"));
pid_t pid = fork();
if (pid == 0) {
fprintf(stderr, "ctdlvisor: executing %s with data directory %s\n", bin, getenv("CTDL_DIR"));
detach_from_tty();
- execlp(bin, "citserver", "-x9", "-h", getenv("CTDL_DIR"), NULL);
+ sprintf(backtrace_filename, "/tmp/citserver-backtrace.%d", getpid());
+ execlp(bin, "citserver", "-x9", "-h", getenv("CTDL_DIR"), "-b", backtrace_filename, NULL);
exit(errno);
}
else {
// If it crashes, however, we will start it back up.
if (who_exited == citserver_pid) {
citserver_exit_code = WEXITSTATUS(status);
- if (citserver_exit_code == 0) {
+ if ((WIFEXITED(status)) && (citserver_exit_code == 0)) {
fprintf(stderr, "ctdlvisor: citserver exited normally - ending AppImage session\n");
shutting_down = 1;
kill(webcit_pid, SIGTERM);
kill(webcits_pid, SIGTERM);
}
- else if ((citserver_exit_code >= 101) && (citserver_exit_code <= 109)) {
+ else if ((WIFEXITED(status)) && (citserver_exit_code >= 101) && (citserver_exit_code <= 109)) {
fprintf(stderr, "ctdlvisor: citserver exited intentionally - ending AppImage session\n");
shutting_down = 1;
kill(webcit_pid, SIGTERM);
kill(webcits_pid, SIGTERM);
}
else {
+ if (WIFSIGNALED(status)) {
+ fprintf(stderr, "ctdlvisor: citserver crashed on signal %d\n", WTERMSIG(status));
+ }
citserver_pid = start_citadel();
}
}