]> 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 49fcc0ff4b8d14d472e9d7f742804da052090a84..afd872f5d12c077ca42f1d75eca4aa0f64e2b267 100644 (file)
@@ -154,8 +154,6 @@ static fd_set nonblocking_fds;
 
 #ifdef OS_IS_WIN32
 
-#include "poll.h"
-
 /* Returns the directory of the current DLL, with '/bin/' removed if it is the last component */
 char *pa_win32_get_toplevel(HANDLE handle) {
     static char *toplevel = NULL;
@@ -328,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;
@@ -420,26 +408,13 @@ ssize_t pa_read(int fd, void *buf, size_t count, int *type) {
 #ifdef OS_IS_WIN32
 
     if (!type || *type == 0) {
-        int err;
         ssize_t r;
 
-retry:
         if ((r = recv(fd, buf, count, 0)) >= 0)
             return r;
 
-        err = WSAGetLastError();
-        if (err != WSAENOTSOCK) {
-            /* transparently handle non-blocking sockets, by waiting
-             * for readiness */
-            if (err == WSAEWOULDBLOCK) {
-                struct pollfd pfd;
-                pfd.fd = fd;
-                pfd.events = POLLIN;
-                if (pa_poll(&pfd, 1, -1) >= 0) {
-                    goto retry;
-                }
-            }
-            errno = err;
+        if (WSAGetLastError() != WSAENOTSOCK) {
+            errno = WSAGetLastError();
             return r;
         }
 
@@ -465,11 +440,7 @@ ssize_t pa_write(int fd, const void *buf, size_t count, int *type) {
 
     if (!type || *type == 0) {
         ssize_t r;
-#ifdef OS_IS_WIN32
-        int err;
 
-retry:
-#endif
         for (;;) {
             if ((r = send(fd, buf, count, MSG_NOSIGNAL)) < 0) {
 
@@ -483,19 +454,8 @@ retry:
         }
 
 #ifdef OS_IS_WIN32
-        err = WSAGetLastError();
-        if (err != WSAENOTSOCK) {
-            /* transparently handle non-blocking sockets, by waiting
-             * for readiness */
-            if (err == WSAEWOULDBLOCK) {
-                struct pollfd pfd;
-                pfd.fd = fd;
-                pfd.events = POLLOUT;
-                if (pa_poll(&pfd, 1, -1) >= 0) {
-                    goto retry;
-                }
-            }
-            errno = err;
+        if (WSAGetLastError() != WSAENOTSOCK) {
+            errno = WSAGetLastError();
             return r;
         }
 #else
@@ -737,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;
@@ -779,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) {
@@ -984,6 +944,7 @@ void pa_reset_priority(void) {
 }
 
 int pa_match(const char *expr, const char *v) {
+#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
     int k;
     regex_t re;
     int r;
@@ -1006,6 +967,10 @@ int pa_match(const char *expr, const char *v) {
         errno = EINVAL;
 
     return r;
+#else
+    errno = ENOSYS;
+    return -1;
+#endif
 }
 
 /* Try to parse a boolean string value.*/