diff options
author | Lennart Poettering <lennart@poettering.net> | 2012-05-08 19:02:25 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2012-05-08 19:02:25 +0200 |
commit | d889a2069a87e4617b32ddbdeace5a53a12c699d (patch) | |
tree | 7b83f31c7e3f02fda73d4e208598bd93713f9685 /src/shared | |
parent | 6edd7d0a09171ea5ae8e01b7b1cbcb0bdfbfeb16 (diff) |
logind: implement suspend/hibernate calls with inhibition logic
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/util.c | 25 | ||||
-rw-r--r-- | src/shared/util.h | 2 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index d8d3f1a16d..5f06c4b7d8 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -5590,3 +5590,28 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value) { return r; } + +int can_sleep(const char *type) { + char *p, *w, *state; + size_t l, k; + bool found = false; + int r; + + assert(type); + + r = read_one_line_file("/sys/power/state", &p); + if (r < 0) + return r == -ENOENT ? 0 : r; + + k = strlen(type); + + FOREACH_WORD_SEPARATOR(w, l, p, WHITESPACE, state) { + if (l == k && strncmp(w, type, l) == 0) { + found = true; + break; + } + } + + free(p); + return found; +} diff --git a/src/shared/util.h b/src/shared/util.h index 59a69a898a..272ab48651 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -505,4 +505,6 @@ int setrlimit_closest(int resource, const struct rlimit *rlim); int getenv_for_pid(pid_t pid, const char *field, char **_value); +int can_sleep(const char *type); + #endif |