]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon: check if rundir is writeable
authorMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 12 Apr 2015 19:48:51 +0000 (21:48 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Sun, 12 Apr 2015 19:48:51 +0000 (21:48 +0200)
daemon/main.c

index ef5bc3790ad5eb8c63371a1cad78bc60b7cd6fc3..2cae4746e97317131d4a6e5b2ff4a84fb14c29ed 100644 (file)
@@ -76,7 +76,7 @@ static const char *set_addr(char *addr, int *port)
 
 int main(int argc, char **argv)
 {
-       const char *addr = "127.0.0.1";
+       const char *addr = NULL;
        int port = 53;
 
        /* Long options. */
@@ -108,12 +108,16 @@ int main(int argc, char **argv)
 
        /* Switch to rundir. */
        if (optind < argc) {
-               ret = chdir(argv[optind]);
+               const char *rundir = argv[optind];
+               if (access(rundir, W_OK) != 0) {
+                       fprintf(stderr, "[system] rundir '%s': not writeable\n", rundir);
+                       return EXIT_FAILURE;
+               }
+               ret = chdir(rundir);
                if (ret != 0) {
-                       fprintf(stderr, "[system] rundir '%s': %s\n", argv[optind], strerror(errno));
+                       fprintf(stderr, "[system] rundir '%s': %s\n", rundir, strerror(errno));
                        return EXIT_FAILURE;
                }
-               printf("[system] rundir '%s'\n", argv[optind]);
        }
 
        /* Block signals. */