From: Mike Yuan Date: Thu, 16 Nov 2023 09:46:56 +0000 (+0800) Subject: logind-inhibit: introduce inhibit_what_is_valid X-Git-Tag: v255-rc3~47^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=febe81313e828f9ca3df14f43eeef4dfe709589c;p=thirdparty%2Fsystemd.git logind-inhibit: introduce inhibit_what_is_valid --- diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index af7879f5616..1566dab0b6c 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -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; diff --git a/src/login/logind-inhibit.h b/src/login/logind-inhibit.h index 6435d41f819..c34c2256768 100644 --- a/src/login/logind-inhibit.h +++ b/src/login/logind-inhibit.h @@ -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);