summaryrefslogtreecommitdiff
path: root/src/login
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2013-03-18 14:38:48 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-18 19:59:33 -0400
commitce0fc5f5f6debc6e37ac3ab0a3ea1c9c35b3ed99 (patch)
treeb94ff8a4451a0484ac307ba9f7894f624c21f722 /src/login
parentc6a818c82035da91e7987920510f0dda61d8781a (diff)
logind: Make more use of cleanup macros
Diffstat (limited to 'src/login')
-rw-r--r--src/login/inhibit.c9
-rw-r--r--src/login/loginctl.c23
-rw-r--r--src/login/logind-dbus.c29
-rw-r--r--src/login/logind-seat-dbus.c22
-rw-r--r--src/login/logind-session-dbus.c29
-rw-r--r--src/login/logind-user-dbus.c22
6 files changed, 32 insertions, 102 deletions
diff --git a/src/login/inhibit.c b/src/login/inhibit.c
index a812195cae..e94843be7f 100644
--- a/src/login/inhibit.c
+++ b/src/login/inhibit.c
@@ -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;
}
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index fe27003a92..387095361d 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -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;
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 1dcdf04b29..ed2ce97156 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -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;
}
diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c
index 4da076e369..585e0c15c3 100644
--- a/src/login/logind-seat-dbus.c
+++ b/src/login/logind-seat-dbus.c
@@ -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;
}
diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c
index c4db315530..1f64c44e2a 100644
--- a/src/login/logind-session-dbus.c
+++ b/src/login/logind-session-dbus.c
@@ -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;
diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c
index 5951c38cb7..32f4062ac5 100644
--- a/src/login/logind-user-dbus.c
+++ b/src/login/logind-user-dbus.c
@@ -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;
}