rpms/pulseaudio/F-9 pulseaudio-0.9.10-lock-file.patch, NONE, 1.1 pulseaudio.spec, 1.38, 1.39

Lennart Poettering lennart at fedoraproject.org
Tue Sep 9 19:44:15 UTC 2008


Author: lennart

Update of /cvs/pkgs/rpms/pulseaudio/F-9
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv6866

Modified Files:
	pulseaudio.spec 
Added Files:
	pulseaudio-0.9.10-lock-file.patch 
Log Message:
Fix lock file handling: properly check if the PID stored in our lock file actually belongs to us. Fixes #438284

pulseaudio-0.9.10-lock-file.patch:

--- NEW FILE pulseaudio-0.9.10-lock-file.patch ---
Index: src/pulsecore/pid.c
===================================================================
--- src/pulsecore/pid.c.orig
+++ src/pulsecore/pid.c
@@ -140,8 +140,51 @@ fail:
     return -1;
 }
 
+static int proc_name_ours(pid_t pid, const char *procname) {
+#ifdef __linux__
+    char bn[PATH_MAX];
+    FILE *f;
+
+    pa_snprintf(bn, sizeof(bn), "/proc/%lu/stat", (unsigned long) pid);
+
+    if (!(f = fopen(bn, "r"))) {
+        pa_log_info("Failed to open %s: %s", bn, pa_cstrerror(errno));
+        return -1;
+    } else {
+        char *expected;
+        pa_bool_t good;
+        char stored[64];
+
+        if (!(fgets(stored, sizeof(stored), f))) {
+            pa_log_info("Failed to read from %s: %s", bn, feof(f) ? "EOF" : pa_cstrerror(errno));
+            fclose(f);
+            return -1;
+        }
+
+        fclose(f);
+
+        expected = pa_sprintf_malloc("%lu (%s)", (unsigned long) pid, procname);
+        good = pa_startswith(stored, expected);
+        pa_xfree(expected);
+
+#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
+
+        return !!good;
+    }
+#endif
+
+    return 1;
+}
+
 /* Create a new PID file for the current process. */
-int pa_pid_file_create(void) {
+int pa_pid_file_create(const char *procname) {
     int fd = -1;
     int ret = -1;
     char fn[PATH_MAX];
@@ -161,14 +204,24 @@ int pa_pid_file_create(void) {
     if ((pid = read_pid(fn, fd)) == (pid_t) -1)
         pa_log_warn("Corrupt PID file, overwriting.");
     else if (pid > 0) {
+
 #ifdef OS_IS_WIN32
         if ((process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid)) != NULL) {
             CloseHandle(process);
 #else
         if (kill(pid, 0) >= 0 || errno != ESRCH) {
 #endif
-            pa_log("Daemon already running.");
-            goto fail;
+	    int ours = 1;
+
+            if (procname)
+                if ((ours = proc_name_ours(pid, procname)) < 0)
+                    goto fail;
+
+            if (ours) {
+                pa_log("Daemon already running.");
+                ret = 1;
+                goto fail;
+            }
         }
 
         pa_log_warn("Stale PID file, overwriting.");
@@ -270,7 +323,7 @@ int pa_pid_file_check_running(pid_t *pid
 /* Kill a current running daemon. Return non-zero on success, -1
  * otherwise. If successful *pid contains the PID of the daemon
  * process. */
-int pa_pid_file_kill(int sig, pid_t *pid, const char *binary_name) {
+int pa_pid_file_kill(int sig, pid_t *pid, const char *procname) {
     int fd = -1;
     char fn[PATH_MAX];
     int ret = -1;
@@ -290,19 +343,14 @@ int pa_pid_file_kill(int sig, pid_t *pid
         goto fail;
 
 #ifdef __linux__
-    if (binary_name) {
-        pa_snprintf(fn, sizeof(fn), "/proc/%lu/exe", (unsigned long) pid);
+    if (procname) {
+        int ours;
 
-        if ((e = pa_readlink(fn))) {
-            char *f = pa_path_get_filename(e);
-            if (strcmp(f, binary_name)
-#if defined(__OPTIMIZE__)
-                /* libtool likes to rename our binary names ... */
-                && !(pa_startswith(f, "lt-") && strcmp(f+3, binary_name) == 0)
-#endif
-            )
-                goto fail;
-        }
+	if ((ours = proc_name_ours(*pid, procname)) < 0)
+	    goto fail;
+
+	if (!ours)
+	    goto fail;
     }
 #endif
 
Index: src/pulsecore/pid.h
===================================================================
--- src/pulsecore/pid.h.orig
+++ src/pulsecore/pid.h
@@ -24,9 +24,9 @@
   USA.
 ***/
 
-int pa_pid_file_create(void);
+int pa_pid_file_create(const char *progname);
 int pa_pid_file_remove(void);
 int pa_pid_file_check_running(pid_t *pid, const char *binary_name);
-int pa_pid_file_kill(int sig, pid_t *pid, const char *binary_name);
+int pa_pid_file_kill(int sig, pid_t *pid, const char *progname);
 
 #endif
Index: src/daemon/main.c
===================================================================
--- src/daemon/main.c.orig
+++ src/daemon/main.c
@@ -687,7 +687,7 @@ int main(int argc, char *argv[]) {
         goto finish;
 
     if (conf->use_pid_file) {
-        if (pa_pid_file_create() < 0) {
+        if (pa_pid_file_create("pulseaudio") < 0) {
             pa_log("pa_pid_file_create() failed.");
 #ifdef HAVE_FORK
             if (conf->daemonize)


Index: pulseaudio.spec
===================================================================
RCS file: /cvs/pkgs/rpms/pulseaudio/F-9/pulseaudio.spec,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- pulseaudio.spec	30 Mar 2008 17:05:05 -0000	1.38
+++ pulseaudio.spec	9 Sep 2008 19:43:44 -0000	1.39
@@ -30,6 +30,7 @@
 #Patch7:	pulseaudio-0.9.8-ltdl-assert.patch
 #Patch8:	pulseaudio-0.9.8-disable-realtime.patch
 #Patch9:	pulseaudio-0.9.8-cputime-abort.patch
+Patch10:	pulseaudio-0.9.10-lock-file.patch
 
 %description
 PulseAudio is a sound server for Linux and other Unix like operating 
@@ -174,6 +175,7 @@
 #%patch7 -p0 -b .ltdl-assert
 #%patch8 -p1 -b .realtime
 #%patch9 -p1 -b .cputime-abort
+%patch10 -p0 -b .lock-file
 
 %build
 %configure --disable-ltdl-install --disable-static --disable-rpath --with-system-user=pulse --with-system-group=pulse --with-realtime-group=pulse-rt --with-access-group=pulse-access
@@ -399,6 +401,10 @@
 %{_mandir}/man1/pax11publish.1.gz
 
 %changelog
+* Thu Sep 9 2008 Lennart Poettering <lpoetter at redhat.com> 0.9.10-2
+- Fix lock file handling: properly check if the PID stored in our lock file
+  actually belongs to us. Fixes #438284
+
 * Sun Mar 30 2008 Lennart Poettering <lpoetter at redhat.com> 0.9.10-1
 - Update to PulseAudio 0.9.10
 - drop all patches, since they have been integrated upstream




More information about the fedora-extras-commits mailing list