From ce33a27c572f079599443cd26617af658e0f16dd Mon Sep 17 00:00:00 2001 From: bol-van Date: Thu, 14 Nov 2024 10:57:02 +0300 Subject: [PATCH] nfqws,tpws: set EXEDIR env var to use in @config --- nfq/helpers.c | 4 ++-- nfq/helpers.h | 2 +- nfq/nfqws.c | 2 ++ tpws/helpers.c | 15 +++++++++++++++ tpws/helpers.h | 2 ++ tpws/tpws.c | 1 + 6 files changed, 23 insertions(+), 3 deletions(-) diff --git a/nfq/helpers.c b/nfq/helpers.c index 274dfb3..aba018c 100644 --- a/nfq/helpers.c +++ b/nfq/helpers.c @@ -367,14 +367,14 @@ void fill_random_az09(uint8_t *p,size_t sz) } } -bool cd_to_exe_dir(const char *argv0) +bool set_env_exedir(const char *argv0) { char *s,*d; bool bOK=false; if ((s = strdup(argv0))) { if ((d = dirname(s))) - bOK = !chdir(d); + setenv("EXEDIR",s,1); free(s); } return bOK; diff --git a/nfq/helpers.h b/nfq/helpers.h index c011ad3..756bab6 100644 --- a/nfq/helpers.h +++ b/nfq/helpers.h @@ -75,7 +75,7 @@ void fill_random_bytes(uint8_t *p,size_t sz); void fill_random_az(uint8_t *p,size_t sz); void fill_random_az09(uint8_t *p,size_t sz); -bool cd_to_exe_dir(const char *argv0); +bool set_env_exedir(const char *argv0); struct cidr4 diff --git a/nfq/nfqws.c b/nfq/nfqws.c index 6d6eaf5..5346aa5 100644 --- a/nfq/nfqws.c +++ b/nfq/nfqws.c @@ -1122,6 +1122,8 @@ void config_from_file(const char *filename) int main(int argc, char **argv) { + set_env_exedir(argv[0]); + #ifdef __CYGWIN__ if (service_run(argc, argv)) { diff --git a/tpws/helpers.c b/tpws/helpers.c index 27425e4..94cff17 100644 --- a/tpws/helpers.c +++ b/tpws/helpers.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "helpers.h" @@ -349,6 +350,20 @@ bool pf_is_empty(const port_filter *pf) } +bool set_env_exedir(const char *argv0) +{ + char *s,*d; + bool bOK=false; + if ((s = strdup(argv0))) + { + if ((d = dirname(s))) + setenv("EXEDIR",s,1); + free(s); + } + return bOK; +} + + static void mask_from_preflen6_make(uint8_t plen, struct in6_addr *a) { if (plen >= 128) diff --git a/tpws/helpers.h b/tpws/helpers.h index e1bb919..ed84f5b 100644 --- a/tpws/helpers.h +++ b/tpws/helpers.h @@ -73,6 +73,8 @@ bool pf_in_range(uint16_t port, const port_filter *pf); bool pf_parse(const char *s, port_filter *pf); bool pf_is_empty(const port_filter *pf); +bool set_env_exedir(const char *argv0); + #ifndef IN_LOOPBACK #define IN_LOOPBACK(a) ((((uint32_t) (a)) & 0xff000000) == 0x7f000000) #endif diff --git a/tpws/tpws.c b/tpws/tpws.c index 9c9b342..8136da3 100644 --- a/tpws/tpws.c +++ b/tpws/tpws.c @@ -1447,6 +1447,7 @@ int main(int argc, char *argv[]) struct salisten_s list[MAX_BINDS]; char ip_port[48]; + set_env_exedir(argv[0]); srand(time(NULL)); mask_from_preflen6_prepare();