From: Wouter Wijngaards Date: Mon, 30 Nov 2015 15:05:26 +0000 (+0000) Subject: - Fix for #724: conf syntax to read files from run dir (on Windows). X-Git-Tag: release-1.5.7rc1~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12b29439f5b1e96ad401d195a363e2fa0eb5f3dd;p=thirdparty%2Funbound.git - 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 --- diff --git a/doc/Changelog b/doc/Changelog index 7336ae9b4..9dfb46055 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -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. diff --git a/doc/unbound.conf.5.in b/doc/unbound.conf.5.in index 1f81c1651..2941a30ec 100644 --- a/doc/unbound.conf.5.in +++ b/doc/unbound.conf.5.in @@ -444,6 +444,8 @@ requires privileges, then a reload will fail; a restart is needed. .TP .B directory: \fI 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 If "" is given, logging goes to stderr, or nowhere once daemonized. diff --git a/winrc/win_svc.c b/winrc/win_svc.c index 57a160d6a..8abb27871 100644 --- a/winrc/win_svc.c +++ b/winrc/win_svc.c @@ -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);