chiark / gitweb /
sd-bus,sd-event: unify error handling of object descriptions
[elogind.git] / src / libsystemd / sd-bus / sd-bus.c
index c17b1a0a0e08b97ab43dfa84db31d4e2f2a44451..a3165fb4f743df7b544d22471022e26ffe2abc6d 100644 (file)
@@ -129,7 +129,7 @@ static void bus_free(sd_bus *b) {
         free(b->machine);
         free(b->fake_label);
         free(b->cgroup_root);
-        free(b->connection_name);
+        free(b->description);
 
         free(b->exec_path);
         strv_free(b->exec_argv);
@@ -323,22 +323,12 @@ _public_ int sd_bus_set_trusted(sd_bus *bus, int b) {
         return 0;
 }
 
-_public_ int sd_bus_set_name(sd_bus *bus, const char *name) {
-        char *n;
-
+_public_ int sd_bus_set_description(sd_bus *bus, const char *description) {
         assert_return(bus, -EINVAL);
-        assert_return(name, -EINVAL);
         assert_return(bus->state == BUS_UNSET, -EPERM);
         assert_return(!bus_pid_changed(bus), -ECHILD);
 
-        n = strdup(name);
-        if (!n)
-                return -ENOMEM;
-
-        free(bus->connection_name);
-        bus->connection_name = n;
-
-        return 0;
+        return free_and_strdup(&bus->description, description);
 }
 
 static int hello_callback(sd_bus *bus, sd_bus_message *reply, void *userdata, sd_bus_error *error) {
@@ -1157,17 +1147,13 @@ int bus_set_address_user(sd_bus *b) {
                         return -ENOMEM;
 
 #ifdef ENABLE_KDBUS
-                asprintf(&b->address, KERNEL_USER_BUS_FMT ";" UNIX_USER_BUS_FMT, getuid(), ee);
+                (void) asprintf(&b->address, KERNEL_USER_BUS_FMT ";" UNIX_USER_BUS_FMT, getuid(), ee);
 #else
-                asprintf(&b->address, UNIX_USER_BUS_FMT, ee);
+                (void) asprintf(&b->address, UNIX_USER_BUS_FMT, ee);
 #endif
         } else {
 #ifdef ENABLE_KDBUS
-                int r;
-
-                r = asprintf(&b->address, KERNEL_USER_BUS_FMT, getuid());
-                if (r < 0)
-                        return -ENOMEM;
+                (void) asprintf(&b->address, KERNEL_USER_BUS_FMT, getuid());
 #else
                 return -ECONNREFUSED;
 #endif
@@ -3019,7 +3005,7 @@ static int attach_io_events(sd_bus *bus) {
                 if (r < 0)
                         return r;
 
-                r = sd_event_source_set_name(bus->input_io_event_source, "bus-input");
+                r = sd_event_source_set_description(bus->input_io_event_source, "bus-input");
         } else
                 r = sd_event_source_set_io_fd(bus->input_io_event_source, bus->input_fd);
 
@@ -3038,7 +3024,7 @@ static int attach_io_events(sd_bus *bus) {
                         if (r < 0)
                                 return r;
 
-                        r = sd_event_source_set_name(bus->input_io_event_source, "bus-output");
+                        r = sd_event_source_set_description(bus->input_io_event_source, "bus-output");
                 } else
                         r = sd_event_source_set_io_fd(bus->output_io_event_source, bus->output_fd);
 
@@ -3091,7 +3077,7 @@ _public_ int sd_bus_attach_event(sd_bus *bus, sd_event *event, int priority) {
         if (r < 0)
                 goto fail;
 
-        r = sd_event_source_set_name(bus->time_event_source, "bus-time");
+        r = sd_event_source_set_description(bus->time_event_source, "bus-time");
         if (r < 0)
                 goto fail;
 
@@ -3099,7 +3085,7 @@ _public_ int sd_bus_attach_event(sd_bus *bus, sd_event *event, int priority) {
         if (r < 0)
                 goto fail;
 
-        r = sd_event_source_set_name(bus->quit_event_source, "bus-exit");
+        r = sd_event_source_set_description(bus->quit_event_source, "bus-exit");
         if (r < 0)
                 goto fail;
 
@@ -3326,12 +3312,13 @@ _public_ int sd_bus_try_close(sd_bus *bus) {
         return 0;
 }
 
-_public_ int sd_bus_get_name(sd_bus *bus, const char **name) {
+_public_ int sd_bus_get_description(sd_bus *bus, const char **description) {
         assert_return(bus, -EINVAL);
-        assert_return(name, -EINVAL);
+        assert_return(description, -EINVAL);
+        assert_return(bus->description, -ENXIO);
         assert_return(!bus_pid_changed(bus), -ECHILD);
 
-        *name = bus->connection_name;
+        *description = bus->description;
         return 0;
 }