Commit 42dd1040 authored by Andrew Price's avatar Andrew Price
Browse files

Add a debug output option separate from --foreground

Sometimes it's useful to run the server in the foreground quietly.
parent abc00bd1
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -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