1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3 
4 typedef struct Inhibitor Inhibitor;
5 
6 typedef enum InhibitWhat {
7         INHIBIT_SHUTDOWN             = 1 << 0,
8         INHIBIT_SLEEP                = 1 << 1,
9         INHIBIT_IDLE                 = 1 << 2,
10         INHIBIT_HANDLE_POWER_KEY     = 1 << 3,
11         INHIBIT_HANDLE_SUSPEND_KEY   = 1 << 4,
12         INHIBIT_HANDLE_HIBERNATE_KEY = 1 << 5,
13         INHIBIT_HANDLE_LID_SWITCH    = 1 << 6,
14         INHIBIT_HANDLE_REBOOT_KEY    = 1 << 7,
15         _INHIBIT_WHAT_MAX            = 1 << 8,
16         _INHIBIT_WHAT_INVALID        = -EINVAL,
17 } InhibitWhat;
18 
19 typedef enum InhibitMode {
20         INHIBIT_BLOCK,
21         INHIBIT_DELAY,
22         _INHIBIT_MODE_MAX,
23         _INHIBIT_MODE_INVALID = -EINVAL,
24 } InhibitMode;
25 
26 #include "logind.h"
27 
28 struct Inhibitor {
29         Manager *manager;
30 
31         sd_event_source *event_source;
32 
33         const char *id;
34         char *state_file;
35 
36         bool started;
37 
38         InhibitWhat what;
39         char *who;
40         char *why;
41         InhibitMode mode;
42 
43         pid_t pid;
44         uid_t uid;
45 
46         dual_timestamp since;
47 
48         char *fifo_path;
49         int fifo_fd;
50 };
51 
52 int inhibitor_new(Inhibitor **ret, Manager *m, const char* id);
53 Inhibitor* inhibitor_free(Inhibitor *i);
54 
55 DEFINE_TRIVIAL_CLEANUP_FUNC(Inhibitor*, inhibitor_free);
56 
57 int inhibitor_load(Inhibitor *i);
58 
59 int inhibitor_start(Inhibitor *i);
60 void inhibitor_stop(Inhibitor *i);
61 
62 int inhibitor_create_fifo(Inhibitor *i);
63 
64 bool inhibitor_is_orphan(Inhibitor *i);
65 
66 InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mm);
67 bool manager_is_inhibited(Manager *m, InhibitWhat w, InhibitMode mm, dual_timestamp *since, bool ignore_inactive, bool ignore_uid, uid_t uid, Inhibitor **offending);
68 
69 const char *inhibit_what_to_string(InhibitWhat k);
70 int inhibit_what_from_string(const char *s);
71 
72 const char *inhibit_mode_to_string(InhibitMode k);
73 InhibitMode inhibit_mode_from_string(const char *s);
74