]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/core-util.c
core-util: Remove redundant check of directory permissions
[pulseaudio] / src / pulsecore / core-util.c
index 06c38841ac5dd5cda226291874c5198ee7e480f8..afd872f5d12c077ca42f1d75eca4aa0f64e2b267 100644 (file)
@@ -326,43 +326,33 @@ again:
         goto fail;
     }
 
-    if (!update_perms)
+    if (!update_perms) {
+        pa_assert_se(pa_close(fd) >= 0);
         return 0;
+    }
 
 #ifdef HAVE_FCHOWN
     if (uid == (uid_t) -1)
         uid = getuid();
     if (gid == (gid_t) -1)
         gid = getgid();
-    if (fchown(fd, uid, gid) < 0)
+    if (((st.st_uid != uid) || (st.st_gid != gid)) && fchown(fd, uid, gid) < 0) {
+        pa_assert_se(pa_close(fd) >= 0);
         goto fail;
+    }
 #endif
 
 #ifdef HAVE_FCHMOD
-    (void) fchmod(fd, m);
+    if (fchmod(fd, m) < 0) {
+        pa_assert_se(pa_close(fd) >= 0);
+        goto fail;
+    };
 #endif
 
     pa_assert_se(pa_close(fd) >= 0);
 }
-#endif
-
-#ifdef HAVE_LSTAT
-    if (lstat(dir, &st) < 0)
 #else
-    if (stat(dir, &st) < 0)
-#endif
-        goto fail;
-
-#ifndef OS_IS_WIN32
-    if (!S_ISDIR(st.st_mode) ||
-        (st.st_uid != uid) ||
-        (st.st_gid != gid) ||
-        ((st.st_mode & 0777) != m)) {
-        errno = EACCES;
-        goto fail;
-    }
-#else
-    pa_log_warn("Secure directory creation not supported on Win32.");
+    pa_log_warn("Secure directory creation not supported on this platform.");
 #endif
 
     return 0;
@@ -707,7 +697,7 @@ static int set_scheduler(int rtprio) {
 #ifdef HAVE_DBUS
     int r;
     long long rttime;
-#ifdef HAVE_SYS_RESOURCE_H
+#ifdef RLIMIT_RTTIME
     struct rlimit rl;
 #endif
     DBusError error;
@@ -749,7 +739,7 @@ static int set_scheduler(int rtprio) {
 
     rttime = rtkit_get_rttime_usec_max(bus);
     if (rttime >= 0) {
-#ifdef HAVE_SYS_RESOURCE_H
+#ifdef RLIMIT_RTTIME
         r = getrlimit(RLIMIT_RTTIME, &rl);
 
         if (r >= 0 && (long long) rl.rlim_max > rttime) {