]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/login/test-login.c
ae041b6a59f70eca0db899749fb4a93943ab0533
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2011 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #include <systemd/sd-login.h>
30 int main(int argc
, char* argv
[]) {
38 char **seats
, **sessions
;
44 assert_se(sd_pid_get_session(0, &session
) == 0);
45 printf("session = %s\n", session
);
47 assert_se(sd_pid_get_owner_uid(0, &u2
) == 0);
48 printf("user = %lu\n", (unsigned long) u2
);
50 r
= sd_uid_get_sessions(u2
, false, &sessions
);
52 assert_se(r
== (int) strv_length(sessions
));
53 assert_se(t
= strv_join(sessions
, ", "));
55 printf("sessions = %s\n", t
);
58 assert_se(r
== sd_uid_get_sessions(u2
, false, NULL
));
60 r
= sd_uid_get_seats(u2
, false, &seats
);
62 assert_se(r
== (int) strv_length(seats
));
63 assert_se(t
= strv_join(seats
, ", "));
65 printf("seats = %s\n", t
);
68 assert_se(r
== sd_uid_get_seats(u2
, false, NULL
));
70 r
= sd_session_is_active(session
);
72 printf("active = %s\n", yes_no(r
));
74 assert_se(sd_session_get_uid(session
, &u
) >= 0);
75 printf("uid = %lu\n", (unsigned long) u
);
78 assert_se(sd_session_get_seat(session
, &seat
) >= 0);
79 printf("seat = %s\n", seat
);
81 r
= sd_seat_can_multi_session(seat
);
83 printf("can do multi session = %s\n", yes_no(r
));
85 assert_se(sd_uid_get_state(u
, &state
) >= 0);
86 printf("state = %s\n", state
);
88 assert_se(sd_uid_is_on_seat(u
, 0, seat
) > 0);
90 k
= sd_uid_is_on_seat(u
, 1, seat
);
92 assert_se(!!r
== !!r
);
94 assert_se(sd_seat_get_active(seat
, &session2
, &u2
) >= 0);
95 printf("session2 = %s\n", session2
);
96 printf("uid2 = %lu\n", (unsigned long) u2
);
98 r
= sd_seat_get_sessions(seat
, &sessions
, &uids
, &n
);
100 printf("n_sessions = %i\n", r
);
101 assert_se(r
== (int) strv_length(sessions
));
102 assert_se(t
= strv_join(sessions
, ", "));
104 printf("sessions = %s\n", t
);
107 for (k
= 0; k
< (int) n
; k
++)
108 printf(" %lu", (unsigned long) uids
[k
]);
112 assert_se(sd_seat_get_sessions(seat
, NULL
, NULL
, NULL
) == r
);
119 r
= sd_get_seats(&seats
);
121 assert_se(r
== (int) strv_length(seats
));
122 assert_se(t
= strv_join(seats
, ", "));
124 printf("n_seats = %i\n", r
);
125 printf("seats = %s\n", t
);
128 assert_se(sd_get_seats(NULL
) == r
);
130 r
= sd_get_sessions(&sessions
);
132 assert_se(r
== (int) strv_length(sessions
));
133 assert_se(t
= strv_join(sessions
, ", "));
135 printf("n_sessions = %i\n", r
);
136 printf("sessions = %s\n", t
);
139 assert_se(sd_get_sessions(NULL
) == r
);
141 r
= sd_get_uids(&uids
);
145 for (k
= 0; k
< r
; k
++)
146 printf(" %lu", (unsigned long) uids
[k
]);
150 printf("n_uids = %i\n", r
);
151 assert_se(sd_get_uids(NULL
) == r
);
153 r
= sd_login_monitor_new("session", &m
);
157 pollfd
.fd
= sd_login_monitor_get_fd(m
);
158 pollfd
.events
= POLLIN
;
160 for (n
= 0; n
< 5; n
++) {
161 r
= poll(&pollfd
, 1, -1);
164 sd_login_monitor_flush(m
);
168 sd_login_monitor_unref(m
);