mirror of
https://github.com/systemd/systemd.git
synced 2025-01-12 13:18:14 +03:00
logind: use extract_first_word()
This commit is contained in:
parent
434fef6de3
commit
46ed9f4ce1
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "env-file.h"
|
#include "env-file.h"
|
||||||
|
#include "errno-list.h"
|
||||||
#include "escape.h"
|
#include "escape.h"
|
||||||
#include "fd-util.h"
|
#include "fd-util.h"
|
||||||
#include "fileio.h"
|
#include "fileio.h"
|
||||||
@ -483,31 +484,39 @@ const char *inhibit_what_to_string(InhibitWhat w) {
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
InhibitWhat inhibit_what_from_string(const char *s) {
|
int inhibit_what_from_string(const char *s) {
|
||||||
InhibitWhat what = 0;
|
InhibitWhat what = 0;
|
||||||
const char *word, *state;
|
|
||||||
size_t l;
|
|
||||||
|
|
||||||
FOREACH_WORD_SEPARATOR(word, l, s, ":", state) {
|
for (const char *p = s;;) {
|
||||||
if (l == 8 && strneq(word, "shutdown", l))
|
_cleanup_free_ char *word = NULL;
|
||||||
|
int r;
|
||||||
|
|
||||||
|
/* A sanity check that our return values fit in an int */
|
||||||
|
assert_cc((int) _INHIBIT_WHAT_MAX == _INHIBIT_WHAT_MAX);
|
||||||
|
|
||||||
|
r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
if (r == 0)
|
||||||
|
return what;
|
||||||
|
|
||||||
|
if (streq(word, "shutdown"))
|
||||||
what |= INHIBIT_SHUTDOWN;
|
what |= INHIBIT_SHUTDOWN;
|
||||||
else if (l == 5 && strneq(word, "sleep", l))
|
else if (streq(word, "sleep"))
|
||||||
what |= INHIBIT_SLEEP;
|
what |= INHIBIT_SLEEP;
|
||||||
else if (l == 4 && strneq(word, "idle", l))
|
else if (streq(word, "idle"))
|
||||||
what |= INHIBIT_IDLE;
|
what |= INHIBIT_IDLE;
|
||||||
else if (l == 16 && strneq(word, "handle-power-key", l))
|
else if (streq(word, "handle-power-key"))
|
||||||
what |= INHIBIT_HANDLE_POWER_KEY;
|
what |= INHIBIT_HANDLE_POWER_KEY;
|
||||||
else if (l == 18 && strneq(word, "handle-suspend-key", l))
|
else if (streq(word, "handle-suspend-key"))
|
||||||
what |= INHIBIT_HANDLE_SUSPEND_KEY;
|
what |= INHIBIT_HANDLE_SUSPEND_KEY;
|
||||||
else if (l == 20 && strneq(word, "handle-hibernate-key", l))
|
else if (streq(word, "handle-hibernate-key"))
|
||||||
what |= INHIBIT_HANDLE_HIBERNATE_KEY;
|
what |= INHIBIT_HANDLE_HIBERNATE_KEY;
|
||||||
else if (l == 17 && strneq(word, "handle-lid-switch", l))
|
else if (streq(word, "handle-lid-switch"))
|
||||||
what |= INHIBIT_HANDLE_LID_SWITCH;
|
what |= INHIBIT_HANDLE_LID_SWITCH;
|
||||||
else
|
else
|
||||||
return _INHIBIT_WHAT_INVALID;
|
return _INHIBIT_WHAT_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
return what;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* const inhibit_mode_table[_INHIBIT_MODE_MAX] = {
|
static const char* const inhibit_mode_table[_INHIBIT_MODE_MAX] = {
|
||||||
|
@ -66,7 +66,7 @@ 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);
|
bool manager_is_inhibited(Manager *m, InhibitWhat w, InhibitMode mm, dual_timestamp *since, bool ignore_inactive, bool ignore_uid, uid_t uid, Inhibitor **offending);
|
||||||
|
|
||||||
const char *inhibit_what_to_string(InhibitWhat k);
|
const char *inhibit_what_to_string(InhibitWhat k);
|
||||||
InhibitWhat inhibit_what_from_string(const char *s);
|
int inhibit_what_from_string(const char *s);
|
||||||
|
|
||||||
const char *inhibit_mode_to_string(InhibitMode k);
|
const char *inhibit_mode_to_string(InhibitMode k);
|
||||||
InhibitMode inhibit_mode_from_string(const char *s);
|
InhibitMode inhibit_mode_from_string(const char *s);
|
||||||
|
Loading…
Reference in New Issue
Block a user