Bug Summary

File:build-scan/../src/login/logind.c
Warning:line 455, column 22
Potential leak of memory pointed to by 'id'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name logind.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -fdenormal-fp-math=preserve-sign,preserve-sign -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/12.0.0 -include config.h -I systemd-logind.p -I . -I .. -I src/basic -I ../src/basic -I src/shared -I ../src/shared -I src/systemd -I ../src/systemd -I src/journal -I ../src/journal -I src/journal-remote -I ../src/journal-remote -I src/nspawn -I ../src/nspawn -I src/resolve -I ../src/resolve -I src/timesync -I ../src/timesync -I ../src/time-wait-sync -I src/login -I ../src/login -I src/udev -I ../src/udev -I src/libudev -I ../src/libudev -I src/core -I ../src/core -I ../src/libsystemd/sd-bus -I ../src/libsystemd/sd-device -I ../src/libsystemd/sd-hwdb -I ../src/libsystemd/sd-id128 -I ../src/libsystemd/sd-netlink -I ../src/libsystemd/sd-network -I src/libsystemd-network -I ../src/libsystemd-network -D _FILE_OFFSET_BITS=64 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wwrite-strings -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -Wno-format-signedness -Wno-error=nonnull -std=gnu99 -fconst-strings -fdebug-compilation-dir /home/mrc0mmand/repos/@redhat-plumbers/systemd-rhel8/build-scan -ferror-limit 19 -fvisibility hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-07-16-221226-1465241-1 -x c ../src/login/logind.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#include <errno(*__errno_location ()).h>
4#include <fcntl.h>
5#include <string.h>
6#include <unistd.h>
7
8#include "libudev.h"
9#include "sd-daemon.h"
10
11#include "alloc-util.h"
12#include "bus-error.h"
13#include "bus-util.h"
14#include "cgroup-util.h"
15#include "def.h"
16#include "dirent-util.h"
17#include "fd-util.h"
18#include "format-util.h"
19#include "fs-util.h"
20#include "logind.h"
21#include "parse-util.h"
22#include "process-util.h"
23#include "selinux-util.h"
24#include "signal-util.h"
25#include "strv.h"
26#include "udev-util.h"
27
28static Manager* manager_unref(Manager *m);
29DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_unref)static inline void manager_unrefp(Manager* *p) { if (*p) manager_unref
(*p); }
;
30
31static int manager_new(Manager **ret) {
32 _cleanup_(manager_unrefp)__attribute__((cleanup(manager_unrefp))) Manager *m = NULL((void*)0);
33 int r;
34
35 assert(ret)do { if ((__builtin_expect(!!(!(ret)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("ret"), "../src/login/logind.c", 35, __PRETTY_FUNCTION__
); } while (0)
;
36
37 m = new0(Manager, 1)((Manager*) calloc((1), sizeof(Manager)));
38 if (!m)
39 return -ENOMEM12;
40
41 m->console_active_fd = -1;
42 m->reserve_vt_fd = -1;
43
44 m->idle_action_not_before_usec = now(CLOCK_MONOTONIC1);
45
46 m->devices = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
47 m->seats = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
48 m->sessions = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
49 m->users = hashmap_new(NULL)internal_hashmap_new(((void*)0) );
50 m->inhibitors = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
51 m->buttons = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
52
53 m->user_units = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
54 m->session_units = hashmap_new(&string_hash_ops)internal_hashmap_new(&string_hash_ops );
55
56 if (!m->devices || !m->seats || !m->sessions || !m->users || !m->inhibitors || !m->buttons || !m->user_units || !m->session_units)
57 return -ENOMEM12;
58
59 m->udev = udev_new();
60 if (!m->udev)
61 return -errno(*__errno_location ());
62
63 r = sd_event_default(&m->event);
64 if (r < 0)
65 return r;
66
67 r = sd_event_add_signal(m->event, NULL((void*)0), SIGINT2, NULL((void*)0), NULL((void*)0));
68 if (r < 0)
69 return r;
70
71 r = sd_event_add_signal(m->event, NULL((void*)0), SIGTERM15, NULL((void*)0), NULL((void*)0));
72 if (r < 0)
73 return r;
74
75 (void) sd_event_set_watchdog(m->event, true1);
76
77 manager_reset_config(m);
78
79 *ret = TAKE_PTR(m)({ typeof(m) _ptr_ = (m); (m) = ((void*)0); _ptr_; });
80 return 0;
81}
82
83static Manager* manager_unref(Manager *m) {
84 Session *session;
85 User *u;
86 Device *d;
87 Seat *s;
88 Inhibitor *i;
89 Button *b;
90
91 if (!m)
92 return NULL((void*)0);
93
94 while ((session = hashmap_first(m->sessions)))
95 session_free(session);
96
97 while ((u = hashmap_first(m->users)))
98 user_free(u);
99
100 while ((d = hashmap_first(m->devices)))
101 device_free(d);
102
103 while ((s = hashmap_first(m->seats)))
104 seat_free(s);
105
106 while ((i = hashmap_first(m->inhibitors)))
107 inhibitor_free(i);
108
109 while ((b = hashmap_first(m->buttons)))
110 button_free(b);
111
112 hashmap_free(m->devices);
113 hashmap_free(m->seats);
114 hashmap_free(m->sessions);
115 hashmap_free(m->users);
116 hashmap_free(m->inhibitors);
117 hashmap_free(m->buttons);
118
119 hashmap_free(m->user_units);
120 hashmap_free(m->session_units);
121
122 sd_event_source_unref(m->idle_action_event_source);
123 sd_event_source_unref(m->inhibit_timeout_source);
124 sd_event_source_unref(m->scheduled_shutdown_timeout_source);
125 sd_event_source_unref(m->nologin_timeout_source);
126 sd_event_source_unref(m->wall_message_timeout_source);
127
128 sd_event_source_unref(m->console_active_event_source);
129 sd_event_source_unref(m->udev_seat_event_source);
130 sd_event_source_unref(m->udev_device_event_source);
131 sd_event_source_unref(m->udev_vcsa_event_source);
132 sd_event_source_unref(m->udev_button_event_source);
133 sd_event_source_unref(m->lid_switch_ignore_event_source);
134
135 safe_close(m->console_active_fd);
136
137 udev_monitor_unref(m->udev_seat_monitor);
138 udev_monitor_unref(m->udev_device_monitor);
139 udev_monitor_unref(m->udev_vcsa_monitor);
140 udev_monitor_unref(m->udev_button_monitor);
141
142 udev_unref(m->udev);
143
144 if (m->unlink_nologin)
145 (void) unlink_or_warn("/run/nologin");
146
147 bus_verify_polkit_async_registry_free(m->polkit_registry);
148
149 sd_bus_unref(m->bus);
150 sd_event_unref(m->event);
151
152 safe_close(m->reserve_vt_fd);
153
154 strv_free(m->kill_only_users);
155 strv_free(m->kill_exclude_users);
156
157 free(m->scheduled_shutdown_type);
158 free(m->scheduled_shutdown_tty);
159 free(m->wall_message);
160 free(m->action_job);
161
162 return mfree(m);
163}
164
165static int manager_enumerate_devices(Manager *m) {
166 struct udev_list_entry *item = NULL((void*)0), *first = NULL((void*)0);
167 _cleanup_(udev_enumerate_unrefp)__attribute__((cleanup(udev_enumerate_unrefp))) struct udev_enumerate *e = NULL((void*)0);
168 int r;
169
170 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 170, __PRETTY_FUNCTION__
); } while (0)
;
171
172 /* Loads devices from udev and creates seats for them as
173 * necessary */
174
175 e = udev_enumerate_new(m->udev);
176 if (!e)
177 return -ENOMEM12;
178
179 r = udev_enumerate_add_match_tag(e, "master-of-seat");
180 if (r < 0)
181 return r;
182
183 r = udev_enumerate_add_match_is_initialized(e);
184 if (r < 0)
185 return r;
186
187 r = udev_enumerate_scan_devices(e);
188 if (r < 0)
189 return r;
190
191 first = udev_enumerate_get_list_entry(e);
192 udev_list_entry_foreach(item, first)for (item = first; item != ((void*)0); item = udev_list_entry_get_next
(item))
{
193 _cleanup_(udev_device_unrefp)__attribute__((cleanup(udev_device_unrefp))) struct udev_device *d = NULL((void*)0);
194 int k;
195
196 d = udev_device_new_from_syspath(m->udev, udev_list_entry_get_name(item));
197 if (!d)
198 return -ENOMEM12;
199
200 k = manager_process_seat_device(m, d);
201 if (k < 0)
202 r = k;
203 }
204
205 return r;
206}
207
208static int manager_enumerate_buttons(Manager *m) {
209 _cleanup_(udev_enumerate_unrefp)__attribute__((cleanup(udev_enumerate_unrefp))) struct udev_enumerate *e = NULL((void*)0);
210 struct udev_list_entry *item = NULL((void*)0), *first = NULL((void*)0);
211 int r;
212
213 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 213, __PRETTY_FUNCTION__
); } while (0)
;
214
215 /* Loads buttons from udev */
216
217 if (manager_all_buttons_ignored(m))
218 return 0;
219
220 e = udev_enumerate_new(m->udev);
221 if (!e)
222 return -ENOMEM12;
223
224 r = udev_enumerate_add_match_subsystem(e, "input");
225 if (r < 0)
226 return r;
227
228 r = udev_enumerate_add_match_tag(e, "power-switch");
229 if (r < 0)
230 return r;
231
232 r = udev_enumerate_add_match_is_initialized(e);
233 if (r < 0)
234 return r;
235
236 r = udev_enumerate_scan_devices(e);
237 if (r < 0)
238 return r;
239
240 first = udev_enumerate_get_list_entry(e);
241 udev_list_entry_foreach(item, first)for (item = first; item != ((void*)0); item = udev_list_entry_get_next
(item))
{
242 _cleanup_(udev_device_unrefp)__attribute__((cleanup(udev_device_unrefp))) struct udev_device *d = NULL((void*)0);
243 int k;
244
245 d = udev_device_new_from_syspath(m->udev, udev_list_entry_get_name(item));
246 if (!d)
247 return -ENOMEM12;
248
249 k = manager_process_button_device(m, d);
250 if (k < 0)
251 r = k;
252 }
253
254 return r;
255}
256
257static int manager_enumerate_seats(Manager *m) {
258 _cleanup_closedir___attribute__((cleanup(closedirp))) DIR *d = NULL((void*)0);
259 struct dirent *de;
260 int r = 0;
261
262 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 262, __PRETTY_FUNCTION__
); } while (0)
;
263
264 /* This loads data about seats stored on disk, but does not
265 * actually create any seats. Removes data of seats that no
266 * longer exist. */
267
268 d = opendir("/run/systemd/seats");
269 if (!d) {
270 if (errno(*__errno_location ()) == ENOENT2)
271 return 0;
272
273 return log_error_errno(errno, "Failed to open /run/systemd/seats: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/login/logind.c", 273, __func__, "Failed to open /run/systemd/seats: %m"
) : -abs(_e); })
;
274 }
275
276 FOREACH_DIRENT(de, d, return -errno)for ((*__errno_location ()) = 0, de = readdir(d);; (*__errno_location
()) = 0, de = readdir(d)) if (!de) { if ((*__errno_location (
)) > 0) { return -(*__errno_location ()); } break; } else if
(hidden_or_backup_file((de)->d_name)) continue; else
{
277 Seat *s;
278 int k;
279
280 if (!dirent_is_file(de))
281 continue;
282
283 s = hashmap_get(m->seats, de->d_name);
284 if (!s) {
285 if (unlinkat(dirfd(d), de->d_name, 0) < 0)
286 log_warning("Failed to remove /run/systemd/seats/%s: %m",({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 287, __func__, "Failed to remove /run/systemd/seats/%s: %m"
, de->d_name) : -abs(_e); })
287 de->d_name)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 287, __func__, "Failed to remove /run/systemd/seats/%s: %m"
, de->d_name) : -abs(_e); })
;
288 continue;
289 }
290
291 k = seat_load(s);
292 if (k < 0)
293 r = k;
294 }
295
296 return r;
297}
298
299static int manager_enumerate_linger_users(Manager *m) {
300 _cleanup_closedir___attribute__((cleanup(closedirp))) DIR *d = NULL((void*)0);
301 struct dirent *de;
302 int r = 0;
303
304 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 304, __PRETTY_FUNCTION__
); } while (0)
;
305
306 d = opendir("/var/lib/systemd/linger");
307 if (!d) {
308 if (errno(*__errno_location ()) == ENOENT2)
309 return 0;
310
311 return log_error_errno(errno, "Failed to open /var/lib/systemd/linger/: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/login/logind.c", 311, __func__, "Failed to open /var/lib/systemd/linger/: %m"
) : -abs(_e); })
;
312 }
313
314 FOREACH_DIRENT(de, d, return -errno)for ((*__errno_location ()) = 0, de = readdir(d);; (*__errno_location
()) = 0, de = readdir(d)) if (!de) { if ((*__errno_location (
)) > 0) { return -(*__errno_location ()); } break; } else if
(hidden_or_backup_file((de)->d_name)) continue; else
{
315 int k;
316
317 if (!dirent_is_file(de))
318 continue;
319
320 k = manager_add_user_by_name(m, de->d_name, NULL((void*)0));
321 if (k < 0) {
322 log_notice_errno(k, "Couldn't add lingering user %s: %m", de->d_name)({ int _level = ((5)), _e = ((k)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 322, __func__, "Couldn't add lingering user %s: %m"
, de->d_name) : -abs(_e); })
;
323 r = k;
324 }
325 }
326
327 return r;
328}
329
330static int manager_enumerate_users(Manager *m) {
331 _cleanup_closedir___attribute__((cleanup(closedirp))) DIR *d = NULL((void*)0);
332 struct dirent *de;
333 int r, k;
334
335 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 335, __PRETTY_FUNCTION__
); } while (0)
;
336
337 /* Add lingering users */
338 r = manager_enumerate_linger_users(m);
339
340 /* Read in user data stored on disk */
341 d = opendir("/run/systemd/users");
342 if (!d) {
343 if (errno(*__errno_location ()) == ENOENT2)
344 return 0;
345
346 return log_error_errno(errno, "Failed to open /run/systemd/users: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/login/logind.c", 346, __func__, "Failed to open /run/systemd/users: %m"
) : -abs(_e); })
;
347 }
348
349 FOREACH_DIRENT(de, d, return -errno)for ((*__errno_location ()) = 0, de = readdir(d);; (*__errno_location
()) = 0, de = readdir(d)) if (!de) { if ((*__errno_location (
)) > 0) { return -(*__errno_location ()); } break; } else if
(hidden_or_backup_file((de)->d_name)) continue; else
{
350 User *u;
351
352 if (!dirent_is_file(de))
353 continue;
354
355 k = manager_add_user_by_name(m, de->d_name, &u);
356 if (k < 0) {
357 log_error_errno(k, "Failed to add user by file name %s: %m", de->d_name)({ int _level = ((3)), _e = ((k)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 357, __func__, "Failed to add user by file name %s: %m"
, de->d_name) : -abs(_e); })
;
358
359 r = k;
360 continue;
361 }
362
363 user_add_to_gc_queue(u);
364
365 k = user_load(u);
366 if (k < 0)
367 r = k;
368 }
369
370 return r;
371}
372
373static int parse_fdname(const char *fdname, char **session_id, dev_t *dev) {
374 _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **parts = NULL((void*)0);
375 _cleanup_free___attribute__((cleanup(freep))) char *id = NULL((void*)0);
376 unsigned int major, minor;
377 int r;
378
379 parts = strv_split(fdname, "-");
380 if (!parts)
41
Assuming 'parts' is non-null
42
Taking false branch
381 return -ENOMEM12;
382 if (strv_length(parts) != 5)
43
Assuming the condition is false
44
Taking false branch
383 return -EINVAL22;
384
385 if (!streq(parts[0], "session")(strcmp((parts[0]),("session")) == 0))
45
Taking false branch
386 return -EINVAL22;
387
388 id = strdup(parts[1]);
46
Memory is allocated
389 if (!id)
47
Assuming 'id' is non-null
48
Taking false branch
390 return -ENOMEM12;
391
392 if (!streq(parts[2], "device")(strcmp((parts[2]),("device")) == 0))
49
Taking false branch
393 return -EINVAL22;
394
395 r = safe_atou(parts[3], &major);
396 if (r < 0)
50
Assuming 'r' is >= 0
51
Taking false branch
397 return r;
398 r = safe_atou(parts[4], &minor);
399 if (r < 0)
52
Assuming 'r' is >= 0
53
Taking false branch
400 return r;
401
402 *dev = makedev(major, minor)gnu_dev_makedev (major, minor);
403 *session_id = TAKE_PTR(id)({ typeof(id) _ptr_ = (id); (id) = ((void*)0); _ptr_; });
404
405 return 0;
406}
407
408static int manager_attach_fds(Manager *m) {
409 _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **fdnames = NULL((void*)0);
410 int n, i, fd;
411
412 /* Upon restart, PID1 will send us back all fds of session devices
413 * that we previously opened. Each file descriptor is associated
414 * with a given session. The session ids are passed through FDNAMES. */
415
416 n = sd_listen_fds_with_names(true1, &fdnames);
417 if (n <= 0)
37
Assuming 'n' is > 0
38
Taking false branch
418 return n;
419
420 for (i = 0; i
38.1
'i' is < 'n'
< n; i++) {
39
Loop condition is true. Entering loop body
421 _cleanup_free___attribute__((cleanup(freep))) char *id = NULL((void*)0);
422 dev_t dev;
423 struct stat st;
424 SessionDevice *sd;
425 Session *s;
426 int r;
427
428 fd = SD_LISTEN_FDS_START3 + i;
429
430 r = parse_fdname(fdnames[i], &id, &dev);
40
Calling 'parse_fdname'
54
Returned allocated memory via 2nd parameter
431 if (r
54.1
'r' is >= 0
< 0) {
55
Taking false branch
432 log_debug_errno(r, "Failed to parse fd name %s: %m", fdnames[i])({ int _level = ((7)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 432, __func__, "Failed to parse fd name %s: %m"
, fdnames[i]) : -abs(_e); })
;
433 close_nointr(fd);
434 continue;
435 }
436
437 s = hashmap_get(m->sessions, id);
438 if (!s) {
56
Assuming 's' is non-null
57
Taking false branch
439 /* If the session doesn't exist anymore, the associated session
440 * device attached to this fd doesn't either. Let's simply close
441 * this fd. */
442 log_debug("Failed to attach fd for unknown session: %s", id)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 442, __func__, "Failed to attach fd for unknown session: %s"
, id) : -abs(_e); })
;
443 close_nointr(fd);
444 continue;
445 }
446
447 if (fstat(fd, &st) < 0) {
58
Assuming the condition is false
59
Taking false branch
448 /* The device is allowed to go away at a random point, in which
449 * case fstat failing is expected. */
450 log_debug_errno(errno, "Failed to stat device fd for session %s: %m", id)({ int _level = ((7)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/login/logind.c", 450, __func__, "Failed to stat device fd for session %s: %m"
, id) : -abs(_e); })
;
451 close_nointr(fd);
452 continue;
453 }
454
455 if (!S_ISCHR(st.st_mode)((((st.st_mode)) & 0170000) == (0020000)) || st.st_rdev != dev) {
60
Potential leak of memory pointed to by 'id'
456 log_debug("Device fd doesn't point to the expected character device node")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 456, __func__, "Device fd doesn't point to the expected character device node"
) : -abs(_e); })
;
457 close_nointr(fd);
458 continue;
459 }
460
461 sd = hashmap_get(s->devices, &dev);
462 if (!sd) {
463 /* Weird, we got an fd for a session device which wasn't
464 * recorded in the session state file... */
465 log_warning("Got fd for missing session device [%u:%u] in session %s",({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 466, __func__, "Got fd for missing session device [%u:%u] in session %s"
, gnu_dev_major (dev), gnu_dev_minor (dev), s->id) : -abs(
_e); })
466 major(dev), minor(dev), s->id)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 466, __func__, "Got fd for missing session device [%u:%u] in session %s"
, gnu_dev_major (dev), gnu_dev_minor (dev), s->id) : -abs(
_e); })
;
467 close_nointr(fd);
468 continue;
469 }
470
471 log_debug("Attaching fd to session device [%u:%u] for session %s",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 472, __func__, "Attaching fd to session device [%u:%u] for session %s"
, gnu_dev_major (dev), gnu_dev_minor (dev), s->id) : -abs(
_e); })
472 major(dev), minor(dev), s->id)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 472, __func__, "Attaching fd to session device [%u:%u] for session %s"
, gnu_dev_major (dev), gnu_dev_minor (dev), s->id) : -abs(
_e); })
;
473
474 session_device_attach_fd(sd, fd, s->was_active);
475 }
476
477 return 0;
478}
479
480static int manager_enumerate_sessions(Manager *m) {
481 _cleanup_closedir___attribute__((cleanup(closedirp))) DIR *d = NULL((void*)0);
482 struct dirent *de;
483 int r = 0, k;
484
485 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 485, __PRETTY_FUNCTION__
); } while (0)
;
26
Taking false branch
27
Loop condition is false. Exiting loop
486
487 /* Read in session data stored on disk */
488 d = opendir("/run/systemd/sessions");
489 if (!d) {
28
Assuming 'd' is non-null
29
Taking false branch
490 if (errno(*__errno_location ()) == ENOENT2)
491 return 0;
492
493 return log_error_errno(errno, "Failed to open /run/systemd/sessions: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/login/logind.c", 493, __func__, "Failed to open /run/systemd/sessions: %m"
) : -abs(_e); })
;
494 }
495
496 FOREACH_DIRENT(de, d, return -errno)for ((*__errno_location ()) = 0, de = readdir(d);; (*__errno_location
()) = 0, de = readdir(d)) if (!de) { if ((*__errno_location (
)) > 0) { return -(*__errno_location ()); } break; } else if
(hidden_or_backup_file((de)->d_name)) continue; else
{
30
Loop condition is true. Entering loop body
31
Assuming 'de' is null
32
Taking true branch
33
Assuming the condition is false
34
Taking false branch
35
Execution continues on line 524
497 struct Session *s;
498
499 if (!dirent_is_file(de))
500 continue;
501
502 if (!session_id_valid(de->d_name)) {
503 log_warning("Invalid session file name '%s', ignoring.", de->d_name)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 503, __func__, "Invalid session file name '%s', ignoring."
, de->d_name) : -abs(_e); })
;
504 r = -EINVAL22;
505 continue;
506 }
507
508 k = manager_add_session(m, de->d_name, &s);
509 if (k < 0) {
510 log_error_errno(k, "Failed to add session by file name %s: %m", de->d_name)({ int _level = ((3)), _e = ((k)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 510, __func__, "Failed to add session by file name %s: %m"
, de->d_name) : -abs(_e); })
;
511 r = k;
512 continue;
513 }
514
515 session_add_to_gc_queue(s);
516
517 k = session_load(s);
518 if (k < 0)
519 r = k;
520 }
521
522 /* We might be restarted and PID1 could have sent us back the
523 * session device fds we previously saved. */
524 k = manager_attach_fds(m);
36
Calling 'manager_attach_fds'
525 if (k < 0)
526 log_warning_errno(k, "Failed to reattach session device fds: %m")({ int _level = ((4)), _e = ((k)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 526, __func__, "Failed to reattach session device fds: %m"
) : -abs(_e); })
;
527
528 return r;
529}
530
531static int manager_enumerate_inhibitors(Manager *m) {
532 _cleanup_closedir___attribute__((cleanup(closedirp))) DIR *d = NULL((void*)0);
533 struct dirent *de;
534 int r = 0;
535
536 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 536, __PRETTY_FUNCTION__
); } while (0)
;
537
538 d = opendir("/run/systemd/inhibit");
539 if (!d) {
540 if (errno(*__errno_location ()) == ENOENT2)
541 return 0;
542
543 return log_error_errno(errno, "Failed to open /run/systemd/inhibit: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/login/logind.c", 543, __func__, "Failed to open /run/systemd/inhibit: %m"
) : -abs(_e); })
;
544 }
545
546 FOREACH_DIRENT(de, d, return -errno)for ((*__errno_location ()) = 0, de = readdir(d);; (*__errno_location
()) = 0, de = readdir(d)) if (!de) { if ((*__errno_location (
)) > 0) { return -(*__errno_location ()); } break; } else if
(hidden_or_backup_file((de)->d_name)) continue; else
{
547 int k;
548 Inhibitor *i;
549
550 if (!dirent_is_file(de))
551 continue;
552
553 k = manager_add_inhibitor(m, de->d_name, &i);
554 if (k < 0) {
555 log_notice_errno(k, "Couldn't add inhibitor %s: %m", de->d_name)({ int _level = ((5)), _e = ((k)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 555, __func__, "Couldn't add inhibitor %s: %m"
, de->d_name) : -abs(_e); })
;
556 r = k;
557 continue;
558 }
559
560 k = inhibitor_load(i);
561 if (k < 0)
562 r = k;
563 }
564
565 return r;
566}
567
568static int manager_dispatch_seat_udev(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
569 _cleanup_(udev_device_unrefp)__attribute__((cleanup(udev_device_unrefp))) struct udev_device *d = NULL((void*)0);
570 Manager *m = userdata;
571
572 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 572, __PRETTY_FUNCTION__
); } while (0)
;
573
574 d = udev_monitor_receive_device(m->udev_seat_monitor);
575 if (!d)
576 return -ENOMEM12;
577
578 manager_process_seat_device(m, d);
579 return 0;
580}
581
582static int manager_dispatch_device_udev(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
583 _cleanup_(udev_device_unrefp)__attribute__((cleanup(udev_device_unrefp))) struct udev_device *d = NULL((void*)0);
584 Manager *m = userdata;
585
586 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 586, __PRETTY_FUNCTION__
); } while (0)
;
587
588 d = udev_monitor_receive_device(m->udev_device_monitor);
589 if (!d)
590 return -ENOMEM12;
591
592 manager_process_seat_device(m, d);
593 return 0;
594}
595
596static int manager_dispatch_vcsa_udev(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
597 _cleanup_(udev_device_unrefp)__attribute__((cleanup(udev_device_unrefp))) struct udev_device *d = NULL((void*)0);
598 Manager *m = userdata;
599 const char *name;
600
601 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 601, __PRETTY_FUNCTION__
); } while (0)
;
602
603 d = udev_monitor_receive_device(m->udev_vcsa_monitor);
604 if (!d)
605 return -ENOMEM12;
606
607 name = udev_device_get_sysname(d);
608
609 /* Whenever a VCSA device is removed try to reallocate our
610 * VTs, to make sure our auto VTs never go away. */
611
612 if (name && startswith(name, "vcsa") && streq_ptr(udev_device_get_action(d), "remove"))
613 seat_preallocate_vts(m->seat0);
614
615 return 0;
616}
617
618static int manager_dispatch_button_udev(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
619 _cleanup_(udev_device_unrefp)__attribute__((cleanup(udev_device_unrefp))) struct udev_device *d = NULL((void*)0);
620 Manager *m = userdata;
621
622 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 622, __PRETTY_FUNCTION__
); } while (0)
;
623
624 d = udev_monitor_receive_device(m->udev_button_monitor);
625 if (!d)
626 return -ENOMEM12;
627
628 manager_process_button_device(m, d);
629 return 0;
630}
631
632static int manager_dispatch_console(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
633 Manager *m = userdata;
634
635 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 635, __PRETTY_FUNCTION__
); } while (0)
;
636 assert(m->seat0)do { if ((__builtin_expect(!!(!(m->seat0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m->seat0"), "../src/login/logind.c",
636, __PRETTY_FUNCTION__); } while (0)
;
637 assert(m->console_active_fd == fd)do { if ((__builtin_expect(!!(!(m->console_active_fd == fd
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("m->console_active_fd == fd"
), "../src/login/logind.c", 637, __PRETTY_FUNCTION__); } while
(0)
;
638
639 seat_read_active_vt(m->seat0);
640 return 0;
641}
642
643static int manager_reserve_vt(Manager *m) {
644 _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0);
645
646 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 646, __PRETTY_FUNCTION__
); } while (0)
;
647
648 if (m->reserve_vt <= 0)
649 return 0;
650
651 if (asprintf(&p, "/dev/tty%u", m->reserve_vt) < 0)
652 return log_oom()log_oom_internal(LOG_REALM_SYSTEMD, "../src/login/logind.c", 652
, __func__)
;
653
654 m->reserve_vt_fd = open(p, O_RDWR02|O_NOCTTY0400|O_CLOEXEC02000000|O_NONBLOCK04000);
655 if (m->reserve_vt_fd < 0) {
656
657 /* Don't complain on VT-less systems */
658 if (errno(*__errno_location ()) != ENOENT2)
659 log_warning_errno(errno, "Failed to pin reserved VT: %m")({ int _level = ((4)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/login/logind.c", 659, __func__, "Failed to pin reserved VT: %m"
) : -abs(_e); })
;
660 return -errno(*__errno_location ());
661 }
662
663 return 0;
664}
665
666static int manager_connect_bus(Manager *m) {
667 int r;
668
669 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 669, __PRETTY_FUNCTION__
); } while (0)
;
670 assert(!m->bus)do { if ((__builtin_expect(!!(!(!m->bus)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("!m->bus"), "../src/login/logind.c", 670
, __PRETTY_FUNCTION__); } while (0)
;
671
672 r = sd_bus_default_system(&m->bus);
673 if (r < 0)
674 return log_error_errno(r, "Failed to connect to system bus: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 674, __func__, "Failed to connect to system bus: %m"
) : -abs(_e); })
;
675
676 r = sd_bus_add_object_vtable(m->bus, NULL((void*)0), "/org/freedesktop/login1", "org.freedesktop.login1.Manager", manager_vtable, m);
677 if (r < 0)
678 return log_error_errno(r, "Failed to add manager object vtable: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 678, __func__, "Failed to add manager object vtable: %m"
) : -abs(_e); })
;
679
680 r = sd_bus_add_fallback_vtable(m->bus, NULL((void*)0), "/org/freedesktop/login1/seat", "org.freedesktop.login1.Seat", seat_vtable, seat_object_find, m);
681 if (r < 0)
682 return log_error_errno(r, "Failed to add seat object vtable: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 682, __func__, "Failed to add seat object vtable: %m"
) : -abs(_e); })
;
683
684 r = sd_bus_add_node_enumerator(m->bus, NULL((void*)0), "/org/freedesktop/login1/seat", seat_node_enumerator, m);
685 if (r < 0)
686 return log_error_errno(r, "Failed to add seat enumerator: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 686, __func__, "Failed to add seat enumerator: %m"
) : -abs(_e); })
;
687
688 r = sd_bus_add_fallback_vtable(m->bus, NULL((void*)0), "/org/freedesktop/login1/session", "org.freedesktop.login1.Session", session_vtable, session_object_find, m);
689 if (r < 0)
690 return log_error_errno(r, "Failed to add session object vtable: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 690, __func__, "Failed to add session object vtable: %m"
) : -abs(_e); })
;
691
692 r = sd_bus_add_node_enumerator(m->bus, NULL((void*)0), "/org/freedesktop/login1/session", session_node_enumerator, m);
693 if (r < 0)
694 return log_error_errno(r, "Failed to add session enumerator: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 694, __func__, "Failed to add session enumerator: %m"
) : -abs(_e); })
;
695
696 r = sd_bus_add_fallback_vtable(m->bus, NULL((void*)0), "/org/freedesktop/login1/user", "org.freedesktop.login1.User", user_vtable, user_object_find, m);
697 if (r < 0)
698 return log_error_errno(r, "Failed to add user object vtable: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 698, __func__, "Failed to add user object vtable: %m"
) : -abs(_e); })
;
699
700 r = sd_bus_add_node_enumerator(m->bus, NULL((void*)0), "/org/freedesktop/login1/user", user_node_enumerator, m);
701 if (r < 0)
702 return log_error_errno(r, "Failed to add user enumerator: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 702, __func__, "Failed to add user enumerator: %m"
) : -abs(_e); })
;
703
704 r = sd_bus_match_signal_async(
705 m->bus,
706 NULL((void*)0),
707 "org.freedesktop.systemd1",
708 "/org/freedesktop/systemd1",
709 "org.freedesktop.systemd1.Manager",
710 "JobRemoved",
711 match_job_removed, NULL((void*)0), m);
712 if (r < 0)
713 return log_error_errno(r, "Failed to request match for JobRemoved: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 713, __func__, "Failed to request match for JobRemoved: %m"
) : -abs(_e); })
;
714
715 r = sd_bus_match_signal_async(
716 m->bus,
717 NULL((void*)0),
718 "org.freedesktop.systemd1",
719 "/org/freedesktop/systemd1",
720 "org.freedesktop.systemd1.Manager",
721 "UnitRemoved",
722 match_unit_removed, NULL((void*)0), m);
723 if (r < 0)
724 return log_error_errno(r, "Failed to request match for UnitRemoved: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 724, __func__, "Failed to request match for UnitRemoved: %m"
) : -abs(_e); })
;
725
726 r = sd_bus_match_signal_async(
727 m->bus,
728 NULL((void*)0),
729 "org.freedesktop.systemd1",
730 NULL((void*)0),
731 "org.freedesktop.DBus.Properties",
732 "PropertiesChanged",
733 match_properties_changed, NULL((void*)0), m);
734 if (r < 0)
735 return log_error_errno(r, "Failed to request match for PropertiesChanged: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 735, __func__, "Failed to request match for PropertiesChanged: %m"
) : -abs(_e); })
;
736
737 r = sd_bus_match_signal_async(
738 m->bus,
739 NULL((void*)0),
740 "org.freedesktop.systemd1",
741 "/org/freedesktop/systemd1",
742 "org.freedesktop.systemd1.Manager",
743 "Reloading",
744 match_reloading, NULL((void*)0), m);
745 if (r < 0)
746 return log_error_errno(r, "Failed to request match for Reloading: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 746, __func__, "Failed to request match for Reloading: %m"
) : -abs(_e); })
;
747
748 r = sd_bus_call_method_async(
749 m->bus,
750 NULL((void*)0),
751 "org.freedesktop.systemd1",
752 "/org/freedesktop/systemd1",
753 "org.freedesktop.systemd1.Manager",
754 "Subscribe",
755 NULL((void*)0), NULL((void*)0),
756 NULL((void*)0));
757 if (r < 0)
758 return log_error_errno(r, "Failed to enable subscription: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 758, __func__, "Failed to enable subscription: %m"
) : -abs(_e); })
;
759
760 r = sd_bus_request_name_async(m->bus, NULL((void*)0), "org.freedesktop.login1", 0, NULL((void*)0), NULL((void*)0));
761 if (r < 0)
762 return log_error_errno(r, "Failed to request name: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 762, __func__, "Failed to request name: %m"
) : -abs(_e); })
;
763
764 r = sd_bus_attach_event(m->bus, m->event, SD_EVENT_PRIORITY_NORMAL);
765 if (r < 0)
766 return log_error_errno(r, "Failed to attach bus to event loop: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 766, __func__, "Failed to attach bus to event loop: %m"
) : -abs(_e); })
;
767
768 return 0;
769}
770
771static int manager_vt_switch(sd_event_source *src, const struct signalfd_siginfo *si, void *data) {
772 Manager *m = data;
773 Session *active, *iter;
774
775 /*
776 * We got a VT-switch signal and we have to acknowledge it immediately.
777 * Preferably, we'd just use m->seat0->active->vtfd, but unfortunately,
778 * old user-space might run multiple sessions on a single VT, *sigh*.
779 * Therefore, we have to iterate all sessions and find one with a vtfd
780 * on the requested VT.
781 * As only VTs with active controllers have VT_PROCESS set, our current
782 * notion of the active VT might be wrong (for instance if the switch
783 * happens while we setup VT_PROCESS). Therefore, read the current VT
784 * first and then use s->active->vtnr as reference. Note that this is
785 * not racy, as no further VT-switch can happen as long as we're in
786 * synchronous VT_PROCESS mode.
787 */
788
789 assert(m->seat0)do { if ((__builtin_expect(!!(!(m->seat0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m->seat0"), "../src/login/logind.c",
789, __PRETTY_FUNCTION__); } while (0)
;
790 seat_read_active_vt(m->seat0);
791
792 active = m->seat0->active;
793 if (!active || active->vtnr < 1) {
794 log_warning("Received VT_PROCESS signal without a registered session on that VT.")({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 794, __func__, "Received VT_PROCESS signal without a registered session on that VT."
) : -abs(_e); })
;
795 return 0;
796 }
797
798 if (active->vtfd >= 0) {
799 session_leave_vt(active);
800 } else {
801 LIST_FOREACH(sessions_by_seat, iter, m->seat0->sessions)for ((iter) = (m->seat0->sessions); (iter); (iter) = (iter
)->sessions_by_seat_next)
{
802 if (iter->vtnr == active->vtnr && iter->vtfd >= 0) {
803 session_leave_vt(iter);
804 break;
805 }
806 }
807 }
808
809 return 0;
810}
811
812static int manager_connect_console(Manager *m) {
813 int r;
814
815 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 815, __PRETTY_FUNCTION__
); } while (0)
;
816 assert(m->console_active_fd < 0)do { if ((__builtin_expect(!!(!(m->console_active_fd < 0
)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("m->console_active_fd < 0"
), "../src/login/logind.c", 816, __PRETTY_FUNCTION__); } while
(0)
;
817
818 /* On certain architectures (S390 and Xen, and containers),
819 /dev/tty0 does not exist, so don't fail if we can't open
820 it. */
821 if (access("/dev/tty0", F_OK0) < 0)
822 return 0;
823
824 m->console_active_fd = open("/sys/class/tty/tty0/active", O_RDONLY00|O_NOCTTY0400|O_CLOEXEC02000000);
825 if (m->console_active_fd < 0) {
826
827 /* On some systems the device node /dev/tty0 may exist
828 * even though /sys/class/tty/tty0 does not. */
829 if (errno(*__errno_location ()) == ENOENT2)
830 return 0;
831
832 return log_error_errno(errno, "Failed to open /sys/class/tty/tty0/active: %m")({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/login/logind.c", 832, __func__, "Failed to open /sys/class/tty/tty0/active: %m"
) : -abs(_e); })
;
833 }
834
835 r = sd_event_add_io(m->event, &m->console_active_event_source, m->console_active_fd, 0, manager_dispatch_console, m);
836 if (r < 0) {
837 log_error("Failed to watch foreground console")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 837, __func__, "Failed to watch foreground console"
) : -abs(_e); })
;
838 return r;
839 }
840
841 /*
842 * SIGRTMIN is used as global VT-release signal, SIGRTMIN + 1 is used
843 * as VT-acquire signal. We ignore any acquire-events (yes, we still
844 * have to provide a valid signal-number for it!) and acknowledge all
845 * release events immediately.
846 */
847
848 if (SIGRTMIN(__libc_current_sigrtmin ()) + 1 > SIGRTMAX(__libc_current_sigrtmax ())) {
849 log_error("Not enough real-time signals available: %u-%u", SIGRTMIN, SIGRTMAX)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 849, __func__, "Not enough real-time signals available: %u-%u"
, (__libc_current_sigrtmin ()), (__libc_current_sigrtmax ()))
: -abs(_e); })
;
850 return -EINVAL22;
851 }
852
853 assert_se(ignore_signals(SIGRTMIN + 1, -1) >= 0)do { if ((__builtin_expect(!!(!(ignore_signals((__libc_current_sigrtmin
()) + 1, -1) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("ignore_signals(SIGRTMIN + 1, -1) >= 0"), "../src/login/logind.c"
, 853, __PRETTY_FUNCTION__); } while (0)
;
854 assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGRTMIN, -1) >= 0)do { if ((__builtin_expect(!!(!(sigprocmask_many(0, ((void*)0
), (__libc_current_sigrtmin ()), -1) >= 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("sigprocmask_many(SIG_BLOCK, NULL, SIGRTMIN, -1) >= 0"
), "../src/login/logind.c", 854, __PRETTY_FUNCTION__); } while
(0)
;
855
856 r = sd_event_add_signal(m->event, NULL((void*)0), SIGRTMIN(__libc_current_sigrtmin ()), manager_vt_switch, m);
857 if (r < 0)
858 return r;
859
860 return 0;
861}
862
863static int manager_connect_udev(Manager *m) {
864 int r;
865
866 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 866, __PRETTY_FUNCTION__
); } while (0)
;
867 assert(!m->udev_seat_monitor)do { if ((__builtin_expect(!!(!(!m->udev_seat_monitor)),0)
)) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!m->udev_seat_monitor"
), "../src/login/logind.c", 867, __PRETTY_FUNCTION__); } while
(0)
;
868 assert(!m->udev_device_monitor)do { if ((__builtin_expect(!!(!(!m->udev_device_monitor)),
0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!m->udev_device_monitor"
), "../src/login/logind.c", 868, __PRETTY_FUNCTION__); } while
(0)
;
869 assert(!m->udev_vcsa_monitor)do { if ((__builtin_expect(!!(!(!m->udev_vcsa_monitor)),0)
)) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!m->udev_vcsa_monitor"
), "../src/login/logind.c", 869, __PRETTY_FUNCTION__); } while
(0)
;
870 assert(!m->udev_button_monitor)do { if ((__builtin_expect(!!(!(!m->udev_button_monitor)),
0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("!m->udev_button_monitor"
), "../src/login/logind.c", 870, __PRETTY_FUNCTION__); } while
(0)
;
871
872 m->udev_seat_monitor = udev_monitor_new_from_netlink(m->udev, "udev");
873 if (!m->udev_seat_monitor)
874 return -ENOMEM12;
875
876 r = udev_monitor_filter_add_match_tag(m->udev_seat_monitor, "master-of-seat");
877 if (r < 0)
878 return r;
879
880 r = udev_monitor_enable_receiving(m->udev_seat_monitor);
881 if (r < 0)
882 return r;
883
884 r = sd_event_add_io(m->event, &m->udev_seat_event_source, udev_monitor_get_fd(m->udev_seat_monitor), EPOLLINEPOLLIN, manager_dispatch_seat_udev, m);
885 if (r < 0)
886 return r;
887
888 m->udev_device_monitor = udev_monitor_new_from_netlink(m->udev, "udev");
889 if (!m->udev_device_monitor)
890 return -ENOMEM12;
891
892 r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_device_monitor, "input", NULL((void*)0));
893 if (r < 0)
894 return r;
895
896 r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_device_monitor, "graphics", NULL((void*)0));
897 if (r < 0)
898 return r;
899
900 r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_device_monitor, "drm", NULL((void*)0));
901 if (r < 0)
902 return r;
903
904 r = udev_monitor_enable_receiving(m->udev_device_monitor);
905 if (r < 0)
906 return r;
907
908 r = sd_event_add_io(m->event, &m->udev_device_event_source, udev_monitor_get_fd(m->udev_device_monitor), EPOLLINEPOLLIN, manager_dispatch_device_udev, m);
909 if (r < 0)
910 return r;
911
912 /* Don't watch keys if nobody cares */
913 if (!manager_all_buttons_ignored(m)) {
914 m->udev_button_monitor = udev_monitor_new_from_netlink(m->udev, "udev");
915 if (!m->udev_button_monitor)
916 return -ENOMEM12;
917
918 r = udev_monitor_filter_add_match_tag(m->udev_button_monitor, "power-switch");
919 if (r < 0)
920 return r;
921
922 r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_button_monitor, "input", NULL((void*)0));
923 if (r < 0)
924 return r;
925
926 r = udev_monitor_enable_receiving(m->udev_button_monitor);
927 if (r < 0)
928 return r;
929
930 r = sd_event_add_io(m->event, &m->udev_button_event_source, udev_monitor_get_fd(m->udev_button_monitor), EPOLLINEPOLLIN, manager_dispatch_button_udev, m);
931 if (r < 0)
932 return r;
933 }
934
935 /* Don't bother watching VCSA devices, if nobody cares */
936 if (m->n_autovts > 0 && m->console_active_fd >= 0) {
937
938 m->udev_vcsa_monitor = udev_monitor_new_from_netlink(m->udev, "udev");
939 if (!m->udev_vcsa_monitor)
940 return -ENOMEM12;
941
942 r = udev_monitor_filter_add_match_subsystem_devtype(m->udev_vcsa_monitor, "vc", NULL((void*)0));
943 if (r < 0)
944 return r;
945
946 r = udev_monitor_enable_receiving(m->udev_vcsa_monitor);
947 if (r < 0)
948 return r;
949
950 r = sd_event_add_io(m->event, &m->udev_vcsa_event_source, udev_monitor_get_fd(m->udev_vcsa_monitor), EPOLLINEPOLLIN, manager_dispatch_vcsa_udev, m);
951 if (r < 0)
952 return r;
953 }
954
955 return 0;
956}
957
958static void manager_gc(Manager *m, bool_Bool drop_not_started) {
959 Seat *seat;
960 Session *session;
961 User *user;
962
963 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 963, __PRETTY_FUNCTION__
); } while (0)
;
964
965 while ((seat = m->seat_gc_queue)) {
966 LIST_REMOVE(gc_queue, m->seat_gc_queue, seat)do { typeof(*(m->seat_gc_queue)) **_head = &(m->seat_gc_queue
), *_item = (seat); do { if ((__builtin_expect(!!(!(_item)),0
))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("_item"), "../src/login/logind.c"
, 966, __PRETTY_FUNCTION__); } while (0); if (_item->gc_queue_next
) _item->gc_queue_next->gc_queue_prev = _item->gc_queue_prev
; if (_item->gc_queue_prev) _item->gc_queue_prev->gc_queue_next
= _item->gc_queue_next; else { do { if ((__builtin_expect
(!!(!(*_head == _item)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("*_head == _item"), "../src/login/logind.c", 966, __PRETTY_FUNCTION__
); } while (0); *_head = _item->gc_queue_next; } _item->
gc_queue_next = _item->gc_queue_prev = ((void*)0); } while
(0)
;
967 seat->in_gc_queue = false0;
968
969 if (seat_may_gc(seat, drop_not_started)) {
970 seat_stop(seat, false0);
971 seat_free(seat);
972 }
973 }
974
975 while ((session = m->session_gc_queue)) {
976 LIST_REMOVE(gc_queue, m->session_gc_queue, session)do { typeof(*(m->session_gc_queue)) **_head = &(m->
session_gc_queue), *_item = (session); do { if ((__builtin_expect
(!!(!(_item)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD,
("_item"), "../src/login/logind.c", 976, __PRETTY_FUNCTION__
); } while (0); if (_item->gc_queue_next) _item->gc_queue_next
->gc_queue_prev = _item->gc_queue_prev; if (_item->gc_queue_prev
) _item->gc_queue_prev->gc_queue_next = _item->gc_queue_next
; else { do { if ((__builtin_expect(!!(!(*_head == _item)),0)
)) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("*_head == _item"
), "../src/login/logind.c", 976, __PRETTY_FUNCTION__); } while
(0); *_head = _item->gc_queue_next; } _item->gc_queue_next
= _item->gc_queue_prev = ((void*)0); } while (0)
;
977 session->in_gc_queue = false0;
978
979 /* First, if we are not closing yet, initiate stopping */
980 if (session_may_gc(session, drop_not_started) &&
981 session_get_state(session) != SESSION_CLOSING)
982 session_stop(session, false0);
983
984 /* Normally, this should make the session referenced
985 * again, if it doesn't then let's get rid of it
986 * immediately */
987 if (session_may_gc(session, drop_not_started)) {
988 session_finalize(session);
989 session_free(session);
990 }
991 }
992
993 while ((user = m->user_gc_queue)) {
994 LIST_REMOVE(gc_queue, m->user_gc_queue, user)do { typeof(*(m->user_gc_queue)) **_head = &(m->user_gc_queue
), *_item = (user); do { if ((__builtin_expect(!!(!(_item)),0
))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("_item"), "../src/login/logind.c"
, 994, __PRETTY_FUNCTION__); } while (0); if (_item->gc_queue_next
) _item->gc_queue_next->gc_queue_prev = _item->gc_queue_prev
; if (_item->gc_queue_prev) _item->gc_queue_prev->gc_queue_next
= _item->gc_queue_next; else { do { if ((__builtin_expect
(!!(!(*_head == _item)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("*_head == _item"), "../src/login/logind.c", 994, __PRETTY_FUNCTION__
); } while (0); *_head = _item->gc_queue_next; } _item->
gc_queue_next = _item->gc_queue_prev = ((void*)0); } while
(0)
;
995 user->in_gc_queue = false0;
996
997 /* First step: queue stop jobs */
998 if (user_may_gc(user, drop_not_started))
999 user_stop(user, false0);
1000
1001 /* Second step: finalize user */
1002 if (user_may_gc(user, drop_not_started)) {
1003 user_finalize(user);
1004 user_free(user);
1005 }
1006 }
1007}
1008
1009static int manager_dispatch_idle_action(sd_event_source *s, uint64_t t, void *userdata) {
1010 Manager *m = userdata;
1011 struct dual_timestamp since;
1012 usec_t n, elapse;
1013 int r;
1014
1015 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 1015, __PRETTY_FUNCTION__
); } while (0)
;
1016
1017 if (m->idle_action == HANDLE_IGNORE ||
1018 m->idle_action_usec <= 0)
1019 return 0;
1020
1021 n = now(CLOCK_MONOTONIC1);
1022
1023 r = manager_get_idle_hint(m, &since);
1024 if (r <= 0)
1025 /* Not idle. Let's check if after a timeout it might be idle then. */
1026 elapse = n + m->idle_action_usec;
1027 else {
1028 /* Idle! Let's see if it's time to do something, or if
1029 * we shall sleep for longer. */
1030
1031 if (n >= since.monotonic + m->idle_action_usec &&
1032 (m->idle_action_not_before_usec <= 0 || n >= m->idle_action_not_before_usec + m->idle_action_usec)) {
1033 log_info("System idle. Taking action.")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1033, __func__, "System idle. Taking action."
) : -abs(_e); })
;
1034
1035 manager_handle_action(m, 0, m->idle_action, false0, false0);
1036 m->idle_action_not_before_usec = n;
1037 }
1038
1039 elapse = MAX(since.monotonic, m->idle_action_not_before_usec)__extension__ ({ const typeof((since.monotonic)) __unique_prefix_A22
= ((since.monotonic)); const typeof((m->idle_action_not_before_usec
)) __unique_prefix_B23 = ((m->idle_action_not_before_usec)
); __unique_prefix_A22 > __unique_prefix_B23 ? __unique_prefix_A22
: __unique_prefix_B23; })
+ m->idle_action_usec;
1040 }
1041
1042 if (!m->idle_action_event_source) {
1043
1044 r = sd_event_add_time(
1045 m->event,
1046 &m->idle_action_event_source,
1047 CLOCK_MONOTONIC1,
1048 elapse, USEC_PER_SEC((usec_t) 1000000ULL)*30,
1049 manager_dispatch_idle_action, m);
1050 if (r < 0)
1051 return log_error_errno(r, "Failed to add idle event source: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1051, __func__, "Failed to add idle event source: %m"
) : -abs(_e); })
;
1052
1053 r = sd_event_source_set_priority(m->idle_action_event_source, SD_EVENT_PRIORITY_IDLE+10);
1054 if (r < 0)
1055 return log_error_errno(r, "Failed to set idle event source priority: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1055, __func__, "Failed to set idle event source priority: %m"
) : -abs(_e); })
;
1056 } else {
1057 r = sd_event_source_set_time(m->idle_action_event_source, elapse);
1058 if (r < 0)
1059 return log_error_errno(r, "Failed to set idle event timer: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1059, __func__, "Failed to set idle event timer: %m"
) : -abs(_e); })
;
1060
1061 r = sd_event_source_set_enabled(m->idle_action_event_source, SD_EVENT_ONESHOT);
1062 if (r < 0)
1063 return log_error_errno(r, "Failed to enable idle event timer: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1063, __func__, "Failed to enable idle event timer: %m"
) : -abs(_e); })
;
1064 }
1065
1066 return 0;
1067}
1068
1069static int manager_dispatch_reload_signal(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
1070 Manager *m = userdata;
1071 int r;
1072
1073 manager_reset_config(m);
1074 r = manager_parse_config_file(m);
1075 if (r < 0)
1076 log_warning_errno(r, "Failed to parse config file, using defaults: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1076, __func__, "Failed to parse config file, using defaults: %m"
) : -abs(_e); })
;
1077 else
1078 log_info("Config file reloaded.")({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1078, __func__, "Config file reloaded."
) : -abs(_e); })
;
1079
1080 return 0;
1081}
1082
1083static int manager_startup(Manager *m) {
1084 int r;
1085 Seat *seat;
1086 Session *session;
1087 User *user;
1088 Button *button;
1089 Inhibitor *inhibitor;
1090 Iterator i;
1091
1092 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 1092, __PRETTY_FUNCTION__
); } while (0)
;
10
Taking false branch
11
Loop condition is false. Exiting loop
1093
1094 r = sd_event_add_signal(m->event, NULL((void*)0), SIGHUP1, manager_dispatch_reload_signal, m);
1095 if (r < 0)
12
Assuming 'r' is >= 0
13
Taking false branch
1096 return log_error_errno(r, "Failed to register SIGHUP handler: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1096, __func__, "Failed to register SIGHUP handler: %m"
) : -abs(_e); })
;
1097
1098 /* Connect to console */
1099 r = manager_connect_console(m);
1100 if (r
13.1
'r' is >= 0
< 0)
14
Taking false branch
1101 return r;
1102
1103 /* Connect to udev */
1104 r = manager_connect_udev(m);
1105 if (r
14.1
'r' is >= 0
< 0)
15
Taking false branch
1106 return log_error_errno(r, "Failed to create udev watchers: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1106, __func__, "Failed to create udev watchers: %m"
) : -abs(_e); })
;
1107
1108 /* Connect to the bus */
1109 r = manager_connect_bus(m);
1110 if (r < 0)
16
Assuming 'r' is >= 0
17
Taking false branch
1111 return r;
1112
1113 /* Instantiate magic seat 0 */
1114 r = manager_add_seat(m, "seat0", &m->seat0);
1115 if (r < 0)
18
Assuming 'r' is >= 0
19
Taking false branch
1116 return log_error_errno(r, "Failed to add seat0: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1116, __func__, "Failed to add seat0: %m"
) : -abs(_e); })
;
1117
1118 r = manager_set_lid_switch_ignore(m, 0 + m->holdoff_timeout_usec);
1119 if (r < 0)
20
Assuming 'r' is >= 0
21
Taking false branch
1120 log_warning_errno(r, "Failed to set up lid switch ignore event source: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1120, __func__, "Failed to set up lid switch ignore event source: %m"
) : -abs(_e); })
;
1121
1122 /* Deserialize state */
1123 r = manager_enumerate_devices(m);
1124 if (r
21.1
'r' is >= 0
< 0)
22
Taking false branch
1125 log_warning_errno(r, "Device enumeration failed: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1125, __func__, "Device enumeration failed: %m"
) : -abs(_e); })
;
1126
1127 r = manager_enumerate_seats(m);
1128 if (r
22.1
'r' is >= 0
< 0)
23
Taking false branch
1129 log_warning_errno(r, "Seat enumeration failed: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1129, __func__, "Seat enumeration failed: %m"
) : -abs(_e); })
;
1130
1131 r = manager_enumerate_users(m);
1132 if (r
23.1
'r' is >= 0
< 0)
24
Taking false branch
1133 log_warning_errno(r, "User enumeration failed: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1133, __func__, "User enumeration failed: %m"
) : -abs(_e); })
;
1134
1135 r = manager_enumerate_sessions(m);
25
Calling 'manager_enumerate_sessions'
1136 if (r < 0)
1137 log_warning_errno(r, "Session enumeration failed: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1137, __func__, "Session enumeration failed: %m"
) : -abs(_e); })
;
1138
1139 r = manager_enumerate_inhibitors(m);
1140 if (r < 0)
1141 log_warning_errno(r, "Inhibitor enumeration failed: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1141, __func__, "Inhibitor enumeration failed: %m"
) : -abs(_e); })
;
1142
1143 r = manager_enumerate_buttons(m);
1144 if (r < 0)
1145 log_warning_errno(r, "Button enumeration failed: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1145, __func__, "Button enumeration failed: %m"
) : -abs(_e); })
;
1146
1147 /* Remove stale objects before we start them */
1148 manager_gc(m, false0);
1149
1150 /* Reserve the special reserved VT */
1151 manager_reserve_vt(m);
1152
1153 /* And start everything */
1154 HASHMAP_FOREACH(seat, m->seats, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); hashmap_iterate((m->seats), &
(i), (void**)&(seat), ((void*)0)); )
1155 seat_start(seat);
1156
1157 HASHMAP_FOREACH(user, m->users, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); hashmap_iterate((m->users), &
(i), (void**)&(user), ((void*)0)); )
1158 user_start(user);
1159
1160 HASHMAP_FOREACH(session, m->sessions, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); hashmap_iterate((m->sessions), &
(i), (void**)&(session), ((void*)0)); )
1161 session_start(session, NULL((void*)0));
1162
1163 HASHMAP_FOREACH(inhibitor, m->inhibitors, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); hashmap_iterate((m->inhibitors),
&(i), (void**)&(inhibitor), ((void*)0)); )
1164 inhibitor_start(inhibitor);
1165
1166 HASHMAP_FOREACH(button, m->buttons, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), .
next_key = ((void*)0) }); hashmap_iterate((m->buttons), &
(i), (void**)&(button), ((void*)0)); )
1167 button_check_switches(button);
1168
1169 manager_dispatch_idle_action(NULL((void*)0), 0, m);
1170
1171 return 0;
1172}
1173
1174static int manager_run(Manager *m) {
1175 int r;
1176
1177 assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("m"), "../src/login/logind.c", 1177, __PRETTY_FUNCTION__
); } while (0)
;
1178
1179 for (;;) {
1180 r = sd_event_get_state(m->event);
1181 if (r < 0)
1182 return r;
1183 if (r == SD_EVENT_FINISHED)
1184 return 0;
1185
1186 manager_gc(m, true1);
1187
1188 r = manager_dispatch_delayed(m, false0);
1189 if (r < 0)
1190 return r;
1191 if (r > 0)
1192 continue;
1193
1194 r = sd_event_run(m->event, (uint64_t) -1);
1195 if (r < 0)
1196 return r;
1197 }
1198}
1199
1200int main(int argc, char *argv[]) {
1201 _cleanup_(manager_unrefp)__attribute__((cleanup(manager_unrefp))) Manager *m = NULL((void*)0);
1202 int r;
1203
1204 log_set_target(LOG_TARGET_AUTO);
1205 log_set_facility(LOG_AUTH(4<<3));
1206 log_parse_environment()log_parse_environment_realm(LOG_REALM_SYSTEMD);
1207 log_open();
1208
1209 umask(0022);
1210
1211 if (argc != 1) {
1
Assuming 'argc' is equal to 1
2
Taking false branch
1212 log_error("This program takes no arguments.")({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1212, __func__, "This program takes no arguments."
) : -abs(_e); })
;
1213 r = -EINVAL22;
1214 goto finish;
1215 }
1216
1217 r = mac_selinux_init();
1218 if (r < 0) {
3
Assuming 'r' is >= 0
4
Taking false branch
1219 log_error_errno(r, "Could not initialize labelling: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1219, __func__, "Could not initialize labelling: %m"
) : -abs(_e); })
;
1220 goto finish;
1221 }
1222
1223 /* Always create the directories people can create inotify watches in. Note that some applications might check
1224 * for the existence of /run/systemd/seats/ to determine whether logind is available, so please always make
1225 * sure these directories are created early on and unconditionally. */
1226 (void) mkdir_label("/run/systemd/seats", 0755);
1227 (void) mkdir_label("/run/systemd/users", 0755);
1228 (void) mkdir_label("/run/systemd/sessions", 0755);
1229
1230 assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGHUP, SIGTERM, SIGINT, -1) >= 0)do { if ((__builtin_expect(!!(!(sigprocmask_many(0, ((void*)0
), 1, 15, 2, -1) >= 0)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD
, ("sigprocmask_many(SIG_BLOCK, NULL, SIGHUP, SIGTERM, SIGINT, -1) >= 0"
), "../src/login/logind.c", 1230, __PRETTY_FUNCTION__); } while
(0)
;
5
Assuming the condition is true
6
Taking false branch
7
Loop condition is false. Exiting loop
1231
1232 r = manager_new(&m);
1233 if (r
7.1
'r' is >= 0
< 0) {
8
Taking false branch
1234 log_error_errno(r, "Failed to allocate manager object: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1234, __func__, "Failed to allocate manager object: %m"
) : -abs(_e); })
;
1235 goto finish;
1236 }
1237
1238 (void) manager_parse_config_file(m);
1239
1240 r = manager_startup(m);
9
Calling 'manager_startup'
1241 if (r < 0) {
1242 log_error_errno(r, "Failed to fully start up daemon: %m")({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1242, __func__, "Failed to fully start up daemon: %m"
) : -abs(_e); })
;
1243 goto finish;
1244 }
1245
1246 log_debug("systemd-logind running as pid "PID_FMT, getpid_cached())({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1246, __func__, "systemd-logind running as pid "
"%" "i", getpid_cached()) : -abs(_e); })
;
1247
1248 (void) sd_notify(false0,
1249 "READY=1\n"
1250 "STATUS=Processing requests...");
1251
1252 r = manager_run(m);
1253
1254 log_debug("systemd-logind stopped as pid "PID_FMT, getpid_cached())({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/login/logind.c", 1254, __func__, "systemd-logind stopped as pid "
"%" "i", getpid_cached()) : -abs(_e); })
;
1255
1256 (void) sd_notify(false0,
1257 "STOPPING=1\n"
1258 "STATUS=Shutting down...");
1259
1260finish:
1261 return r < 0 ? EXIT_FAILURE1 : EXIT_SUCCESS0;
1262}