]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/login/logind-inhibit.h
logind-inhibit: get rid of basename() in inhibitor_new()
[thirdparty/systemd.git] / src / login / logind-inhibit.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include "pidref.h"
5
6 typedef struct Inhibitor Inhibitor;
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_DELAY,
24 _INHIBIT_MODE_MAX,
25 _INHIBIT_MODE_INVALID = -EINVAL,
26 } InhibitMode;
27
28 #include "logind.h"
29
30 struct Inhibitor {
31 Manager *manager;
32
33 sd_event_source *event_source;
34
35 char *id;
36 char *state_file;
37
38 bool started;
39
40 InhibitWhat what;
41 char *who;
42 char *why;
43 InhibitMode mode;
44
45 PidRef pid;
46 uid_t uid;
47
48 dual_timestamp since;
49
50 char *fifo_path;
51 int fifo_fd;
52 };
53
54 int inhibitor_new(Manager *m, const char* id, Inhibitor **ret);
55 Inhibitor* inhibitor_free(Inhibitor *i);
56
57 DEFINE_TRIVIAL_CLEANUP_FUNC(Inhibitor*, inhibitor_free);
58
59 int inhibitor_load(Inhibitor *i);
60
61 int inhibitor_start(Inhibitor *i);
62 void inhibitor_stop(Inhibitor *i);
63
64 int inhibitor_create_fifo(Inhibitor *i);
65
66 bool inhibitor_is_orphan(Inhibitor *i);
67
68 InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mm);
69 bool manager_is_inhibited(Manager *m, InhibitWhat w, InhibitMode mm, dual_timestamp *since, bool ignore_inactive, bool ignore_uid, uid_t uid, Inhibitor **offending);
70
71 static inline bool inhibit_what_is_valid(InhibitWhat w) {
72 return w > 0 && w < _INHIBIT_WHAT_MAX;
73 }
74
75 const char *inhibit_what_to_string(InhibitWhat k);
76 int inhibit_what_from_string(const char *s);
77
78 const char *inhibit_mode_to_string(InhibitMode k);
79 InhibitMode inhibit_mode_from_string(const char *s);