chiark / gitweb /
logind: exploit previous cleanups and simplify returns
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 19 Mar 2013 00:31:21 +0000 (20:31 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 19 Mar 2013 00:58:39 +0000 (20:58 -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 e94843b..9cb321f 100644 (file)
@@ -64,7 +64,7 @@ static int inhibit(DBusConnection *bus, DBusError *error) {
         if (!dbus_message_get_args(reply, error,
                                    DBUS_TYPE_UNIX_FD, &r,
                                    DBUS_TYPE_INVALID))
-                r = -EIO;
+                return -EIO;
 
         return r;
 }
@@ -85,27 +85,21 @@ static int print_inhibitors(DBusConnection *bus, DBusError *error) {
                         NULL,
                         DBUS_TYPE_INVALID);
         if (r < 0)
-                goto finish;
+                return r;
 
-        if (!dbus_message_iter_init(reply, &iter)) {
-                r = -ENOMEM;
-                goto finish;
-        }
+        if (!dbus_message_iter_init(reply, &iter))
+                return -ENOMEM;
 
-        if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
-                r = -EIO;
-                goto finish;
-        }
+        if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY)
+                return -EIO;
 
         dbus_message_iter_recurse(&iter, &sub);
         while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
                 const char *what, *who, *why, *mode;
                 dbus_uint32_t uid, pid;
 
-                if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) {
-                        r = -EIO;
-                        goto finish;
-                }
+                if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT)
+                        return -EIO;
 
                 dbus_message_iter_recurse(&sub, &sub2);
 
@@ -114,10 +108,8 @@ static int print_inhibitors(DBusConnection *bus, DBusError *error) {
                     bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &why, true) < 0 ||
                     bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &mode, true) < 0 ||
                     bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_UINT32, &uid, true) < 0 ||
-                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_UINT32, &pid, false) < 0) {
-                        r = -EIO;
-                        goto finish;
-                }
+                    bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_UINT32, &pid, false) < 0)
+                        return -EIO;
 
                 printf("     Who: %s (UID %lu, PID %lu)\n"
                        "    What: %s\n"
@@ -134,10 +126,7 @@ static int print_inhibitors(DBusConnection *bus, DBusError *error) {
         }
 
         printf("%u inhibitors listed.\n", n);
-        r = 0;
-
-finish:
-        return r;
+        return 0;
 }
 
 static int help(void) {
@@ -240,7 +229,7 @@ int main(int argc, char *argv[]) {
         int r, exit_code = 0;
         DBusConnection *bus = NULL;
         DBusError error;
-        int fd = -1;
+        int _cleanup_close_ fd = -1;
 
         dbus_error_init(&error);
 
@@ -313,8 +302,5 @@ finish:
 
         dbus_error_free(&error);
 
-        if (fd >= 0)
-                close_nointr_nofail(fd);
-
         return r < 0 ? EXIT_FAILURE : exit_code;
 }
index 3870953..6c229c6 100644 (file)
@@ -89,14 +89,13 @@ static int list_sessions(DBusConnection *bus, char **args, unsigned n) {
                         NULL,
                         DBUS_TYPE_INVALID);
         if (r)
-                goto finish;
+                return r;
 
         if (!dbus_message_iter_init(reply, &iter) ||
             dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
             dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRUCT)  {
                 log_error("Failed to parse reply.");
-                r = -EIO;
-                goto finish;
+                return -EIO;
         }
 
         dbus_message_iter_recurse(&iter, &sub);
@@ -110,8 +109,7 @@ static int list_sessions(DBusConnection *bus, char **args, unsigned n) {
 
                 if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) {
                         log_error("Failed to parse reply.");
-                        r = -EIO;
-                        goto finish;
+                        return -EIO;
                 }
 
                 dbus_message_iter_recurse(&sub, &sub2);
@@ -122,8 +120,7 @@ static int list_sessions(DBusConnection *bus, char **args, unsigned n) {
                     bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &seat, true) < 0 ||
                     bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_OBJECT_PATH, &object, false) < 0) {
                         log_error("Failed to parse reply.");
-                        r = -EIO;
-                        goto finish;
+                        return -EIO;
                 }
 
                 printf("%10s %10u %-16s %-16s\n", id, (unsigned) uid, user, seat);
