- Fix for #724: conf syntax to read files from run dir (on Windows).

git-svn-id: file:///svn/unbound/trunk@3551 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
Wouter Wijngaards 2015-11-30 15:05:26 +00:00
parent 2c36a9a8bf
commit 12b29439f5
3 changed files with 21 additions and 3 deletions

View file

@ -1,3 +1,6 @@
30 November 2015: Wouter
- Fix for #724: conf syntax to read files from run dir (on Windows).
25 November 2015: Wouter
- Fix for #720, fix unbound-control-setup windows batch file.

View file

@ -444,6 +444,8 @@ requires privileges, then a reload will fail; a restart is needed.
.TP
.B directory: \fI<directory>
Sets the working directory for the program. Default is "@UNBOUND_RUN_DIR@".
On Windows the string "%EXECUTABLE%" tries to change to the directory
that unbound.exe resides in.
.TP
.B logfile: \fI<filename>
If "" is given, logging goes to stderr, or nowhere once daemonized.

View file

@ -334,14 +334,27 @@ service_init(int r, struct daemon** d, struct config_file** c)
/* apply settings and init */
verbosity = cfg->verbosity + service_cmdline_verbose;
if(cfg->directory && cfg->directory[0]) {
if(chdir(cfg->directory)) {
char* dir = cfg->directory;
if(strcmp(dir, "%EXECUTABLE%") == 0) {
/* get executable path, and if that contains
* directories, snip off the filename part */
TCHAR dirbuf[2*MAX_PATH+4];
dirbuf[0] = 0;
if(!GetModuleFileName(NULL, path+1, MAX_PATH))
log_err("could not GetModuleFileName");
if(strrchr(dirbuf, '\\')) {
(strrchr(dirbuf, '\\'))[0] = 0;
} else log_err("GetModuleFileName had no path");
dir = dirbuf;
}
if(chdir(dir)) {
log_err("could not chdir to %s: %s",
cfg->directory, strerror(errno));
dir, strerror(errno));
if(errno != ENOENT)
return 0;
log_warn("could not change directory - continuing");
} else
verbose(VERB_QUERY, "chdir to %s", cfg->directory);
verbose(VERB_QUERY, "chdir to %s", dir);
}
log_init(cfg->logfile, cfg->use_syslog, cfg->chrootdir);
if(!r) report_status(SERVICE_START_PENDING, NO_ERROR, 2400);