|
Zbigniew Jędrzejewski-Szmek |
3e123d |
From aee1d734a5034d47005a339ec5b2b39583795039 Mon Sep 17 00:00:00 2001
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
Date: Wed, 16 Dec 2020 15:56:44 +0100
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
Subject: [PATCH] test-login: skip consistency checks when logind is not active
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
MIME-Version: 1.0
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
Content-Type: text/plain; charset=UTF-8
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
Content-Transfer-Encoding: 8bit
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
There are two ways in swich sd_login_* functions acquire data:
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
some are derived from the cgroup path, but others use the data serialized
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
by logind.
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
When the tests are executed under Fedora's mock, without systemd-spawn
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
but instead in a traditional chroot, test-login gets confused:
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
the "outside" cgroup path is visible, so sd_pid_get_unit() and
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
sd_pid_get_session() work, but sd_session_is_active() and other functions
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
that need logind data fail.
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
Such a buildroot setup is fairly bad, but it can be encountered in the wild, so
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
let's just skip the tests in that case.
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
/* Information printed is from the live system */
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
sd_pid_get_unit(0, …) → "session-237.scope"
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
sd_pid_get_user_unit(0, …) → "n/a"
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
sd_pid_get_slice(0, …) → "user-1000.slice"
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
sd_pid_get_session(0, …) → "237"
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
sd_pid_get_owner_uid(0, …) → 1000
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
sd_pid_get_cgroup(0, …) → "/user.slice/user-1000.slice/session-237.scope"
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
sd_uid_get_display(1000, …) → "(null)"
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
sd_uid_get_sessions(1000, …) → [0] ""
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
sd_uid_get_seats(1000, …) → [0] ""
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
Assertion 'r >= 0' failed at src/libsystemd/sd-login/test-login.c:104, function test_login(). Aborting.
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
---
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
src/libsystemd/sd-login/test-login.c | 98 +++++++++++++++-------------
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
1 file changed, 52 insertions(+), 46 deletions(-)
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
diff --git a/src/libsystemd/sd-login/test-login.c b/src/libsystemd/sd-login/test-login.c
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
index 5b2ff93e1c..f762b8475b 100644
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
--- a/src/libsystemd/sd-login/test-login.c
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+++ b/src/libsystemd/sd-login/test-login.c
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
@@ -112,68 +112,74 @@ static void test_login(void) {
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
if (session) {
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
r = sd_session_is_active(session);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(r >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- log_info("sd_session_is_active(\"%s\") → %s", session, yes_no(r));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ if (r == -ENXIO)
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ log_notice("sd_session_is_active failed with ENXIO, it seems logind is not running.");
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ else {
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ /* All those tests will fail with ENXIO, so let's skip them. */
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- r = sd_session_is_remote(session);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(r >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- log_info("sd_session_is_remote(\"%s\") → %s", session, yes_no(r));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(r >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ log_info("sd_session_is_active(\"%s\") → %s", session, yes_no(r));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- r = sd_session_get_state(session, &state);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(r == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- log_info("sd_session_get_state(\"%s\") → \"%s\"", session, state);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ r = sd_session_is_remote(session);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(r >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ log_info("sd_session_is_remote(\"%s\") → %s", session, yes_no(r));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(sd_session_get_uid(session, &u) >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- log_info("sd_session_get_uid(\"%s\") → "UID_FMT, session, u);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(u == u2);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ r = sd_session_get_state(session, &state);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(r == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ log_info("sd_session_get_state(\"%s\") → \"%s\"", session, state);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(sd_session_get_type(session, &type) >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- log_info("sd_session_get_type(\"%s\") → \"%s\"", session, type);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(sd_session_get_uid(session, &u) >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ log_info("sd_session_get_uid(\"%s\") → "UID_FMT, session, u);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(u == u2);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(sd_session_get_class(session, &class) >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- log_info("sd_session_get_class(\"%s\") → \"%s\"", session, class);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(sd_session_get_type(session, &type) >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ log_info("sd_session_get_type(\"%s\") → \"%s\"", session, type);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- r = sd_session_get_display(session, &display);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(IN_SET(r, 0, -ENODATA));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- log_info("sd_session_get_display(\"%s\") → \"%s\"", session, strna(display));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(sd_session_get_class(session, &class) >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ log_info("sd_session_get_class(\"%s\") → \"%s\"", session, class);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- r = sd_session_get_remote_user(session, &remote_user);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(IN_SET(r, 0, -ENODATA));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- log_info("sd_session_get_remote_user(\"%s\") → \"%s\"",
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- session, strna(remote_user));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ r = sd_session_get_display(session, &display);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(IN_SET(r, 0, -ENODATA));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ log_info("sd_session_get_display(\"%s\") → \"%s\"", session, strna(display));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- r = sd_session_get_remote_host(session, &remote_host);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(IN_SET(r, 0, -ENODATA));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- log_info("sd_session_get_remote_host(\"%s\") → \"%s\"",
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- session, strna(remote_host));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ r = sd_session_get_remote_user(session, &remote_user);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(IN_SET(r, 0, -ENODATA));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ log_info("sd_session_get_remote_user(\"%s\") → \"%s\"",
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ session, strna(remote_user));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- r = sd_session_get_seat(session, &seat;;
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- if (r >= 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(seat);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ r = sd_session_get_remote_host(session, &remote_host);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(IN_SET(r, 0, -ENODATA));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ log_info("sd_session_get_remote_host(\"%s\") → \"%s\"",
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ session, strna(remote_host));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- log_info("sd_session_get_seat(\"%s\") → \"%s\"", session, seat);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ r = sd_session_get_seat(session, &seat;;
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ if (r >= 0) {
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(seat);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ log_info("sd_session_get_seat(\"%s\") → \"%s\"", session, seat);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
#pragma GCC diagnostic push
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- r = sd_seat_can_multi_session(seat);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ r = sd_seat_can_multi_session(seat);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
#pragma GCC diagnostic pop
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(r == 1);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- log_info("sd_session_can_multi_seat(\"%s\") → %s", seat, yes_no(r));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(r == 1);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ log_info("sd_session_can_multi_seat(\"%s\") → %s", seat, yes_no(r));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- r = sd_seat_can_tty(seat);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(r >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- log_info("sd_session_can_tty(\"%s\") → %s", seat, yes_no(r));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ r = sd_seat_can_tty(seat);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(r >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ log_info("sd_session_can_tty(\"%s\") → %s", seat, yes_no(r));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- r = sd_seat_can_graphical(seat);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(r >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- log_info("sd_session_can_graphical(\"%s\") → %s", seat, yes_no(r));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- } else {
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- log_info_errno(r, "sd_session_get_seat(\"%s\"): %m", session);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(r == -ENODATA);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ r = sd_seat_can_graphical(seat);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(r >= 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ log_info("sd_session_can_graphical(\"%s\") → %s", seat, yes_no(r));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ } else {
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ log_info_errno(r, "sd_session_get_seat(\"%s\"): %m", session);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(r == -ENODATA);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ }
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(sd_uid_get_state(u, &state2) == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ log_info("sd_uid_get_state("UID_FMT", …) → %s", u, state2);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
}
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
-
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(sd_uid_get_state(u, &state2) == 0);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- log_info("sd_uid_get_state("UID_FMT", …) → %s", u, state2);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
}
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
if (seat) {
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
@@ -214,7 +220,7 @@ static void test_login(void) {
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
assert_se(sd_get_seats(NULL) == r);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
r = sd_seat_get_active(NULL, &t, NULL);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
- assert_se(IN_SET(r, 0, -ENODATA));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
+ assert_se(IN_SET(r, 0, -ENODATA, -ENXIO));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
log_info("sd_seat_get_active(NULL, …) (active session on current seat) → %s / \"%s\"", e(r), strnull(t));
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
free(t);
|
|
Zbigniew Jędrzejewski-Szmek |
3e123d |
|