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/>.
29 int main(int argc, char* argv[]) {
37 char **seats, **sessions;
43 assert_se(sd_pid_get_session(0, &session) == 0);
44 printf("session = %s\n", session);
46 assert_se(sd_pid_get_owner_uid(0, &u2) == 0);
47 printf("user = %lu\n", (unsigned long) u2);
49 r = sd_uid_get_sessions(u2, false, &sessions);
51 assert_se(t = strv_join(sessions, ", "));
53 printf("sessions = %s\n", t);
56 r = sd_uid_get_seats(u2, false, &seats);
58 assert_se(t = strv_join(seats, ", "));
60 printf("seats = %s\n", t);
63 r = sd_session_is_active(session);
65 printf("active = %s\n", yes_no(r));
67 assert_se(sd_session_get_uid(session, &u) >= 0);
68 printf("uid = %lu\n", (unsigned long) u);
71 assert_se(sd_session_get_seat(session, &seat) >= 0);
72 printf("seat = %s\n", seat);
74 assert_se(sd_uid_get_state(u, &state) >= 0);
75 printf("state = %s\n", state);
77 assert_se(sd_uid_is_on_seat(u, 0, seat) > 0);
79 k = sd_uid_is_on_seat(u, 1, seat);
81 assert_se(!!r == !!r);
83 assert_se(sd_seat_get_active(seat, &session2, &u2) >= 0);
84 printf("session2 = %s\n", session2);
85 printf("uid2 = %lu\n", (unsigned long) u2);
87 assert_se(sd_seat_get_sessions(seat, &sessions, &uids, &n) >= 0);
88 assert_se(t = strv_join(sessions, ", "));
90 printf("sessions = %s\n", t);
93 for (k = 0; k < (int) n; k++)
94 printf(" %lu", (unsigned long) uids[k]);
103 assert_se(sd_get_seats(&seats) >= 0);
104 assert_se(t = strv_join(seats, ", "));
106 printf("seats = %s\n", t);
109 assert_se(sd_get_sessions(&sessions) >= 0);
110 assert_se(t = strv_join(sessions, ", "));
112 printf("sessions = %s\n", t);
115 r = sd_get_uids(&uids);
119 for (k = 0; k < r; k++)
120 printf(" %lu", (unsigned long) uids[k]);
125 r = sd_login_monitor_new("session", &m);
129 pollfd.fd = sd_login_monitor_get_fd(m);
130 pollfd.events = POLLIN;
132 for (n = 0; n < 5; n++) {
133 r = poll(&pollfd, 1, -1);
136 sd_login_monitor_flush(m);
140 sd_login_monitor_unref(m);