]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/login/logind-core.c
conf: replace config_parse_many_nulstr() with config_parse_config_file()
[thirdparty/systemd.git] / src / login / logind-core.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <fcntl.h>
4 #include <sys/ioctl.h>
5 #include <sys/types.h>
6 #include <linux/vt.h>
7
8 #include "sd-device.h"
9
10 #include "alloc-util.h"
11 #include "bus-error.h"
12 #include "bus-util.h"
13 #include "cgroup-util.h"
14 #include "conf-parser.h"
15 #include "device-util.h"
16 #include "efi-loader.h"
17 #include "errno-util.h"
18 #include "fd-util.h"
19 #include "limits-util.h"
20 #include "logind.h"
21 #include "parse-util.h"
22 #include "path-util.h"
23 #include "process-util.h"
24 #include "stdio-util.h"
25 #include "strv.h"
26 #include "terminal-util.h"
27 #include "udev-util.h"
28 #include "user-util.h"
29 #include "userdb.h"
30 #include "utmp-wtmp.h"
31
32 void manager_reset_config(Manager *m) {
33 assert(m);
34
35 m->n_autovts = 6;
36 m->reserve_vt = 6;
37 m->remove_ipc = true;
38 m->inhibit_delay_max = 5 * USEC_PER_SEC;
39 m->user_stop_delay = 10 * USEC_PER_SEC;
40
41 m->handle_power_key = HANDLE_POWEROFF;
42 m->handle_power_key_long_press = HANDLE_IGNORE;
43 m->handle_reboot_key = HANDLE_REBOOT;
44 m->handle_reboot_key_long_press = HANDLE_POWEROFF;
45 m->handle_suspend_key = HANDLE_SUSPEND;
46 m->handle_suspend_key_long_press = HANDLE_HIBERNATE;
47 m->handle_hibernate_key = HANDLE_HIBERNATE;
48 m->handle_hibernate_key_long_press = HANDLE_IGNORE;
49
50 m->handle_lid_switch = HANDLE_SUSPEND;
51 m->handle_lid_switch_ep = _HANDLE_ACTION_INVALID;
52 m->handle_lid_switch_docked = HANDLE_IGNORE;
53
54 m->power_key_ignore_inhibited = false;
55 m->suspend_key_ignore_inhibited = false;
56 m->hibernate_key_ignore_inhibited = false;
57 m->lid_switch_ignore_inhibited = true;
58 m->reboot_key_ignore_inhibited = false;
59
60 m->holdoff_timeout_usec = 30 * USEC_PER_SEC;
61
62 m->idle_action_usec = 30 * USEC_PER_MINUTE;
63 m->idle_action = HANDLE_IGNORE;
64
65 m->runtime_dir_size = physical_memory_scale(10U, 100U); /* 10% */
66 m->runtime_dir_inodes = DIV_ROUND_UP(m->runtime_dir_size, 4096); /* 4k per inode */
67 m->sessions_max = 8192;
68 m->inhibitors_max = 8192;
69
70 m->kill_user_processes = KILL_USER_PROCESSES;
71
72 m->kill_only_users = strv_free(m->kill_only_users);
73 m->kill_exclude_users = strv_free(m->kill_exclude_users);
74
75 m->stop_idle_session_usec = USEC_INFINITY;
76 }
77
78 int manager_parse_config_file(Manager *m) {
79 assert(m);
80
81 return config_parse_config_file("logind.conf", "Login\0",
82 config_item_perf_lookup, logind_gperf_lookup,
83 CONFIG_PARSE_WARN, m);
84 }
85
86 int manager_add_device(Manager *m, const char *sysfs, bool master, Device **ret_device) {
87 Device *d;
88
89 assert(m);
90 assert(sysfs);
91
92 d = hashmap_get(m->devices, sysfs);
93 if (d)
94 /* we support adding master-flags, but not removing them */
95 d->master = d->master || master;
96 else {
97 d = device_new(m, sysfs, master);
98 if (!d)
99 return -ENOMEM;
100 }
101
102 if (ret_device)
103 *ret_device = d;
104
105 return 0;
106 }
107
108 int manager_add_seat(Manager *m, const char *id, Seat **ret_seat) {
109 Seat *s;
110 int r;
111
112 assert(m);
113 assert(id);
114
115 s = hashmap_get(m->seats, id);
116 if (!s) {
117 r = seat_new(&s, m, id);
118 if (r < 0)
119 return r;
120 }
121
122 if (ret_seat)
123 *ret_seat = s;
124
125 return 0;
126 }
127
128 int manager_add_session(Manager *m, const char *id, Session **ret_session) {
129 Session *s;
130 int r;
131
132 assert(m);
133 assert(id);
134
135 s = hashmap_get(m->sessions, id);
136 if (!s) {
137 r = session_new(&s, m, id);
138 if (r < 0)
139 return r;
140 }
141
142 if (ret_session)
143 *ret_session = s;
144
145 return 0;
146 }
147
148 int manager_add_user(
149 Manager *m,
150 UserRecord *ur,
151 User **ret_user) {
152
153 User *u;
154 int r;
155
156 assert(m);
157 assert(ur);
158
159 u = hashmap_get(m->users, UID_TO_PTR(ur->uid));
160 if (!u) {
161 r = user_new(&u, m, ur);
162 if (r < 0)
163 return r;
164 }
165
166 if (ret_user)
167 *ret_user = u;
168
169 return 0;
170 }
171
172 int manager_add_user_by_name(
173 Manager *m,
174 const char *name,
175 User **ret_user) {
176
177 _cleanup_(user_record_unrefp) UserRecord *ur = NULL;
178 int r;
179
180 assert(m);
181 assert(name);
182
183 r = userdb_by_name(name, USERDB_SUPPRESS_SHADOW, &ur);
184 if (r < 0)
185 return r;
186
187 return manager_add_user(m, ur, ret_user);
188 }
189
190 int manager_add_user_by_uid(
191 Manager *m,
192 uid_t uid,
193 User **ret_user) {
194
195 _cleanup_(user_record_unrefp) UserRecord *ur = NULL;
196 int r;
197
198 assert(m);
199 assert(uid_is_valid(uid));
200
201 r = userdb_by_uid(uid, USERDB_SUPPRESS_SHADOW, &ur);
202 if (r < 0)
203 return r;
204
205 return manager_add_user(m, ur, ret_user);
206 }
207
208 int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **ret) {
209 Inhibitor *i;
210 int r;
211
212 assert(m);
213 assert(id);
214
215 i = hashmap_get(m->inhibitors, id);
216 if (!i) {
217 r = inhibitor_new(&i, m, id);
218 if (r < 0)
219 return r;
220 }
221
222 if (ret)
223 *ret = i;
224
225 return 0;
226 }
227
228 int manager_add_button(Manager *m, const char *name, Button **ret_button) {
229 Button *b;
230
231 assert(m);
232 assert(name);
233
234 b = hashmap_get(m->buttons, name);
235 if (!b) {
236 b = button_new(m, name);
237 if (!b)
238 return -ENOMEM;
239 }
240
241 if (ret_button)
242 *ret_button = b;
243
244 return 0;
245 }
246
247 int manager_process_seat_device(Manager *m, sd_device *d) {
248 Device *device;
249 int r;
250
251 assert(m);
252
253 if (device_for_action(d, SD_DEVICE_REMOVE) ||
254 sd_device_has_current_tag(d, "seat") <= 0) {
255 const char *syspath;
256
257 r = sd_device_get_syspath(d, &syspath);
258 if (r < 0)
259 return 0;
260
261 device = hashmap_get(m->devices, syspath);
262 if (!device)
263 return 0;
264
265 seat_add_to_gc_queue(device->seat);
266 device_free(device);
267
268 } else {
269 const char *sn, *syspath;
270 bool master;
271 Seat *seat;
272
273 if (sd_device_get_property_value(d, "ID_SEAT", &sn) < 0 || isempty(sn))
274 sn = "seat0";
275
276 if (!seat_name_is_valid(sn)) {
277 log_device_warning(d, "Device with invalid seat name %s found, ignoring.", sn);
278 return 0;
279 }
280
281 seat = hashmap_get(m->seats, sn);
282 master = sd_device_has_current_tag(d, "master-of-seat") > 0;
283
284 /* Ignore non-master devices for unknown seats */
285 if (!master && !seat)
286 return 0;
287
288 r = sd_device_get_syspath(d, &syspath);
289 if (r < 0)
290 return r;
291
292 r = manager_add_device(m, syspath, master, &device);
293 if (r < 0)
294 return r;
295
296 if (!seat) {
297 r = manager_add_seat(m, sn, &seat);
298 if (r < 0) {
299 if (!device->seat)
300 device_free(device);
301
302 return r;
303 }
304 }
305
306 device_attach(device, seat);
307 seat_start(seat);
308 }
309
310 return 0;
311 }
312
313 int manager_process_button_device(Manager *m, sd_device *d) {
314 const char *sysname;
315 Button *b;
316 int r;
317
318 assert(m);
319
320 r = sd_device_get_sysname(d, &sysname);
321 if (r < 0)
322 return r;
323
324 if (device_for_action(d, SD_DEVICE_REMOVE) ||
325 sd_device_has_current_tag(d, "power-switch") <= 0) {
326
327 b = hashmap_get(m->buttons, sysname);
328 if (!b)
329 return 0;
330
331 button_free(b);
332
333 } else {
334 const char *sn;
335
336 r = manager_add_button(m, sysname, &b);
337 if (r < 0)
338 return r;
339
340 if (sd_device_get_property_value(d, "ID_SEAT", &sn) < 0 || isempty(sn))
341 sn = "seat0";
342
343 button_set_seat(b, sn);
344
345 r = button_open(b);
346 if (r < 0) /* event device doesn't have any keys or switches relevant to us? (or any other error
347 * opening the device?) let's close the button again. */
348 button_free(b);
349 }
350
351 return 0;
352 }
353
354 int manager_get_session_by_pid(Manager *m, pid_t pid, Session **ret) {
355 _cleanup_free_ char *unit = NULL;
356 Session *s;
357 int r;
358
359 assert(m);
360
361 if (!pid_is_valid(pid))
362 return -EINVAL;
363
364 s = hashmap_get(m->sessions_by_leader, PID_TO_PTR(pid));
365 if (!s) {
366 r = cg_pid_get_unit(pid, &unit);
367 if (r >= 0)
368 s = hashmap_get(m->session_units, unit);
369 }
370
371 if (ret)
372 *ret = s;
373
374 return !!s;
375 }
376
377 int manager_get_user_by_pid(Manager *m, pid_t pid, User **ret) {
378 _cleanup_free_ char *unit = NULL;
379 User *u = NULL;
380 int r;
381
382 assert(m);
383
384 if (!pid_is_valid(pid))
385 return -EINVAL;
386
387 r = cg_pid_get_slice(pid, &unit);
388 if (r >= 0)
389 u = hashmap_get(m->user_units, unit);
390
391 if (ret)
392 *ret = u;
393
394 return !!u;
395 }
396
397 int manager_get_idle_hint(Manager *m, dual_timestamp *t) {
398 Session *s;
399 bool idle_hint;
400 dual_timestamp ts = DUAL_TIMESTAMP_NULL;
401
402 assert(m);
403
404 idle_hint = !manager_is_inhibited(m, INHIBIT_IDLE, INHIBIT_BLOCK, t, false, false, 0, NULL);
405
406 HASHMAP_FOREACH(s, m->sessions) {
407 dual_timestamp k;
408 int ih;
409
410 ih = session_get_idle_hint(s, &k);
411 if (ih < 0)
412 return ih;
413
414 if (!ih) {
415 if (!idle_hint) {
416 if (k.monotonic < ts.monotonic)
417 ts = k;
418 } else {
419 idle_hint = false;
420 ts = k;
421 }
422 } else if (idle_hint) {
423
424 if (k.monotonic > ts.monotonic)
425 ts = k;
426 }
427 }
428
429 if (t)
430 *t = ts;
431
432 return idle_hint;
433 }
434
435 bool manager_shall_kill(Manager *m, const char *user) {
436 assert(m);
437 assert(user);
438
439 if (!m->kill_exclude_users && streq(user, "root"))
440 return false;
441
442 if (strv_contains(m->kill_exclude_users, user))
443 return false;
444
445 if (!strv_isempty(m->kill_only_users))
446 return strv_contains(m->kill_only_users, user);
447
448 return m->kill_user_processes;
449 }
450
451 int config_parse_n_autovts(
452 const char *unit,
453 const char *filename,
454 unsigned line,
455 const char *section,
456 unsigned section_line,
457 const char *lvalue,
458 int ltype,
459 const char *rvalue,
460 void *data,
461 void *userdata) {
462
463 unsigned *n = ASSERT_PTR(data);
464 unsigned o;
465 int r;
466
467 assert(filename);
468 assert(lvalue);
469 assert(rvalue);
470
471 r = safe_atou(rvalue, &o);
472 if (r < 0) {
473 log_syntax(unit, LOG_WARNING, filename, line, r,
474 "Failed to parse number of autovts, ignoring: %s", rvalue);
475 return 0;
476 }
477
478 if (o > 15) {
479 log_syntax(unit, LOG_WARNING, filename, line, 0,
480 "A maximum of 15 autovts are supported, ignoring: %s", rvalue);
481 return 0;
482 }
483
484 *n = o;
485 return 0;
486 }
487
488 static int vt_is_busy(unsigned vtnr) {
489 struct vt_stat vt_stat;
490 int r;
491 _cleanup_close_ int fd = -EBADF;
492
493 assert(vtnr >= 1);
494
495 /* VT_GETSTATE "cannot return state for more than 16 VTs, since v_state is short" */
496 assert(vtnr <= 15);
497
498 /* We explicitly open /dev/tty1 here instead of /dev/tty0. If
499 * we'd open the latter we'd open the foreground tty which
500 * hence would be unconditionally busy. By opening /dev/tty1
501 * we avoid this. Since tty1 is special and needs to be an
502 * explicitly loaded getty or DM this is safe. */
503
504 fd = open_terminal("/dev/tty1", O_RDWR|O_NOCTTY|O_CLOEXEC);
505 if (fd < 0)
506 return -errno;
507
508 if (ioctl(fd, VT_GETSTATE, &vt_stat) < 0)
509 r = -errno;
510 else
511 r = !!(vt_stat.v_state & (1 << vtnr));
512
513 return r;
514 }
515
516 int manager_spawn_autovt(Manager *m, unsigned vtnr) {
517 _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
518 char name[sizeof("autovt@tty.service") + DECIMAL_STR_MAX(unsigned)];
519 int r;
520
521 assert(m);
522 assert(vtnr >= 1);
523
524 if (vtnr > m->n_autovts &&
525 vtnr != m->reserve_vt)
526 return 0;
527
528 if (vtnr != m->reserve_vt) {
529 /* If this is the reserved TTY, we'll start the getty
530 * on it in any case, but otherwise only if it is not
531 * busy. */
532
533 r = vt_is_busy(vtnr);
534 if (r < 0)
535 return r;
536 else if (r > 0)
537 return -EBUSY;
538 }
539
540 xsprintf(name, "autovt@tty%u.service", vtnr);
541 r = sd_bus_call_method(
542 m->bus,
543 "org.freedesktop.systemd1",
544 "/org/freedesktop/systemd1",
545 "org.freedesktop.systemd1.Manager",
546 "StartUnit",
547 &error,
548 NULL,
549 "ss", name, "fail");
550 if (r < 0)
551 return log_error_errno(r, "Failed to start %s: %s", name, bus_error_message(&error, r));
552
553 return 0;
554 }
555
556 bool manager_is_lid_closed(Manager *m) {
557 Button *b;
558
559 HASHMAP_FOREACH(b, m->buttons)
560 if (b->lid_closed)
561 return true;
562
563 return false;
564 }
565
566 static bool manager_is_docked(Manager *m) {
567 Button *b;
568
569 HASHMAP_FOREACH(b, m->buttons)
570 if (b->docked)
571 return true;
572
573 return false;
574 }
575
576 static int manager_count_external_displays(Manager *m) {
577 _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
578 sd_device *d;
579 int r, n = 0;
580
581 r = sd_device_enumerator_new(&e);
582 if (r < 0)
583 return r;
584
585 r = sd_device_enumerator_allow_uninitialized(e);
586 if (r < 0)
587 return r;
588
589 r = sd_device_enumerator_add_match_subsystem(e, "drm", true);
590 if (r < 0)
591 return r;
592
593 FOREACH_DEVICE(e, d) {
594 const char *status, *enabled, *dash, *nn, *subsys;
595 sd_device *p;
596
597 if (sd_device_get_parent(d, &p) < 0)
598 continue;
599
600 /* If the parent shares the same subsystem as the
601 * device we are looking at then it is a connector,
602 * which is what we are interested in. */
603 if (sd_device_get_subsystem(p, &subsys) < 0 || !streq(subsys, "drm"))
604 continue;
605
606 if (sd_device_get_sysname(d, &nn) < 0)
607 continue;
608
609 /* Ignore internal displays: the type is encoded in the sysfs name, as the second dash
610 * separated item (the first is the card name, the last the connector number). We implement a
611 * deny list of external displays here, rather than an allow list of internal ones, to ensure
612 * we don't block suspends too eagerly. */
613 dash = strchr(nn, '-');
614 if (!dash)
615 continue;
616
617 dash++;
618 if (!STARTSWITH_SET(dash,
619 "VGA-", "DVI-I-", "DVI-D-", "DVI-A-"
620 "Composite-", "SVIDEO-", "Component-",
621 "DIN-", "DP-", "HDMI-A-", "HDMI-B-", "TV-"))
622 continue;
623
624 /* Ignore ports that are not enabled */
625 if (sd_device_get_sysattr_value(d, "enabled", &enabled) < 0 || !streq(enabled, "enabled"))
626 continue;
627
628 /* We count any connector which is not explicitly
629 * "disconnected" as connected. */
630 if (sd_device_get_sysattr_value(d, "status", &status) < 0 || !streq(status, "disconnected"))
631 n++;
632 }
633
634 return n;
635 }
636
637 bool manager_is_docked_or_external_displays(Manager *m) {
638 int n;
639
640 /* If we are docked don't react to lid closing */
641 if (manager_is_docked(m)) {
642 log_debug("System is docked.");
643 return true;
644 }
645
646 /* If we have more than one display connected,
647 * assume that we are docked. */
648 n = manager_count_external_displays(m);
649 if (n < 0)
650 log_warning_errno(n, "Display counting failed: %m");
651 else if (n >= 1) {
652 log_debug("External (%i) displays connected.", n);
653 return true;
654 }
655
656 return false;
657 }
658
659 bool manager_is_on_external_power(void) {
660 int r;
661
662 /* For now we only check for AC power, but 'external power' can apply to anything that isn't an internal
663 * battery */
664 r = on_ac_power();
665 if (r < 0)
666 log_warning_errno(r, "Failed to read AC power status: %m");
667
668 return r != 0; /* Treat failure as 'on AC' */
669 }
670
671 bool manager_all_buttons_ignored(Manager *m) {
672 assert(m);
673
674 if (m->handle_power_key != HANDLE_IGNORE)
675 return false;
676 if (m->handle_power_key_long_press != HANDLE_IGNORE)
677 return false;
678 if (m->handle_suspend_key != HANDLE_IGNORE)
679 return false;
680 if (m->handle_suspend_key_long_press != HANDLE_IGNORE)
681 return false;
682 if (m->handle_hibernate_key != HANDLE_IGNORE)
683 return false;
684 if (m->handle_hibernate_key_long_press != HANDLE_IGNORE)
685 return false;
686 if (m->handle_reboot_key != HANDLE_IGNORE)
687 return false;
688 if (m->handle_reboot_key_long_press != HANDLE_IGNORE)
689 return false;
690 if (m->handle_lid_switch != HANDLE_IGNORE)
691 return false;
692 if (!IN_SET(m->handle_lid_switch_ep, _HANDLE_ACTION_INVALID, HANDLE_IGNORE))
693 return false;
694 if (m->handle_lid_switch_docked != HANDLE_IGNORE)
695 return false;
696
697 return true;
698 }
699
700 int manager_read_utmp(Manager *m) {
701 #if ENABLE_UTMP
702 int r;
703 _unused_ _cleanup_(utxent_cleanup) bool utmpx = false;
704
705 assert(m);
706
707 if (utmpxname(_PATH_UTMPX) < 0)
708 return log_error_errno(errno, "Failed to set utmp path to " _PATH_UTMPX ": %m");
709
710 utmpx = utxent_start();
711
712 for (;;) {
713 _cleanup_free_ char *t = NULL;
714 struct utmpx *u;
715 const char *c;
716 Session *s;
717
718 errno = 0;
719 u = getutxent();
720 if (!u) {
721 if (errno == ENOENT)
722 log_debug_errno(errno, _PATH_UTMPX " does not exist, ignoring.");
723 else if (errno != 0)
724 log_warning_errno(errno, "Failed to read " _PATH_UTMPX ", ignoring: %m");
725 return 0;
726 }
727
728 if (u->ut_type != USER_PROCESS)
729 continue;
730
731 if (!pid_is_valid(u->ut_pid))
732 continue;
733
734 t = strndup(u->ut_line, sizeof(u->ut_line));
735 if (!t)
736 return log_oom();
737
738 c = path_startswith(t, "/dev/");
739 if (c) {
740 r = free_and_strdup(&t, c);
741 if (r < 0)
742 return log_oom();
743 }
744
745 if (isempty(t))
746 continue;
747
748 s = hashmap_get(m->sessions_by_leader, PID_TO_PTR(u->ut_pid));
749 if (!s)
750 continue;
751
752 if (s->tty_validity == TTY_FROM_UTMP && !streq_ptr(s->tty, t)) {
753 /* This may happen on multiplexed SSH connection (i.e. 'SSH connection sharing'). In
754 * this case PAM and utmp sessions don't match. In such a case let's invalidate the TTY
755 * information and never acquire it again. */
756
757 s->tty = mfree(s->tty);
758 s->tty_validity = TTY_UTMP_INCONSISTENT;
759 log_debug("Session '%s' has inconsistent TTY information, dropping TTY information.", s->id);
760 continue;
761 }
762
763 /* Never override what we figured out once */
764 if (s->tty || s->tty_validity >= 0)
765 continue;
766
767 s->tty = TAKE_PTR(t);
768 s->tty_validity = TTY_FROM_UTMP;
769 log_debug("Acquired TTY information '%s' from utmp for session '%s'.", s->tty, s->id);
770 }
771
772 #else
773 return 0;
774 #endif
775 }
776
777 #if ENABLE_UTMP
778 static int manager_dispatch_utmp(sd_event_source *s, const struct inotify_event *event, void *userdata) {
779 Manager *m = ASSERT_PTR(userdata);
780
781 /* If there's indication the file itself might have been removed or became otherwise unavailable, then let's
782 * reestablish the watch on whatever there's now. */
783 if ((event->mask & (IN_ATTRIB|IN_DELETE_SELF|IN_MOVE_SELF|IN_Q_OVERFLOW|IN_UNMOUNT)) != 0)
784 manager_connect_utmp(m);
785
786 (void) manager_read_utmp(m);
787 return 0;
788 }
789 #endif
790
791 void manager_connect_utmp(Manager *m) {
792 #if ENABLE_UTMP
793 sd_event_source *s = NULL;
794 int r;
795
796 assert(m);
797
798 /* Watch utmp for changes via inotify. We do this to deal with tools such as ssh, which will register the PAM
799 * session early, and acquire a TTY only much later for the connection. Thus during PAM the TTY won't be known
800 * yet. ssh will register itself with utmp when it finally acquired the TTY. Hence, let's make use of this, and
801 * watch utmp for the TTY asynchronously. We use the PAM session's leader PID as key, to find the right entry.
802 *
803 * Yes, relying on utmp is pretty ugly, but it's good enough for informational purposes, as well as idle
804 * detection (which, for tty sessions, relies on the TTY used) */
805
806 r = sd_event_add_inotify(m->event, &s, _PATH_UTMPX, IN_MODIFY|IN_MOVE_SELF|IN_DELETE_SELF|IN_ATTRIB, manager_dispatch_utmp, m);
807 if (r < 0)
808 log_full_errno(r == -ENOENT ? LOG_DEBUG: LOG_WARNING, r, "Failed to create inotify watch on " _PATH_UTMPX ", ignoring: %m");
809 else {
810 r = sd_event_source_set_priority(s, SD_EVENT_PRIORITY_IDLE);
811 if (r < 0)
812 log_warning_errno(r, "Failed to adjust utmp event source priority, ignoring: %m");
813
814 (void) sd_event_source_set_description(s, "utmp");
815 }
816
817 sd_event_source_unref(m->utmp_event_source);
818 m->utmp_event_source = s;
819 #endif
820 }
821
822 void manager_reconnect_utmp(Manager *m) {
823 #if ENABLE_UTMP
824 assert(m);
825
826 if (m->utmp_event_source)
827 return;
828
829 manager_connect_utmp(m);
830 #endif
831 }
832
833 int manager_read_efi_boot_loader_entries(Manager *m) {
834 #if ENABLE_EFI
835 int r;
836
837 assert(m);
838 if (m->efi_boot_loader_entries_set)
839 return 0;
840
841 r = efi_loader_get_entries(&m->efi_boot_loader_entries);
842 if (r == -ENOENT || ERRNO_IS_NOT_SUPPORTED(r)) {
843 log_debug_errno(r, "Boot loader reported no entries.");
844 m->efi_boot_loader_entries_set = true;
845 return 0;
846 }
847 if (r < 0)
848 return log_error_errno(r, "Failed to determine entries reported by boot loader: %m");
849
850 m->efi_boot_loader_entries_set = true;
851 return 1;
852 #else
853 return 0;
854 #endif
855 }