summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon McVittie <simon.mcvittie@collabora.co.uk>2015-02-20 22:06:56 +0000
committerSimon McVittie <simon.mcvittie@collabora.co.uk>2015-02-24 11:16:13 +0000
commit71c11a9e487ec5c4b533371098201efb5d966961 (patch)
tree4a129a62c52a6322f76397b71decf29064756b30
parent2a6cefbc3bd3ed9392603da6a76b49c0dcba7e0d (diff)
downloaddbus-71c11a9e487ec5c4b533371098201efb5d966961.tar.gz
dbus-71c11a9e487ec5c4b533371098201efb5d966961.tar.bz2
dbus-71c11a9e487ec5c4b533371098201efb5d966961.zip
dbus-launch: use libdbus to read the UUID
As a side benefit, this means that dbus-launch now understands /etc/machine-id and not just /var/lib/dbus/machine-id. Since machine_uuid comes out of libdbus allocated with dbus_malloc, to avoid having to copy it from malloc-allocated to dbus_malloc-allocated storage, it makes sense to change it to be consistently dbus_malloc-allocated (particularly now that Bug #83115 has made use of internal symbols relatively painless). However, I'm deliberately not changing the allocation model of any other strings in dbus-launch right now; that's a larger yak-shaving exercise.
-rw-r--r--tools/Makefile.am16
-rw-r--r--tools/dbus-launch.c38
-rw-r--r--tools/dbus-launch.h2
3 files changed, 21 insertions, 35 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 68a59707..0743b52e 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -51,7 +51,17 @@ else
dbus_launch_SOURCES= \
dbus-launch.c \
dbus-launch-x11.c \
- dbus-launch.h
+ dbus-launch.h \
+ tool-common.c \
+ tool-common.h \
+ $(NULL)
+dbus_launch_CPPFLAGS = \
+ $(AM_CPPFLAGS) \
+ $(NULL)
+dbus_launch_LDADD = \
+ $(top_builddir)/dbus/libdbus-1.la \
+ $(DBUS_X_LIBS) \
+ $(NULL)
dbus_run_session_SOURCES = \
dbus-run-session.c
@@ -80,10 +90,6 @@ dbus_uuidgen_LDADD = \
$(top_builddir)/dbus/libdbus-1.la \
$(NULL)
-dbus_launch_LDADD = \
- $(DBUS_X_LIBS) \
- $(NULL)
-
examplesdir = ${docdir}/examples
dist_examples_SCRIPTS = \
GetAllMatchRules.py \
diff --git a/tools/dbus-launch.c b/tools/dbus-launch.c
index 41a20e83..604663e2 100644
--- a/tools/dbus-launch.c
+++ b/tools/dbus-launch.c
@@ -38,6 +38,9 @@
#include <sys/select.h>
#include <time.h>
+#include <dbus/dbus.h>
+#include "dbus/dbus-internals.h"
+
#ifdef DBUS_BUILD_X11
#include <X11/Xlib.h>
extern Display *xdisplay;
@@ -102,50 +105,25 @@ save_machine_uuid (const char *uuid_arg)
exit (1);
}
- machine_uuid = xstrdup (uuid_arg);
+ machine_uuid = _dbus_strdup (uuid_arg);
}
#ifdef DBUS_BUILD_X11
-#define UUID_MAXLEN 40
/* Read the machine uuid from file if needed. Returns TRUE if machine_uuid is
* set after this function */
static int
read_machine_uuid_if_needed (void)
{
- FILE *f;
- char uuid[UUID_MAXLEN];
- size_t len;
- int ret = FALSE;
-
if (machine_uuid != NULL)
return TRUE;
- f = fopen (DBUS_MACHINE_UUID_FILE, "r");
- if (f == NULL)
- return FALSE;
-
- if (fgets (uuid, UUID_MAXLEN, f) == NULL)
- goto out;
-
- len = strlen (uuid);
- if (len < 32)
- goto out;
+ machine_uuid = dbus_get_local_machine_id ();
- /* rstrip the read uuid */
- while (len > 31 && isspace((int) uuid[len - 1]))
- len--;
-
- if (len != 32)
- goto out;
+ if (machine_uuid == NULL)
+ return FALSE;
- uuid[len] = '\0';
- machine_uuid = xstrdup (uuid);
verbose ("UID: %s\n", machine_uuid);
- ret = TRUE;
-
-out:
- fclose(f);
- return ret;
+ return TRUE;
}
#endif /* DBUS_BUILD_X11 */
diff --git a/tools/dbus-launch.h b/tools/dbus-launch.h
index 8220bb8e..d0ede6ba 100644
--- a/tools/dbus-launch.h
+++ b/tools/dbus-launch.h
@@ -26,6 +26,8 @@
#include <sys/types.h>
+#include <dbus/dbus.h>
+
#ifndef TRUE
#define TRUE (1)
#endif