httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r1206832 - /httpd/httpd/branches/2.4.x/modules/cache/mod_socache_dbm.c
Date Sun, 27 Nov 2011 20:29:00 GMT
Author: sf
Date: Sun Nov 27 20:28:59 2011
New Revision: 1206832

URL: http://svn.apache.org/viewvc?rev=1206832&view=rev
Log:
Merge r1206827:
Fix some warn_unused_result compiler warnings by checking the return code of
chown and logging an error if the error was not ENOENT.

Modified:
    httpd/httpd/branches/2.4.x/modules/cache/mod_socache_dbm.c

Modified: httpd/httpd/branches/2.4.x/modules/cache/mod_socache_dbm.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/cache/mod_socache_dbm.c?rev=1206832&r1=1206831&r2=1206832&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/cache/mod_socache_dbm.c (original)
+++ httpd/httpd/branches/2.4.x/modules/cache/mod_socache_dbm.c Sun Nov 27 20:28:59 2011
@@ -95,6 +95,23 @@ static const char *socache_dbm_create(ap
     return NULL;
 }
 
+static int try_chown(apr_pool_t *p, server_rec *s,
+                     const char *name, const char *suffix)
+{
+    if (suffix)
+        name = apr_pstrcat(p, name, suffix, NULL);
+    if (-1 == chown(name, ap_unixd_config.user_id,
+                    (gid_t)-1 /* no gid change */ ))
+    {
+        if (errno != ENOENT)
+            ap_log_error(APLOG_MARK, APLOG_ERR, APR_FROM_OS_ERROR(errno), s,
+                         "Can't change owner of %s", name);
+        return -1;
+    }
+    return 0;
+}
+
+
 static apr_status_t socache_dbm_init(ap_socache_instance_t *ctx,
                                      const char *namespace,
                                      const struct ap_socache_hints *hints,
@@ -140,21 +157,13 @@ static apr_status_t socache_dbm_init(ap_
      * cannot exactly determine the suffixes we try all possibilities.
      */
     if (geteuid() == 0 /* is superuser */) {
-        chown(ctx->data_file, ap_unixd_config.user_id, -1 /* no gid change */);
-        if (chown(apr_pstrcat(p, ctx->data_file, DBM_FILE_SUFFIX_DIR, NULL),
-                  ap_unixd_config.user_id, -1) == -1) {
-            if (chown(apr_pstrcat(p, ctx->data_file, ".db", NULL),
-                      ap_unixd_config.user_id, -1) == -1)
-                chown(apr_pstrcat(p, ctx->data_file, ".dir", NULL),
-                      ap_unixd_config.user_id, -1);
-        }
-        if (chown(apr_pstrcat(p, ctx->data_file, DBM_FILE_SUFFIX_PAG, NULL),
-                  ap_unixd_config.user_id, -1) == -1) {
-            if (chown(apr_pstrcat(p, ctx->data_file, ".db", NULL),
-                      ap_unixd_config.user_id, -1) == -1)
-                chown(apr_pstrcat(p, ctx->data_file, ".pag", NULL),
-                      ap_unixd_config.user_id, -1);
-        }
+        try_chown(p, s, ctx->data_file, NULL);
+        if (try_chown(p, s, ctx->data_file, DBM_FILE_SUFFIX_DIR))
+            if (try_chown(p, s, ctx->data_file, ".db"))
+                try_chown(p, s, ctx->data_file, ".dir");
+        if (try_chown(p, s, ctx->data_file, DBM_FILE_SUFFIX_PAG))
+            if (try_chown(p, s, ctx->data_file, ".db"))
+                try_chown(p, s, ctx->data_file, ".pag");
     }
 #endif
     socache_dbm_expire(ctx, s);



Mime
View raw message