[pulseaudio-commits] r1077 - in /trunk: configure.ac src/pulse/util.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Thu Jul 13 17:17:32 PDT 2006


Author: lennart
Date: Fri Jul 14 02:17:31 2006
New Revision: 1077

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1077&root=pulseaudio&view=rev
Log:
* fall back to prctl(PR_GET_NAME) in pa_get_binary_name() if readlink() fails
* call pa_path_get_filename() in all cases before returning in pa_get_binary_name(). We already did so on Win32, but didn't on Linux.

Modified:
    trunk/configure.ac
    trunk/src/pulse/util.c

Modified: trunk/configure.ac
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/configure.ac?rev=1077&root=pulseaudio&r1=1076&r2=1077&view=diff
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Fri Jul 14 02:17:31 2006
@@ -160,6 +160,8 @@
 
 AM_CONDITIONAL([HAVE_EVDEV], [test "x$HAVE_EVDEV" = "x1"])
 
+AC_CHECK_HEADERS([sys/prctl.h])
+
 # Solaris
 AC_CHECK_HEADERS([sys/filio.h])
 

Modified: trunk/src/pulse/util.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulse/util.c?rev=1077&root=pulseaudio&r1=1076&r2=1077&view=diff
==============================================================================
--- trunk/src/pulse/util.c (original)
+++ trunk/src/pulse/util.c Fri Jul 14 02:17:31 2006
@@ -49,6 +49,10 @@
 #include <windows.h>
 #endif
 
+#ifdef HAVE_SYS_PRCTL_H
+#include <sys/prctl.h>
+#endif
+
 #include "../pulsecore/winsock.h"
 
 #include <pulsecore/core-error.h>
@@ -152,28 +156,51 @@
 
 char *pa_get_binary_name(char *s, size_t l) {
 
+    assert(s);
+    assert(l);
+
+#if defined(OS_IS_WIN32)
+    {
+        char path[PATH_MAX];
+        
+        if (GetModuleFileName(NULL, path, PATH_MAX))
+            return pa_strlcpy(s, pa_path_get_filename(path), l);
+    }
+#endif
+    
 #ifdef HAVE_READLINK
-    char path[PATH_MAX];
-    int i;
-    assert(s && l);
-
-    /* This works on Linux only */
-    
-    snprintf(path, sizeof(path), "/proc/%u/exe", (unsigned) getpid());
-    if ((i = readlink(path, s, l-1)) < 0)
-        return NULL;
-
-    s[i] = 0;
-    return s;
-#elif defined(OS_IS_WIN32)
-    char path[PATH_MAX];
-    if (!GetModuleFileName(NULL, path, PATH_MAX))
-        return NULL;
-    pa_strlcpy(s, pa_path_get_filename(path), l);
-    return s;
-#else
+    {
+        int i;
+        char path[PATH_MAX];
+        /* This works on Linux only */
+        
+        if ((i = readlink("/proc/self/exe", path, sizeof(path)-1)) >= 0) {
+            path[i] = 0;
+            return pa_strlcpy(s, pa_path_get_filename(path), l);
+        }
+    }
+    
+#endif
+    
+#if defined(HAVE_SYS_PRCTL_H) && defined(PR_GET_NAME)
+    {
+
+        #ifndef TASK_COMM_LEN
+        /* Actually defined in linux/sched.h */
+        #define TASK_COMM_LEN 16
+        #endif
+
+        char tcomm[TASK_COMM_LEN+1];
+        memset(tcomm, 0, sizeof(tcomm));
+        
+        /* This works on Linux only */
+        if (prctl(PR_GET_NAME, (unsigned long) tcomm, 0, 0, 0) == 0)
+            return pa_strlcpy(s, tcomm, l);
+        
+    }
+#endif
+    
     return NULL;
-#endif
 }
 
 const char *pa_path_get_filename(const char *p) {




More information about the pulseaudio-commits mailing list