]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/pid.c
Remove unnecessary #includes
[pulseaudio] / src / pulsecore / pid.c
index ce8ef19bf1f043da1cf29e80e03509e71c14feb7..50968deace70d664ed62e1ed6c975bf13f052ef6 100644 (file)
@@ -6,7 +6,7 @@
 
   PulseAudio is free software; you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as
-  published by the Free Software Foundation; either version 2 of the
+  published by the Free Software Foundation; either version 2.1 of the
   License, or (at your option) any later version.
 
   PulseAudio is distributed in the hope that it will be useful, but
@@ -40,7 +40,6 @@
 #endif
 
 #include <pulse/xmalloc.h>
-#include <pulse/util.h>
 
 #include <pulsecore/core-error.h>
 #include <pulsecore/core-util.h>
@@ -81,17 +80,14 @@ static pid_t read_pid(const char *fn, int fd) {
 }
 
 static int open_pid_file(const char *fn, int mode) {
-    int fd = -1;
+    int fd;
 
     pa_assert(fn);
 
     for (;;) {
         struct stat st;
 
-        if ((fd = open(fn, mode
-#ifdef O_NOCTTY
-                       |O_NOCTTY
-#endif
+        if ((fd = pa_open_cloexec(fn, mode
 #ifdef O_NOFOLLOW
                        |O_NOFOLLOW
 #endif
@@ -123,8 +119,6 @@ static int open_pid_file(const char *fn, int mode) {
             fd = -1;
             goto fail;
         }
-
-        fd = -1;
     }
 
     return fd;
@@ -148,7 +142,7 @@ static int proc_name_ours(pid_t pid, const char *procname) {
 
     pa_snprintf(bn, sizeof(bn), "/proc/%lu/stat", (unsigned long) pid);
 
-    if (!(f = fopen(bn, "r"))) {
+    if (!(f = pa_fopen_cloexec(bn, "r"))) {
         pa_log_info("Failed to open %s: %s", bn, pa_cstrerror(errno));
         return -1;
     } else {
@@ -171,14 +165,14 @@ static int proc_name_ours(pid_t pid, const char *procname) {
         good = pa_startswith(stored, expected);
         pa_xfree(expected);
 
-#if !defined(__OPTIMIZE__)
+/*#if !defined(__OPTIMIZE__)*/
         if (!good) {
             /* libtool likes to rename our binary names ... */
             expected = pa_sprintf_malloc("%lu (lt-%s)", (unsigned long) pid, procname);
             good = pa_startswith(stored, expected);
             pa_xfree(expected);
         }
-#endif
+/*#endif*/
 
         return !!good;
     }
@@ -211,6 +205,7 @@ int pa_pid_file_create(const char *procname) {
     if ((pid = read_pid(fn, fd)) == (pid_t) -1)
         pa_log_warn("Corrupt PID file, overwriting.");
     else if (pid > 0) {
+        int ours = 1;
 
 #ifdef OS_IS_WIN32
         if ((process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid)) != NULL) {
@@ -218,11 +213,13 @@ int pa_pid_file_create(const char *procname) {
 #else
         if (kill(pid, 0) >= 0 || errno != ESRCH) {
 #endif
-            int ours = 1;
 
             if (procname)
-                if ((ours = proc_name_ours(pid, procname)) < 0)
+                if ((ours = proc_name_ours(pid, procname)) < 0) {
+                    pa_log_warn("Could not check to see if pid %lu is a pulseaudio process. "
+                                "Assuming it is and the daemon is already running.", (unsigned long) pid);
                     goto fail;
+                }
 
             if (ours) {
                 pa_log("Daemon already running.");