[examples] Added daemonize option to services in examples;

v0.4.xx
leonid-ed 9 years ago
parent ce1fec47b2
commit 678afa32d7

@ -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 <PORTNUM>] -r <PATH to Root CA> -u <PATH"
" to SSL certificate>\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 */

@ -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 <path> -u | --master-x509 <path> "
" [-p | --listen-port <port>] [-R | --root-dir <directory>]\n", fmtname);
" [-p | --listen-port <port>] [-R | --root-dir <directory>] "
" [-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 <port>", DEFAULT_PORT);
fprintf(fso, "\t%-33s Remote directory becoming root for user [default: %s].\n",
"-R | --root-dir <directory>", 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 */

@ -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 <path> -u | --master-x509 <path> "
" [-p | --listen-port <port>]\n", fmtname);
" [-p | --listen-port <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 <path>");
fprintf(fso, "\t%-33s Remote host listening port number [default: %d].\n",
"-p | --listen-port <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 */

Loading…
Cancel
Save