[systemd-devel] [PATCH] libsystemd-bus: clean up bus-control.c file

Lukasz Skalski l.skalski at partner.samsung.com
Fri Nov 29 08:57:00 PST 2013


I added also assert_return(!bus->is_kernel, -ENOTSUP) to sd_bus_get_owner()
function until ioctl(KDBUS_CMD_NAME_QUERY) is not implemented yet.
---
 src/libsystemd-bus/bus-control.c | 52 ++++++++++++++--------------------------
 1 file changed, 18 insertions(+), 34 deletions(-)

diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
index b222175..90bdce2 100644
--- a/src/libsystemd-bus/bus-control.c
+++ b/src/libsystemd-bus/bus-control.c
@@ -38,12 +38,9 @@
 _public_ int sd_bus_get_unique_name(sd_bus *bus, const char **unique) {
         int r;
 
-        if (!bus)
-                return -EINVAL;
-        if (!unique)
-                return -EINVAL;
-        if (bus_pid_changed(bus))
-                return -ECHILD;
+        assert_return(bus, -EINVAL);
+        assert_return(unique, -EINVAL);
+        assert_return(!bus_pid_changed(bus), -ECHILD);
 
         r = bus_ensure_running(bus);
         if (r < 0)
@@ -58,16 +55,11 @@ _public_ int sd_bus_request_name(sd_bus *bus, const char *name, int flags) {
         uint32_t ret;
         int r;
 
-        if (!bus)
-                return -EINVAL;
-        if (!name)
-                return -EINVAL;
-        if (!bus->bus_client)
-                return -EINVAL;
-        if (!BUS_IS_OPEN(bus->state))
-                return -ENOTCONN;
-        if (bus_pid_changed(bus))
-                return -ECHILD;
+        assert_return(bus, -EINVAL);
+        assert_return(name, -EINVAL);
+        assert_return(bus->bus_client, -EINVAL);
+        assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
+        assert_return(!bus_pid_changed(bus), -ECHILD);
 
         if (bus->is_kernel) {
                 struct kdbus_cmd_name *n;
@@ -126,16 +118,11 @@ _public_ int sd_bus_release_name(sd_bus *bus, const char *name) {
         uint32_t ret;
         int r;
 
-        if (!bus)
-                return -EINVAL;
-        if (!name)
-                return -EINVAL;
-        if (!bus->bus_client)
-                return -EINVAL;
-        if (!BUS_IS_OPEN(bus->state))
-                return -ENOTCONN;
-        if (bus_pid_changed(bus))
-                return -ECHILD;
+        assert_return(bus, -EINVAL);
+        assert_return(name, -EINVAL);
+        assert_return(bus->bus_client, -EINVAL);
+        assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
+        assert_return(!bus_pid_changed(bus), -ECHILD);
 
         if (bus->is_kernel) {
                 struct kdbus_cmd_name *n;
@@ -181,14 +168,10 @@ _public_ int sd_bus_list_names(sd_bus *bus, char ***l) {
         char **x = NULL;
         int r;
 
-        if (!bus)
-                return -EINVAL;
-        if (!l)
-                return -EINVAL;
-        if (!BUS_IS_OPEN(bus->state))
-                return -ENOTCONN;
-        if (bus_pid_changed(bus))
-                return -ECHILD;
+        assert_return(bus, -EINVAL);
+        assert_return(l, -EINVAL);
+        assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
+        assert_return(!bus_pid_changed(bus), -ECHILD);
 
         if (bus->is_kernel) {
                 _cleanup_free_ struct kdbus_cmd_names *names = NULL;
@@ -296,6 +279,7 @@ _public_ int sd_bus_get_owner(
         assert_return(mask == 0 || creds, -EINVAL);
         assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
         assert_return(!bus_pid_changed(bus), -ECHILD);
+        assert_return(!bus->is_kernel, -ENOTSUP);
 
         /* Only query the owner if the caller wants to know it or if
          * the caller just wants to check whether a name exists */
-- 
1.8.3.2



More information about the systemd-devel mailing list