@@ -136,10 +133,7 @@ static int list_sessions(DBusConnection *bus, char **args, unsigned n) {
         if (on_tty())
                 printf("\n%u sessions listed.\n", k);
 
-        r = 0;
-
-finish:
-        return r;
+        return 0;
 }
 
 static int list_users(DBusConnection *bus, char **args, unsigned n) {
@@ -160,14 +154,13 @@ static int list_users(DBusConnection *bus, char **args, unsigned n) {
                         NULL,
                         DBUS_TYPE_INVALID);
         if (r)
-              goto finish;
+                return r;
 
         if (!dbus_message_iter_init(reply, &iter) ||
             dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
             dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRUCT)  {
                 log_error("Failed to parse reply.");
-                r = -EIO;
-                goto finish;
+                return -EIO;
         }
 
         dbus_message_iter_recurse(&iter, &sub);
@@ -181,8 +174,7 @@ static int list_users(DBusConnection *bus, char **args, unsigned n) {
 
                 if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) {
                         log_error("Failed to parse reply.");
-                        r = -EIO;
-                        goto finish;
+                        return -EIO;
                 }
 
                 dbus_message_iter_recurse(&sub, &sub2);
@@ -191,8 +183,7 @@ static int list_users(DBusConnection *bus, char **args, unsigned n) {
                     bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &user, true) < 0 ||
                     bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_OBJECT_PATH, &object, false) < 0) {
                         log_error("Failed to parse reply.");
-                        r = -EIO;
-                        goto finish;
+                        return -EIO;
                 }
 
                 printf("%10u %-16s\n", (unsigned) uid, user);
