ocserv: added the --no-chdir command line option

This allows running on the background but without changing the
current directory.

Signed-off-by: Nikos Mavrogiannopoulos <nmav@gnutls.org>
This commit is contained in:
Nikos Mavrogiannopoulos
2018-05-10 20:03:08 +02:00
parent e1c3ed95b0
commit 579d99ee39
3 changed files with 8 additions and 1 deletions

View File

@@ -1371,12 +1371,14 @@ static void check_cfg(vhost_cfg_st *vhost, vhost_cfg_st *defvhost, unsigned sile
}
#define OPT_NO_CHDIR 1
static const struct option long_options[] = {
{"debug", 1, 0, 'd'},
{"config", 1, 0, 'c'},
{"pid-file", 1, 0, 'p'},
{"test-config", 0, 0, 't'},
{"foreground", 0, 0, 'f'},
{"no-chdir", 0, 0, OPT_NO_CHDIR},
{"help", 0, 0, 'h'},
{"version", 0, 0, 'v'},
{NULL, 0, 0, 0}
@@ -1395,6 +1397,7 @@ void usage(void)
fprintf(stderr, " -c, --config=file Configuration file for the server\n");
fprintf(stderr, " - file must exist\n");
fprintf(stderr, " -t, --test-config Test the provided configuration file\n");
fprintf(stderr, " --no-chdir Do not perform a chdir on daemonize\n");
fprintf(stderr, " -p, --pid-file=file Specify pid file for the server\n");
fprintf(stderr, " -v, --version output version information and exit\n");
fprintf(stderr, " -h, --help display extended usage information and exit\n\n");
@@ -1435,6 +1438,9 @@ int cmd_parser (void *pool, int argc, char **argv, struct list_head *head)
case 't':
test_only = 1;
break;
case OPT_NO_CHDIR:
vhost->perm_config.no_chdir = 1;
break;
case 'h':
usage();
exit(0);

View File

@@ -1345,7 +1345,7 @@ int main(int argc, char** argv)
#endif
if (GETPCONFIG(s)->foreground == 0) {
if (daemon(0, 0) == -1) {
if (daemon(GETPCONFIG(s)->no_chdir, 0) == -1) {
e = errno;
fprintf(stderr, "daemon failed: %s\n", strerror(e));
exit(1);

View File

@@ -378,6 +378,7 @@ struct perm_cfg_st {
unsigned int stats_reset_time;
unsigned foreground;
unsigned no_chdir;
unsigned debug;
char *ca;