summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-08-06 19:00:49 +0200
committerSven Eden <sven.eden@prydeworx.com>2018-10-29 10:18:34 +0100
commitd1f2956082e945c96fb74ec19a3302763d209325 (patch)
tree8fbeba61983a85e93183f0ed1fc249dedee03a14
parent882fa3df6c9720f0eb32e54ec812d38e9cc683ef (diff)
logind: make unit/job active checking more debuggable
Let's log the error messages if we get any at debug level. (cherry picked from commit bd26aee1f6bea13fe25b3feb2a5e9cd1be522e7e)
-rw-r--r--src/login/logind-dbus.c10
-rw-r--r--src/login/logind-session.c26
-rw-r--r--src/login/logind-user.c18
-rw-r--r--src/login/logind.h4
4 files changed, 43 insertions, 15 deletions
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 1da47300b..90861eab7 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -3305,7 +3305,7 @@ int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo
"ssi", unit, who == KILL_LEADER ? "main" : "all", signo);
}
-int manager_unit_is_active(Manager *manager, const char *unit) {
+int manager_unit_is_active(Manager *manager, const char *unit, sd_bus_error *ret_error) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
_cleanup_free_ char *path = NULL;
@@ -3341,17 +3341,18 @@ int manager_unit_is_active(Manager *manager, const char *unit) {
sd_bus_error_has_name(&error, BUS_ERROR_LOAD_FAILED))
return false;
+ sd_bus_error_move(ret_error, &error);
return r;
}
r = sd_bus_message_read(reply, "s", &state);
if (r < 0)
- return -EINVAL;
+ return r;
- return !streq(state, "inactive") && !streq(state, "failed");
+ return !STR_IN_SET(state, "inactive", "failed");
}
-int manager_job_is_active(Manager *manager, const char *path) {
+int manager_job_is_active(Manager *manager, const char *path, sd_bus_error *ret_error) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
int r;
@@ -3376,6 +3377,7 @@ int manager_job_is_active(Manager *manager, const char *path) {
if (sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_OBJECT))
return false;
+ sd_bus_error_move(ret_error, &error);
return r;
}
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index e599a8d30..a65fc06b2 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -1072,6 +1072,8 @@ static void session_remove_fifo(Session *s) {
}
bool session_may_gc(Session *s, bool drop_not_started) {
+ int r;
+
assert(s);
if (drop_not_started && !s->started)
@@ -1086,12 +1088,26 @@ bool session_may_gc(Session *s, bool drop_not_started) {
}
#if 0 /// elogind supports neither scopes nor jobs
- if (s->scope_job && manager_job_is_active(s->manager, s->scope_job))
- return false;
-
- if (s->scope && manager_unit_is_active(s->manager, s->scope))
- return false;
#endif // 0
+ if (s->scope_job) {
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+
+ r = manager_job_is_active(s->manager, s->scope_job, &error);
+ if (r < 0)
+ log_debug_errno(r, "Failed to determine whether job '%s' is pending, ignoring: %s", s->scope_job, bus_error_message(&error, r));
+ if (r != 0)
+ return false;
+ }
+
+ if (s->scope) {
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
+
+ r = manager_unit_is_active(s->manager, s->scope, &error);
+ if (r < 0)
+ log_debug_errno(r, "Failed to determine whether unit '%s' is active, ignoring: %s", s->scope, bus_error_message(&error, r));
+ if (r != 0)
+ return false;
+ }
return true;
}
diff --git a/src/login/logind-user.c b/src/login/logind-user.c
index 9468d493d..12b8bf63e 100644
--- a/src/login/logind-user.c
+++ b/src/login/logind-user.c
@@ -579,6 +579,8 @@ int user_check_linger_file(User *u) {
}
bool user_may_gc(User *u, bool drop_not_started) {
+ int r;
+
assert(u);
if (drop_not_started && !u->started)
@@ -591,12 +593,20 @@ bool user_may_gc(User *u, bool drop_not_started) {
return false;
#if 0 /// elogind neither supports service nor slice jobs
- if (u->slice_job && manager_job_is_active(u->manager, u->slice_job))
- return false;
+ /* Check if our job is still pending */
+ if (u->service_job) {
+ _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
- if (u->service_job && manager_job_is_active(u->manager, u->service_job))
- return false;
#endif // 0
+ r = manager_job_is_active(u->manager, u->service_job, &error);
+ if (r < 0)
+ log_debug_errno(r, "Failed to determine whether job '%s' is pending, ignoring: %s", u->service_job, bus_error_message(&error, r));
+ if (r != 0)
+ return false;
+ }
+
+ /* Note that we don't care if the three units we manage for each user object are up or not, as we are managing
+ * their state rather than tracking it. */
return true;
}
diff --git a/src/login/logind.h b/src/login/logind.h
index 3f17d5d6d..a740a53d2 100644
--- a/src/login/logind.h
+++ b/src/login/logind.h
@@ -217,9 +217,9 @@ int manager_start_unit(Manager *manager, const char *unit, sd_bus_error *error,
int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
int manager_abandon_scope(Manager *manager, const char *scope, sd_bus_error *error);
int manager_kill_unit(Manager *manager, const char *unit, KillWho who, int signo, sd_bus_error *error);
-int manager_unit_is_active(Manager *manager, const char *unit);
-int manager_job_is_active(Manager *manager, const char *path);
#endif // 0
+int manager_unit_is_active(Manager *manager, const char *unit, sd_bus_error *error);
+int manager_job_is_active(Manager *manager, const char *path, sd_bus_error *error);
/* gperf lookup function */
const struct ConfigPerfItem* logind_gperf_lookup(const char *key, GPERF_LEN_TYPE length);