summaryrefslogtreecommitdiffstats
path: root/src/pulse/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/pulse/util.c')
-rw-r--r--src/pulse/util.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/src/pulse/util.c b/src/pulse/util.c
index a5f0e8e2..c0911b51 100644
--- a/src/pulse/util.c
+++ b/src/pulse/util.c
@@ -1,5 +1,3 @@
-/* $Id$ */
-
/***
This file is part of PulseAudio.
@@ -55,6 +53,7 @@
#include <sys/prctl.h>
#endif
+#include <pulse/xmalloc.h>
#include <pulsecore/winsock.h>
#include <pulsecore/core-error.h>
#include <pulsecore/log.h>
@@ -64,7 +63,7 @@
#include "util.h"
char *pa_get_user_name(char *s, size_t l) {
- char *p;
+ const char *p;
char buf[1024];
#ifdef HAVE_PWD_H
@@ -74,7 +73,10 @@ char *pa_get_user_name(char *s, size_t l) {
pa_assert(s);
pa_assert(l > 0);
- if (!(p = getenv("USER")) && !(p = getenv("LOGNAME")) && !(p = getenv("USERNAME"))) {
+ if (!(p = (getuid() == 0 ? "root" : NULL)) &&
+ !(p = getenv("USER")) &&
+ !(p = getenv("LOGNAME")) &&
+ !(p = getenv("USERNAME"))) {
#ifdef HAVE_PWD_H
#ifdef HAVE_GETPWUID_R
@@ -110,12 +112,12 @@ char *pa_get_host_name(char *s, size_t l) {
pa_assert(s);
pa_assert(l > 0);
-
+
if (gethostname(s, l) < 0) {
pa_log("gethostname(): %s", pa_cstrerror(errno));
return NULL;
}
-
+
s[l-1] = 0;
return s;
}
@@ -172,13 +174,13 @@ char *pa_get_binary_name(char *s, size_t l) {
#ifdef __linux__
{
- int i;
- char path[PATH_MAX];
+ char *rp;
/* 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);
+ if ((rp = pa_readlink("/proc/self/exe"))) {
+ pa_strlcpy(s, pa_path_get_filename(rp), l);
+ pa_xfree(rp);
+ return s;
}
}
@@ -224,7 +226,7 @@ char *pa_get_fqdn(char *s, size_t l) {
pa_assert(s);
pa_assert(l > 0);
-
+
if (!pa_get_host_name(hn, sizeof(hn)))
return NULL;