1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
From: Simon McVittie <simon.mcvittie@collabora.co.uk>
Date: Tue, 17 Feb 2015 13:46:53 +0000
Subject: 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.
I'm using the "internal" (static) version of libdbus rather than
the shared version, because my next commit is going to need that
anyway.
---
tools/Makefile.am | 17 ++++++++++++-----
tools/dbus-launch.c | 36 ++++++++++--------------------------
tools/dbus-launch.h | 2 ++
3 files changed, 24 insertions(+), 31 deletions(-)
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 9046282..fafee1b 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -48,7 +48,18 @@ 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) \
+ -DDBUS_STATIC_BUILD \
+ $(NULL)
+dbus_launch_LDADD = \
+ $(top_builddir)/dbus/libdbus-internal.la \
+ $(DBUS_X_LIBS) \
+ $(NULL)
dbus_run_session_SOURCES = \
dbus-run-session.c
@@ -77,10 +88,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 41a20e8..1d9ab3e 100644
--- a/tools/dbus-launch.c
+++ b/tools/dbus-launch.c
@@ -106,46 +106,30 @@ save_machine_uuid (const char *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;
+ char *uuid;
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;
+ uuid = dbus_get_local_machine_id ();
- len = strlen (uuid);
- if (len < 32)
- goto out;
+ if (uuid == NULL)
+ return FALSE;
- /* rstrip the read uuid */
- while (len > 31 && isspace((int) uuid[len - 1]))
- len--;
+ /* one is allocated with malloc and the other with dbus_malloc so copy it */
+ machine_uuid = xstrdup (uuid);
- if (len != 32)
- goto out;
+ if (machine_uuid == NULL)
+ tool_oom ("reading machine UUID");
- uuid[len] = '\0';
- machine_uuid = xstrdup (uuid);
+ dbus_free (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 8220bb8..d0ede6b 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
|