]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test-login.c
update TODO
[thirdparty/systemd.git] / src / test-login.c
CommitLineData
74b91131
LP
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3/***
4 This file is part of systemd.
5
6 Copyright 2011 Lennart Poettering
7
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.
12
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.
17
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/>.
20***/
21
034a2a52
LP
22#include <sys/poll.h>
23#include <string.h>
24
74b91131
LP
25#include "sd-login.h"
26#include "util.h"
034a2a52 27#include "strv.h"
74b91131
LP
28
29int main(int argc, char* argv[]) {
034a2a52
LP
30 int r, k;
31 uid_t u, u2;
74b91131
LP
32 char *seat;
33 char *session;
34 char *state;
35 char *session2;
034a2a52
LP
36 char *t;
37 char **seats, **sessions;
38 uid_t *uids;
39 unsigned n;
40 struct pollfd pollfd;
41 sd_login_monitor *m;
74b91131
LP
42
43 assert_se(sd_pid_get_session(0, &session) == 0);
44 printf("session = %s\n", session);
45
034a2a52
LP
46 assert_se(sd_pid_get_owner_uid(0, &u2) == 0);
47 printf("user = %lu\n", (unsigned long) u2);
48
49 r = sd_uid_get_sessions(u2, false, &sessions);
50 assert_se(r >= 0);
51 assert_se(t = strv_join(sessions, ", "));
52 strv_free(sessions);
53 printf("sessions = %s\n", t);
54 free(t);
55
56 r = sd_uid_get_seats(u2, false, &seats);
57 assert_se(r >= 0);
58 assert_se(t = strv_join(seats, ", "));
59 strv_free(seats);
60 printf("seats = %s\n", t);
61 free(t);
62
74b91131
LP
63 r = sd_session_is_active(session);
64 assert_se(r >= 0);
65 printf("active = %s\n", yes_no(r));
66
67 assert_se(sd_session_get_uid(session, &u) >= 0);
68 printf("uid = %lu\n", (unsigned long) u);
034a2a52 69 assert_se(u == u2);
74b91131
LP
70
71 assert_se(sd_session_get_seat(session, &seat) >= 0);
72 printf("seat = %s\n", seat);
73
add30678
LP
74 r = sd_seat_can_multi_session(seat);
75 assert_se(r >= 0);
76 printf("can do multi session = %s\n", yes_no(r));
77
74b91131
LP
78 assert_se(sd_uid_get_state(u, &state) >= 0);
79 printf("state = %s\n", state);
80
034a2a52 81 assert_se(sd_uid_is_on_seat(u, 0, seat) > 0);
74b91131 82
034a2a52 83 k = sd_uid_is_on_seat(u, 1, seat);
74b91131
LP
84 assert_se(k >= 0);
85 assert_se(!!r == !!r);
86
87 assert_se(sd_seat_get_active(seat, &session2, &u2) >= 0);
88 printf("session2 = %s\n", session2);
89 printf("uid2 = %lu\n", (unsigned long) u2);
90
034a2a52
LP
91 assert_se(sd_seat_get_sessions(seat, &sessions, &uids, &n) >= 0);
92 assert_se(t = strv_join(sessions, ", "));
93 strv_free(sessions);
94 printf("sessions = %s\n", t);
95 free(t);
96 printf("uids =");
97 for (k = 0; k < (int) n; k++)
98 printf(" %lu", (unsigned long) uids[k]);
99 printf("\n");
100 free(uids);
101
74b91131
LP
102 free(session);
103 free(state);
104 free(session2);
105 free(seat);
106
034a2a52
LP
107 assert_se(sd_get_seats(&seats) >= 0);
108 assert_se(t = strv_join(seats, ", "));
109 strv_free(seats);
110 printf("seats = %s\n", t);
111 free(t);
112
113 assert_se(sd_get_sessions(&sessions) >= 0);
114 assert_se(t = strv_join(sessions, ", "));
115 strv_free(sessions);
116 printf("sessions = %s\n", t);
117 free(t);
118
119 r = sd_get_uids(&uids);
120 assert_se(r >= 0);
121
122 printf("uids =");
123 for (k = 0; k < r; k++)
124 printf(" %lu", (unsigned long) uids[k]);
125 printf("\n");
126
127 free(uids);
128
129 r = sd_login_monitor_new("session", &m);
130 assert_se(r >= 0);
131
132 zero(pollfd);
133 pollfd.fd = sd_login_monitor_get_fd(m);
134 pollfd.events = POLLIN;
135
136 for (n = 0; n < 5; n++) {
137 r = poll(&pollfd, 1, -1);
138 assert_se(r >= 0);
139
140 sd_login_monitor_flush(m);
141 printf("Wake!\n");
142 }
143
144 sd_login_monitor_unref(m);
145
74b91131
LP
146 return 0;
147}