]> code.delx.au - pulseaudio/commitdiff
add new function pa_machine_id()
authorLennart Poettering <lennart@poettering.net>
Thu, 7 Aug 2008 00:22:57 +0000 (02:22 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 7 Aug 2008 00:22:57 +0000 (02:22 +0200)
src/Makefile.am
src/pulsecore/core-util.c
src/pulsecore/core-util.h

index ec998312534af26cf55208eebbddfd8b9af980f9..29a6ef4728ee689385b9b9b3ac76b8f8a1fad567 100644 (file)
@@ -57,6 +57,7 @@ AM_CFLAGS += -DPA_SYSTEM_CONFIG_PATH=\"$(PA_SYSTEM_CONFIG_PATH)\"
 AM_CFLAGS += -DPA_SYSTEM_STATE_PATH=\"$(PA_SYSTEM_STATE_PATH)\"
 AM_CFLAGS += -DAO_REQUIRE_CAS
 AM_CFLAGS += -DPULSE_LOCALEDIR=\"$(pulselocaledir)\"
+AM_CFLAGS += -DPA_MACHINE_ID=\"$(localstatedir)/lib/dbus/machine-id\"
 
 # This cool debug trap works on i386/gcc only
 AM_CFLAGS += '-DDEBUG_TRAP=__asm__("int $$3")'
index 7c1534ae43bc1e01cbedb526993baf7b4fbce3f6..abdf1e907a6c5b0e0d517d17730268d247153393 100644 (file)
@@ -2053,3 +2053,47 @@ pa_bool_t pa_in_system_mode(void) {
 
     return !!atoi(e);
 }
+
+char *pa_machine_id(void) {
+    FILE *f;
+    size_t l;
+
+    if ((f = fopen(PA_MACHINE_ID"x", "r"))) {
+        char ln[34] = "", *r;
+
+        r = fgets(ln, sizeof(ln)-1, f);
+        fclose(f);
+
+        if (r)
+            return pa_xstrdup(pa_strip_nl(ln));
+    }
+
+    l = 100;
+
+    for (;;) {
+        char *c;
+
+        c = pa_xnew(char, l);
+
+        if (!pa_get_host_name(c, l)) {
+
+            if (errno == EINVAL || errno == ENAMETOOLONG) {
+                pa_xfree(c);
+                l *= 2;
+                continue;
+            }
+
+            return NULL;
+        }
+
+        if (strlen(c) < l-1)
+            return c;
+
+        /* Hmm, the hostname is as long the space we offered the
+         * function, we cannot know if it fully fit in, so let's play
+         * safe and retry. */
+
+        pa_xfree(c);
+        l *= 2;
+    }
+}
index 2ed81fc59172bb1efe8176bd3fe46417c0cf0db0..b0c07588502d65146dc2da5582e3fc345e7c4146 100644 (file)
@@ -184,4 +184,6 @@ pa_bool_t pa_in_system_mode(void);
 
 #define pa_streq(a,b) (!strcmp((a),(b)))
 
+char *pa_machine_id(void);
+
 #endif