]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/core-util.c
core-util: Call fchown() only when necessary
[pulseaudio] / src / pulsecore / core-util.c
index 2efa280eebe6b7ccae0e85456c7e54c346fd6a2c..3e2c615ffa67c024e6d0e573e0009c0838223ba6 100644 (file)
@@ -326,16 +326,20 @@ 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