Template
1
0
mirror of https://github.com/bol-van/zapret2.git synced 2026-03-14 06:13:09 +00:00

nfqws2: --chdir

This commit is contained in:
bol-van
2026-02-14 16:08:01 +03:00
parent 6f6850707a
commit eb9a1e9f6b
3 changed files with 25 additions and 1 deletions

View File

@@ -1589,7 +1589,7 @@ static bool windivert_recv_exit(void)
sigset_t pending; sigset_t pending;
// make signals working // make signals working
sigpending(&pending); usleep(0);
if (bQuit) if (bQuit)
{ {

View File

@@ -659,7 +659,12 @@ bool set_env_exedir(const char *argv0)
if ((s = strdup(argv0))) if ((s = strdup(argv0)))
{ {
if ((d = dirname(s))) if ((d = dirname(s)))
{
char d_abs[PATH_MAX];
if (realpath(d, d_abs))
d=d_abs;
bOK = !setenv("EXEDIR", d, 1); bOK = !setenv("EXEDIR", d, 1);
}
free(s); free(s);
} }
return bOK; return bOK;

View File

@@ -1677,6 +1677,7 @@ static void exithelp(void)
" --port=<port>\t\t\t\t\t\t; divert port\n" " --port=<port>\t\t\t\t\t\t; divert port\n"
#endif #endif
" --daemon\t\t\t\t\t\t; daemonize\n" " --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" " --pidfile=<filename>\t\t\t\t\t; write pid to file\n"
#ifndef __CYGWIN__ #ifndef __CYGWIN__
" --user=<username>\t\t\t\t\t; drop root privs\n" " --user=<username>\t\t\t\t\t; drop root privs\n"
@@ -1840,6 +1841,7 @@ enum opt_indices {
IDX_PORT, IDX_PORT,
#endif #endif
IDX_DAEMON, IDX_DAEMON,
IDX_CHDIR,
IDX_PIDFILE, IDX_PIDFILE,
#ifndef __CYGWIN__ #ifndef __CYGWIN__
IDX_USER, IDX_USER,
@@ -1944,6 +1946,7 @@ static const struct option long_options[] = {
[IDX_PORT] = {"port", required_argument, 0, 0}, [IDX_PORT] = {"port", required_argument, 0, 0},
#endif #endif
[IDX_DAEMON] = {"daemon", no_argument, 0, 0}, [IDX_DAEMON] = {"daemon", no_argument, 0, 0},
[IDX_CHDIR] = {"chdir", optional_argument, 0, 0},
[IDX_PIDFILE] = {"pidfile", required_argument, 0, 0}, [IDX_PIDFILE] = {"pidfile", required_argument, 0, 0},
#ifndef __CYGWIN__ #ifndef __CYGWIN__
[IDX_USER] = {"user", required_argument, 0, 0}, [IDX_USER] = {"user", required_argument, 0, 0},
@@ -2249,6 +2252,22 @@ int main(int argc, char **argv)
case IDX_DAEMON: case IDX_DAEMON:
params.daemon = true; params.daemon = true;
break; 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: case IDX_PIDFILE:
snprintf(params.pidfile, sizeof(params.pidfile), "%s", optarg); snprintf(params.pidfile, sizeof(params.pidfile), "%s", optarg);
break; break;