From 37d930ac4afa9642b7b918b60ca0e0cb42b50682 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 10 Aug 2004 13:00:12 +0000 Subject: glib mainloop fix implement server status command support for sink_list/source_list in polyplib git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@110 fefdeb5f-60dc-0310-8127-8f9354f1896f --- polyp/util.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'polyp/util.c') diff --git a/polyp/util.c b/polyp/util.c index 98d91075..70766a06 100644 --- a/polyp/util.c +++ b/polyp/util.c @@ -33,6 +33,9 @@ #include #include #include +#include +#include +#include #include "util.h" #include "xmalloc.h" @@ -109,14 +112,27 @@ ssize_t pa_loop_write(int fd, const void*data, size_t size) { void pa_check_for_sigpipe(void) { struct sigaction sa; + sigset_t set; + + if (pthread_sigmask(SIG_SETMASK, NULL, &set) < 0) { + if (sigprocmask(SIG_SETMASK, NULL, &set) < 0) { + fprintf(stderr, __FILE__": sigprocmask() failed: %s\n", strerror(errno)); + return; + } + } + if (sigismember(&set, SIGPIPE)) + return; + if (sigaction(SIGPIPE, NULL, &sa) < 0) { fprintf(stderr, __FILE__": sigaction() failed: %s\n", strerror(errno)); return; } - if (sa.sa_handler == SIG_DFL) - fprintf(stderr, "polypaudio: WARNING: SIGPIPE is not trapped. This might cause malfunction!\n"); + if (sa.sa_handler != SIG_DFL) + return; + + fprintf(stderr, "polypaudio: WARNING: SIGPIPE is not trapped. This might cause malfunction!\n"); } /* The following is based on an example from the GNU libc documentation */ @@ -145,3 +161,30 @@ char *pa_sprintf_malloc(const char *format, ...) { size *= 2; } } + +char *pa_get_user_name(char *s, size_t l) { + struct passwd pw, *r; + char buf[1024]; + char *p; + + if (!(p = getenv("USER"))) + if (!(p = getenv("LOGNAME"))) + if (!(p = getenv("USERNAME"))) { + + if (getpwuid_r(getuid(), &pw, buf, sizeof(buf), &r) != 0 || !r) { + snprintf(s, l, "%lu", (unsigned long) getuid()); + return s; + } + + p = r->pw_name; + } + + snprintf(s, l, "%s", p); + return s; +} + +char *pa_get_host_name(char *s, size_t l) { + gethostname(s, l); + s[l-1] = 0; + return s; +} -- cgit