mirror of
https://github.com/bol-van/zapret2.git
synced 2026-03-13 22:03:09 +00:00
nfqws2: --chdir
This commit is contained in:
@@ -1589,7 +1589,7 @@ static bool windivert_recv_exit(void)
|
||||
sigset_t pending;
|
||||
|
||||
// make signals working
|
||||
sigpending(&pending);
|
||||
usleep(0);
|
||||
|
||||
if (bQuit)
|
||||
{
|
||||
|
||||
@@ -659,7 +659,12 @@ bool set_env_exedir(const char *argv0)
|
||||
if ((s = strdup(argv0)))
|
||||
{
|
||||
if ((d = dirname(s)))
|
||||
{
|
||||
char d_abs[PATH_MAX];
|
||||
if (realpath(d, d_abs))
|
||||
d=d_abs;
|
||||
bOK = !setenv("EXEDIR", d, 1);
|
||||
}
|
||||
free(s);
|
||||
}
|
||||
return bOK;
|
||||
|
||||
19
nfq2/nfqws.c
19
nfq2/nfqws.c
@@ -1677,6 +1677,7 @@ static void exithelp(void)
|
||||
" --port=<port>\t\t\t\t\t\t; divert port\n"
|
||||
#endif
|
||||
" --daemon\t\t\t\t\t\t; daemonize\n"
|
||||
" --chdir[=path]\t\t\t\t\t\t; change current directory. if no path specified use EXEDIR\n"
|
||||
" --pidfile=<filename>\t\t\t\t\t; write pid to file\n"
|
||||
#ifndef __CYGWIN__
|
||||
" --user=<username>\t\t\t\t\t; drop root privs\n"
|
||||
@@ -1840,6 +1841,7 @@ enum opt_indices {
|
||||
IDX_PORT,
|
||||
#endif
|
||||
IDX_DAEMON,
|
||||
IDX_CHDIR,
|
||||
IDX_PIDFILE,
|
||||
#ifndef __CYGWIN__
|
||||
IDX_USER,
|
||||
@@ -1944,6 +1946,7 @@ static const struct option long_options[] = {
|
||||
[IDX_PORT] = {"port", required_argument, 0, 0},
|
||||
#endif
|
||||
[IDX_DAEMON] = {"daemon", no_argument, 0, 0},
|
||||
[IDX_CHDIR] = {"chdir", optional_argument, 0, 0},
|
||||
[IDX_PIDFILE] = {"pidfile", required_argument, 0, 0},
|
||||
#ifndef __CYGWIN__
|
||||
[IDX_USER] = {"user", required_argument, 0, 0},
|
||||
@@ -2249,6 +2252,22 @@ int main(int argc, char **argv)
|
||||
case IDX_DAEMON:
|
||||
params.daemon = true;
|
||||
break;
|
||||
case IDX_CHDIR:
|
||||
{
|
||||
const char *d = optarg ? optarg : getenv("EXEDIR");
|
||||
if (!d)
|
||||
{
|
||||
DLOG_ERR("chdir: directory unknown\n");
|
||||
exit_clean(1);
|
||||
}
|
||||
DLOG("changing dir to '%s'\n",d);
|
||||
if (chdir(d))
|
||||
{
|
||||
DLOG_PERROR("chdir");
|
||||
exit_clean(1);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IDX_PIDFILE:
|
||||
snprintf(params.pidfile, sizeof(params.pidfile), "%s", optarg);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user