[pulseaudio-commits] r1843 - in /branches/lennart: configure.ac src/Makefile.am src/daemon/main.c src/pulsecore/core-util.c src/pulsecore/core-util.h src/pulsecore/rtpoll.c src/tests/sig2str-test.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Mon Sep 17 08:26:20 PDT 2007


Author: lennart
Date: Mon Sep 17 17:26:18 2007
New Revision: 1843

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=1843&root=pulseaudio&view=rev
Log:
Rename pa_strsignal() to pa_sig2str(), since we return the symbolical signal name, not a human readable string. This follows the Solaris API of sig2str() a bit. Also, add all remaining signals to the list of signal names.

Added:
    branches/lennart/src/tests/sig2str-test.c   (with props)
Modified:
    branches/lennart/configure.ac
    branches/lennart/src/Makefile.am
    branches/lennart/src/daemon/main.c
    branches/lennart/src/pulsecore/core-util.c
    branches/lennart/src/pulsecore/core-util.h
    branches/lennart/src/pulsecore/rtpoll.c

Modified: branches/lennart/configure.ac
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/configure.ac?rev=1843&root=pulseaudio&r1=1842&r2=1843&view=diff
==============================================================================
--- branches/lennart/configure.ac (original)
+++ branches/lennart/configure.ac Mon Sep 17 17:26:18 2007
@@ -291,7 +291,7 @@
 
 # Non-standard
 
-AC_CHECK_FUNCS([setresuid setresgid setreuid setregid seteuid setegid ppoll])
+AC_CHECK_FUNCS([setresuid setresgid setreuid setregid seteuid setegid ppoll strsignal sig2str])
 
 #### POSIX threads ####
 

Modified: branches/lennart/src/Makefile.am
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/Makefile.am?rev=1843&root=pulseaudio&r1=1842&r2=1843&view=diff
==============================================================================
--- branches/lennart/src/Makefile.am (original)
+++ branches/lennart/src/Makefile.am Mon Sep 17 17:26:18 2007
@@ -235,7 +235,8 @@
 		asyncq-test \
 		asyncmsgq-test \
 		queue-test \
-		rtpoll-test
+		rtpoll-test \
+		sig2str-test
 
 if HAVE_SIGXCPU
 noinst_PROGRAMS += \
@@ -374,6 +375,11 @@
 interpol_test_LDADD = $(AM_LDADD) libpulse.la
 interpol_test_CFLAGS = $(AM_CFLAGS)
 interpol_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
+
+sig2str_test_SOURCES = tests/sig2str-test.c
+sig2str_test_LDADD = $(AM_LDADD) libpulsecore.la
+sig2str_test_CFLAGS = $(AM_CFLAGS)
+sig2str_test_LDFLAGS = $(AM_LDFLAGS) $(BINLDFLAGS)
 
 ###################################
 #         Client library          #

Modified: branches/lennart/src/daemon/main.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/daemon/main.c?rev=1843&root=pulseaudio&r1=1842&r2=1843&view=diff
==============================================================================
--- branches/lennart/src/daemon/main.c (original)
+++ branches/lennart/src/daemon/main.c Mon Sep 17 17:26:18 2007
@@ -130,7 +130,7 @@
 #endif
 
 static void signal_callback(pa_mainloop_api*m, PA_GCC_UNUSED pa_signal_event *e, int sig, void *userdata) {
-    pa_log_info("Got signal %s.", pa_strsignal(sig));
+    pa_log_info("Got signal %s.", pa_sig2str(sig));
 
     switch (sig) {
 #ifdef SIGUSR1

Modified: branches/lennart/src/pulsecore/core-util.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/core-util.c?rev=1843&root=pulseaudio&r1=1842&r2=1843&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/core-util.c (original)
+++ branches/lennart/src/pulsecore/core-util.c Mon Sep 17 17:26:18 2007
@@ -90,6 +90,7 @@
 #include <pulsecore/winsock.h>
 #include <pulsecore/log.h>
 #include <pulsecore/macro.h>
+#include <pulsecore/thread.h>
 
 #include "core-util.h"
 
@@ -411,9 +412,9 @@
     if (sa.sa_handler != SIG_DFL)
         return;
 
-    pa_log_warn("%s is not trapped. This might cause malfunction!", pa_strsignal(sig));
+    pa_log_warn("%s is not trapped. This might cause malfunction!", pa_sig2str(sig));
 #else /* HAVE_SIGACTION */
-    pa_log_warn("%s might not be trapped. This might cause malfunction!", pa_strsignal(sig));
+    pa_log_warn("%s might not be trapped. This might cause malfunction!", pa_sig2str(sig));
 #endif
 }
 
@@ -616,31 +617,93 @@
     return pa_xstrndup(current, l);
 }
 
