diff --git a/src/lib/parse_conf.c b/src/lib/parse_conf.c index 3400da01ced..f1dee0dcafa 100644 --- a/src/lib/parse_conf.c +++ b/src/lib/parse_conf.c @@ -1374,39 +1374,66 @@ const char *get_default_configdir() * Returns false on error * true on OK, with full_path set to where config file should be */ -static bool -find_config_file(const char *config_file, char *full_path, int max_path) +static bool find_config_file(const char *config_file, char *full_path, int max_path) { - int file_length = strlen(config_file) + 1; + int dir_length, file_length; + const char *config_dir; +#if defined(HAVE_SETENV) || defined(HAVE_PUTENV) + char *bp; + POOL_MEM env_string(PM_NAME); +#endif /* * If a full path specified, use it */ + file_length = strlen(config_file) + 1; if (first_path_separator(config_file) != NULL) { if (file_length > max_path) { return false; } + bstrncpy(full_path, config_file, file_length); + +#ifdef HAVE_SETENV + pm_strcpy(env_string, config_file); + bp = (char *)last_path_separator(env_string.c_str()); + *bp = '\0'; + setenv("BAREOS_CFGDIR", env_string.c_str(), 1); +#elif HAVE_PUTENV + Mmsg(env_string, "BAREOS_CFGDIR=%s", config_file); + bp = (char *)last_path_separator(env_string.c_str()); + *bp = '\0'; + putenv(bstrdup(env_string.c_str())); +#endif + return true; } /* * config_file is default file name, now find default dir */ - const char *config_dir = get_default_configdir(); - int dir_length = strlen(config_dir); + config_dir = get_default_configdir(); + dir_length = strlen(config_dir); if ((dir_length + 1 + file_length) > max_path) { return false; } +#ifdef HAVE_SETENV + pm_strcpy(env_string, config_dir); + setenv("BAREOS_CFGDIR", env_string.c_str(), 1); +#elif HAVE_PUTENV + Mmsg(env_string, "BAREOS_CFGDIR=%s", config_dir); + putenv(bstrdup(env_string.c_str())); +#endif + memcpy(full_path, config_dir, dir_length + 1); if (!IsPathSeparator(full_path[dir_length - 1])) { full_path[dir_length++] = '/'; } - memcpy(&full_path[dir_length], config_file, file_length); + memcpy(full_path + dir_length, config_file, file_length); return true; } diff --git a/src/win32/compat/include/mingwconfig.h b/src/win32/compat/include/mingwconfig.h index a95cc627668..49ae62572d6 100644 --- a/src/win32/compat/include/mingwconfig.h +++ b/src/win32/compat/include/mingwconfig.h @@ -130,19 +130,22 @@ #define HAVE_NANOSLEEP 1 /* Define to 1 if you have the header file. */ -/*#define HAVE_PWD_H 1*/ +/* #undef HAVE_PWD_H */ /* Define to 1 if you have the `readdir_r' function. */ /* #undef HAVE_READDIR_R */ /* Define to 1 if you have the header file. */ -/*#define HAVE_RESOLV_H 1*/ +/* #undef HAVE_RESOLV_H */ /* Define to 1 if you have the `select' function. */ #define HAVE_SELECT 1 /* Define to 1 if you have the `setenv' function. */ -#define HAVE_SETENV 1 +/* #undef HAVE_SETENV */ + +/* Define to 1 if you have the `putenv' function. */ +#define HAVE_PUTENV 1 /* Define to 1 if you have the `setlocale' function. */ #undef HAVE_SETLOCALE