[systemd-commits] 25 commits - configure.ac Makefile.am man/systemd-udevd.service.xml man/udev.xml src/core src/import src/journal src/libsystemd src/libsystemd-network src/resolve src/run src/shared src/test src/timesync src/udev
David Herrmann
dvdhrm at kemper.freedesktop.org
Wed Jun 10 11:36:05 PDT 2015
Makefile.am | 3
configure.ac | 1
man/systemd-udevd.service.xml | 2
man/udev.xml | 3
src/core/manager.c | 2
src/core/namespace.c | 3
src/core/selinux-access.c | 2
src/import/importd.c | 2
src/journal/journald-server.c | 2
src/journal/journald-stream.c | 32 ++-------
src/libsystemd-network/sd-dhcp-client.c | 2
src/libsystemd-network/sd-dhcp-server.c | 2
src/libsystemd/sd-bus/bus-bloom.c | 10 ++
src/libsystemd/sd-bus/bus-container.c | 2
src/libsystemd/sd-bus/bus-control.c | 29 +++++---
src/libsystemd/sd-bus/bus-creds.c | 13 +--
src/libsystemd/sd-bus/bus-internal.c | 30 +++++++-
src/libsystemd/sd-bus/bus-internal.h | 2
src/libsystemd/sd-bus/bus-kernel.c | 1
src/libsystemd/sd-bus/bus-message.c | 21 ------
src/libsystemd/sd-bus/bus-message.h | 2
src/libsystemd/sd-bus/bus-socket.c | 88 ++++++--------------------
src/libsystemd/sd-bus/sd-bus.c | 28 ++++----
src/libsystemd/sd-bus/test-bus-gvariant.c | 2
src/libsystemd/sd-bus/test-bus-kernel-bloom.c | 25 ++++++-
src/libsystemd/sd-bus/test-bus-marshal.c | 2
src/libsystemd/sd-bus/test-bus-signature.c | 13 ++-
src/libsystemd/sd-network/sd-network.c | 8 +-
src/libsystemd/sd-rtnl/rtnl-message.c | 2
src/resolve/resolved-dns-stream.c | 3
src/resolve/resolved-manager.c | 2
src/run/run.c | 2
src/shared/macro.h | 3
src/shared/util.c | 4 -
src/test/test-copy.c | 35 ++++++++++
src/timesync/timesyncd-manager.c | 2
src/udev/udevd.c | 2
37 files changed, 204 insertions(+), 183 deletions(-)
New commits:
commit 4061eed4d91226f1f75e79350c5e1bdd4529d578
Author: Mike Gilbert <floppym at gentoo.org>
Date: Tue Jun 9 23:13:36 2015 -0400
Include tools/compile-unifont.py in the source tarball
This prevents a build failure when /usr/share/fonts/unifont/unifont.hex
is newer than unifont-glyph-array.bin.
diff --git a/Makefile.am b/Makefile.am
index 5d30d7d..e98e8b8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3603,6 +3603,9 @@ test_unifont_LDADD = \
src/libsystemd-terminal/unifont-glyph-array.bin: tools/compile-unifont.py $(UNIFONT)
$(AM_V_GEN)$(PYTHON) $< <$(UNIFONT) >$@
+EXTRA_DIST += \
+ tools/compile-unifont.py
+
# ------------------------------------------------------------------------------
include_HEADERS += \
src/libudev/libudev.h
commit 26589352b2c7c067da0917ce95d5b31657ee7446
Author: David Herrmann <dh.herrmann at gmail.com>
Date: Wed Jun 10 20:14:56 2015 +0200
bus: we now support path_namespace=/
Our bloom-filters support root-path matching. Make sure we properly add
the path_namespace= tag.
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index c6d9621..7a59702 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -1291,10 +1291,8 @@ int bus_add_match_internal_kernel(
break;
case BUS_MATCH_PATH_NAMESPACE:
- if (!streq(c->value_str, "/")) {
- bloom_add_pair(bloom, bus->bloom_size, bus->bloom_n_hash, "path-slash-prefix", c->value_str);
- using_bloom = true;
- }
+ bloom_add_pair(bloom, bus->bloom_size, bus->bloom_n_hash, "path-slash-prefix", c->value_str);
+ using_bloom = true;
break;
case BUS_MATCH_ARG...BUS_MATCH_ARG_LAST: {
diff --git a/src/libsystemd/sd-bus/test-bus-kernel-bloom.c b/src/libsystemd/sd-bus/test-bus-kernel-bloom.c
index 01f784f..90eb1f2 100644
--- a/src/libsystemd/sd-bus/test-bus-kernel-bloom.c
+++ b/src/libsystemd/sd-bus/test-bus-kernel-bloom.c
@@ -123,6 +123,7 @@ int main(int argc, char *argv[]) {
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/foo'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/quux'", false);
+ test_one("/", "waldo.com", "Piep", false, "foobar", "path_namespace='/'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo/'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/'", false);
commit 744dccdd361afff8220221c1d385cf54aeb823e0
Author: David Herrmann <dh.herrmann at gmail.com>
Date: Wed Jun 10 19:34:05 2015 +0200
bus: fix pattern matching
DBus-spec defines two different pattern matchings:
1) Path and namespace prefix matching. In this case, A matches B either
if both are equal, or if B is fully included in the namespace of A.
In other words, A has to be a prefix of B, but end with a separator
character (or the following character in B must be one).
This is used for path_namespace= and arg0namespace=
2) The other pattern matching is used for arg0path= which does a two-way
matching. That is, A must be a prefix of B, or B a prefix of A.
Furthermore, the prefix must end with a separator.
Fix the sd-bus helpers to reflect that. The 'simple_' and 'complex_'
prefixes don't make any sense now, but.. eh..
diff --git a/src/libsystemd/sd-bus/bus-internal.c b/src/libsystemd/sd-bus/bus-internal.c
index 91b288c..37793e4 100644
--- a/src/libsystemd/sd-bus/bus-internal.c
+++ b/src/libsystemd/sd-bus/bus-internal.c
@@ -211,6 +211,17 @@ bool member_name_is_valid(const char *p) {
return true;
}
+/*
+ * Complex pattern match
+ * This checks whether @a is a 'complex-prefix' of @b, or @b is a
+ * 'complex-prefix' of @a, based on strings that consist of labels with @c as
+ * spearator. This function returns true if:
+ * - both strings are equal
+ * - either is a prefix of the other and ends with @c
+ * The second rule makes sure that either string needs to be fully included in
+ * the other, and the string which is considered the prefix needs to end with a
+ * separator.
+ */
static bool complex_pattern_check(char c, const char *a, const char *b) {
bool separator = false;
@@ -222,9 +233,7 @@ static bool complex_pattern_check(char c, const char *a, const char *b) {
for (;;) {
if (*a != *b)
- return (separator && (*a == 0 || *b == 0)) ||
- (*a == 0 && *b == c && b[1] == 0) ||
- (*b == 0 && *a == c && a[1] == 0);
+ return (separator && (*a == 0 || *b == 0));
if (*a == 0)
return true;
@@ -243,7 +252,18 @@ bool path_complex_pattern(const char *pattern, const char *value) {
return complex_pattern_check('/', pattern, value);
}
+/*
+ * Simple pattern match
+ * This checks whether @a is a 'simple-prefix' of @b, based on strings that
+ * consist of labels with @c as separator. This function returns true, if:
+ * - if @a and @b are equal
+ * - if @a is a prefix of @b, and the first following character in @b (or the
+ * last character in @a) is @c
+ * The second rule basically makes sure that if @a is a prefix of @b, then @b
+ * must follow with a new label separated by @c. It cannot extend the label.
+ */
static bool simple_pattern_check(char c, const char *a, const char *b) {
+ bool separator = false;
if (!a && !b)
return true;
@@ -253,11 +273,13 @@ static bool simple_pattern_check(char c, const char *a, const char *b) {
for (;;) {
if (*a != *b)
- return *a == 0 && *b == c;
+ return *a == 0 && (*b == c || separator);
if (*a == 0)
return true;
+ separator = *a == c;
+
a++, b++;
}
}
diff --git a/src/libsystemd/sd-bus/test-bus-kernel-bloom.c b/src/libsystemd/sd-bus/test-bus-kernel-bloom.c
index 8ebbbfa..01f784f 100644
--- a/src/libsystemd/sd-bus/test-bus-kernel-bloom.c
+++ b/src/libsystemd/sd-bus/test-bus-kernel-bloom.c
@@ -124,5 +124,15 @@ int main(int argc, char *argv[]) {
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/quux'", false);
+ test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/bar/waldo/'", false);
+ test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path='/foo/'", false);
+ test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/foo/bar/waldo/'", false);
+ test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "foobar", "path_namespace='/foo/'", true);
+
+ test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "/foo/bar/waldo", "arg0path='/foo/'", true);
+ test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "/foo", "arg0path='/foo'", true);
+ test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "/foo", "arg0path='/foo/bar/waldo'", false);
+ test_one("/foo/bar/waldo", "waldo.com", "Piep", false, "/foo/", "arg0path='/foo/bar/waldo'", true);
+
return 0;
}
diff --git a/src/libsystemd/sd-bus/test-bus-signature.c b/src/libsystemd/sd-bus/test-bus-signature.c
index 4165c92..17c6188 100644
--- a/src/libsystemd/sd-bus/test-bus-signature.c
+++ b/src/libsystemd/sd-bus/test-bus-signature.c
@@ -95,23 +95,28 @@ int main(int argc, char *argv[]) {
assert_se(!namespace_complex_pattern("foo.", ""));
assert_se(path_complex_pattern("", ""));
- assert_se(path_complex_pattern("", "/"));
- assert_se(path_complex_pattern("/", ""));
+ assert_se(!path_complex_pattern("", "/"));
+ assert_se(!path_complex_pattern("/", ""));
assert_se(path_complex_pattern("/", "/"));
assert_se(path_complex_pattern("/foobar/", "/"));
- assert_se(path_complex_pattern("/foobar/", "/foobar"));
+ assert_se(!path_complex_pattern("/foobar/", "/foobar"));
assert_se(path_complex_pattern("/foobar", "/foobar"));
- assert_se(path_complex_pattern("/foobar", "/foobar/"));
+ assert_se(!path_complex_pattern("/foobar", "/foobar/"));
assert_se(!path_complex_pattern("/foobar", "/foobar/waldo"));
assert_se(path_complex_pattern("/foobar/", "/foobar/waldo"));
+ assert_se(path_complex_pattern("/foobar/waldo", "/foobar/"));
+
+ assert_se(path_simple_pattern("/foo/", "/foo/bar/waldo"));
assert_se(namespace_simple_pattern("", ""));
+ assert_se(namespace_simple_pattern("", ".foobar"));
assert_se(namespace_simple_pattern("foobar", "foobar"));
assert_se(namespace_simple_pattern("foobar.waldo", "foobar.waldo"));
assert_se(namespace_simple_pattern("foobar", "foobar.waldo"));
assert_se(!namespace_simple_pattern("foobar.waldo", "foobar"));
assert_se(!namespace_simple_pattern("", "foo"));
assert_se(!namespace_simple_pattern("foo", ""));
+ assert_se(namespace_simple_pattern("foo.", "foo.bar.waldo"));
assert_se(streq(object_path_startswith("/foo/bar", "/foo"), "bar"));
assert_se(streq(object_path_startswith("/foo", "/foo"), ""));
commit 2e90f867f994a2c9ff3a6d268305ce666420d83b
Author: David Herrmann <dh.herrmann at gmail.com>
Date: Wed Jun 10 18:47:31 2015 +0200
bus: fix test-bus-kerne-bloom.c to match properly
Make sure we actually verify our match-rules are executed properly. Right
now all we test is the bloom-matches, which are non-reliable as they leave
through false-positives.
diff --git a/src/libsystemd/sd-bus/test-bus-kernel-bloom.c b/src/libsystemd/sd-bus/test-bus-kernel-bloom.c
index b11c43b..8ebbbfa 100644
--- a/src/libsystemd/sd-bus/test-bus-kernel-bloom.c
+++ b/src/libsystemd/sd-bus/test-bus-kernel-bloom.c
@@ -26,6 +26,14 @@
#include "bus-kernel.h"
#include "bus-util.h"
+static int test_match(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) {
+ int *found = userdata;
+
+ *found = 1;
+
+ return 0;
+}
+
static void test_one(
const char *path,
const char *interface,
@@ -39,7 +47,7 @@ static void test_one(
_cleanup_free_ char *name = NULL, *bus_name = NULL, *address = NULL;
_cleanup_bus_message_unref_ sd_bus_message *m = NULL;
sd_bus *a, *b;
- int r;
+ int r, found = 0;
assert_se(asprintf(&name, "deine-mutter-%u", (unsigned) getpid()) >= 0);
@@ -71,7 +79,7 @@ static void test_one(
assert_se(r >= 0);
log_debug("match");
- r = sd_bus_add_match(b, NULL, match, NULL, NULL);
+ r = sd_bus_add_match(b, NULL, match, test_match, &found);
assert_se(r >= 0);
log_debug("signal");
@@ -83,7 +91,7 @@ static void test_one(
assert_se(r >= 0);
r = sd_bus_process(b, &m);
- assert_se(r >= 0 && (good == !!m));
+ assert_se(r >= 0 && good == !!found);
sd_bus_unref(a);
sd_bus_unref(b);
commit a867b0022616511cceb02f801e7643427d9f3776
Author: David Herrmann <dh.herrmann at gmail.com>
Date: Wed Jun 10 20:04:53 2015 +0200
bus: fix arg0path= two-way matching
DBus spec clearly defines arg0path= to be a two-way matching. That is,
either the matcher or the matchee can be a prefix of the other to match.
This is not possible to implement with bloom-filters. Instead, we'd have
to add a separate filter for each prefix. This is non-trivial, though.
Hence, just skip the match for now and match locally.
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index 1103903..c6d9621 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -1310,11 +1310,18 @@ int bus_add_match_internal_kernel(
}
case BUS_MATCH_ARG_PATH...BUS_MATCH_ARG_PATH_LAST: {
- char buf[sizeof("arg")-1 + 2 + sizeof("-slash-prefix")];
-
- xsprintf(buf, "arg%i-slash-prefix", c->type - BUS_MATCH_ARG_PATH);
- bloom_add_pair(bloom, bus->bloom_size, bus->bloom_n_hash, buf, c->value_str);
- using_bloom = true;
+ /*
+ * XXX: DBus spec defines arg[0..63]path= matching to be
+ * a two-way glob. That is, if either string is a prefix
+ * of the other, it matches.
+ * This is really hard to realize in bloom-filters, as
+ * we would have to create a bloom-match for each prefix
+ * of @c->value_str. This is excessive, hence we just
+ * ignore all those matches and accept everything from
+ * the kernel. People should really avoid those matches.
+ * If they're used in real-life some day, we will have
+ * to properly support multiple-matches here.
+ */
break;
}
commit 7cd4dbe9ca492eabc4c3821e1cb296649a967125
Author: David Herrmann <dh.herrmann at gmail.com>
Date: Wed Jun 10 18:26:16 2015 +0200
bus: fix bloom_add_prefixes() to add all required data
Lets look at an example where we add arg0="/foo/bar/waldo" to a
bloom-filter. The following strings are added:
"arg0:/foo/bar/waldo"
"arg0-slash-prefix:/foo/bar"
"arg0-slash-prefix:/foo"
Two problems arise:
1) If we match on "arg0path=/foo/bar/waldo", the dbus-spec explicitly
states that equal strings are also considered prefixes. However, in the
bloom-match, we can only provide a single match-filter. Therefore, we have
to add "arg0-slash-prefix:/foo/bar/waldo" there, but this never occured in
the bloom-mask of the message.
Hence, this patch makes sure bloom_add_prefixes() adds the full path as
prefix, too.
2) If we match on "arg0path=/foo/", the dbus-spec states that arg0path
does prefix-matching with the trailing slash _included_, unlike
path_namespace= matches, which does *not* include them. This is
inconsistent, but we have to support the specs. Therefore, we must add
prefixes with _and_ without trailing separators.
Hence, this patch makes sure bloom_add_prefixes() adds all prefixes with
the trailing slash included.
The final set of strings added therefore is:
"arg0:/foo/bar/waldo"
"arg0-slash-prefix:/foo/bar/waldo"
"arg0-slash-prefix:/foo/bar/"
"arg0-slash-prefix:/foo/bar"
"arg0-slash-prefix:/foo/"
"arg0-slash-prefix:/foo"
"arg0-slash-prefix:/"
diff --git a/src/libsystemd/sd-bus/bus-bloom.c b/src/libsystemd/sd-bus/bus-bloom.c
index 3556774..91fab90 100644
--- a/src/libsystemd/sd-bus/bus-bloom.c
+++ b/src/libsystemd/sd-bus/bus-bloom.c
@@ -116,11 +116,19 @@ void bloom_add_prefixes(uint64_t filter[], size_t size, unsigned k, const char *
p = stpcpy(stpcpy(c, a), ":");
strcpy(p, b);
+ bloom_add_data(filter, size, k, c, n);
+
for (;;) {
char *e;
e = strrchr(p, sep);
- if (!e || e == p)
+ if (!e)
+ break;
+
+ *(e + 1) = 0;
+ bloom_add_data(filter, size, k, c, e - c + 1);
+
+ if (e == p)
break;
*e = 0;
commit a8467435a0c4962cab89574f65e7318ef389351f
Merge: 1f8cc12 2a1288f
Author: Daniel Mack <github at zonque.org>
Date: Wed Jun 10 20:06:43 2015 +0200
Merge pull request #147 from poettering/cmsg
util: introduce CMSG_FOREACH() macro and make use of it everywhere
commit 2a1288ff89322a2f49c79f6d1832c8164c14a05c
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jun 10 19:10:47 2015 +0200
util: introduce CMSG_FOREACH() macro and make use of it everywhere
It's only marginally shorter then the usual for() loop, but certainly
more readable.
diff --git a/src/core/manager.c b/src/core/manager.c
index 564fb5d..eb80dd1 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -1546,7 +1546,7 @@ static int manager_dispatch_notify_fd(sd_event_source *source, int fd, uint32_t
return -errno;
}
- for (cmsg = CMSG_FIRSTHDR(&msghdr); cmsg; cmsg = CMSG_NXTHDR(&msghdr, cmsg)) {
+ CMSG_FOREACH(cmsg, &msghdr) {
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
fd_array = (int*) CMSG_DATA(cmsg);
diff --git a/src/core/namespace.c b/src/core/namespace.c
index 01a817b..045321e 100644
--- a/src/core/namespace.c
+++ b/src/core/namespace.c
@@ -696,12 +696,11 @@ int setup_netns(int netns_storage_socket[2]) {
} else {
/* Yay, found something, so let's join the namespace */
- for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg)) {
+ CMSG_FOREACH(cmsg, &mh)
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
assert(cmsg->cmsg_len == CMSG_LEN(sizeof(int)));
netns = *(int*) CMSG_DATA(cmsg);
}
- }
if (setns(netns, CLONE_NEWNET) < 0) {
r = -errno;
diff --git a/src/import/importd.c b/src/import/importd.c
index e2df44a..05a619a 100644
--- a/src/import/importd.c
+++ b/src/import/importd.c
@@ -599,7 +599,7 @@ static int manager_on_notify(sd_event_source *s, int fd, uint32_t revents, void
cmsg_close_all(&msghdr);
- for (cmsg = CMSG_FIRSTHDR(&msghdr); cmsg; cmsg = CMSG_NXTHDR(&msghdr, cmsg)) {
+ CMSG_FOREACH(cmsg, &msghdr) {
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_CREDENTIALS &&
cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred))) {
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 3353024..32da8d6 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -1177,7 +1177,7 @@ int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void
return -errno;
}
- for (cmsg = CMSG_FIRSTHDR(&msghdr); cmsg; cmsg = CMSG_NXTHDR(&msghdr, cmsg)) {
+ CMSG_FOREACH(cmsg, &msghdr) {
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_CREDENTIALS &&
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c
index 0193e42..6853038 100644
--- a/src/libsystemd-network/sd-dhcp-client.c
+++ b/src/libsystemd-network/sd-dhcp-client.c
@@ -1588,7 +1588,7 @@ static int client_receive_message_raw(sd_event_source *s, int fd,
} else if ((size_t)len < sizeof(DHCPPacket))
return 0;
- for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+ CMSG_FOREACH(cmsg, &msg) {
if (cmsg->cmsg_level == SOL_PACKET &&
cmsg->cmsg_type == PACKET_AUXDATA &&
cmsg->cmsg_len == CMSG_LEN(sizeof(struct tpacket_auxdata))) {
diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c
index a0a2320..cc5e032 100644
--- a/src/libsystemd-network/sd-dhcp-server.c
+++ b/src/libsystemd-network/sd-dhcp-server.c
@@ -902,7 +902,7 @@ static int server_receive_message(sd_event_source *s, int fd,
else if ((size_t)len < sizeof(DHCPMessage))
return 0;
- for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+ CMSG_FOREACH(cmsg, &msg) {
if (cmsg->cmsg_level == IPPROTO_IP &&
cmsg->cmsg_type == IP_PKTINFO &&
cmsg->cmsg_len == CMSG_LEN(sizeof(struct in_pktinfo))) {
diff --git a/src/libsystemd/sd-bus/bus-container.c b/src/libsystemd/sd-bus/bus-container.c
index f157c25..fa7a207 100644
--- a/src/libsystemd/sd-bus/bus-container.c
+++ b/src/libsystemd/sd-bus/bus-container.c
@@ -222,7 +222,7 @@ int bus_container_connect_kernel(sd_bus *b) {
if (recvmsg(pair[0], &mh, MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) < 0)
return -errno;
- for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg))
+ CMSG_FOREACH(cmsg, &mh)
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
int *fds;
unsigned n_fds;
diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c
index 9f3756f..322d57d 100644
--- a/src/libsystemd/sd-bus/bus-socket.c
+++ b/src/libsystemd/sd-bus/bus-socket.c
@@ -502,7 +502,6 @@ static int bus_socket_read_auth(sd_bus *b) {
struct cmsghdr cmsghdr;
uint8_t buf[CMSG_SPACE(sizeof(int) * BUS_FDS_MAX)];
} control;
- struct cmsghdr *cmsg;
bool handle_cmsg = false;
assert(b);
@@ -552,8 +551,10 @@ static int bus_socket_read_auth(sd_bus *b) {
b->rbuffer_size += k;
- if (handle_cmsg)
- for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg))
+ if (handle_cmsg) {
+ struct cmsghdr *cmsg;
+
+ CMSG_FOREACH(cmsg, &mh)
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_RIGHTS) {
int j;
@@ -567,6 +568,7 @@ static int bus_socket_read_auth(sd_bus *b) {
} else
log_debug("Got unexpected auxiliary data with level=%d and type=%d",
cmsg->cmsg_level, cmsg->cmsg_type);
+ }
r = bus_socket_auth_verify(b);
if (r != 0)
@@ -916,7 +918,6 @@ int bus_socket_read_message(sd_bus *bus) {
struct cmsghdr cmsghdr;
uint8_t buf[CMSG_SPACE(sizeof(int) * BUS_FDS_MAX)];
} control;
- struct cmsghdr *cmsg;
bool handle_cmsg = false;
assert(bus);
@@ -961,8 +962,10 @@ int bus_socket_read_message(sd_bus *bus) {
bus->rbuffer_size += k;
- if (handle_cmsg)
- for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg))
+ if (handle_cmsg) {
+ struct cmsghdr *cmsg;
+
+ CMSG_FOREACH(cmsg, &mh)
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_RIGHTS) {
int n, *f;
@@ -990,6 +993,7 @@ int bus_socket_read_message(sd_bus *bus) {
} else
log_debug("Got unexpected auxiliary data with level=%d and type=%d",
cmsg->cmsg_level, cmsg->cmsg_type);
+ }
r = bus_socket_read_message_need(bus, &need);
if (r < 0)
diff --git a/src/libsystemd/sd-rtnl/rtnl-message.c b/src/libsystemd/sd-rtnl/rtnl-message.c
index bab2a4f..9dcf7df 100644
--- a/src/libsystemd/sd-rtnl/rtnl-message.c
+++ b/src/libsystemd/sd-rtnl/rtnl-message.c
@@ -1442,7 +1442,7 @@ static int socket_recv_message(int fd, struct iovec *iov, uint32_t *_group, bool
return (errno == EAGAIN || errno == EINTR) ? 0 : -errno;
}
- for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+ CMSG_FOREACH(cmsg, &msg) {
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_CREDENTIALS &&
cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred))) {
diff --git a/src/resolve/resolved-dns-stream.c b/src/resolve/resolved-dns-stream.c
index 4c0b557..7f47e72 100644
--- a/src/resolve/resolved-dns-stream.c
+++ b/src/resolve/resolved-dns-stream.c
@@ -113,7 +113,8 @@ static int dns_stream_identify(DnsStream *s) {
mh.msg_control = &control;
mh.msg_controllen = sl;
- for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg)) {
+
+ CMSG_FOREACH(cmsg, &mh) {
if (cmsg->cmsg_level == IPPROTO_IPV6) {
assert(s->peer.sa.sa_family == AF_INET6);
diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c
index 5269537..7fc2803 100644
--- a/src/resolve/resolved-manager.c
+++ b/src/resolve/resolved-manager.c
@@ -920,7 +920,7 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) {
} else
return -EAFNOSUPPORT;
- for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg)) {
+ CMSG_FOREACH(cmsg, &mh) {
if (cmsg->cmsg_level == IPPROTO_IPV6) {
assert(p->family == AF_INET6);
diff --git a/src/shared/macro.h b/src/shared/macro.h
index 7ae1ed8..cc1c9e7 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -467,4 +467,7 @@ do { \
} \
struct __useless_struct_to_allow_trailing_semicolon__
+#define CMSG_FOREACH(cmsg, mh) \
+ for ((cmsg) = CMSG_FIRSTHDR(mh); (cmsg); (cmsg) = CMSG_NXTHDR((mh), (cmsg)))
+
#include "log.h"
diff --git a/src/shared/util.c b/src/shared/util.c
index a20e7bb..6f6906f 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -5520,7 +5520,7 @@ int openpt_in_namespace(pid_t pid, int flags) {
if (recvmsg(pair[0], &mh, MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) < 0)
return -errno;
- for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg))
+ CMSG_FOREACH(cmsg, &mh)
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS) {
int *fds;
unsigned n_fds;
@@ -5908,7 +5908,7 @@ void cmsg_close_all(struct msghdr *mh) {
assert(mh);
- for (cmsg = CMSG_FIRSTHDR(mh); cmsg; cmsg = CMSG_NXTHDR(mh, cmsg))
+ CMSG_FOREACH(cmsg, mh)
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
close_many((int*) CMSG_DATA(cmsg), (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int));
}
diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c
index 88e9cf9..40e0fd3 100644
--- a/src/timesync/timesyncd-manager.c
+++ b/src/timesync/timesyncd-manager.c
@@ -528,7 +528,7 @@ static int manager_receive_response(sd_event_source *source, int fd, uint32_t re
}
recv_time = NULL;
- for (cmsg = CMSG_FIRSTHDR(&msghdr); cmsg; cmsg = CMSG_NXTHDR(&msghdr, cmsg)) {
+ CMSG_FOREACH(cmsg, &msghdr) {
if (cmsg->cmsg_level != SOL_SOCKET)
continue;
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index 26aae89..2affb59 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -875,7 +875,7 @@ static int on_worker(sd_event_source *s, int fd, uint32_t revents, void *userdat
continue;
}
- for (cmsg = CMSG_FIRSTHDR(&msghdr); cmsg; cmsg = CMSG_NXTHDR(&msghdr, cmsg)) {
+ CMSG_FOREACH(cmsg, &msghdr) {
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_CREDENTIALS &&
cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred)))
commit 1f8cc1284c586b06ddf2ba5e5d8c9f13f987a1c5
Merge: cd32b97 9de4d0c
Author: Tom Gundersen <teg at jklm.no>
Date: Wed Jun 10 19:27:22 2015 +0200
Merge pull request #146 from arvidjaar/pr/udev-import-program-exit-code-man
man: clarify that IMPORT{program} is done only for zero exit code
commit cd32b977facd20145f570efbfdf541ffc2780c4e
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Wed Jun 10 11:06:00 2015 -0400
Fix typo
Follow up for 7c918141ed.
diff --git a/src/run/run.c b/src/run/run.c
index 5b9f31c..f18f77b 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -68,7 +68,7 @@ static void help(void) {
printf("%s [OPTIONS...] {COMMAND} [ARGS...]\n\n"
"Run the specified command in a transient scope or service or timer\n"
"unit. If timer option is specified and unit is exist which is\n"
- "specified with --unit option then command can be ommited.\n\n"
+ "specified with --unit option then command can be omitted.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --user Run as user unit\n"
commit 9de4d0ce2d6ceb7530fba4d686be58596c0a7bc1
Author: Andrei Borzenkov <arvidjaar at gmail.com>
Date: Wed Jun 10 19:43:36 2015 +0300
man: clarify that IMPORT{program} is done only for zero exit code
diff --git a/man/udev.xml b/man/udev.xml
index d5d8a17..70f4f59 100644
--- a/man/udev.xml
+++ b/man/udev.xml
@@ -472,7 +472,8 @@
<varlistentry>
<term><literal>program</literal></term>
<listitem>
- <para>Execute an external program specified as the assigned value and
+ <para>Execute an external program specified as the assigned
+ value and if it returns successfully
import its output, which must be in environment key
format. Path specification, command/argument separation,
and quoting work like in <varname>RUN</varname>.</para>
commit 5410b2ed62289d8ab6575e64951ac7b6bda51d40
Merge: 94cf036 0b34762
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jun 10 16:59:43 2015 +0200
Merge pull request #142 from teg/sd-network-unref-NULL
sd-network: allow NULL in sd_network_monitor_unref
commit 94cf03671172ab5a86548e149f51025d746c57f1
Merge: b078b5a 87aeefc
Author: Daniel Mack <github at zonque.org>
Date: Wed Jun 10 16:46:17 2015 +0200
Merge pull request #140 from teg/man-udev-timeout
man: udevd - correct default event timeout
commit 0b3476266f6600b59b1d2c5b7dccf7fba4947850
Author: Tom Gundersen <teg at jklm.no>
Date: Wed Jun 10 15:55:09 2015 +0200
sd-network: allow NULL in sd_network_monitor_unref
Match rest of codebase, we always allow unref'ing NULL.
diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c
index db1f699..5879414 100644
--- a/src/libsystemd/sd-network/sd-network.c
+++ b/src/libsystemd/sd-network/sd-network.c
@@ -329,10 +329,10 @@ _public_ int sd_network_monitor_new(sd_network_monitor **m, const char *category
_public_ sd_network_monitor* sd_network_monitor_unref(sd_network_monitor *m) {
int fd;
- assert_return(m, NULL);
-
- fd = MONITOR_TO_FD(m);
- close_nointr(fd);
+ if (m) {
+ fd = MONITOR_TO_FD(m);
+ close_nointr(fd);
+ }
return NULL;
}
commit b078b5a7abf4ca81d83fc1db7d6fb1047129280f
Merge: ad5ecc1 2de56f7
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Wed Jun 10 10:20:50 2015 -0400
Merge pull request #85 from keszybz/selinux-context
commit ad5ecc113821fbfa33f6fd43cdaee9c538cdff78
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Tue Jun 2 12:55:27 2015 -0400
test-copy: test copy_bytes()
diff --git a/src/test/test-copy.c b/src/test/test-copy.c
index 403d85b..e55ffaa 100644
--- a/src/test/test-copy.c
+++ b/src/test/test-copy.c
@@ -133,10 +133,45 @@ static void test_copy_tree(void) {
(void) rm_rf(original_dir, REMOVE_ROOT|REMOVE_PHYSICAL);
}
+static void test_copy_bytes(void) {
+ _cleanup_close_pair_ int pipefd[2] = {-1, -1};
+ _cleanup_close_ int infd = -1;
+ int r, r2;
+ char buf[1024], buf2[1024];
+
+ infd = open("/etc/os-release", O_RDONLY|O_CLOEXEC);
+ assert_se(infd >= 0);
+
+ assert_se(pipe2(pipefd, O_CLOEXEC) == 0);
+
+ r = copy_bytes(infd, pipefd[1], (off_t) -1, false);
+ assert_se(r == 0);
+
+ r = read(pipefd[0], buf, sizeof(buf));
+ assert_se(r >= 0);
+
+ assert_se(lseek(infd, 0, SEEK_SET) == 0);
+ r2 = read(infd, buf2, sizeof(buf2));
+ assert_se(r == r2);
+
+ assert_se(strneq(buf, buf2, r));
+
+ /* test copy_bytes with invalid descriptors */
+ r = copy_bytes(pipefd[0], pipefd[0], 1, false);
+ assert_se(r == -EBADF);
+
+ r = copy_bytes(pipefd[1], pipefd[1], 1, false);
+ assert_se(r == -EBADF);
+
+ r = copy_bytes(pipefd[1], infd, 1, false);
+ assert_se(r == -EBADF);
+}
+
int main(int argc, char *argv[]) {
test_copy_file();
test_copy_file_fd();
test_copy_tree();
+ test_copy_bytes();
return 0;
}
commit 87aeefc31e8eedf7eada1710014a1a172f9a5dba
Author: Tom Gundersen <teg at jklm.no>
Date: Tue Jun 9 23:56:02 2015 +0200
man: udevd - correct default event timeout
This was changed from 30 to 180 seconds quite some time ago.
diff --git a/man/systemd-udevd.service.xml b/man/systemd-udevd.service.xml
index c0d3230..7a4b62a 100644
--- a/man/systemd-udevd.service.xml
+++ b/man/systemd-udevd.service.xml
@@ -106,7 +106,7 @@
<term><option>--event-timeout=</option></term>
<listitem>
<para>Set the number of seconds to wait for events to finish. After
- this time the event will be terminated. The default is 30 seconds.</para>
+ this time the event will be terminated. The default is 180 seconds.</para>
</listitem>
</varlistentry>
commit aa0d0ed6b87d41367fd6c4401472df7d45dd1b13
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jun 10 15:52:14 2015 +0200
sd-bus: remove ucred parameter from bus_message_from_header() since we don't use it anymore
diff --git a/src/libsystemd/sd-bus/bus-kernel.c b/src/libsystemd/sd-bus/bus-kernel.c
index 572a9c6..3aaaabf 100644
--- a/src/libsystemd/sd-bus/bus-kernel.c
+++ b/src/libsystemd/sd-bus/bus-kernel.c
@@ -498,7 +498,6 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
footer, footer_size,
n_bytes,
fds, n_fds,
- NULL,
seclabel, 0, &m);
if (r < 0)
return r;
diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c
index 6ee209d..c38b2a5 100644
--- a/src/libsystemd/sd-bus/bus-message.c
+++ b/src/libsystemd/sd-bus/bus-message.c
@@ -435,7 +435,6 @@ int bus_message_from_header(
size_t message_size,
int *fds,
unsigned n_fds,
- const struct ucred *ucred,
const char *label,
size_t extra,
sd_bus_message **ret) {
@@ -528,23 +527,6 @@ int bus_message_from_header(
m->fds = fds;
m->n_fds = n_fds;
- if (ucred) {
- m->creds.pid = ucred->pid;
- m->creds.euid = ucred->uid;
- m->creds.egid = ucred->gid;
-
- /* Due to namespace translations some data might be
- * missing from this ucred record. */
- if (m->creds.pid > 0)
- m->creds.mask |= SD_BUS_CREDS_PID;
-
- if (m->creds.euid != UID_INVALID)
- m->creds.mask |= SD_BUS_CREDS_EUID;
-
- if (m->creds.egid != GID_INVALID)
- m->creds.mask |= SD_BUS_CREDS_EGID;
- }
-
if (label) {
m->creds.label = (char*) m + ALIGN(sizeof(sd_bus_message)) + ALIGN(extra);
memcpy(m->creds.label, label, label_sz + 1);
@@ -565,7 +547,6 @@ int bus_message_from_malloc(
size_t length,
int *fds,
unsigned n_fds,
- const struct ucred *ucred,
const char *label,
sd_bus_message **ret) {
@@ -579,7 +560,7 @@ int bus_message_from_malloc(
buffer, length,
length,
fds, n_fds,
- ucred, label,
+ label,
0, &m);
if (r < 0)
return r;
diff --git a/src/libsystemd/sd-bus/bus-message.h b/src/libsystemd/sd-bus/bus-message.h
index d784e60..088d5b1 100644
--- a/src/libsystemd/sd-bus/bus-message.h
+++ b/src/libsystemd/sd-bus/bus-message.h
@@ -205,7 +205,6 @@ int bus_message_from_header(
size_t message_size,
int *fds,
unsigned n_fds,
- const struct ucred *ucred,
const char *label,
size_t extra,
sd_bus_message **ret);
@@ -216,7 +215,6 @@ int bus_message_from_malloc(
size_t length,
int *fds,
unsigned n_fds,
- const struct ucred *ucred,
const char *label,
sd_bus_message **ret);
diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c
index 93ebe80..5209db8 100644
--- a/src/libsystemd/sd-bus/bus-socket.c
+++ b/src/libsystemd/sd-bus/bus-socket.c
@@ -915,7 +915,6 @@ static int bus_socket_make_message(sd_bus *bus, size_t size) {
bus->rbuffer, size,
bus->fds, bus->n_fds,
NULL,
- NULL,
&t);
if (r < 0) {
free(b);
diff --git a/src/libsystemd/sd-bus/test-bus-gvariant.c b/src/libsystemd/sd-bus/test-bus-gvariant.c
index 992edac..22ea00c 100644
--- a/src/libsystemd/sd-bus/test-bus-gvariant.c
+++ b/src/libsystemd/sd-bus/test-bus-gvariant.c
@@ -198,7 +198,7 @@ static void test_marshal(void) {
}
#endif
- assert_se(bus_message_from_malloc(bus, blob, sz, NULL, 0, NULL, NULL, &n) >= 0);
+ assert_se(bus_message_from_malloc(bus, blob, sz, NULL, 0, NULL, &n) >= 0);
blob = NULL;
assert_se(bus_message_dump(n, NULL, BUS_MESSAGE_DUMP_WITH_HEADER) >= 0);
diff --git a/src/libsystemd/sd-bus/test-bus-marshal.c b/src/libsystemd/sd-bus/test-bus-marshal.c
index f8ecadf..a866a56 100644
--- a/src/libsystemd/sd-bus/test-bus-marshal.c
+++ b/src/libsystemd/sd-bus/test-bus-marshal.c
@@ -212,7 +212,7 @@ int main(int argc, char *argv[]) {
m = sd_bus_message_unref(m);
- r = bus_message_from_malloc(bus, buffer, sz, NULL, 0, NULL, NULL, &m);
+ r = bus_message_from_malloc(bus, buffer, sz, NULL, 0, NULL, &m);
assert_se(r >= 0);
bus_message_dump(m, stdout, BUS_MESSAGE_DUMP_WITH_HEADER);
commit 3c42e8b281b092b4d10f24c80e21d69b0f232b96
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jun 10 15:51:40 2015 +0200
sd-bus: fix early exit when we lack all data in bus_get_owner_creds_dbus1()
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index 43ddfc6..b4ca177 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -980,7 +980,7 @@ static int bus_get_owner_creds_dbus1(sd_bus *bus, uint64_t mask, sd_bus_creds **
pid_t pid = 0;
int r;
- if (!bus->ucred_valid && !isempty(bus->label))
+ if (!bus->ucred_valid && isempty(bus->label))
return -ENODATA;
c = bus_creds_new();
commit d9cea815b6107839d1aa56858165649858a21e18
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jun 10 15:44:03 2015 +0200
build-sys: upgrade shadow variable warnings to errors
diff --git a/configure.ac b/configure.ac
index b767175..878b23b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -163,6 +163,7 @@ CC_CHECK_FLAGS_APPEND([with_cflags], [CFLAGS], [\
-Werror=implicit-function-declaration \
-Werror=missing-declarations \
-Werror=return-type \
+ -Werror=shadow \
-Wstrict-prototypes \
-Wredundant-decls \
-Wmissing-noreturn \
commit b56c4604faf486e897f836ac2293dd147e980352
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jun 10 15:51:14 2015 +0200
bus-message: remove shadow warning with log_debug_bus_message()
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index f3df1c1..598b1be 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -49,19 +49,20 @@
#include "bus-track.h"
#include "bus-slot.h"
-#define log_debug_bus_message(m) do { \
- sd_bus_message *_m = (m); \
- log_debug("Got message type=%s sender=%s destination=%s object=%s interface=%s member=%s cookie=%" PRIu64 " reply_cookie=%" PRIu64 " error=%s", \
- bus_message_type_to_string(_m->header->type), \
- strna(sd_bus_message_get_sender(_m)), \
- strna(sd_bus_message_get_destination(_m)), \
- strna(sd_bus_message_get_path(_m)), \
- strna(sd_bus_message_get_interface(_m)), \
- strna(sd_bus_message_get_member(_m)), \
- BUS_MESSAGE_COOKIE(_m), \
- _m->reply_cookie, \
- strna(_m->error.message)); \
- } while (false)
+#define log_debug_bus_message(m) \
+ do { \
+ sd_bus_message *_mm = (m); \
+ log_debug("Got message type=%s sender=%s destination=%s object=%s interface=%s member=%s cookie=%" PRIu64 " reply_cookie=%" PRIu64 " error=%s", \
+ bus_message_type_to_string(_mm->header->type), \
+ strna(sd_bus_message_get_sender(_mm)), \
+ strna(sd_bus_message_get_destination(_mm)), \
+ strna(sd_bus_message_get_path(_mm)), \
+ strna(sd_bus_message_get_interface(_mm)), \
+ strna(sd_bus_message_get_member(_mm)), \
+ BUS_MESSAGE_COOKIE(_mm), \
+ _mm->reply_cookie, \
+ strna(_mm->error.message)); \
+ } while (false)
static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec);
static int attach_io_events(sd_bus *b);
commit 2de56f70941eaf91a4520bf33de47a87ebd8b2cb
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Sat Jun 6 21:36:52 2015 -0400
journald: simplify context handling
By using our homegrown function we can dispense with all the iffdefery.
diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
index b572147..db2f581 100644
--- a/src/journal/journald-stream.c
+++ b/src/journal/journald-stream.c
@@ -59,10 +59,7 @@ struct StdoutStream {
int fd;
struct ucred ucred;
-#ifdef HAVE_SELINUX
- security_context_t security_context;
-#endif
-
+ char *label;
char *identifier;
char *unit_id;
int priority;
@@ -99,12 +96,7 @@ void stdout_stream_free(StdoutStream *s) {
}
safe_close(s->fd);
-
-#ifdef HAVE_SELINUX
- if (s->security_context)
- freecon(s->security_context);
-#endif
-
+ free(s->label);
free(s->identifier);
free(s->unit_id);
free(s->state_file);
@@ -225,8 +217,7 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
char syslog_facility[sizeof("SYSLOG_FACILITY=")-1 + DECIMAL_STR_MAX(int) + 1];
_cleanup_free_ char *message = NULL, *syslog_identifier = NULL;
unsigned n = 0;
- char *label = NULL;
- size_t label_len = 0;
+ size_t label_len;
assert(s);
assert(p);
@@ -271,14 +262,8 @@ static int stdout_stream_log(StdoutStream *s, const char *p) {
if (message)
IOVEC_SET_STRING(iovec[n++], message);
-#ifdef HAVE_SELINUX
- if (s->security_context) {
- label = (char*) s->security_context;
- label_len = strlen((char*) s->security_context);
- }
-#endif
-
- server_dispatch_message(s->server, iovec, n, ELEMENTSOF(iovec), &s->ucred, NULL, label, label_len, s->unit_id, priority, 0);
+ label_len = s->label ? strlen(s->label) : 0;
+ server_dispatch_message(s->server, iovec, n, ELEMENTSOF(iovec), &s->ucred, NULL, s->label, label_len, s->unit_id, priority, 0);
return 0;
}
@@ -489,12 +474,11 @@ static int stdout_stream_install(Server *s, int fd, StdoutStream **ret) {
if (r < 0)
return log_error_errno(r, "Failed to determine peer credentials: %m");
-#ifdef HAVE_SELINUX
if (mac_selinux_use()) {
- if (getpeercon(fd, &stream->security_context) < 0 && errno != ENOPROTOOPT)
- log_error_errno(errno, "Failed to determine peer security context: %m");
+ r = getpeersec(fd, &stream->label);
+ if (r < 0 && r != -EOPNOTSUPP)
+ (void) log_warning_errno(r, "Failed to determine peer security context: %m");
}
-#endif
(void) shutdown(fd, SHUT_WR);
commit c4e6556c46cea1b7195cfb81c8cfab8342ebd852
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Sat Jun 6 21:24:45 2015 -0400
sd-bus: store selinux context at connection time
This appears to be the right time to do it for SOCK_STREAM
unix sockets.
Also: condition bus_get_owner_creds_dbus1 was reversed. Split
it out to a separate variable for clarity and fix.
https://bugzilla.redhat.com/show_bug.cgi?id=1224211
diff --git a/src/libsystemd/sd-bus/bus-control.c b/src/libsystemd/sd-bus/bus-control.c
index 43ddfc6..1103903 100644
--- a/src/libsystemd/sd-bus/bus-control.c
+++ b/src/libsystemd/sd-bus/bus-control.c
@@ -979,8 +979,10 @@ static int bus_get_owner_creds_dbus1(sd_bus *bus, uint64_t mask, sd_bus_creds **
_cleanup_bus_creds_unref_ sd_bus_creds *c = NULL;
pid_t pid = 0;
int r;
+ bool do_label = bus->label && (mask & SD_BUS_CREDS_SELINUX_CONTEXT);
- if (!bus->ucred_valid && !isempty(bus->label))
+ /* Avoid allocating anything if we have no chance of returning useful data */
+ if (!bus->ucred_valid && !do_label)
return -ENODATA;
c = bus_creds_new();
@@ -1004,7 +1006,7 @@ static int bus_get_owner_creds_dbus1(sd_bus *bus, uint64_t mask, sd_bus_creds **
}
}
- if (!isempty(bus->label) && (mask & SD_BUS_CREDS_SELINUX_CONTEXT)) {
+ if (do_label) {
c->label = strdup(bus->label);
if (!c->label)
return -ENOMEM;
diff --git a/src/libsystemd/sd-bus/bus-internal.h b/src/libsystemd/sd-bus/bus-internal.h
index 1351938..2ee0eab 100644
--- a/src/libsystemd/sd-bus/bus-internal.h
+++ b/src/libsystemd/sd-bus/bus-internal.h
@@ -261,7 +261,7 @@ struct sd_bus {
usec_t auth_timeout;
struct ucred ucred;
- char label[NAME_MAX];
+ char *label;
uint64_t creds_mask;
diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c
index facfd73..bcd49ef 100644
--- a/src/libsystemd/sd-bus/bus-socket.c
+++ b/src/libsystemd/sd-bus/bus-socket.c
@@ -588,10 +588,17 @@ void bus_socket_setup(sd_bus *b) {
}
static void bus_get_peercred(sd_bus *b) {
+ int r;
+
assert(b);
/* Get the peer for socketpair() sockets */
b->ucred_valid = getpeercred(b->input_fd, &b->ucred) >= 0;
+
+ /* Get the SELinux context of the peer */
+ r = getpeersec(b->input_fd, &b->label);
+ if (r < 0 && r != -EOPNOTSUPP)
+ log_debug_errno(r, "Failed to determine peer security context: %m");
}
static int bus_socket_start_auth_client(sd_bus *b) {
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index edc27ae..0cd5cad 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -116,6 +116,7 @@ static void bus_free(sd_bus *b) {
if (b->kdbus_buffer)
munmap(b->kdbus_buffer, KDBUS_POOL_SIZE);
+ free(b->label);
free(b->rbuffer);
free(b->unique_name);
free(b->auth_buffer);
commit d868f2a3a1cc97b1e081b7692e80a1182efccda4
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Sat Jun 6 18:59:27 2015 -0400
sd-bus: do not use per-datagram auxiliary information
SELinux information cannot be retrieved this way, since we are
using stream unix sockets and SCM_SECURITY does not work for
them.
SCM_CREDENTIALS use dropped to be consistent. We also should
get this information at connection time.
https://bugzilla.redhat.com/show_bug.cgi?id=1224211
"SCM_SECURITY was only added for datagram sockets."
diff --git a/src/libsystemd/sd-bus/bus-socket.c b/src/libsystemd/sd-bus/bus-socket.c
index 4fffc65..facfd73 100644
--- a/src/libsystemd/sd-bus/bus-socket.c
+++ b/src/libsystemd/sd-bus/bus-socket.c
@@ -500,9 +500,7 @@ static int bus_socket_read_auth(sd_bus *b) {
void *p;
union {
struct cmsghdr cmsghdr;
- uint8_t buf[CMSG_SPACE(sizeof(int) * BUS_FDS_MAX) +
- CMSG_SPACE(sizeof(struct ucred)) +
- CMSG_SPACE(NAME_MAX)]; /*selinux label */
+ uint8_t buf[CMSG_SPACE(sizeof(int) * BUS_FDS_MAX)];
} control;
struct cmsghdr *cmsg;
bool handle_cmsg = false;
@@ -554,8 +552,8 @@ static int bus_socket_read_auth(sd_bus *b) {
b->rbuffer_size += k;
- if (handle_cmsg) {
- for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg)) {
+ if (handle_cmsg)
+ for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg))
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_RIGHTS) {
int j;
@@ -566,31 +564,9 @@ static int bus_socket_read_auth(sd_bus *b) {
j = (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int);
close_many((int*) CMSG_DATA(cmsg), j);
return -EIO;
-
- } else if (cmsg->cmsg_level == SOL_SOCKET &&
- cmsg->cmsg_type == SCM_CREDENTIALS &&
- cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred))) {
-
- /* Ignore bogus data, which we might
- * get on socketpair() sockets */
- if (((struct ucred*) CMSG_DATA(cmsg))->pid != 0) {
- memcpy(&b->ucred, CMSG_DATA(cmsg), sizeof(struct ucred));
- b->ucred_valid = true;
- }
-
- } else if (cmsg->cmsg_level == SOL_SOCKET &&
- cmsg->cmsg_type == SCM_SECURITY) {
-
- size_t l;
-
- l = cmsg->cmsg_len - CMSG_LEN(0);
- if (l > 0) {
- memcpy(&b->label, CMSG_DATA(cmsg), l);
- b->label[l] = 0;
- }
- }
- }
- }
+ } else
+ log_debug("Got unexpected auxiliary data with level=%d and type=%d",
+ cmsg->cmsg_level, cmsg->cmsg_type);
r = bus_socket_auth_verify(b);
if (r != 0)
@@ -600,18 +576,8 @@ static int bus_socket_read_auth(sd_bus *b) {
}
void bus_socket_setup(sd_bus *b) {
- int enable;
-
assert(b);
- /* Enable SO_PASSCRED + SO_PASSEC. We try this on any
- * socket, just in case. */
- enable = !b->bus_client;
- (void) setsockopt(b->input_fd, SOL_SOCKET, SO_PASSCRED, &enable, sizeof(enable));
-
- enable = !b->bus_client && (b->attach_flags & KDBUS_ATTACH_SECLABEL);
- (void) setsockopt(b->input_fd, SOL_SOCKET, SO_PASSSEC, &enable, sizeof(enable));
-
/* Increase the buffers to 8 MB */
fd_inc_rcvbuf(b->input_fd, SNDBUF_SIZE);
fd_inc_sndbuf(b->output_fd, SNDBUF_SIZE);
@@ -941,9 +907,7 @@ int bus_socket_read_message(sd_bus *bus) {
void *b;
union {
struct cmsghdr cmsghdr;
- uint8_t buf[CMSG_SPACE(sizeof(int) * BUS_FDS_MAX) +
- CMSG_SPACE(sizeof(struct ucred)) +
- CMSG_SPACE(NAME_MAX)]; /*selinux label */
+ uint8_t buf[CMSG_SPACE(sizeof(int) * BUS_FDS_MAX)];
} control;
struct cmsghdr *cmsg;
bool handle_cmsg = false;
@@ -990,8 +954,8 @@ int bus_socket_read_message(sd_bus *bus) {
bus->rbuffer_size += k;
- if (handle_cmsg) {
- for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg)) {
+ if (handle_cmsg)
+ for (cmsg = CMSG_FIRSTHDR(&mh); cmsg; cmsg = CMSG_NXTHDR(&mh, cmsg))
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_RIGHTS) {
int n, *f;
@@ -1016,29 +980,9 @@ int bus_socket_read_message(sd_bus *bus) {
memcpy(f + bus->n_fds, CMSG_DATA(cmsg), n * sizeof(int));
bus->fds = f;
bus->n_fds += n;
- } else if (cmsg->cmsg_level == SOL_SOCKET &&
- cmsg->cmsg_type == SCM_CREDENTIALS &&
- cmsg->cmsg_len == CMSG_LEN(sizeof(struct ucred))) {
-
- /* Ignore bogus data, which we might
- * get on socketpair() sockets */
- if (((struct ucred*) CMSG_DATA(cmsg))->pid != 0) {
- memcpy(&bus->ucred, CMSG_DATA(cmsg), sizeof(struct ucred));
- bus->ucred_valid = true;
- }
-
- } else if (cmsg->cmsg_level == SOL_SOCKET &&
- cmsg->cmsg_type == SCM_SECURITY) {
-
- size_t l;
- l = cmsg->cmsg_len - CMSG_LEN(0);
- if (l > 0) {
- memcpy(&bus->label, CMSG_DATA(cmsg), l);
- bus->label[l] = 0;
- }
- }
- }
- }
+ } else
+ log_debug("Got unexpected auxiliary data with level=%d and type=%d",
+ cmsg->cmsg_level, cmsg->cmsg_type);
r = bus_socket_read_message_need(bus, &need);
if (r < 0)
commit 236f83afa935d6e07fcd5c17b5db7b1cf424267a
Author: Zbigniew Jędrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Sun May 24 20:20:06 2015 -0400
bus-creds: always set SD_BUS_CREDS_PID when we set pid in the mask
Also reorder the code a bit to be easier to parse.
diff --git a/src/core/selinux-access.c b/src/core/selinux-access.c
index 5e9a4a5..decd42f 100644
--- a/src/core/selinux-access.c
+++ b/src/core/selinux-access.c
@@ -261,7 +261,7 @@ int mac_selinux_generic_access_check(
audit_info.path = path;
audit_info.cmdline = cl;
- r = selinux_check_access((security_context_t) scon, fcon, tclass, permission, &audit_info);
+ r = selinux_check_access(scon, fcon, tclass, permission, &audit_info);
if (r < 0)
r = sd_bus_error_setf(error, SD_BUS_ERROR_ACCESS_DENIED, "SELinux policy denies access.");
diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c
index 4d67619..1c365b7 100644
--- a/src/libsystemd/sd-bus/bus-creds.c
+++ b/src/libsystemd/sd-bus/bus-creds.c
@@ -773,11 +773,13 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
return 0;
/* Try to retrieve PID from creds if it wasn't passed to us */
- if (pid <= 0 && (c->mask & SD_BUS_CREDS_PID))
+ if (pid > 0) {
+ c->pid = pid;
+ c->mask |= SD_BUS_CREDS_PID;
+ } else if (c->mask & SD_BUS_CREDS_PID)
pid = c->pid;
-
- /* Without pid we cannot do much... */
- if (pid <= 0)
+ else
+ /* Without pid we cannot do much... */
return 0;
/* Try to retrieve TID from creds if it wasn't passed to us */
@@ -789,9 +791,6 @@ int bus_creds_add_more(sd_bus_creds *c, uint64_t mask, pid_t pid, pid_t tid) {
if (missing == 0)
return 0;
- c->pid = pid;
- c->mask |= SD_BUS_CREDS_PID;
-
if (tid > 0) {
c->tid = tid;
c->mask |= SD_BUS_CREDS_TID;
More information about the systemd-commits
mailing list