Open
Description
Related to #220, it was very hard to for me to find what exactly caused the exit, since in many cases there is no logging when exiting. In this case there was a log that I found eventually, but it took a while to track it down since it was only printing the exception message, nothing to identify where the exception occurred.
Potential patch (not a full one, there's probably more blind spots but it's a start):
diff --git a/src/main/main.cc b/src/main/main.cc
index 3aabf250..a2398cc5 100644
--- a/src/main/main.cc
+++ b/src/main/main.cc
@@ -149,7 +149,7 @@ bool initialize(const std::vector<RunTab> &tabs) {
break;
}
} catch (const std::exception &e) {
- safs_pretty_syslog(LOG_ERR, "%s", e.what());
+ safs::log_err("unhandled exception ({}): {}", typeid(e).name(), e.what());
isOk = false;
break;
}
@@ -684,18 +684,19 @@ void makedaemon() {
fflush(stdout);
fflush(stderr);
if (pipe(piped)<0) {
- safs_pretty_syslog(LOG_ERR, "pipe error");
+ safs::log_err("pipe error: {}", strerr(errno));
exit(SAUNAFS_EXIT_STATUS_ERROR);
}
f = fork();
if (f<0) {
- safs_pretty_errlog(LOG_ERR, "first fork error");
+ safs::log_err("pipe error: {}", strerr(errno));
exit(SAUNAFS_EXIT_STATUS_ERROR);
}
if (f>0) {
wait(&f); // just get child status - prevents child from being zombie during initialization stage
if (f) {
safs_pretty_syslog(LOG_ERR, "child status: %d",f);
+ safs::log_err("{}", strerr(errno));
exit(SAUNAFS_EXIT_STATUS_ERROR);
}
close(piped[1]);
@@ -706,12 +707,13 @@ void makedaemon() {
happy = fwrite(pipebuff,1,r-1,stderr);
(void)happy;
}
+ safs::log_err("pipe error: {}", strerr(errno));
exit(SAUNAFS_EXIT_STATUS_ERROR);
}
happy = fwrite(pipebuff,1,r,stderr);
(void)happy;
} else {
- safs_pretty_errlog(LOG_ERR,"error reading pipe");
+ safs::log_err("pipe error: {}", strerr(errno));
exit(SAUNAFS_EXIT_STATUS_ERROR);
}
}
@@ -721,9 +723,9 @@ void makedaemon() {
setpgid(0,getpid());
f = fork();
if (f<0) {
- safs_pretty_errlog(LOG_ERR,"second fork error");
+ safs::log_err("second fork error: {}", strerr(errno));
if (write(piped[1],"fork error\n",11)!=11) {
- safs_pretty_errlog(LOG_ERR,"pipe write error");
+ safs::log_err("pipe error: {}", strerr(errno));
}
close(piped[1]);
exit(SAUNAFS_EXIT_STATUS_ERROR);
@@ -953,7 +955,7 @@ int main(int argc,char **argv) {
if (chdir(wrkdir)<0) {
- safs_pretty_syslog(LOG_ERR,"can't set working directory to %s",wrkdir);
+ safs::log_err("can't set working directory to {}: {}", wrkdir, strerr(errno));
if (gRunAsDaemon) {
fputc(0,stderr);
close_msg_channel();
@@ -962,7 +964,7 @@ int main(int argc,char **argv) {
return SAUNAFS_EXIT_STATUS_ERROR;
} else {
if (runmode==RunMode::kStart || runmode==RunMode::kRestart) {
- safs_pretty_syslog(LOG_INFO,"changed working directory to: %s",wrkdir);
+ safs::log_info("changed working directory to: {}", wrkdir);
}
}
free(wrkdir);
@@ -972,6 +974,7 @@ int main(int argc,char **argv) {
eventloop_pollregister(signal_pipe_desc, signal_pipe_serv);
if (!initialize_early()) {
+ safs::log_err("couldn't initialize early functions");
if (gRunAsDaemon) {
fputc(0, stderr);
close_msg_channel();
@@ -983,6 +986,7 @@ int main(int argc,char **argv) {
// Only kStart should check for lock file consistency
FileLock fl(runmode, locktimeout);
if (fl.lockstatus() == FileLock::LockStatus::kFail) {
+ safs::log_err("couldn't not acquire lock on {}", fl.name());
if (gRunAsDaemon) {
fputc(0,stderr);
close_msg_channel();
@@ -1062,6 +1066,7 @@ int main(int argc,char **argv) {
ch=SAUNAFS_EXIT_STATUS_ERROR;
}
} else {
+ safs::log_err("couldn't initialize functions");
if (gRunAsDaemon) {
fputc(0,stderr);
close_msg_channel();