Skip to contentSkip to conversation

enable stderr logging for mountd

PATCH New Denis Vlasenko 1 participant 1 message Mar 10, 2005

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 enable stderr logging for mountd

I run my daemons under daemontools.
In this setup, they are best run as foreground processes with logging to stout or stderr. mountd has some support for this, but it is commented out. Let's enable it.

Patch also fixes handling of failure to open("/dev/null").

A few comments:
* We need xlog_background() BEFORE xlog_open(), or else log won't be directed to stderr.
* no need to add "mountd:", it is added by xlog() itself.

Please apply.
--
vda

utils/mountd/mountd.c renamed from utils/mountd/mountd.c.orig +4 -3
@@ -531,7 +531,8 @@ main(int argc, char **argv)
 		}
 	}
 	/* Initialize logging. */
-/*	xlog_open("mountd"); */
+	if (!foreground) xlog_background();
+	xlog_open("mountd");
 
 	sa.sa_handler = SIG_IGN;
 	sa.sa_flags = 0;
@@ -576,20 +577,20 @@ main(int argc, char **argv)
 		if ((c = fork()) > 0)
 			exit(0);
 		if (c < 0) {
-			xlog(L_FATAL, "mountd: cannot fork: %s\n",
+			xlog(L_FATAL, "cannot fork: %s\n",
 						strerror(errno));
 		}
 		/* Now we remove ourselves from the foreground.
 		   Redirect stdin/stdout/stderr first. */
 		{
 			int fd = open("/dev/null", O_RDWR);
+			if (fd < 0) xlog(L_FATAL, "cannot open /dev/null");
 			(void) dup2(fd, 0);
 			(void) dup2(fd, 1);
 			(void) dup2(fd, 2);
 			if (fd > 2) (void) close(fd);
 		}
 		setsid();
-		xlog_background();
 	}
 
 	my_svc_run();