[mw-devel] [Git][arthur/mw][master] Add a debug output option separate from --foreground

Andrew Price welshbyte at sucs.org
Wed Feb 15 22:52:58 GMT 2017


Andrew Price pushed to branch master at Justin Mitchell / mw


Commits:
42dd1040 by Andrew Price at 2017-02-15T22:52:53+00:00
Add a debug output option separate from --foreground

Sometimes it's useful to run the server in the foreground quietly.

- - - - -


1 changed file:

- src/server/mwserv.c


Changes:

=====================================
src/server/mwserv.c
=====================================
--- a/src/server/mwserv.c
+++ b/src/server/mwserv.c
@@ -27,6 +27,7 @@ static void usage(char *name)
 	       "[--foreground|-f]"
 	       "[--port|-p <port>]"
 	       "[--print-config|-P]"
+	       "[--debug|-D]"
 	       "\n", name);
 }
 
@@ -40,6 +41,7 @@ static const struct cfg_default_opt defcfgs[] = {
 	CFG_OPT(BOOL, "foreground", 0),
 	CFG_OPT(INT, "port", 9999),
 	CFG_OPT(STR, "user", MWUSER),
+	CFG_OPT(BOOL, "debug", 0),
 	CFG_END
 };
 
@@ -78,6 +80,7 @@ static int getconfig(int argc, char **argv)
 	static struct option loptspec[] = {
 		{"config",       required_argument, 0, 'c'},
 		{"foreground",   no_argument,       0, 'f'},
+		{"debug",        no_argument,       0, 'D'},
 		{"help",         no_argument,       0, 'h'},
 		{"print-config", no_argument,       0, 'P'},
 		{"port",         required_argument, 0, 'p'},
@@ -89,7 +92,7 @@ static int getconfig(int argc, char **argv)
 		return ret;
 
 	while (1) {
-		c = getopt_long(argc, argv, "c:fhPp:", loptspec, &optidx);
+		c = getopt_long(argc, argv, "c:fDhPp:", loptspec, &optidx);
 		if (c == -1)
 			break;
 
@@ -115,6 +118,9 @@ static int getconfig(int argc, char **argv)
 			case 'f':
 				cfg_set_bool("foreground", 1);
 				break;
+			case 'D':
+				cfg_set_bool("debug", 1);
+				break;
 			case 'h':
 				usage(argv[0]);
 				exit(0);
@@ -176,6 +182,10 @@ int main(int argc, char **argv)
 	}
 
 	migrate_old_folders();
+	if (!cfg_get_bool("debug")) {
+		freopen("/dev/null", "w", stdout);
+		freopen("/dev/null", "w", stderr);
+	}
 	if (cfg_get_bool("foreground"))
 		setlinebuf(stdout);
 	else



View it on GitLab: https://projects.sucs.org/arthur/mw/commit/42dd10400888430690457b9605ec54053fc328b1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sucs.org/pipermail/mw-devel/attachments/20170215/0ee1c135/attachment-0001.html>


More information about the mw-devel mailing list