@@ -46,14 +46,15 @@ static const char *flag_description[] = {
4646 "Set a configuration file to load and use" ,
4747 "Set the listening host address" ,
4848 "Set the listening port" ,
49- "Enable all logs, setting log level to DEBUG"
49+ "Enable all logs, setting log level to DEBUG" ,
50+ "Run in daemon mode"
5051};
5152
5253void print_help (char * me ) {
5354 printf ("\nSol v%s MQTT broker 3.1.1\n\n" , VERSION );
54- printf ("Usage: %s [-a addr] [-p port] [-c conf] [-v]\n\n" , me );
55- const char flags [5 ] = "hcapv " ;
56- for (int i = 0 ; i < 5 ; ++ i )
55+ printf ("Usage: %s [-a addr] [-p port] [-c conf] [-v|-d|-h ]\n\n" , me );
56+ const char flags [6 ] = "hcapvd " ;
57+ for (int i = 0 ; i < 6 ; ++ i )
5758 printf (" -%c: %s\n" , flags [i ], flag_description [i ]);
5859 printf ("\n" );
5960}
@@ -66,13 +67,13 @@ int main (int argc, char **argv) {
6667 char * addr = DEFAULT_HOSTNAME ;
6768 char * port = DEFAULT_PORT ;
6869 char * confpath = DEFAULT_CONF_PATH ;
69- int debug = 0 ;
70+ int debug = 0 , daemon = 0 ;
7071 int opt ;
7172
7273 // Set default configuration
7374 config_set_default ();
7475
75- while ((opt = getopt (argc , argv , "a:c:p:m:vhn :" )) != -1 ) {
76+ while ((opt = getopt (argc , argv , "a:c:p:m:vhdn :" )) != -1 ) {
7677 switch (opt ) {
7778 case 'a' :
7879 addr = optarg ;
@@ -88,6 +89,9 @@ int main (int argc, char **argv) {
8889 case 'v' :
8990 debug = 1 ;
9091 break ;
92+ case 'd' :
93+ daemon = 1 ;
94+ break ;
9195 case 'h' :
9296 print_help (argv [0 ]);
9397 exit (EXIT_SUCCESS );
@@ -107,6 +111,9 @@ int main (int argc, char **argv) {
107111
108112 sol_log_init (conf -> logpath );
109113
114+ if (daemon == 1 )
115+ daemonize ();
116+
110117 // Print configuration
111118 config_print ();
112119
0 commit comments