1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-03 17:47:28 +03:00

logind-inhibit: introduce inhibit_what_is_valid

This commit is contained in:
Mike Yuan 2023-11-16 17:46:56 +08:00
parent ddd0c2be81
commit febe81313e
No known key found for this signature in database
GPG Key ID: 417471C0A40F58B3
2 changed files with 7 additions and 2 deletions

View File

@ -411,7 +411,8 @@ bool manager_is_inhibited(
bool inhibited = false;
assert(m);
assert(w > 0 && w < _INHIBIT_WHAT_MAX);
assert(w > 0);
assert(w < _INHIBIT_WHAT_MAX);
HASHMAP_FOREACH(i, m->inhibitors) {
if (!i->started)
@ -457,7 +458,7 @@ const char *inhibit_what_to_string(InhibitWhat w) {
"handle-reboot-key")+1];
char *p;
if (w < 0 || w >= _INHIBIT_WHAT_MAX)
if (!inhibit_what_is_valid(w))
return NULL;
p = buffer;

View File

@ -68,6 +68,10 @@ bool inhibitor_is_orphan(Inhibitor *i);
InhibitWhat manager_inhibit_what(Manager *m, InhibitMode mm);
bool manager_is_inhibited(Manager *m, InhibitWhat w, InhibitMode mm, dual_timestamp *since, bool ignore_inactive, bool ignore_uid, uid_t uid, Inhibitor **offending);
static inline bool inhibit_what_is_valid(InhibitWhat w) {
return w > 0 && w < _INHIBIT_WHAT_MAX;
}
const char *inhibit_what_to_string(InhibitWhat k);
int inhibit_what_from_string(const char *s);