@@ -205,10 +196,7 @@ static int list_users(DBusConnection *bus, char **args, unsigned n) {
         if (on_tty())
                 printf("\n%u users listed.\n", k);
 
-        r = 0;
-
-finish:
-        return r;
+        return 0;
 }
 
 static int list_seats(DBusConnection *bus, char **args, unsigned n) {
@@ -229,14 +217,13 @@ static int list_seats(DBusConnection *bus, char **args, unsigned n) {
                         NULL,
                         DBUS_TYPE_INVALID);
         if (r)
-                goto finish;
+                return r;
 
         if (!dbus_message_iter_init(reply, &iter) ||
             dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY ||
             dbus_message_iter_get_element_type(&iter) != DBUS_TYPE_STRUCT)  {
                 log_error("Failed to parse reply.");
-                r = -EIO;
-                goto finish;
+                return -EIO;
         }
 
         dbus_message_iter_recurse(&iter, &sub);
@@ -249,8 +236,7 @@ static int list_seats(DBusConnection *bus, char **args, unsigned n) {
 
                 if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRUCT) {
                         log_error("Failed to parse reply.");
-                        r = -EIO;
-                        goto finish;
+                        return -EIO;
                 }
 
                 dbus_message_iter_recurse(&sub, &sub2);
@@ -258,8 +244,7 @@ static int list_seats(DBusConnection *bus, char **args, unsigned n) {
                 if (bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_STRING, &seat, true) < 0 ||
                     bus_iter_get_basic_and_next(&sub2, DBUS_TYPE_OBJECT_PATH, &object, false) < 0) {
                         log_error("Failed to parse reply.");
-                        r = -EIO;
-                        goto finish;
+                        return -EIO;
                 }
 
                 printf("%-16s\n", seat);
@@ -272,10 +257,7 @@ static int list_seats(DBusConnection *bus, char **args, unsigned n) {
         if (on_tty())
                 printf("\n%u seats listed.\n", k);
 
-        r = 0;
-
-finish:
-        return r;
+        return 0;
 }
 
 typedef struct SessionStatusInfo {
@@ -1077,7 +1059,6 @@ finish:
 }
 
 static int kill_session(DBusConnection *bus, char **args, unsigned n) {
-        int ret = 0;
         unsigned i;
 
         assert(args);
@@ -1086,28 +1067,28 @@ static int kill_session(DBusConnection *bus, char **args, unsigned n) {
                 arg_kill_who = "all";
 
         for (i = 1; i < n; i++) {
-                ret = bus_method_call_with_reply (
-                                bus,
-                                "org.freedesktop.login1",
-                                "/org/freedesktop/login1",
-                                "org.freedesktop.login1.Manager",
-                                "KillSession",
-                                NULL,
-                                NULL,
-                                DBUS_TYPE_STRING, &args[i],
-                                DBUS_TYPE_STRING, &arg_kill_who,
-                                DBUS_TYPE_INT32, &arg_signal,
-                                DBUS_TYPE_INVALID);
-                if (ret)
-                        goto finish;
+                int r;
+
+                r = bus_method_call_with_reply (
+                        bus,
+                        "org.freedesktop.login1",
+                        "/org/freedesktop/login1",
+                        "org.freedesktop.login1.Manager",
+                        "KillSession",
+                        NULL,
+                        NULL,
+                        DBUS_TYPE_STRING, &args[i],
+                        DBUS_TYPE_STRING, &arg_kill_who,
+                        DBUS_TYPE_INT32, &arg_signal,
+                        DBUS_TYPE_INVALID);
+                if (r)
+                        return r;
         }
 
-finish:
-        return ret;
+        return 0;
 }
 
 static int enable_linger(DBusConnection *bus, char **args, unsigned n) {
-        int ret = 0;
         unsigned i;
         dbus_bool_t b, interactive = true;
 
@@ -1120,36 +1101,35 @@ static int enable_linger(DBusConnection *bus, char **args, unsigned n) {
         for (i = 1; i < n; i++) {
                 uint32_t u;
                 uid_t uid;
+                int r;
 
-                ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
-                if (ret < 0) {
-                        log_error("Failed to resolve user %s: %s", args[i], strerror(-ret));
-                        goto finish;
+                r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
+                if (r < 0) {
+                        log_error("Failed to resolve user %s: %s", args[i], strerror(-r));
+                        return r;
                 }
 
                 u = (uint32_t) uid;
-                ret = bus_method_call_with_reply (
-                                bus,
-                                "org.freedesktop.login1",
-                                "/org/freedesktop/login1",
-                                "org.freedesktop.login1.Manager",
-                                "SetUserLinger",
-                                NULL,
-                                NULL,
-                                DBUS_TYPE_UINT32, &u,
-                                DBUS_TYPE_BOOLEAN, &b,
-                                DBUS_TYPE_BOOLEAN, &interactive,
-                                DBUS_TYPE_INVALID);
-                if (ret)
-                        goto finish;
+                r = bus_method_call_with_reply (
+                        bus,
+                        "org.freedesktop.login1",
+                        "/org/freedesktop/login1",
+                        "org.freedesktop.login1.Manager",
+                        "SetUserLinger",
+                        NULL,
+                        NULL,
+                        DBUS_TYPE_UINT32, &u,
+                        DBUS_TYPE_BOOLEAN, &b,
+                        DBUS_TYPE_BOOLEAN, &interactive,
+                        DBUS_TYPE_INVALID);
+                if (r)
+                        return r;
         }
 
-finish:
-        return ret;
+        return 0;
 }
 
 static int terminate_user(DBusConnection *bus, char **args, unsigned n) {
-        int ret = 0;
         unsigned i;
 
         assert(args);
@@ -1157,34 +1137,33 @@ static int terminate_user(DBusConnection *bus, char **args, unsigned n) {
         for (i = 1; i < n; i++) {
                 uint32_t u;
                 uid_t uid;
+                int r;
 
-                ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
-                if (ret < 0) {
-                        log_error("Failed to look up user %s: %s", args[i], strerror(-ret));
-                        goto finish;
+                r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
+                if (r < 0) {
+                        log_error("Failed to look up user %s: %s", args[i], strerror(-r));
+                        return r;
                 }
 
                 u = (uint32_t) uid;
-                ret = bus_method_call_with_reply (
-                                bus,
-                                "org.freedesktop.login1",
-                                "/org/freedesktop/login1",
-                                "org.freedesktop.login1.Manager",
-                                "TerminateUser",
-                                NULL,
-                                NULL,
-                                DBUS_TYPE_UINT32, &u,
-                                DBUS_TYPE_INVALID);
-                if (ret)
-                        goto finish;
+                r = bus_method_call_with_reply (
+                        bus,
+                        "org.freedesktop.login1",
+                        "/org/freedesktop/login1",
+                        "org.freedesktop.login1.Manager",
+                        "TerminateUser",
+                        NULL,
+                        NULL,
+                        DBUS_TYPE_UINT32, &u,
+                        DBUS_TYPE_INVALID);
+                if (r)
+                        return r;
         }
 
-finish:
-        return ret;
+        return 0;
 }
 
 static int kill_user(DBusConnection *bus, char **args, unsigned n) {
-        int ret = 0;
         unsigned i;
 
         assert(args);
@@ -1195,35 +1174,34 @@ static int kill_user(DBusConnection *bus, char **args, unsigned n) {
         for (i = 1; i < n; i++) {
                 uid_t uid;
                 uint32_t u;
+                int r;
 
-                ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
-                if (ret < 0) {
-                        log_error("Failed to look up user %s: %s", args[i], strerror(-ret));
-                        goto finish;
+                r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
+                if (r < 0) {
+                        log_error("Failed to look up user %s: %s", args[i], strerror(-r));
+                        return r;
                 }
 
                 u = (uint32_t) uid;
-                ret = bus_method_call_with_reply (
-                                bus,
-                                "org.freedesktop.login1",
-                                "/org/freedesktop/login1",
-                                "org.freedesktop.login1.Manager",
-                                "KillUser",
-                                NULL,
-                                NULL,
-                                DBUS_TYPE_UINT32, &u,
-                                DBUS_TYPE_INT32, &arg_signal,
-                                DBUS_TYPE_INVALID);
-                if (ret)
-                        goto finish;
+                r = bus_method_call_with_reply (
+                        bus,
+                        "org.freedesktop.login1",
+                        "/org/freedesktop/login1",
+                        "org.freedesktop.login1.Manager",
+                        "KillUser",
+                        NULL,
+                        NULL,
+                        DBUS_TYPE_UINT32, &u,
+                        DBUS_TYPE_INT32, &arg_signal,
+                        DBUS_TYPE_INVALID);
+                if (r)
+                        return r;
         }
 
-finish:
-        return ret;
+        return 0;
 }
 
 static int attach(DBusConnection *bus, char **args, unsigned n) {
-        int ret = 0;
         unsigned i;
         dbus_bool_t interactive = true;
 
@@ -1232,24 +1210,25 @@ static int attach(DBusConnection *bus, char **args, unsigned n) {
         polkit_agent_open_if_enabled();
 
         for (i = 2; i < n; i++) {
-                ret = bus_method_call_with_reply (
-                                bus,
-                                "org.freedesktop.login1",
-                                "/org/freedesktop/login1",
-                                "org.freedesktop.login1.Manager",
-                                "AttachDevice",
-                                NULL,
-                                NULL,
-                                DBUS_TYPE_STRING, &args[1],
-                                DBUS_TYPE_STRING, &args[i],
-                                DBUS_TYPE_BOOLEAN, &interactive,
-                                DBUS_TYPE_INVALID);
-                if (ret)
-                        goto finish;
+                int r;
+
+                r = bus_method_call_with_reply (
+                        bus,
+                        "org.freedesktop.login1",
+                        "/org/freedesktop/login1",
+                        "org.freedesktop.login1.Manager",
+                        "AttachDevice",
+                        NULL,
+                        NULL,
+                        DBUS_TYPE_STRING, &args[1],
+                        DBUS_TYPE_STRING, &args[i],
+                        DBUS_TYPE_BOOLEAN, &interactive,
+                        DBUS_TYPE_INVALID);
+                if (r)
+                        return r;
         }
 
-finish:
-        return ret;
+        return 0;
 }
 
 static int flush_devices(DBusConnection *bus, char **args, unsigned n) {
@@ -1288,28 +1267,28 @@ static int lock_sessions(DBusConnection *bus, char **args, unsigned n) {
 }
 
 static int terminate_seat(DBusConnection *bus, char **args, unsigned n) {
-        int ret = 0;
         unsigned i;
 
         assert(args);
 
         for (i = 1; i < n; i++) {
-                ret = bus_method_call_with_reply (
-                                bus,
-                                "org.freedesktop.login1",
-                                "/org/freedesktop/login1",
-                                "org.freedesktop.login1.Manager",
-                                "TerminateSeat",
-                                NULL,
-                                NULL,
-                                DBUS_TYPE_STRING, &args[i],
-                                DBUS_TYPE_INVALID);
-                if (ret)
-                        goto finish;
+                int r;
+
+                r = bus_method_call_with_reply (
+                        bus,
+                        "org.freedesktop.login1",
+                        "/org/freedesktop/login1",
+                        "org.freedesktop.login1.Manager",
+                        "TerminateSeat",
+                        NULL,
+                        NULL,
+                        DBUS_TYPE_STRING, &args[i],
+                        DBUS_TYPE_INVALID);
+                if (r)
+                        return r;
         }
 
-finish:
-        return ret;
+        return 0;
 }
 
 static int help(void) {
index ed2ce97..4ae8362 100644 (file)
@@ -901,7 +901,7 @@ finish:
 
 static int attach_device(Manager *m, const char *seat, const char *sysfs) {
         struct udev_device *d;
-        char *rule = NULL, *file = NULL;
+        char _cleanup_free_ *rule = NULL, *file = NULL;
         const char *id_for_seat;
         int r;
 
@@ -943,9 +943,6 @@ static int attach_device(Manager *m, const char *seat, const char *sysfs) {
         r = trigger_device(m, d);
 
 finish:
-        free(rule);
-        free(file);
-
         if (d)
                 udev_device_unref(d);
 
@@ -953,7 +950,7 @@ finish:
 }
 
 static int flush_devices(Manager *m) {
-        DIR *d;
+        DIR _cleanup_closedir_ *d;
 
         assert(m);
 
@@ -978,8 +975,6 @@ static int flush_devices(Manager *m) {
                         if (unlinkat(dirfd(d), de->d_name, 0) < 0)
                                 log_warning("Failed to unlink %s: %m", de->d_name);
                 }
-
-                closedir(d);
         }
 
         return trigger_device(m, NULL);
@@ -1222,9 +1217,8 @@ finish:
                         reply,
                         DBUS_TYPE_STRING, &result,
                         DBUS_TYPE_INVALID);
-        if (!b) {
+        if (!b)
                 return -ENOMEM;
-        }
 
         *_reply = reply;
         reply = NULL;
@@ -2406,21 +2400,19 @@ DBusHandlerResult bus_message_filter(
 
 int manager_send_changed(Manager *manager, const char *properties) {
         _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
-        int r = -ENOMEM;
 
         assert(manager);
 
-        m = bus_properties_changed_new("/org/freedesktop/login1", "org.freedesktop.login1.Manager", properties);
+        m = bus_properties_changed_new("/org/freedesktop/login1",
+                                       "org.freedesktop.login1.Manager",
+                                       properties);
         if (!m)
-                goto finish;
+                return -ENOMEM;
 
         if (!dbus_connection_send(manager->bus, m, NULL))
-                goto finish;
-
-        r = 0;
+                return -ENOMEM;
 
-finish:
-        return r;
+        return 0;
 }
 
 int manager_dispatch_delayed(Manager *manager) {
index 585e0c1..82f25a0 100644 (file)
@@ -61,7 +61,7 @@ static int bus_seat_append_active(DBusMessageIter *i, const char *property, void
         DBusMessageIter sub;
         Seat *s = data;
         const char *id, *path;
-        char *p = NULL;
+        char _cleanup_free_ *p = NULL;
 
         assert(i);
         assert(property);
@@ -82,12 +82,8 @@ static int bus_seat_append_active(DBusMessageIter *i, const char *property, void
         }
 
         if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &id) ||
-            !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path)) {
-                free(p);
+            !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path))
                 return -ENOMEM;
-        }
-
-        free(p);
 
         if (!dbus_message_iter_close_container(i, &sub))
                 return -ENOMEM;
@@ -108,7 +104,7 @@ static int bus_seat_append_sessions(DBusMessageIter *i, const char *property, vo
                 return -ENOMEM;
 
         LIST_FOREACH(sessions_by_seat, session, s->sessions) {
-                char *p;
+                char _cleanup_free_ *p = NULL;
 
                 if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_STRUCT, NULL, &sub2))
                         return -ENOMEM;
@@ -118,12 +114,8 @@ static int bus_seat_append_sessions(DBusMessageIter *i, const char *property, vo
                         return -ENOMEM;
 
                 if (!dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &session->id) ||
-                    !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &p)) {
-                        free(p);
+                    !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_OBJECT_PATH, &p))
                         return -ENOMEM;
-                }
-
-                free(p);
 
                 if (!dbus_message_iter_close_container(&sub, &sub2))
                         return -ENOMEM;
@@ -356,7 +348,7 @@ const DBusObjectPathVTable bus_seat_vtable = {
 };
 
 char *seat_bus_path(Seat *s) {
-        char *t, *r;
+        char _cleanup_free_ *t;
 
         assert(s);
 
@@ -364,15 +356,11 @@ char *seat_bus_path(Seat *s) {
         if (!t)
                 return NULL;
 
-        r = strappend("/org/freedesktop/login1/seat/", t);
-        free(t);
-
-        return r;
+        return strappend("/org/freedesktop/login1/seat/", t);
 }
 
 int seat_send_signal(Seat *s, bool new_seat) {
         _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
-        int r = -ENOMEM;
         _cleanup_free_ char *p = NULL;
 
         assert(s);
@@ -380,33 +368,28 @@ int seat_send_signal(Seat *s, bool new_seat) {
         m = dbus_message_new_signal("/org/freedesktop/login1",
                                     "org.freedesktop.login1.Manager",
                                     new_seat ? "SeatNew" : "SeatRemoved");
-
         if (!m)
                 return -ENOMEM;
 
         p = seat_bus_path(s);
         if (!p)
-                goto finish;
+                return -ENOMEM;
 
         if (!dbus_message_append_args(
                             m,
                             DBUS_TYPE_STRING, &s->id,
                             DBUS_TYPE_OBJECT_PATH, &p,
                             DBUS_TYPE_INVALID))
-                goto finish;
+                return -ENOMEM;
 
         if (!dbus_connection_send(s->manager->bus, m, NULL))
-                goto finish;
-
-        r = 0;
+                return -ENOMEM;
 
-finish:
-        return r;
+        return 0;
 }
 
 int seat_send_changed(Seat *s, const char *properties) {
         _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
-        int r = -ENOMEM;
         _cleanup_free_ char *p = NULL;
 
         assert(s);
@@ -420,13 +403,10 @@ int seat_send_changed(Seat *s, const char *properties) {
 
         m = bus_properties_changed_new(p, "org.freedesktop.login1.Seat", properties);
         if (!m)
-                goto finish;
+                return -ENOMEM;
 
         if (!dbus_connection_send(s->manager->bus, m, NULL))
-                goto finish;
-
-        r = 0;
+                return -ENOMEM;
 
-finish:
-        return r;
+        return 0;
 }
index 1f64c44..0e425e4 100644 (file)
@@ -108,12 +108,8 @@ static int bus_session_append_seat(DBusMessageIter *i, const char *property, voi
         }
 
         if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &id) ||
-            !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path)) {
-                free(p);
+            !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path))
                 return -ENOMEM;
-        }
-
-        free(p);
 
         if (!dbus_message_iter_close_container(i, &sub))
                 return -ENOMEM;
@@ -124,7 +120,7 @@ static int bus_session_append_seat(DBusMessageIter *i, const char *property, voi
 static int bus_session_append_user(DBusMessageIter *i, const char *property, void *data) {
         DBusMessageIter sub;
         User *u = data;
-        char *p = NULL;
+        char _cleanup_free_ *p = NULL;
 
         assert(i);
         assert(property);
@@ -138,12 +134,8 @@ static int bus_session_append_user(DBusMessageIter *i, const char *property, voi
                 return -ENOMEM;
 
         if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_UINT32, &u->uid) ||
-            !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &p)) {
-                free(p);
+            !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &p))
                 return -ENOMEM;
-        }
-
-        free(p);
 
         if (!dbus_message_iter_close_container(i, &sub))
                 return -ENOMEM;
@@ -205,7 +197,7 @@ static int bus_session_append_idle_hint_since(DBusMessageIter *i, const char *pr
 
 static int bus_session_append_default_cgroup(DBusMessageIter *i, const char *property, void *data) {
         Session *s = data;
-        char *t;
+        char _cleanup_free_ *t = NULL;
         int r;
         bool success;
 
@@ -218,8 +210,6 @@ static int bus_session_append_default_cgroup(DBusMessageIter *i, const char *pro
                 return r;
 
         success = dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t);
-        free(t);
-
         return success ? 0 : -ENOMEM;
 }
 
@@ -458,7 +448,7 @@ const DBusObjectPathVTable bus_session_vtable = {
 };
 
 char *session_bus_path(Session *s) {
-        char *t, *r;
+        char _cleanup_free_ *t;
 
         assert(s);
 
@@ -466,15 +456,11 @@ char *session_bus_path(Session *s) {
         if (!t)
                 return NULL;
 
-        r = strappend("/org/freedesktop/login1/session/", t);
-        free(t);
-
-        return r;
+        return strappend("/org/freedesktop/login1/session/", t);
 }
 
 int session_send_signal(Session *s, bool new_session) {
         _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
-        int r = -ENOMEM;
         _cleanup_free_ char *p = NULL;
 
         assert(s);
@@ -488,27 +474,23 @@ int session_send_signal(Session *s, bool new_session) {
 
         p = session_bus_path(s);
         if (!p)
-                goto finish;
+                return -ENOMEM;
 
         if (!dbus_message_append_args(
                             m,
                             DBUS_TYPE_STRING, &s->id,
                             DBUS_TYPE_OBJECT_PATH, &p,
                             DBUS_TYPE_INVALID))
-                goto finish;
+                return -ENOMEM;
 
         if (!dbus_connection_send(s->manager->bus, m, NULL))
-                goto finish;
-
-        r = 0;
+                return -ENOMEM;
 
-finish:
-        return r;
+        return 0;
 }
 
 int session_send_changed(Session *s, const char *properties) {
         _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
-        int r = -ENOMEM;
         _cleanup_free_ char *p = NULL;
 
         assert(s);
@@ -522,15 +504,12 @@ int session_send_changed(Session *s, const char *properties) {
 
         m = bus_properties_changed_new(p, "org.freedesktop.login1.Session", properties);
         if (!m)
-                goto finish;
+                return -ENOMEM;
 
         if (!dbus_connection_send(s->manager->bus, m, NULL))
-                goto finish;
-
-        r = 0;
+                return -ENOMEM;
 
-finish:
-        return r;
+        return 0;
 }
 
 int session_send_lock(Session *s, bool lock) {
index 32f4062..8cc1dd4 100644 (file)
@@ -65,7 +65,7 @@ static int bus_user_append_display(DBusMessageIter *i, const char *property, voi
         DBusMessageIter sub;
         User *u = data;
         const char *id, *path;
-        char *p = NULL;
+        char _cleanup_free_ *p = NULL;
 
         assert(i);
         assert(property);
@@ -86,12 +86,8 @@ static int bus_user_append_display(DBusMessageIter *i, const char *property, voi
         }
 
         if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &id) ||
-            !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path)) {
-                free(p);
+            !dbus_message_iter_append_basic(&sub, DBUS_TYPE_OBJECT_PATH, &path))
                 return -ENOMEM;
-        }
-
-        free(p);
 
         if (!dbus_message_iter_close_container(i, &sub))
                 return -ENOMEM;
@@ -191,7 +187,7 @@ static int bus_user_append_idle_hint_since(DBusMessageIter *i, const char *prope
 
 static int bus_user_append_default_cgroup(DBusMessageIter *i, const char *property, void *data) {
         User *u = data;
-        char *t;
+        char _cleanup_free_ *t = NULL;
         int r;
         bool success;
 
@@ -204,8 +200,6 @@ static int bus_user_append_default_cgroup(DBusMessageIter *i, const char *proper
                 return r;
 
         success = dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t);
-        free(t);
-
         return success ? 0 : -ENOMEM;
 }
 
@@ -362,7 +356,6 @@ char *user_bus_path(User *u) {
 
 int user_send_signal(User *u, bool new_user) {
         _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
-        int r = -ENOMEM;
         _cleanup_free_ char *p = NULL;
         uint32_t uid;
 
@@ -377,7 +370,7 @@ int user_send_signal(User *u, bool new_user) {
 
         p = user_bus_path(u);
         if (!p)
-                goto finish;
+                return -ENOMEM;
 
         uid = u->uid;
 
@@ -386,20 +379,16 @@ int user_send_signal(User *u, bool new_user) {
                             DBUS_TYPE_UINT32, &uid,
                             DBUS_TYPE_OBJECT_PATH, &p,
                             DBUS_TYPE_INVALID))
-                goto finish;
+                return -ENOMEM;
 
         if (!dbus_connection_send(u->manager->bus, m, NULL))
-                goto finish;
-
-        r = 0;
+                return -ENOMEM;
 
-finish:
-        return r;
+        return 0;
 }
 
 int user_send_changed(User *u, const char *properties) {
         _cleanup_dbus_message_unref_ DBusMessage *m = NULL;
-        int r = -ENOMEM;
         _cleanup_free_ char *p = NULL;
 
         assert(u);
@@ -413,13 +402,10 @@ int user_send_changed(User *u, const char *properties) {
 
         m = bus_properties_changed_new(p, "org.freedesktop.login1.User", properties);
         if (!m)
-                goto finish;
+                return -ENOMEM;
 
         if (!dbus_connection_send(u->manager->bus, m, NULL))
-                goto finish;
-
-        r = 0;
+                return -ENOMEM;
 
-finish:
-        return r;
+        return 0;
 }