summaryrefslogtreecommitdiffstats
path: root/src/pulsecore/core-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pulsecore/core-util.c')
-rw-r--r--src/pulsecore/core-util.c96
1 files changed, 73 insertions, 23 deletions
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 294f63cb..b747cd84 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -2235,7 +2235,7 @@ int pa_close_all(int except_fd, ...) {
int pa_close_allv(const int except_fds[]) {
struct rlimit rl;
- int fd;
+ int maxfd, fd;
int saved_errno;
#ifdef __linux__
@@ -2302,10 +2302,12 @@ int pa_close_allv(const int except_fds[]) {
#endif
- if (getrlimit(RLIMIT_NOFILE, &rl) < 0)
- return -1;
+ if (getrlimit(RLIMIT_NOFILE, &rl) >= 0)
+ maxfd = (int) rl.rlim_max;
+ else
+ maxfd = sysconf(_SC_OPEN_MAX);
- for (fd = 3; fd < (int) rl.rlim_max; fd++) {
+ for (fd = 3; fd < maxfd; fd++) {
int i;
pa_bool_t found;
@@ -2467,31 +2469,29 @@ pa_bool_t pa_in_system_mode(void) {
return !!atoi(e);
}
-char *pa_machine_id(void) {
- FILE *f;
- size_t l;
+char *pa_get_user_name_malloc(void) {
+ ssize_t k;
+ char *u;
- /* The returned value is supposed be some kind of ascii identifier
- * that is unique and stable across reboots. */
+#ifdef _SC_LOGIN_NAME_MAX
+ k = (ssize_t) sysconf(_SC_LOGIN_NAME_MAX);
- /* First we try the D-Bus UUID, which is the best option we have,
- * since it fits perfectly our needs and is not as volatile as the
- * hostname which might be set from dhcp. */
-
- if ((f = fopen(PA_MACHINE_ID, "r"))) {
- char ln[34] = "", *r;
+ if (k <= 0)
+#endif
+ k = 32;
- r = fgets(ln, sizeof(ln)-1, f);
- fclose(f);
+ u = pa_xnew(char, k+1);
- pa_strip_nl(ln);
-
- if (r && ln[0])
- return pa_utf8_filter(ln);
+ if (!(pa_get_user_name(u, k))) {
+ pa_xfree(u);
+ return NULL;
}
- /* The we fall back to the host name. It supposed to be somewhat
- * unique, at least in a network, but may change. */
+ return u;
+}
+
+char *pa_get_host_name_malloc(void) {
+ size_t l;
l = 100;
for (;;) {
@@ -2525,6 +2525,35 @@ char *pa_machine_id(void) {
l *= 2;
}
+ return NULL;
+}
+
+char *pa_machine_id(void) {
+ FILE *f;
+ char *h;
+
+ /* The returned value is supposed be some kind of ascii identifier
+ * that is unique and stable across reboots. */
+
+ /* First we try the D-Bus UUID, which is the best option we have,
+ * since it fits perfectly our needs and is not as volatile as the
+ * hostname which might be set from dhcp. */
+
+ if ((f = fopen(PA_MACHINE_ID, "r"))) {
+ char ln[34] = "", *r;
+
+ r = fgets(ln, sizeof(ln)-1, f);
+ fclose(f);
+
+ pa_strip_nl(ln);
+
+ if (r && ln[0])
+ return pa_utf8_filter(ln);
+ }
+
+ if ((h = pa_get_host_name_malloc()))
+ return h;
+
/* If no hostname was set we use the POSIX hostid. It's usually
* the IPv4 address. Might not be that stable. */
return pa_sprintf_malloc("%08lx", (unsigned long) gethostid);
@@ -2682,3 +2711,24 @@ char *pa_realpath(const char *path) {
return t;
}
+
+void pa_disable_sigpipe(void) {
+
+#ifdef SIGPIPE
+ struct sigaction sa;
+
+ pa_zero(sa);
+
+ if (sigaction(SIGPIPE, NULL, &sa) < 0) {
+ pa_log("sigaction(): %s", pa_cstrerror(errno));
+ return;
+ }
+
+ sa.sa_handler = SIG_IGN;
+
+ if (sigaction(SIGPIPE, &sa, NULL) < 0) {
+ pa_log("sigaction(): %s", pa_cstrerror(errno));
+ return;
+ }
+#endif
+}