X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Ftest-login.c;h=2ab083bb71960b447acda01b082fdd3a67fb72ae;hb=bf34ab149f3038686bc75e1592179abac1700322;hp=ae041b6a59f70eca0db899749fb4a93943ab0533;hpb=81527be142678057215665be66e4b3c8306a7ab3;p=elogind.git diff --git a/src/login/test-login.c b/src/login/test-login.c index ae041b6a5..2ab083bb7 100644 --- a/src/login/test-login.c +++ b/src/login/test-login.c @@ -6,16 +6,16 @@ Copyright 2011 Lennart Poettering systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. systemd is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + Lesser General Public License for more details. - You should have received a copy of the GNU General Public License + You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . ***/ @@ -27,19 +27,21 @@ #include "util.h" #include "strv.h" -int main(int argc, char* argv[]) { +static void test_login(void) { + _cleanup_close_pipe_ int pair[2] = { -1, -1 }; + _cleanup_free_ char *pp = NULL, *qq = NULL; int r, k; uid_t u, u2; - char *seat; + char *seat, *type, *class, *display, *remote_user, *remote_host; char *session; char *state; char *session2; char *t; - char **seats, **sessions; + char **seats, **sessions, **machines; uid_t *uids; unsigned n; struct pollfd pollfd; - sd_login_monitor *m; + sd_login_monitor *m = NULL; assert_se(sd_pid_get_session(0, &session) == 0); printf("session = %s\n", session); @@ -47,6 +49,11 @@ int main(int argc, char* argv[]) { assert_se(sd_pid_get_owner_uid(0, &u2) == 0); printf("user = %lu\n", (unsigned long) u2); + assert_se(socketpair(AF_UNIX, SOCK_STREAM, 0, pair) == 0); + sd_peer_get_session(pair[0], &pp); + sd_peer_get_session(pair[1], &qq); + assert_se(streq_ptr(pp, qq)); + r = sd_uid_get_sessions(u2, false, &sessions); assert_se(r >= 0); assert_se(r == (int) strv_length(sessions)); @@ -71,10 +78,39 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); printf("active = %s\n", yes_no(r)); + r = sd_session_is_remote(session); + assert_se(r >= 0); + printf("remote = %s\n", yes_no(r)); + + r = sd_session_get_state(session, &state); + assert_se(r >= 0); + printf("state = %s\n", state); + free(state); + assert_se(sd_session_get_uid(session, &u) >= 0); printf("uid = %lu\n", (unsigned long) u); assert_se(u == u2); + assert_se(sd_session_get_type(session, &type) >= 0); + printf("type = %s\n", type); + free(type); + + assert_se(sd_session_get_class(session, &class) >= 0); + printf("class = %s\n", class); + free(class); + + assert_se(sd_session_get_display(session, &display) >= 0); + printf("display = %s\n", display); + free(display); + + assert_se(sd_session_get_remote_user(session, &remote_user) >= 0); + printf("remote_user = %s\n", remote_user); + free(remote_user); + + assert_se(sd_session_get_remote_host(session, &remote_host) >= 0); + printf("remote_host = %s\n", remote_host); + free(remote_host); + assert_se(sd_session_get_seat(session, &seat) >= 0); printf("seat = %s\n", seat); @@ -82,6 +118,14 @@ int main(int argc, char* argv[]) { assert_se(r >= 0); printf("can do multi session = %s\n", yes_no(r)); + r = sd_seat_can_tty(seat); + assert_se(r >= 0); + printf("can do tty = %s\n", yes_no(r)); + + r = sd_seat_can_graphical(seat); + assert_se(r >= 0); + printf("can do graphical = %s\n", yes_no(r)); + assert_se(sd_uid_get_state(u, &state) >= 0); printf("state = %s\n", state); @@ -127,6 +171,11 @@ int main(int argc, char* argv[]) { assert_se(sd_get_seats(NULL) == r); + r = sd_seat_get_active(NULL, &t, NULL); + assert_se(r >= 0); + printf("active session on current seat = %s\n", t); + free(t); + r = sd_get_sessions(&sessions); assert_se(r >= 0); assert_se(r == (int) strv_length(sessions)); @@ -150,15 +199,34 @@ int main(int argc, char* argv[]) { printf("n_uids = %i\n", r); assert_se(sd_get_uids(NULL) == r); - r = sd_login_monitor_new("session", &m); + r = sd_get_machine_names(&machines); assert_se(r >= 0); + assert_se(r == (int) strv_length(machines)); + assert_se(t = strv_join(machines, ", ")); + strv_free(machines); + printf("n_machines = %i\n", r); + printf("machines = %s\n", t); + free(t); - zero(pollfd); - pollfd.fd = sd_login_monitor_get_fd(m); - pollfd.events = POLLIN; + r = sd_login_monitor_new("session", &m); + assert_se(r >= 0); for (n = 0; n < 5; n++) { - r = poll(&pollfd, 1, -1); + usec_t timeout, nw; + + zero(pollfd); + assert_se((pollfd.fd = sd_login_monitor_get_fd(m)) >= 0); + assert_se((pollfd.events = sd_login_monitor_get_events(m)) >= 0); + + assert_se(sd_login_monitor_get_timeout(m, &timeout) >= 0); + + nw = now(CLOCK_MONOTONIC); + + r = poll(&pollfd, 1, + timeout == (uint64_t) -1 ? -1 : + timeout > nw ? (int) ((timeout - nw) / 1000) : + 0); + assert_se(r >= 0); sd_login_monitor_flush(m); @@ -166,6 +234,13 @@ int main(int argc, char* argv[]) { } sd_login_monitor_unref(m); +} + +int main(int argc, char* argv[]) { + log_parse_environment(); + log_open(); + + test_login(); return 0; }