Skip to content

Commit

Permalink
Prep 239.4: Fix test-login when elogind hasn't run before
Browse files Browse the repository at this point in the history
When elogind is built, it might be a fresh install.
The test-login program might then crash if /run/systemd is either
absent or not populated.

This patch checks for these circumstances and skips tests that can
succeed.

Bug: #45
Bug: #108
Signed-off-by: Sven Eden <sven.eden@prydeworx.com>
  • Loading branch information
Yamakuzure committed Feb 20, 2019
1 parent f5449ed commit 655ac42
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/libelogind/sd-login/test-login.c
Expand Up @@ -68,7 +68,17 @@ static void test_login(void) {
} else {
log_info("sd_pid_get_session(0, …) → \"%s\"", session);

#if 0 /// elogind might just be getting installed, and /run/systemd be nonexistant
assert_se(sd_pid_get_owner_uid(0, &u2) == 0);
#else
r = sd_pid_get_owner_uid(0, &u2);
if (-ENODATA == r) {
log_info("No session data found, skipping session tests...");
if (session)
session = mfree(session);
} else {
assert_se(r == 0);
#endif
log_info("sd_pid_get_owner_uid(0, …) → "UID_FMT, u2);

assert_se(sd_pid_get_cgroup(0, &cgroup) == 0);
Expand Down Expand Up @@ -103,6 +113,9 @@ static void test_login(void) {
free(t);

assert_se(r == sd_uid_get_seats(u2, false, NULL));
#if 1 /// another bracket for elogind ...
}
#endif // 1
}

if (session) {
Expand Down Expand Up @@ -206,9 +219,19 @@ static void test_login(void) {
assert_se(sd_get_seats(NULL) == r);

r = sd_seat_get_active(NULL, &t, NULL);
#if 1 /// If elogind is just installed, this might give -ENXIO back
if (-ENXIO == r) {
log_info("No seat data found, skipping seat tests... ");
if (t)
t = mfree(t);
} else {
#endif // 1
assert_se(IN_SET(r, 0, -ENODATA));
log_info("sd_seat_get_active(NULL, …) (active session on current seat) → %s", strnull(t));
free(t);
#if 1 /// another bracket for elogind ...
}
#endif // 1

r = sd_get_sessions(&sessions);
assert_se(r >= 0);
Expand Down

0 comments on commit 655ac42

Please sign in to comment.