summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-08-07 10:10:12 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2018-08-07 10:10:12 +0900
commitfb2367edd943d37f418725c90498a940016e80bd (patch)
treeb8fa8338084d63285a7de80a1520efd98b68dd63 /src
parent73e47c42ab5ec6b99de34c5e673f4fc3d5cf1b6e (diff)
downloadsystemd-fb2367edd943d37f418725c90498a940016e80bd.tar.gz
login: use free_and_replace() and TAKE_PTR()
Diffstat (limited to 'src')
-rw-r--r--src/login/logind-session.c17
-rw-r--r--src/login/logind-user.c20
2 files changed, 13 insertions, 24 deletions
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index 69d5a10319..226cc49b01 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -547,7 +547,8 @@ static int session_start_scope(Session *s, sd_bus_message *properties) {
if (!s->scope) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- char *scope, *job = NULL;
+ _cleanup_free_ char *scope = NULL;
+ char *job = NULL;
const char *description;
scope = strjoin("session-", s->id, ".scope");
@@ -567,16 +568,12 @@ static int session_start_scope(Session *s, sd_bus_message *properties) {
properties,
&error,
&job);
- if (r < 0) {
- log_error_errno(r, "Failed to start session scope %s: %s", scope, bus_error_message(&error, r));
- free(scope);
- return r;
- } else {
- s->scope = scope;
+ if (r < 0)
+ return log_error_errno(r, "Failed to start session scope %s: %s", scope, bus_error_message(&error, r));
- free(s->scope_job);
- s->scope_job = job;
- }
+
+ s->scope = TAKE_PTR(scope);
+ free_and_replace(s->scope_job, job);
}
if (s->scope)
diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index 346f792fb8..f2664c323e 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -391,15 +391,10 @@ static int user_stop_slice(User *u) {
assert(u);
r = manager_stop_unit(u->manager, u->slice, &error, &job);
- if (r < 0) {
- log_error("Failed to stop user slice: %s", bus_error_message(&error, r));
- return r;
- }
-
- free(u->slice_job);
- u->slice_job = job;
+ if (r < 0)
+ return log_error_errno(r, "Failed to stop user slice: %s", bus_error_message(&error, r));
- return r;
+ return free_and_replace(u->slice_job, job);
}
static int user_stop_service(User *u) {
@@ -410,13 +405,10 @@ static int user_stop_service(User *u) {
assert(u);
r = manager_stop_unit(u->manager, u->service, &error, &job);
- if (r < 0) {
- log_error("Failed to stop user service: %s", bus_error_message(&error, r));
- return r;
- }
+ if (r < 0)
+ return log_error_errno(r, "Failed to stop user service: %s", bus_error_message(&error, r));
- free_and_replace(u->service_job, job);
- return r;
+ return free_and_replace(u->service_job, job);
}
int user_stop(User *u, bool force) {