[Sheepdog] [PATCH 3/3] sheep: do not automatically log to syslog if run in foreground

Christoph Hellwig hch at infradead.org
Wed Apr 25 08:59:29 CEST 2012


Add a new --stdout option to explicitly chose logging to stdout instead of
automatically selecting it when running in foreground.  Many daemons like
upstart, supervisord or systemd prefer programs to not daemonize, but don't
nessecarily handle logging to stdout very well.  To support these better
allow running in foreground while still logging to syslog.

Signed-off-by: Christoph Hellwig <hch at lst.de>

Index: sheepdog/include/logger.h
===================================================================
--- sheepdog.orig/include/logger.h	2012-04-25 08:46:09.236042174 +0200
+++ sheepdog/include/logger.h	2012-04-25 08:49:23.200047143 +0200
@@ -46,7 +46,8 @@ struct logarea {
 	int fd;
 };
 
-extern int log_init(char * progname, int size, int daemon, int level, char *outfile);
+extern int log_init(char *progname, int size, int to_stdout, int level,
+		char *outfile);
 extern void log_close(void);
 extern void dump_logmsg(void *);
 extern void log_write(int prio, const char *func, int line, const char *fmt, ...)
Index: sheepdog/lib/logger.c
===================================================================
--- sheepdog.orig/lib/logger.c	2012-04-25 08:46:25.692042596 +0200
+++ sheepdog/lib/logger.c	2012-04-25 08:47:22.236044041 +0200
@@ -397,7 +397,8 @@ static notrace void crash_handler(int si
 	exit(1);
 }
 
-notrace int log_init(char *program_name, int size, int is_daemon, int level, char *outfile)
+notrace int log_init(char *program_name, int size, int to_stdout, int level,
+		char *outfile)
 {
 	off_t offset;
 	size_t log_size;
@@ -410,7 +411,7 @@ notrace int log_init(char *program_name,
 
 	semkey = random();
 
-	if (is_daemon) {
+	if (!to_stdout) {
 		struct sigaction sa_old;
 		struct sigaction sa_new;
 		int fd;
Index: sheepdog/sheep/sheep.c
===================================================================
--- sheepdog.orig/sheep/sheep.c	2012-04-25 08:46:09.236042174 +0200
+++ sheepdog/sheep/sheep.c	2012-04-25 08:47:22.236044041 +0200
@@ -34,22 +34,23 @@ LIST_HEAD(cluster_drivers);
 static char program_name[] = "sheep";
 
 static struct option const long_options[] = {
-	{"port", required_argument, NULL, 'p'},
-	{"foreground", no_argument, NULL, 'f'},
-	{"loglevel", required_argument, NULL, 'l'},
+	{"asyncflush", no_argument, NULL, 'a'},
+	{"cluster", required_argument, NULL, 'c'},
 	{"debug", no_argument, NULL, 'd'},
 	{"directio", no_argument, NULL, 'D'},
-	{"asyncflush", no_argument, NULL, 'a'},
+	{"foreground", no_argument, NULL, 'f'},
 	{"nr_gateway_worker", required_argument, NULL, 'g'},
+	{"help", no_argument, NULL, 'h'},
 	{"nr_io_worker", required_argument, NULL, 'i'},
-	{"zone", required_argument, NULL, 'z'},
+	{"loglevel", required_argument, NULL, 'l'},
+	{"stdout", no_argument, NULL, 'o'},
+	{"port", required_argument, NULL, 'p'},
 	{"vnodes", required_argument, NULL, 'v'},
-	{"cluster", required_argument, NULL, 'c'},
-	{"help", no_argument, NULL, 'h'},
+	{"zone", required_argument, NULL, 'z'},
 	{NULL, 0, NULL, 0},
 };
 
-static const char *short_options = "p:fl:dDag:i:z:v:c:h";
+static const char *short_options = "ac:dDfg:hi:l:op:v:z:";
 
 static void usage(int status)
 {
@@ -61,18 +62,18 @@ static void usage(int status)
 Sheepdog daemon (version %s)\n\
 Usage: %s [OPTION]... [PATH]\n\
 Options:\n\
-  -p, --port              specify the TCP port on which to listen\n\
-  -f, --foreground        make the program run in the foreground\n\
-  -l, --loglevel          specify the level of logging detail\n\
+  -a, --asyncflush        flush the object cache asynchronously\n\
+  -c, --cluster           specify the cluster driver\n\
   -d, --debug             include debug messages in the log\n\
   -D, --directio          use direct IO when accessing the object from object cache\n\
-  -a, --asyncflush        flush the object cache asynchronously\n\
+  -f, --foreground        make the program run in the foreground\n\
   -g, --nr_gateway_worker set the number of workers for Guests' requests (default 4)\n\
+  -h, --help              display this help and exit\n\
   -i, --nr_io_worker      set the number of workers for sheep internal requests (default 4)\n\
-  -z, --zone              specify the zone id\n\
+  -l, --loglevel          specify the level of logging detail\n\
+  -p, --port              specify the TCP port on which to listen\n\
   -v, --vnodes            specify the number of virtual nodes\n\
-  -c, --cluster           specify the cluster driver\n\
-  -h, --help              display this help and exit\n\
+  -z, --zone              specify the zone id\n\
 ", PACKAGE_VERSION, program_name);
 	exit(status);
 }
@@ -101,6 +102,7 @@ int main(int argc, char **argv)
 	int ret, port = SD_LISTEN_PORT;
 	const char *dir = DEFAULT_OBJECT_DIR;
 	int is_daemon = 1;
+	int to_stdout = 0;
 	int log_level = SDOG_INFO;
 	char path[PATH_MAX];
 	int64_t zone = -1;
@@ -163,6 +165,9 @@ int main(int argc, char **argv)
 				exit(1);
 			}
 			break;
+		case 'o':
+			to_stdout = 1;
+			break;
 		case 'z':
 			zone = strtol(optarg, &p, 10);
 			if (optarg == p || zone < 0 || UINT32_MAX < zone) {
@@ -219,7 +224,7 @@ int main(int argc, char **argv)
 	if (ret)
 		exit(1);
 
-	ret = log_init(program_name, LOG_SPACE_SIZE, is_daemon, log_level, path);
+	ret = log_init(program_name, LOG_SPACE_SIZE, to_stdout, log_level, path);
 	if (ret)
 		exit(1);
 



More information about the sheepdog mailing list