Skip to content

Commit

Permalink
Fill the process environment with an BAREOS_CFGDIR
Browse files Browse the repository at this point in the history
When we parse a configfile we push the directory we found it in into the
process environment as BAREOS_CFGDIR so you can use that same directory
as %BAREOS_CFGDIR% on windows and $BAREOS_CFGDIR on UNIX when
referencing an other configfile in that same directory.
  • Loading branch information
Marco van Wieringen committed Feb 17, 2015
1 parent a4bb497 commit 2b47741
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
39 changes: 33 additions & 6 deletions src/lib/parse_conf.c
Expand Up @@ -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;
}
Expand Down
9 changes: 6 additions & 3 deletions src/win32/compat/include/mingwconfig.h
Expand Up @@ -130,19 +130,22 @@
#define HAVE_NANOSLEEP 1

/* Define to 1 if you have the <pwd.h> 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 <resolv.h> 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
Expand Down

0 comments on commit 2b47741

Please sign in to comment.