-/* Return the name of an UNIX signal. Similar to GNU's strsignal() */
-const char *pa_strsignal(int sig) {
+PA_STATIC_TLS_DECLARE(signame, pa_xfree);
+
+/* Return the name of an UNIX signal. Similar to Solaris sig2str() */
+const char *pa_sig2str(int sig) {
+    char *t;
+
+    if (sig <= 0 || sig >= _NSIG)
+        goto fail;
+    
+#ifdef HAVE_SIG2STR
+    {
+        char buf[SIG2STR_MAX];
+        
+        if (str2sig(sig, buf) == 0) {
+            pa_xfree(PA_STATIC_TLS_GET(signame));
+            t = pa_sprintf_malloc("SIG%s", buf);
+            PA_STATIC_TLS_SET(signame, t);
+            return t;
+        }
+    }
+#else
+
     switch(sig) {
-        case SIGINT: return "SIGINT";
-        case SIGTERM: return "SIGTERM";
+#ifdef SIGHUP
+        case SIGHUP:    return "SIGHUP";
+#endif
+        case SIGINT:    return "SIGINT";
+        case SIGQUIT:   return "SIGQUIT";
+        case SIGILL:    return "SIGULL";
+        case SIGTRAP:   return "SIGTRAP";
+        case SIGABRT:   return "SIGABRT";
+        case SIGBUS:    return "SIGBUS";
+        case SIGFPE:    return "SIGFPE";
+        case SIGKILL:   return "SIGKILL";
 #ifdef SIGUSR1
-        case SIGUSR1: return "SIGUSR1";
-#endif
+        case SIGUSR1:   return "SIGUSR1";
+#endif
+        case SIGSEGV:   return "SIGSEGV";
 #ifdef SIGUSR2
-        case SIGUSR2: return "SIGUSR2";
-#endif
+        case SIGUSR2:   return "SIGUSR2";
+#endif
+#ifdef SIGPIPE
+        case SIGPIPE:   return "SIGPIPE";
+#endif
+        case SIGALRM:   return "SIGALRM";
+        case SIGTERM:   return "SIGTERM";
+        case SIGSTKFLT: return "SIGSTKFLT";
+#ifdef SIGCHLD
+        case SIGCHLD:   return "SIGCHLD";
+#endif
+        case SIGCONT:   return "SIGCONT";
+        case SIGSTOP:   return "SIGSTOP";
+        case SIGTSTP:   return "SIGTSTP";
+        case SIGTTIN:   return "SIGTTIN";
+        case SIGTTOU:   return "SIGTTOU";
+        case SIGURG:    return "SIGURG";
 #ifdef SIGXCPU
-        case SIGXCPU: return "SIGXCPU";
-#endif
-#ifdef SIGPIPE
-        case SIGPIPE: return "SIGPIPE";
-#endif
-#ifdef SIGCHLD
-        case SIGCHLD: return "SIGCHLD";
-#endif
-#ifdef SIGHUP
-        case SIGHUP: return "SIGHUP";
-#endif
-        default: return "UNKNOWN SIGNAL";
-    }
+        case SIGXCPU:   return "SIGXCPU";
+#endif
+#ifdef SIGXFSZ
+        case SIGXFSZ:   return "SIGXFSZ";
+#endif
+        case SIGVTALRM: return "SIGVTALRM";
+        case SIGPROF:   return "SIGPROF";
+        case SIGWINCH:  return "SIGWINCH";
+        case SIGIO:     return "SIGIO";
+        case SIGPWR:    return "SIGPWR";
+        case SIGSYS:    return "SIGSYS";
+    }
+
+#ifdef SIGRTMIN
+    if (sig >= SIGRTMIN && sig <= SIGRTMAX) {
+        pa_xfree(PA_STATIC_TLS_GET(signame));
+        t = pa_sprintf_malloc("SIGRTMIN+%i", sig - SIGRTMIN);
+        PA_STATIC_TLS_SET(signame, t);
+        return t;
+    }
+#endif        
+    
+#endif
+
+fail:
+
+    pa_xfree(PA_STATIC_TLS_GET(signame));
+    t = pa_sprintf_malloc("SIG%i", sig);
+    PA_STATIC_TLS_SET(signame, t);
+    return t;
 }
 
 #ifdef HAVE_GRP_H

Modified: branches/lennart/src/pulsecore/core-util.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/core-util.h?rev=1843&root=pulseaudio&r1=1842&r2=1843&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/core-util.h (original)
+++ branches/lennart/src/pulsecore/core-util.h Mon Sep 17 17:26:18 2007
@@ -68,7 +68,7 @@
 
 char *pa_strip_nl(char *s);
 
-const char *pa_strsignal(int sig) PA_GCC_PURE;
+const char *pa_sig2str(int sig) PA_GCC_PURE;
 
 int pa_own_uid_in_group(const char *name, gid_t *gid);
 int pa_uid_in_group(uid_t uid, const char *name);

Modified: branches/lennart/src/pulsecore/rtpoll.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/rtpoll.c?rev=1843&root=pulseaudio&r1=1842&r2=1843&view=diff
==============================================================================
--- branches/lennart/src/pulsecore/rtpoll.c (original)
+++ branches/lennart/src/pulsecore/rtpoll.c Mon Sep 17 17:26:18 2007
@@ -157,7 +157,7 @@
         return;
     }
 
-    pa_log_debug("Acquired POSIX realtime signal SIGRTMIN+%i", p->rtsig - SIGRTMIN);
+    pa_log_debug("Acquired POSIX realtime signal %s", pa_sig2str(p->rtsig));
 
     {
         sigset_t ss;

Added: branches/lennart/src/tests/sig2str-test.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/tests/sig2str-test.c?rev=1843&root=pulseaudio&view=auto
==============================================================================
--- branches/lennart/src/tests/sig2str-test.c (added)
+++ branches/lennart/src/tests/sig2str-test.c Mon Sep 17 17:26:18 2007
@@ -1,0 +1,39 @@
+/* $Id$ */
+
+/***
+  This file is part of PulseAudio.
+
+  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 License,
+  or (at your option) any later version.
+
+  PulseAudio is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with PulseAudio; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+  USA.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <signal.h>
+#include <stdio.h>
+
+#include <pulsecore/macro.h>
+#include <pulsecore/core-util.h>
+
+int main(int argc, char *argv[]) {
+    int sig;
+    
+    for (sig = -1; sig < _NSIG+1; sig++)
+        printf("%i = %s\n", sig, pa_sig2str(sig));
+
+    return 0;
+}

Propchange: branches/lennart/src/tests/sig2str-test.c
------------------------------------------------------------------------------
    svn:keywords = Id




More information about the pulseaudio-commits mailing list