summaryrefslogtreecommitdiffstats
path: root/src/pulsecore
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-04-29 01:54:44 +0200
committerLennart Poettering <lennart@poettering.net>2009-04-29 01:54:44 +0200
commita8f0d7ec1e5cb3f52c4b1abfce1016ed6d9b00f8 (patch)
treeb2c7490f9a1b013b6afe9211a9ac842a5221364a /src/pulsecore
parent4abd5fae1431d47398d3b007fdceac5fda7607a8 (diff)
core-util: introduce pa_get_host_name_malloc() and pa_get_user_name_malloc()
Diffstat (limited to 'src/pulsecore')
-rw-r--r--src/pulsecore/core-util.c65
-rw-r--r--src/pulsecore/core-util.h3
2 files changed, 49 insertions, 19 deletions
diff --git a/src/pulsecore/core-util.c b/src/pulsecore/core-util.c
index 294f63cb..4658eb52 100644
--- a/src/pulsecore/core-util.c
+++ b/src/pulsecore/core-util.c
@@ -2467,31 +2467,29 @@ pa_bool_t pa_in_system_mode(void) {
return !!atoi(e);
}
-char *pa_machine_id(void) {
- FILE *f;
- size_t l;
-
- /* The returned value is supposed be some kind of ascii identifier
- * that is unique and stable across reboots. */
+char *pa_get_user_name_malloc(void) {
+ ssize_t k;
+ char *u;
- /* 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;
+#ifdef _SC_LOGIN_NAME_MAX
+ k = (ssize_t) sysconf(_SC_LOGIN_NAME_MAX);
- r = fgets(ln, sizeof(ln)-1, f);
- fclose(f);
+ if (k <= 0)
+#endif
+ k = 32;
- pa_strip_nl(ln);
+ u = pa_xnew(char, k+1);
- 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 +2523,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);
diff --git a/src/pulsecore/core-util.h b/src/pulsecore/core-util.h
index f96fa443..91a4c55a 100644
--- a/src/pulsecore/core-util.h
+++ b/src/pulsecore/core-util.h
@@ -201,6 +201,9 @@ pa_bool_t pa_in_system_mode(void);
#define pa_streq(a,b) (!strcmp((a),(b)))
+char *pa_get_host_name_malloc(void);
+char *pa_get_user_name_malloc(void);
+
char *pa_machine_id(void);
char *pa_session_id(void);
char *pa_uname_string(void);