X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fsleep-config.c;h=d8de644a92cd692bf4a25937fec932bbbe297646;hb=f32d2db140150b9d38684a699c9875b6e24ca27c;hp=4b2b0fe1003c154dfd1c5a0d16bc254934e7b50b;hpb=e9f3d2d508bfd9fb5b54e82994bda365a71eb864;p=elogind.git diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index 4b2b0fe10..d8de644a9 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -48,19 +48,9 @@ int parse_sleep_config(const char *verb, char ***_modes, char ***_states) { {} }; - int r; - _cleanup_fclose_ FILE *f; - - f = fopen(PKGSYSCONFDIR "/sleep.conf", "re"); - if (!f) - log_full(errno == ENOENT ? LOG_DEBUG: LOG_WARNING, - "Failed to open configuration file " PKGSYSCONFDIR "/sleep.conf: %m"); - else { - r = config_parse(NULL, PKGSYSCONFDIR "/sleep.conf", f, "Sleep\0", - config_item_table_lookup, items, false, false, NULL); - if (r < 0) - log_warning("Failed to parse configuration file: %s", strerror(-r)); - } + config_parse(NULL, PKGSYSCONFDIR "/sleep.conf", NULL, + "Sleep\0", + config_item_table_lookup, items, false, false, true, NULL); if (streq(verb, "suspend")) { /* empty by default */ @@ -108,7 +98,7 @@ int parse_sleep_config(const char *verb, char ***_modes, char ***_states) { } int can_sleep_state(char **types) { - char *w, *state, **type; + char **type; int r; _cleanup_free_ char *p = NULL; @@ -124,11 +114,12 @@ int can_sleep_state(char **types) { return false; STRV_FOREACH(type, types) { + const char *word, *state; size_t l, k; k = strlen(*type); - FOREACH_WORD_SEPARATOR(w, l, p, WHITESPACE, state) - if (l == k && memcmp(w, *type, l) == 0) + FOREACH_WORD_SEPARATOR(word, l, p, WHITESPACE, state) + if (l == k && memcmp(word, *type, l) == 0) return true; } @@ -136,7 +127,7 @@ int can_sleep_state(char **types) { } int can_sleep_disk(char **types) { - char *w, *state, **type; + char **type; int r; _cleanup_free_ char *p = NULL; @@ -152,14 +143,18 @@ int can_sleep_disk(char **types) { return false; STRV_FOREACH(type, types) { + const char *word, *state; size_t l, k; k = strlen(*type); - FOREACH_WORD_SEPARATOR(w, l, p, WHITESPACE, state) { - if (l == k && memcmp(w, *type, l) == 0) + FOREACH_WORD_SEPARATOR(word, l, p, WHITESPACE, state) { + if (l == k && memcmp(word, *type, l) == 0) return true; - if (l == k + 2 && w[0] == '[' && memcmp(w + 1, *type, l - 2) == 0 && w[l-1] == ']') + if (l == k + 2 && + word[0] == '[' && + memcmp(word + 1, *type, l - 2) == 0 && + word[l-1] == ']') return true; } }