chiark / gitweb /
logind: Make more use of cleanup macros
authorColin Walters <walters@verbum.org>
Mon, 18 Mar 2013 18:38:48 +0000 (14:38 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 18 Mar 2013 23:59:33 +0000 (19:59 -0400)
src/login/inhibit.c
src/login/loginctl.c
src/login/logind-dbus.c
src/login/logind-seat-dbus.c
src/login/logind-session-dbus.c
src/login/logind-user-dbus.c

index a812195..e94843b 100644 (file)
@@ -42,7 +42,7 @@ static enum {
 } arg_action = ACTION_INHIBIT;
 
 static int inhibit(DBusConnection *bus, DBusError *error) {
-        DBusMessage *reply = NULL;
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         int r;
 
         r = bus_method_call_with_reply(
@@ -66,13 +66,11 @@ static int inhibit(DBusConnection *bus, DBusError *error) {
                                    DBUS_TYPE_INVALID))
                 r = -EIO;
 
-        dbus_message_unref(reply);
-
         return r;
 }
 
 static int print_inhibitors(DBusConnection *bus, DBusError *error) {
-        DBusMessage *reply = NULL;
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         unsigned n = 0;
         DBusMessageIter iter, sub, sub2;
         int r;
@@ -139,9 +137,6 @@ static int print_inhibitors(DBusConnection *bus, DBusError *error) {
         r = 0;
 
 finish:
-        if (reply)
-                dbus_message_unref(reply);
-
         return r;
 }
 
index fe27003..3870953 100644 (file)
@@ -72,7 +72,7 @@ static void polkit_agent_open_if_enabled(void) {
 }
 
 static int list_sessions(DBusConnection *bus, char **args, unsigned n) {
-        DBusMessage *reply = NULL;
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         int r;
         DBusMessageIter iter, sub, sub2;
         unsigned k = 0;
@@ -139,14 +139,11 @@ static int list_sessions(DBusConnection *bus, char **args, unsigned n) {
         r = 0;
 
 finish:
-        if (reply)
-                dbus_message_unref(reply);
-
         return r;
 }
 
 static int list_users(DBusConnection *bus, char **args, unsigned n) {
-        DBusMessage *reply = NULL;
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         int r;
         DBusMessageIter iter, sub, sub2;
         unsigned k = 0;
@@ -211,14 +208,11 @@ static int list_users(DBusConnection *bus, char **args, unsigned n) {
         r = 0;
 
 finish:
-        if (reply)
-                dbus_message_unref(reply);
-
         return r;
 }
 
 static int list_seats(DBusConnection *bus, char **args, unsigned n) {
-        DBusMessage *reply = NULL;
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         int r;
         DBusMessageIter iter, sub, sub2;
         unsigned k = 0;
@@ -281,9 +275,6 @@ static int list_seats(DBusConnection *bus, char **args, unsigned n) {
         r = 0;
 
 finish:
-        if (reply)
-                dbus_message_unref(reply);
-
         return r;
 }
 
@@ -961,7 +952,7 @@ finish:
 }
 
 static int show(DBusConnection *bus, char **args, unsigned n) {
-        DBusMessage *reply = NULL;
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         int r, ret = 0;
         DBusError error;
         unsigned i;
@@ -1048,15 +1039,9 @@ static int show(DBusConnection *bus, char **args, unsigned n) {
                 r = show_one(args[0], bus, path, show_properties, &new_line);
                 if (r != 0)
                         ret = r;
-
-                dbus_message_unref(reply);
-                reply = NULL;
         }
 
 finish:
-        if (reply)
-                dbus_message_unref(reply);
-
         dbus_error_free(&error);
 
         return ret;
index 1dcdf04..ed2ce97 100644 (file)
@@ -319,7 +319,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess
         int r;
         uint32_t vtnr = 0;
         _cleanup_close_ int fifo_fd = -1;
-        DBusMessage *reply = NULL;
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         Session *session = NULL;
         User *user = NULL;
         Seat *seat = NULL;
@@ -536,6 +536,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess
                 }
 
                 *_reply = reply;
+                reply = NULL;
 
                 return 0;
         }
@@ -681,6 +682,7 @@ static int bus_manager_create_session(Manager *m, DBusMessage *message, DBusMess
         }
 
         *_reply = reply;
+        reply = NULL;
 
         return 0;
 
@@ -691,9 +693,6 @@ fail:
         if (user)
                 user_add_to_gc_queue(user);
 
-        if (reply)
-                dbus_message_unref(reply);
-
         return r;
 }
 
@@ -712,7 +711,7 @@ static int bus_manager_inhibit(
         InhibitMode mm;
         unsigned long ul;
         int r, fifo_fd = -1;
-        DBusMessage *reply = NULL;
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
 
         assert(m);
         assert(connection);
@@ -833,6 +832,7 @@ static int bus_manager_inhibit(
 
         close_nointr_nofail(fifo_fd);
         *_reply = reply;
+        reply = NULL;
 
         inhibitor_start(i);
 
@@ -845,9 +845,6 @@ fail:
         if (fifo_fd >= 0)
                 close_nointr_nofail(fifo_fd);
 
-        if (reply)
-                dbus_message_unref(reply);
-
         return r;
 }
 
@@ -1126,7 +1123,7 @@ static int bus_manager_can_shutdown_or_sleep(
 
         bool multiple_sessions, challenge, blocked, b;
         const char *result;
-        DBusMessage *reply = NULL;
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         int r;
         unsigned long ul;
 
@@ -1226,11 +1223,11 @@ finish:
                         DBUS_TYPE_STRING, &result,
                         DBUS_TYPE_INVALID);
         if (!b) {
-                dbus_message_unref(reply);
                 return -ENOMEM;
         }
 
         *_reply = reply;
+        reply = NULL;
         return 0;
 }
 
@@ -1430,7 +1427,7 @@ static DBusHandlerResult manager_message_handler(
         Manager *m = userdata;
 
         DBusError error;
-        DBusMessage *reply = NULL;
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         int r;
 
         assert(connection);
@@ -2338,16 +2335,11 @@ static DBusHandlerResult manager_message_handler(
         if (reply) {
                 if (!bus_maybe_send_reply(connection, message, reply))
                                 goto oom;
-
-                dbus_message_unref(reply);
         }
 
         return DBUS_HANDLER_RESULT_HANDLED;
 
 oom:
-        if (reply)
-                dbus_message_unref(reply);
-
         dbus_error_free(&error);
 
         return DBUS_HANDLER_RESULT_NEED_MEMORY;
@@ -2413,7 +2405,7 @@ DBusHandlerResult bus_message_filter(
 }
 
 int manager_send_changed(Manager *manager, const char *properties) {
-        DBusMessage *m;
+        _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
         int r = -ENOMEM;
 
         assert(manager);
@@ -2428,9 +2420,6 @@ int manager_send_changed(Manager *manager, const char *properties) {
         r = 0;
 
 finish:
-        if (m)
-                dbus_message_unref(m);
-
         return r;
 }
 
index 4da076e..585e0c1 100644 (file)
@@ -260,7 +260,7 @@ static DBusHandlerResult seat_message_dispatch(
                 DBusMessage *message) {
 
         DBusError error;
-        DBusMessage *reply = NULL;
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         int r;
 
         assert(s);
@@ -312,16 +312,11 @@ static DBusHandlerResult seat_message_dispatch(
         if (reply) {
                 if (!bus_maybe_send_reply(connection, message, reply))
                         goto oom;
-
-                dbus_message_unref(reply);
         }
 
         return DBUS_HANDLER_RESULT_HANDLED;
 
 oom:
-        if (reply)
-                dbus_message_unref(reply);
-
         dbus_error_free(&error);
 
         return DBUS_HANDLER_RESULT_NEED_MEMORY;
@@ -376,9 +371,9 @@ char *seat_bus_path(Seat *s) {
 }
 
 int seat_send_signal(Seat *s, bool new_seat) {
-        DBusMessage *m;
+        _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
         int r = -ENOMEM;
-        char *p = NULL;
+        _cleanup_free_ char *p = NULL;
 
         assert(s);
 
@@ -406,16 +401,13 @@ int seat_send_signal(Seat *s, bool new_seat) {
         r = 0;
 
 finish:
-        dbus_message_unref(m);
-        free(p);
-
         return r;
 }
 
 int seat_send_changed(Seat *s, const char *properties) {
-        DBusMessage *m;
+        _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
         int r = -ENOMEM;
-        char *p = NULL;
+        _cleanup_free_ char *p = NULL;
 
         assert(s);
 
@@ -436,9 +428,5 @@ int seat_send_changed(Seat *s, const char *properties) {
         r = 0;
 
 finish:
-        if (m)
-                dbus_message_unref(m);
-        free(p);
-
         return r;
 }
index c4db315..1f64c44 100644 (file)
@@ -307,7 +307,7 @@ static DBusHandlerResult session_message_dispatch(
                 DBusMessage *message) {
 
         DBusError error;
-        DBusMessage *reply = NULL;
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         int r;
 
         assert(s);
@@ -414,16 +414,11 @@ static DBusHandlerResult session_message_dispatch(
         if (reply) {
                 if (!bus_maybe_send_reply(connection, message, reply))
                         goto oom;
-
-                dbus_message_unref(reply);
         }
 
         return DBUS_HANDLER_RESULT_HANDLED;
 
 oom:
-        if (reply)
-                dbus_message_unref(reply);
-
         dbus_error_free(&error);
 
         return DBUS_HANDLER_RESULT_NEED_MEMORY;
@@ -478,9 +473,9 @@ char *session_bus_path(Session *s) {
 }
 
 int session_send_signal(Session *s, bool new_session) {
-        DBusMessage *m;
+        _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
         int r = -ENOMEM;
-        char *p = NULL;
+        _cleanup_free_ char *p = NULL;
 
         assert(s);
 
@@ -508,16 +503,13 @@ int session_send_signal(Session *s, bool new_session) {
         r = 0;
 
 finish:
-        dbus_message_unref(m);
-        free(p);
-
         return r;
 }
 
 int session_send_changed(Session *s, const char *properties) {
-        DBusMessage *m;
+        _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
         int r = -ENOMEM;
-        char *p = NULL;
+        _cleanup_free_ char *p = NULL;
 
         assert(s);
 
@@ -538,17 +530,13 @@ int session_send_changed(Session *s, const char *properties) {
         r = 0;
 
 finish:
-        if (m)
-                dbus_message_unref(m);
-        free(p);
-
         return r;
 }
 
 int session_send_lock(Session *s, bool lock) {
-        DBusMessage *m;
+        _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
         bool b;
-        char *p;
+        _cleanup_free_ char *p = NULL;
 
         assert(s);
 
@@ -557,14 +545,11 @@ int session_send_lock(Session *s, bool lock) {
                 return -ENOMEM;
 
         m = dbus_message_new_signal(p, "org.freedesktop.login1.Session", lock ? "Lock" : "Unlock");
-        free(p);
 
         if (!m)
                 return -ENOMEM;
 
         b = dbus_connection_send(s->manager->bus, m, NULL);
-        dbus_message_unref(m);
-
         if (!b)
                 return -ENOMEM;
 
index 5951c38..32f4062 100644 (file)
@@ -257,7 +257,7 @@ static DBusHandlerResult user_message_dispatch(
                 DBusMessage *message) {
 
         DBusError error;
-        DBusMessage *reply = NULL;
+        _cleanup_dbus_message_unref_ DBusMessage *reply = NULL;
         int r;
 
         assert(u);
@@ -306,16 +306,11 @@ static DBusHandlerResult user_message_dispatch(
         if (reply) {
                 if (!bus_maybe_send_reply(connection, message, reply))
                         goto oom;
-
-                dbus_message_unref(reply);
         }
 
         return DBUS_HANDLER_RESULT_HANDLED;
 
 oom:
-        if (reply)
-                dbus_message_unref(reply);
-
         dbus_error_free(&error);
 
         return DBUS_HANDLER_RESULT_NEED_MEMORY;
@@ -366,9 +361,9 @@ char *user_bus_path(User *u) {
 }
 
 int user_send_signal(User *u, bool new_user) {
-        DBusMessage *m;
+        _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
         int r = -ENOMEM;
-        char *p = NULL;
+        _cleanup_free_ char *p = NULL;
         uint32_t uid;
 
         assert(u);
@@ -399,16 +394,13 @@ int user_send_signal(User *u, bool new_user) {
         r = 0;
 
 finish:
-        dbus_message_unref(m);
-        free(p);
-
         return r;
 }
 
 int user_send_changed(User *u, const char *properties) {
-        DBusMessage *m;
+        _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
         int r = -ENOMEM;
-        char *p = NULL;
+        _cleanup_free_ char *p = NULL;
 
         assert(u);
 
@@ -429,9 +421,5 @@ int user_send_changed(User *u, const char *properties) {
         r = 0;
 
 finish:
-        if (m)
-                dbus_message_unref(m);
-        free(p);
-
         return r;
 }