]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
2555. [port] Solaris: mkdir(2) on tmpfs filesystems does not do the
authorMark Andrews <marka@isc.org>
Mon, 16 Feb 2009 00:13:02 +0000 (00:13 +0000)
committerMark Andrews <marka@isc.org>
Mon, 16 Feb 2009 00:13:02 +0000 (00:13 +0000)
                        error checks in the correct order resulting in the
                        wrong error code sometimes being returned. [RT #19249]

CHANGES
bin/named/unix/os.c

diff --git a/CHANGES b/CHANGES
index f3f7c2c56f7d82e49a4c4741eb91d09f197cb7b9..11d16ff39470731125b10c232fd424fb15bbe504 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,7 @@
+2555.  [port]          Solaris: mkdir(2) on tmpfs filesystems does not do the
+                       error checks in the correct order resulting in the
+                       wrong error code sometimes being returned. [RT #19249]
+                       
 2554.  [func]          dig: when emitting a hex dump also display the
                        corresponding characters. [RT #19258]
 
index 7c65f03f69f952629b13e5c3c034ddcc24623df2..f0ae1fcc47ecb372d271a12c53e1a9507eaf594d 100644 (file)
@@ -15,7 +15,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: os.c,v 1.90 2008/12/01 03:51:47 marka Exp $ */
+/* $Id: os.c,v 1.91 2009/02/16 00:13:02 marka Exp $ */
 
 /*! \file */
 
@@ -661,6 +661,44 @@ cleanup_pidfile(void) {
        pidfile = NULL;
 }
 
+static int
+mkdirpath(char *filename, void (*report)(const char *, ...)) {
+       char *slash = strrchr(filename, '/');
+       char strbuf[ISC_STRERRORSIZE];
+       unsigned int mode;
+
+       if (slash != NULL && slash != filename) {
+               struct stat sb;
+               *slash = '\0';
+
+               if (stat(filename, &sb) == -1) {
+                       if (errno != ENOENT) {
+                               isc__strerror(errno, strbuf, sizeof(strbuf));
+                               (*report)("couldn't stat '%s': %s", filename,
+                                         strbuf);
+                               goto error;
+                       }
+                       if (mkdirpath(filename, report) == -1) 
+                               goto error;
+                       mode = S_IRUSR | S_IWUSR | S_IXUSR;     /* u=rwx */
+                       mode |= S_IRGRP | S_IXGRP;              /* g=rx */
+                       mode |= S_IROTH | S_IXOTH;              /* o=rx */
+                       if (mkdir(filename, mode) == -1) {
+                               isc__strerror(errno, strbuf, sizeof(strbuf));
+                               (*report)("couldn't mkdir '%s': %s", filename,
+                                         strbuf);
+                               goto error;
+                       }
+               }
+               *slash = '/';
+       }
+       return (0);
+
+ error:
+       *slash = '/';
+       return (-1);
+}
+
 void
 ns_os_writepidfile(const char *filename, isc_boolean_t first_time) {
        int fd;
@@ -669,9 +707,6 @@ ns_os_writepidfile(const char *filename, isc_boolean_t first_time) {
        pid_t pid;
        char strbuf[ISC_STRERRORSIZE];
        void (*report)(const char *, ...);
-       unsigned int mode;
-       char *slash;
-       int n;
 
        /*
         * The caller must ensure any required synchronization.
@@ -691,28 +726,17 @@ ns_os_writepidfile(const char *filename, isc_boolean_t first_time) {
                (*report)("couldn't malloc '%s': %s", filename, strbuf);
                return;
        }
+
        /* This is safe. */
        strcpy(pidfile, filename);
 
        /*
         * Make the containing directory if it doesn't exist.
         */
-       slash = strrchr(pidfile, '/');
-       if (slash != NULL && slash != pidfile) {
-               *slash = '\0';
-               mode = S_IRUSR | S_IWUSR | S_IXUSR;     /* u=rwx */
-               mode |= S_IRGRP | S_IXGRP;              /* g=rx */
-               mode |= S_IROTH | S_IXOTH;              /* o=rx */
-               n = mkdir(pidfile, mode);
-               if (n == -1 && errno != EEXIST) {
-                       isc__strerror(errno, strbuf, sizeof(strbuf));
-                       (*report)("couldn't mkdir %s': %s", filename,
-                                 strbuf);
-                       free(pidfile);
-                       pidfile = NULL;
-                       return;
-               }
-               *slash = '/';
+       if (mkdirpath(pidfile, report) == -1) {
+               free(pidfile);
+               pidfile = NULL;
+               return;
        }
 
        fd = safe_open(filename, ISC_FALSE);