Debian Codegraph @

src/login/logind-inhibit.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "logind-forward.h"
5 #include "pidref.h"
6 #include "time-util.h"
7
8 typedef enum InhibitWhat {
9 INHIBIT_SHUTDOWN = 1 << 0,
10 INHIBIT_SLEEP = 1 << 1,
11 INHIBIT_IDLE = 1 << 2,
12 INHIBIT_HANDLE_POWER_KEY = 1 << 3,
13 INHIBIT_HANDLE_SUSPEND_KEY = 1 << 4,
14 INHIBIT_HANDLE_HIBERNATE_KEY = 1 << 5,
15 INHIBIT_HANDLE_LID_SWITCH = 1 << 6,
16 INHIBIT_HANDLE_REBOOT_KEY = 1 << 7,
17 _INHIBIT_WHAT_MAX = 1 << 8,
18 _INHIBIT_WHAT_INVALID = -EINVAL,
19 } InhibitWhat;
20
21 typedef enum InhibitMode {
22 INHIBIT_BLOCK,
23 INHIBIT_BLOCK_WEAK,
24 INHIBIT_DELAY,
25 _INHIBIT_MODE_MAX,
26 _INHIBIT_MODE_INVALID = -EINVAL,
27 } InhibitMode;
28
29 typedef struct Inhibitor {
30 Manager *manager;
31
32 sd_event_source *event_source;
33
34 char *id;
35 char *state_file;
36
37 bool started;
38
39 InhibitWhat what;
40 char *who;
41 char *why;
42 InhibitMode mode;
43
44 PidRef pid;
45 uid_t uid;
46
47 dual_timestamp since;
48
49 char *fifo_path;
50 int fifo_fd;
51 } Inhibitor;
52
53 int inhibitor_new(Manager *m, const char* id, Inhibitor **ret);
54 Inhibitor* inhibitor_free(Inhibitor *i);
55
56 DEFINE_TRIVIAL_CLEANUP_FUNC(Inhibitor*, inhibitor_free);
57
58 int inhibitor_load(Inhibitor *i);
59
60 int inhibitor_start(Inhibitor *i);
61 void inhibitor_stop(Inhibitor *i);
62
63 int inhibitor_create_fifo(Inhibitor *i);
64
65 bool inhibitor_is_orphan(Inhibitor *i);
66
67 InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mode);
68
69 typedef enum ManagerIsInhibitedFlags {
70 MANAGER_IS_INHIBITED_CHECK_DELAY = 1 << 0, /* When set, we only check delay inhibitors.
71 * Otherwise, we only check block inhibitors. */
72 MANAGER_IS_INHIBITED_IGNORE_INACTIVE = 1 << 1, /* When set, ignore inactive sessions. */
73 } ManagerIsInhibitedFlags;
74
75 bool manager_is_inhibited(
76 Manager *m,
77 InhibitWhat w,
78 dual_timestamp *since,
79 ManagerIsInhibitedFlags flags,
80 uid_t uid_to_ignore,
81 Inhibitor **ret_offending);
82
83 int inhibitor_build_json(Inhibitor *i, sd_json_variant **ret);
84
85 static inline bool inhibit_what_is_valid(InhibitWhat w) {
86 return w > 0 && w < _INHIBIT_WHAT_MAX;
87 }
88
89 const char* inhibit_what_to_string(InhibitWhat w);
90 int inhibit_what_from_string(const char *s);
91
92 DECLARE_STRING_TABLE_LOOKUP(inhibit_mode, InhibitMode);