Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hard to debug exit errors #221

Open
uristdwarf opened this issue Oct 16, 2024 · 0 comments
Open

Hard to debug exit errors #221

uristdwarf opened this issue Oct 16, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request Priority: Low Documentation, minor bug

Comments

@uristdwarf
Copy link
Collaborator

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();
@uristdwarf uristdwarf self-assigned this Oct 16, 2024
@uristdwarf uristdwarf added the enhancement New feature or request label Nov 1, 2024
uristdwarf added a commit that referenced this issue Nov 4, 2024
Improve logging to better debug errors and where they occured, also use
safs functions.

Closes #221
@uristdwarf uristdwarf added the Priority: Low Documentation, minor bug label Nov 7, 2024
uristdwarf added a commit that referenced this issue Nov 28, 2024
Improve logging to better debug errors and where they occured, also use
safs functions.

Closes #221
uristdwarf added a commit that referenced this issue Nov 28, 2024
Improve logging to better debug errors and where they occured, also use
safs functions.

Closes #221
ralcolea pushed a commit that referenced this issue Dec 27, 2024
Improve logging to better debug errors and where they occured, also use
safs functions.

Closes #221
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Priority: Low Documentation, minor bug
Projects
None yet
Development

No branches or pull requests

1 participant