chiark / gitweb /
test-bus-chat: various modernizations
authorLennart Poettering <lennart@poettering.net>
Thu, 14 May 2015 20:41:19 +0000 (22:41 +0200)
committerSven Eden <yamakuzure@gmx.net>
Tue, 14 Mar 2017 08:56:08 +0000 (09:56 +0100)
src/libelogind/sd-bus/test-bus-chat.c

index 1e50dfc43323950eb2d189d20370be229ca88515..046e999008283941f1087f37f2fc5466f0a66a70 100644 (file)
@@ -263,10 +263,10 @@ fail:
 static void* client1(void*p) {
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_bus_close_unref_ sd_bus *bus = NULL;
-        sd_bus_error error = SD_BUS_ERROR_NULL;
+        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         const char *hello;
         int r;
-        int pp[2] = { -1, -1 };
+        _cleanup_close_pair_ int pp[2] = { -1, -1 };
         char x;
 
         r = sd_bus_open_user(&bus);
@@ -347,10 +347,6 @@ finish:
 
         }
 
-        sd_bus_error_free(&error);
-
-        safe_close_pair(pp);
-
         return INT_TO_PTR(r);
 }
 
@@ -365,8 +361,8 @@ static int quit_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_er
 
 static void* client2(void*p) {
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
-        sd_bus *bus = NULL;
-        sd_bus_error error = SD_BUS_ERROR_NULL;
+        _cleanup_bus_close_unref_ sd_bus *bus = NULL;
+        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         bool quit = false;
         const char *mid;
         int r;
@@ -395,8 +391,7 @@ static void* client2(void*p) {
                 goto finish;
         }
 
-        sd_bus_message_unref(m);
-        m = NULL;
+        m = sd_bus_message_unref(m);
 
         r = sd_bus_message_new_signal(
                         bus,
@@ -415,8 +410,7 @@ static void* client2(void*p) {
                 goto finish;
         }
 
-        sd_bus_message_unref(m);
-        m = NULL;
+        m = sd_bus_message_unref(m);
 
         r = sd_bus_message_new_method_call(
                         bus,
@@ -444,8 +438,7 @@ static void* client2(void*p) {
 
         log_info("Machine ID is %s.", mid);
 
-        sd_bus_message_unref(m);
-        m = NULL;
+        m = sd_bus_message_unref(m);
 
         r = sd_bus_message_new_method_call(
                         bus,
@@ -459,8 +452,7 @@ static void* client2(void*p) {
                 goto finish;
         }
 
-        sd_bus_message_unref(reply);
-        reply = NULL;
+        reply = sd_bus_message_unref(reply);
 
         r = sd_bus_call(bus, m, 200 * USEC_PER_MSEC, &error, &reply);
         if (r < 0)
@@ -468,8 +460,7 @@ static void* client2(void*p) {
         else
                 log_info("Slow call succeed.");
 
-        sd_bus_message_unref(m);
-        m = NULL;
+        m = sd_bus_message_unref(m);
 
         r = sd_bus_message_new_method_call(
                         bus,
@@ -522,12 +513,9 @@ finish:
                         goto finish;
                 }
 
-                sd_bus_send(bus, q, NULL);
-                sd_bus_flush(bus);
-                sd_bus_unref(bus);
+                (void) sd_bus_send(bus, q, NULL);
         }
 
-        sd_bus_error_free(&error);
         return INT_TO_PTR(r);
 }