]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hostnamed: use sd_bus_reply_method_return() to shorten code a bit
authorLennart Poettering <lennart@poettering.net>
Sat, 2 Mar 2024 18:39:13 +0000 (19:39 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 2 Mar 2024 22:03:25 +0000 (22:03 +0000)
src/hostname/hostnamed.c

index e5679ab93156ace0d6b0d8ffda4e2ac5abdf5b26..9dc51a59b506bab62ec4bfdcccbb43b102dc5974 100644 (file)
@@ -1345,7 +1345,6 @@ static int method_get_product_uuid(sd_bus_message *m, void *userdata, sd_bus_err
 }
 
 static int method_get_hardware_serial(sd_bus_message *m, void *userdata, sd_bus_error *error) {
-        _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
         _cleanup_free_ char *serial = NULL;
         Context *c = ASSERT_PTR(userdata);
         int r;
@@ -1368,15 +1367,7 @@ static int method_get_hardware_serial(sd_bus_message *m, void *userdata, sd_bus_
                 return sd_bus_error_set(error, BUS_ERROR_NO_HARDWARE_SERIAL,
                                         "Failed to read hardware serial from firmware.");
 
-        r = sd_bus_message_new_method_return(m, &reply);
-        if (r < 0)
-                return r;
-
-        r = sd_bus_message_append(reply, "s", serial);
-        if (r < 0)
-                return r;
-
-        return sd_bus_send(NULL, reply, NULL);
+        return sd_bus_reply_method_return(m, "s", serial);
 }
 
 static int build_describe_response(Context *c, bool privileged, JsonVariant **ret) {
@@ -1489,7 +1480,6 @@ static int build_describe_response(Context *c, bool privileged, JsonVariant **re
 }
 
 static int method_describe(sd_bus_message *m, void *userdata, sd_bus_error *error) {
-        _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
         _cleanup_(json_variant_unrefp) JsonVariant *v = NULL;
         Context *c = ASSERT_PTR(userdata);
         _cleanup_free_ char *text = NULL;
@@ -1519,15 +1509,7 @@ static int method_describe(sd_bus_message *m, void *userdata, sd_bus_error *erro
         if (r < 0)
                 return log_error_errno(r, "Failed to format JSON data: %m");
 
-        r = sd_bus_message_new_method_return(m, &reply);
-        if (r < 0)
-                return r;
-
-        r = sd_bus_message_append(reply, "s", text);
-        if (r < 0)
-                return r;
-
-        return sd_bus_send(NULL, reply, NULL);
+        return sd_bus_reply_method_return(m, "s", text);
 }
 
 static const sd_bus_vtable hostname_vtable[] = {