From: Lennart Poettering Date: Fri, 20 Dec 2013 22:25:43 +0000 (+0100) Subject: bus: wrap KDBUS_CMD_BYEBYE with a high-level call sd_bus_try_close() X-Git-Tag: submit/kdbus-integration/20140207.094352~448 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ae095f860593c87d217773976cfe5f89a6993c89;p=platform%2Fupstream%2Fsystemd.git bus: wrap KDBUS_CMD_BYEBYE with a high-level call sd_bus_try_close() --- diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c index 369eac4..2802187 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 0a825d7..67690f8 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 7dbfcf9..3529b79 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 9c564de..a394955 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 785e245..8380b2c 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 3c3cea0..e757d1d 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);