diff options
author | Bruce Guenter <bruce@untroubled.org> | 2016-01-18 12:04:41 -0600 |
---|---|---|
committer | Bruce Guenter <bruce@untroubled.org> | 2016-01-19 09:26:56 -0600 |
commit | b83af86a6fe9f308e51ed9528df700acce1626fd (patch) | |
tree | 3c4f4a8dd90206b0f3c50fc4f492cc9089a20063 /lib | |
parent | 84e4916f1a3fed45ac55611b342f661e9b0c7644 (diff) |
lib: Add program_path function for calculating program names
Diffstat (limited to 'lib')
-rw-r--r-- | lib/forkexec.cc | 24 | ||||
-rw-r--r-- | lib/forkexec.h | 3 |
2 files changed, 18 insertions, 9 deletions
diff --git a/lib/forkexec.cc b/lib/forkexec.cc index 750d7ac..55a7690 100644 --- a/lib/forkexec.cc +++ b/lib/forkexec.cc @@ -131,18 +131,24 @@ bool fork_exec::wait() return true; } -static const char* nqpath() +mystring program_path(const char* basedir, const char* program, const char* envvar) { - static mystring cache; - if (!cache) { + if (envvar) { const char* env; - if ((env = getenv("NULLMAILER_QUEUE")) != 0) - cache = env; - else { - cache = SBIN_DIR; - cache += "/nullmailer-queue"; - } + if ((env = getenv(envvar)) != NULL) + return env; } + mystring path = basedir; + path += '/'; + path += program; + return path; +} + +static const char* nqpath() +{ + static mystring cache; + if (!cache) + cache = program_path(SBIN_DIR, "nullmailer-queue", "NULLMAILER_QUEUE"); return cache.c_str(); } diff --git a/lib/forkexec.h b/lib/forkexec.h index 16091ab..7a83764 100644 --- a/lib/forkexec.h +++ b/lib/forkexec.h @@ -3,8 +3,11 @@ #include <sys/types.h> #include <sys/wait.h> +#include "mystring/mystring.h" #include "autoclose.h" +mystring program_path(const char* basedir, const char* name, const char* envvar); + #define REDIRECT_NULL -2 #define REDIRECT_PIPE_FROM -3 #define REDIRECT_PIPE_TO -4 |