From 69ab80881552d5f79ca95f6b3be48ad122ab1ec2 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Fri, 13 Sep 2013 19:41:52 -0400 Subject: Advertise hibernation only if there's enough free swap Condition that is checked is taken from upower: active(anon) < free swap * 0.98 This is really stupid, because the kernel knows the situation better, e.g. there could be two swap files, and then hibernation would be impossible despite passing this check, or the kernel could start supporting compressed swap and/or compressed hibernation images, and then this this check would be too stringent. Nevertheless, until we have something better, this should at least return a true negative if there's no swap. Logging of capabilities in the journal is changed to not strip leading zeros. I consider this more readable anyway. http://cgit.freedesktop.org/upower/tree/src/up-daemon.c#n613 https://bugzilla.redhat.com/show_bug.cgi?id=1007059 --- src/shared/fileio.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/shared/fileio.c') diff --git a/src/shared/fileio.c b/src/shared/fileio.c index 77fd05955a..4e2b4442db 100644 --- a/src/shared/fileio.c +++ b/src/shared/fileio.c @@ -648,3 +648,37 @@ int executable_is_script(const char *path, char **interpreter) { *interpreter = ans; return 1; } + +/** + * Retrieve one field from a file like /proc/self/status. + * pattern should start with '\n' and end with ':'. Whitespace + * after ':' will be skipped. field must be freed afterwards. + */ +int get_status_field(const char *filename, const char *pattern, char **field) { + _cleanup_free_ char *status = NULL; + char *t; + size_t len; + int r; + + assert(filename); + assert(field); + + r = read_full_file(filename, &status, NULL); + if (r < 0) + return r; + + t = strstr(status, pattern); + if (!t) + return -ENOENT; + + t += strlen(pattern); + t += strspn(t, WHITESPACE); + + len = strcspn(t, WHITESPACE); + + *field = strndup(t, len); + if (!*field) + return -ENOMEM; + + return 0; +} -- cgit v1.2.3-54-g00ecf