From: Alain Spineux Date: Thu, 16 Jul 2020 11:40:01 +0000 (+0200) Subject: Initialize the working_directory to a useful value until read from config file X-Git-Tag: Release-11.3.2~850 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e057965ddfbdd620104e47e815d24d42825dd972;p=thirdparty%2Fbacula.git Initialize the working_directory to a useful value until read from config file - to generate a backtrace in a valid directory - use /tmp by default or the Windows directory given by GetTempPath() --- diff --git a/bacula/src/dird/dird.c b/bacula/src/dird/dird.c index 98f66e9a5..c54d4f8cc 100644 --- a/bacula/src/dird/dird.c +++ b/bacula/src/dird/dird.c @@ -255,6 +255,7 @@ int main (int argc, char *argv[]) char *uid = NULL; char *gid = NULL; + init_working_directory(); /* DELETE ME when bugs in MA1512, MA1632 MA1639 are fixed */ MA1512_reload_job_end_cb = reload_job_end_cb; diff --git a/bacula/src/filed/filed.c b/bacula/src/filed/filed.c index 964a13821..d15962480 100644 --- a/bacula/src/filed/filed.c +++ b/bacula/src/filed/filed.c @@ -95,6 +95,7 @@ int main (int argc, char *argv[]) char *gid = NULL; mark_heap(); + init_working_directory(); setlocale(LC_ALL, ""); bindtextdomain("bacula", LOCALEDIR); textdomain("bacula"); diff --git a/bacula/src/lib/util.c b/bacula/src/lib/util.c index fe6dea5ae..66736f518 100644 --- a/bacula/src/lib/util.c +++ b/bacula/src/lib/util.c @@ -1005,7 +1005,27 @@ POOLMEM *edit_job_codes(JCR *jcr, POOLMEM *&omsg, char *imsg, const char *to, jo return omsg; } -void set_working_directory(char *wd) +/* initialize working_directory with a valid value until read from the config + * file, to have valid directory for backtrace + */ +void init_working_directory() +{ +#ifdef HAVE_WIN32 + static char tmp[MAX_PATH+1]; + int ret = GetTempPathA(sizeof(tmp), tmp); + if (ret != 0) { + working_directory = tmp; + } +#else + /* TMPDIR is the POSIX env variable, this is a better candidate than TMP */ + working_directory = getenv("TMPDIR"); + if (working_directory == NULL) { + working_directory = "/tmp"; + } +#endif +} + +void set_working_directory(const char *wd) { struct stat stat_buf; diff --git a/bacula/src/stored/stored.c b/bacula/src/stored/stored.c index 00280a907..3de4ff523 100644 --- a/bacula/src/stored/stored.c +++ b/bacula/src/stored/stored.c @@ -132,6 +132,7 @@ int main (int argc, char *argv[]) device_default_open_mode = omd_write; mark_heap(); + init_working_directory(); setlocale(LC_ALL, ""); bindtextdomain("bacula", LOCALEDIR); textdomain("bacula");