summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-12-20 23:25:43 +0100
committerLennart Poettering <lennart@poettering.net>2013-12-20 23:26:11 +0100
commitae095f860593c87d217773976cfe5f89a6993c89 (patch)
tree5a014286ac5088e72e2044faa028962774ebcdf9 /src
parent5a884f93fdb2a6f89605e44a0e7f4d2db5470b5b (diff)
bus: wrap KDBUS_CMD_BYEBYE with a high-level call sd_bus_try_close()
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-bus/bus-kernel.c10
-rw-r--r--src/libsystemd-bus/bus-kernel.h2
-rw-r--r--src/libsystemd-bus/libsystemd-bus.sym1
-rw-r--r--src/libsystemd-bus/sd-bus.c16
-rw-r--r--src/libsystemd-bus/test-bus-kernel.c6
-rw-r--r--src/systemd/sd-bus.h1
6 files changed, 36 insertions, 0 deletions
diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index 369eac468b..2802187e70 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -1266,3 +1266,13 @@ int bus_kernel_create_monitor(const char *bus) {
return fd;
}
+
+int bus_kernel_try_close(sd_bus *bus) {
+ assert(bus);
+ assert(bus->is_kernel);
+
+ if (ioctl(bus->input_fd, KDBUS_CMD_BYEBYE) < 0)
+ return -errno;
+
+ return 0;
+}
diff --git a/src/libsystemd-bus/bus-kernel.h b/src/libsystemd-bus/bus-kernel.h
index 0a825d7b8e..67690f8dee 100644
--- a/src/libsystemd-bus/bus-kernel.h
+++ b/src/libsystemd-bus/bus-kernel.h
@@ -75,3 +75,5 @@ int bus_kernel_parse_unique_name(const char *s, uint64_t *id);
int kdbus_translate_request_name_flags(uint64_t sd_bus_flags, uint64_t *kdbus_flags);
int kdbus_translate_attach_flags(uint64_t sd_bus_flags, uint64_t *kdbus_flags);
+
+int bus_kernel_try_close(sd_bus *bus);
diff --git a/src/libsystemd-bus/libsystemd-bus.sym b/src/libsystemd-bus/libsystemd-bus.sym
index 7dbfcf9acb..3529b7942f 100644
--- a/src/libsystemd-bus/libsystemd-bus.sym
+++ b/src/libsystemd-bus/libsystemd-bus.sym
@@ -31,6 +31,7 @@ global:
sd_bus_negotiate_attach_creds;
sd_bus_start;
sd_bus_close;
+ sd_bus_try_close;
sd_bus_ref;
sd_bus_unref;
sd_bus_is_open;
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 9c564de764..a39495541b 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -2956,3 +2956,19 @@ _public_ int sd_bus_get_peer_creds(sd_bus *bus, uint64_t mask, sd_bus_creds **re
*ret = c;
return 0;
}
+
+_public_ int sd_bus_try_close(sd_bus *bus) {
+ int r;
+
+ assert_return(bus, -EINVAL);
+ assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
+ assert_return(!bus_pid_changed(bus), -ECHILD);
+ assert_return(bus->is_kernel, -ENOTSUP);
+
+ r = bus_kernel_try_close(bus);
+ if (r < 0)
+ return r;
+
+ sd_bus_close(bus);
+ return 0;
+}
diff --git a/src/libsystemd-bus/test-bus-kernel.c b/src/libsystemd-bus/test-bus-kernel.c
index 785e2450bf..8380b2c311 100644
--- a/src/libsystemd-bus/test-bus-kernel.c
+++ b/src/libsystemd-bus/test-bus-kernel.c
@@ -95,6 +95,9 @@ int main(int argc, char *argv[]) {
r = sd_bus_emit_signal(a, "/foo/bar/waldo", "waldo.com", "Piep", "sss", "I am a string", "/this/is/a/path", "and.this.a.domain.name");
assert_se(r >= 0);
+ r = sd_bus_try_close(b);
+ assert_se(r == -EBUSY);
+
r = sd_bus_process(b, &m);
assert_se(r > 0);
assert_se(m);
@@ -160,6 +163,9 @@ int main(int argc, char *argv[]) {
r = sd_bus_release_name(a, "net.x0pointer.foobar");
assert_se(r == -ESRCH);
+ r = sd_bus_try_close(a);
+ assert_se(r >= 0);
+
sd_bus_unref(a);
sd_bus_unref(b);
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 3c3cea042e..e757d1d45f 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -115,6 +115,7 @@ int sd_bus_negotiate_attach_timestamp(sd_bus *bus, int b);
int sd_bus_negotiate_attach_creds(sd_bus *bus, uint64_t creds_mask);
int sd_bus_start(sd_bus *ret);
+int sd_bus_try_close(sd_bus *bus);
void sd_bus_close(sd_bus *bus);
sd_bus *sd_bus_ref(sd_bus *bus);