diff --git a/examples/filelistd.c b/examples/filelistd.c index 228c38d..1a22eb9 100644 --- a/examples/filelistd.c +++ b/examples/filelistd.c @@ -325,9 +325,13 @@ int main(int argc, char **argv) sxhub_t *sxmphub = sxhub_create(); int port = DEFAULT_PORT; int opt; + int is_daemon = 0; - while((opt = getopt(argc, argv, "p:r:u:")) != -1) { + while((opt = getopt(argc, argv, "dp:r:u:")) != -1) { switch(opt) { + case 'd': + is_daemon = 1; + break; case 'p': port = atoi(optarg); break; @@ -339,7 +343,7 @@ int main(int argc, char **argv) break; default: fprintf(stderr, "usage: %s [-p ] -r -u \n", argv[0]); + " to SSL certificate> [-d]\n", argv[0]); return EINVAL; } } @@ -354,6 +358,12 @@ int main(int argc, char **argv) return EINVAL; } + /* become daemon if it's necessary */ + if (is_daemon && (opt = daemonize())) { + fprintf(stderr, "daemonize() failed (%d).\n Failure.\n", opt); + return EINVAL; + } + sxmp_init(); /* all is fine let's init connection subsystem */ diff --git a/examples/smpfd.c b/examples/smpfd.c index 1aa6ee0..0a75452 100644 --- a/examples/smpfd.c +++ b/examples/smpfd.c @@ -233,7 +233,8 @@ static void __help_print(FILE *fso, const char *fmtname) /* usage options */ fprintf(fso, "Usage:\n"); fprintf(fso, "\t%s -r | --root-x509 -u | --master-x509 " - " [-p | --listen-port ] [-R | --root-dir ]\n", fmtname); + " [-p | --listen-port ] [-R | --root-dir ] " + " [-d | --daemonize]\n", fmtname); /* defaults */ fprintf(fso, "\t%s -h | --help\n", fmtname); @@ -249,6 +250,7 @@ static void __help_print(FILE *fso, const char *fmtname) "-p | --listen-port ", DEFAULT_PORT); fprintf(fso, "\t%-33s Remote directory becoming root for user [default: %s].\n", "-R | --root-dir ", DEFAULT_ROOT_DIR); + fprintf(fso, "\t%-33s Work as a daemon.\n", "-d | --daemonize"); fprintf(fso, "\t%-33s Show help screen.\n", "-h | --help"); fprintf(fso, "\t%-33s Print version information.\n", "-v | --version"); return; @@ -511,6 +513,7 @@ int main(int argc, char **argv) sxhub_t *sxmphub = sxhub_create(); int port = DEFAULT_PORT; int opt; + int is_daemon = 0; while(1) { int option_index = 0; @@ -523,10 +526,11 @@ int main(int argc, char **argv) {"master-x509", required_argument, NULL, 'm'}, {"root-dir", required_argument, NULL, 'R'}, {"listen-port", required_argument, NULL, 'p'}, + {"daemonize", required_argument, NULL, 'd'}, { NULL, 0, NULL, 0 }, }; - if((opt = getopt_long(argc, argv, "hvr:m:R:p:", long_options, + if((opt = getopt_long(argc, argv, "dhvr:m:R:p:", long_options, &option_index)) == -1) break; switch(opt) { @@ -550,6 +554,9 @@ int main(int argc, char **argv) case 'R': root_dir = strdup(optarg); break; + case 'd': + is_daemon = 1; + break; } } @@ -565,6 +572,12 @@ int main(int argc, char **argv) return EINVAL; } + /* become daemon if it's necessary */ + if (is_daemon && (opt = daemonize())) { + fprintf(stderr, "daemonize() failed (%d).\n Failure.\n", opt); + return EINVAL; + } + sxmp_init(); /* all is fine let's init connection subsystem */ diff --git a/examples/streamfld.c b/examples/streamfld.c index 3402704..ca3f9d3 100644 --- a/examples/streamfld.c +++ b/examples/streamfld.c @@ -235,7 +235,7 @@ static void __help_print(FILE *fso, const char *fmtname) /* usage options */ fprintf(fso, "Usage:\n"); fprintf(fso, "\t%s -r | --root-x509 -u | --master-x509 " - " [-p | --listen-port ]\n", fmtname); + " [-p | --listen-port ] [-d | --daemonize]\n", fmtname); /* defaults */ fprintf(fso, "\t%s -h | --help\n", fmtname); @@ -249,6 +249,7 @@ static void __help_print(FILE *fso, const char *fmtname) "-m | --master-x509 "); fprintf(fso, "\t%-33s Remote host listening port number [default: %d].\n", "-p | --listen-port ", DEFAULT_PORT); + fprintf(fso, "\t%-33s Work as a daemon.\n", "-d | --daemonize"); fprintf(fso, "\t%-33s Show help screen.\n", "-h | --help"); fprintf(fso, "\t%-33s Print version information.\n", "-v | --version"); return; @@ -260,6 +261,7 @@ int main(int argc, char **argv) sxhub_t *sxmphub = sxhub_create(); int port = DEFAULT_PORT; int opt; + int is_daemon = 0; while(1) { int option_index = 0; @@ -271,10 +273,11 @@ int main(int argc, char **argv) {"root-x509", required_argument, NULL, 'r'}, {"master-x509", required_argument, NULL, 'm'}, {"listen-port", required_argument, NULL, 'p'}, + {"daemonize", required_argument, NULL, 'd'}, { NULL, 0, NULL, 0 }, }; - if((opt = getopt_long(argc, argv, "hvr:m:p:", long_options, + if((opt = getopt_long(argc, argv, "dhvr:m:p:", long_options, &option_index)) == -1) break; switch(opt) { @@ -295,6 +298,9 @@ int main(int argc, char **argv) case 'p': port = atoi(optarg); break; + case 'd': + is_daemon = 1; + break; } } @@ -310,6 +316,12 @@ int main(int argc, char **argv) return EINVAL; } + /* become daemon if it's necessary */ + if (is_daemon && (opt = daemonize())) { + fprintf(stderr, "daemonize() failed (%d).\n Failure.\n", opt); + return EINVAL; + } + sxmp_init(); /* all is fine let's init connection subsystem */