chiark / gitweb /
sd-bus,sd-event: unify error handling of object descriptions
[elogind.git] / src / libsystemd / sd-bus / sd-bus.c
index 318cf6bae59c270ce9e03f110fdcdb039f1c2320..a3165fb4f743df7b544d22471022e26ffe2abc6d 100644 (file)
@@ -324,21 +324,11 @@ _public_ int sd_bus_set_trusted(sd_bus *bus, int b) {
 }
 
 _public_ int sd_bus_set_description(sd_bus *bus, const char *description) {
-        char *n;
-
         assert_return(bus, -EINVAL);
-        assert_return(description, -EINVAL);
         assert_return(bus->state == BUS_UNSET, -EPERM);
         assert_return(!bus_pid_changed(bus), -ECHILD);
 
-        n = strdup(description);
-        if (!n)
-                return -ENOMEM;
-
-        free(bus->description);
-        bus->description = 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) {
@@ -3015,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);
 
@@ -3034,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);
 
@@ -3087,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;
 
@@ -3095,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;
 
@@ -3325,6 +3315,7 @@ _public_ int sd_bus_try_close(sd_bus *bus) {
 _public_ int sd_bus_get_description(sd_bus *bus, const char **description) {
         assert_return(bus, -EINVAL);
         assert_return(description, -EINVAL);
+        assert_return(bus->description, -ENXIO);
         assert_return(!bus_pid_changed(bus), -ECHILD);
 
         *description = bus->description;