]> git.ipfire.org Git - thirdparty/unbound.git/commitdiff
- Fix for #724: conf syntax to read files from run dir (on Windows).
authorWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 30 Nov 2015 15:05:26 +0000 (15:05 +0000)
committerWouter Wijngaards <wouter@nlnetlabs.nl>
Mon, 30 Nov 2015 15:05:26 +0000 (15:05 +0000)
git-svn-id: file:///svn/unbound/trunk@3551 be551aaa-1e26-0410-a405-d3ace91eadb9

doc/Changelog
doc/unbound.conf.5.in
winrc/win_svc.c

index 7336ae9b42eb32d00852264810ebd30cdb4162b5..9dfb46055ae3d77dc268d2f6104448082832ac07 100644 (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.
 
index 1f81c1651117456352485b4f134df88a79c8592d..2941a30eccba3058cfd3946ab191f10406fa0e5d 100644 (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.
index 57a160d6ae73098d985ec0edf1543fd28f9162eb..8abb27871243762f61d9ae581487b70e62ffc95d 100644 (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);