sleep-config.c | sleep-config.c | |||
---|---|---|---|---|
skipping to change at line 51 | skipping to change at line 51 | |||
const ConfigTableItem items[] = { | const ConfigTableItem items[] = { | |||
{ "Sleep", "SuspendMode", config_parse_strv, 0, &su spend_mode }, | { "Sleep", "SuspendMode", config_parse_strv, 0, &su spend_mode }, | |||
{ "Sleep", "SuspendState", config_parse_strv, 0, &su spend_state }, | { "Sleep", "SuspendState", config_parse_strv, 0, &su spend_state }, | |||
{ "Sleep", "HibernateMode", config_parse_strv, 0, &hi bernate_mode }, | { "Sleep", "HibernateMode", config_parse_strv, 0, &hi bernate_mode }, | |||
{ "Sleep", "HibernateState", config_parse_strv, 0, &hi bernate_state }, | { "Sleep", "HibernateState", config_parse_strv, 0, &hi bernate_state }, | |||
{ "Sleep", "HybridSleepMode", config_parse_strv, 0, &hy brid_mode }, | { "Sleep", "HybridSleepMode", config_parse_strv, 0, &hy brid_mode }, | |||
{ "Sleep", "HybridSleepState", config_parse_strv, 0, &hy brid_state }, | { "Sleep", "HybridSleepState", config_parse_strv, 0, &hy brid_state }, | |||
{} | {} | |||
}; | }; | |||
int r; | config_parse(NULL, PKGSYSCONFDIR "/sleep.conf", NULL, | |||
_cleanup_fclose_ FILE *f; | "Sleep\0", | |||
config_item_table_lookup, items, false, false, true, N | ||||
f = fopen(PKGSYSCONFDIR "/sleep.conf", "re"); | ULL); | |||
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, "Sle | ||||
ep\0", | ||||
config_item_table_lookup, (void*) items, f | ||||
alse, false, NULL); | ||||
if (r < 0) | ||||
log_warning("Failed to parse configuration file: %s | ||||
", strerror(-r)); | ||||
} | ||||
if (streq(verb, "suspend")) { | if (streq(verb, "suspend")) { | |||
/* empty by default */ | /* empty by default */ | |||
USE(modes, suspend_mode); | USE(modes, suspend_mode); | |||
if (suspend_state) | if (suspend_state) | |||
USE(states, suspend_state); | USE(states, suspend_state); | |||
else | else | |||
states = strv_new("mem", "standby", "freeze", NULL) ; | states = strv_new("mem", "standby", "freeze", NULL) ; | |||
skipping to change at line 111 | skipping to change at line 101 | |||
strv_free(states); | strv_free(states); | |||
return log_oom(); | return log_oom(); | |||
} | } | |||
*_modes = modes; | *_modes = modes; | |||
*_states = states; | *_states = states; | |||
return 0; | return 0; | |||
} | } | |||
int can_sleep_state(char **types) { | int can_sleep_state(char **types) { | |||
char *w, *state, **type; | char **type; | |||
int r; | int r; | |||
_cleanup_free_ char *p = NULL; | _cleanup_free_ char *p = NULL; | |||
if (strv_isempty(types)) | if (strv_isempty(types)) | |||
return true; | return true; | |||
/* If /sys is read-only we cannot sleep */ | /* If /sys is read-only we cannot sleep */ | |||
if (access("/sys/power/state", W_OK) < 0) | if (access("/sys/power/state", W_OK) < 0) | |||
return false; | return false; | |||
r = read_one_line_file("/sys/power/state", &p); | r = read_one_line_file("/sys/power/state", &p); | |||
if (r < 0) | if (r < 0) | |||
return false; | return false; | |||
STRV_FOREACH(type, types) { | STRV_FOREACH(type, types) { | |||
const char *word, *state; | ||||
size_t l, k; | size_t l, k; | |||
k = strlen(*type); | k = strlen(*type); | |||
FOREACH_WORD_SEPARATOR(w, l, p, WHITESPACE, state) | FOREACH_WORD_SEPARATOR(word, l, p, WHITESPACE, state) | |||
if (l == k && memcmp(w, *type, l) == 0) | if (l == k && memcmp(word, *type, l) == 0) | |||
return true; | return true; | |||
} | } | |||
return false; | return false; | |||
} | } | |||
int can_sleep_disk(char **types) { | int can_sleep_disk(char **types) { | |||
char *w, *state, **type; | char **type; | |||
int r; | int r; | |||
_cleanup_free_ char *p = NULL; | _cleanup_free_ char *p = NULL; | |||
if (strv_isempty(types)) | if (strv_isempty(types)) | |||
return true; | return true; | |||
/* If /sys is read-only we cannot sleep */ | /* If /sys is read-only we cannot sleep */ | |||
if (access("/sys/power/disk", W_OK) < 0) | if (access("/sys/power/disk", W_OK) < 0) | |||
return false; | return false; | |||
r = read_one_line_file("/sys/power/disk", &p); | r = read_one_line_file("/sys/power/disk", &p); | |||
if (r < 0) | if (r < 0) | |||
return false; | return false; | |||
STRV_FOREACH(type, types) { | STRV_FOREACH(type, types) { | |||
const char *word, *state; | ||||
size_t l, k; | size_t l, k; | |||
k = strlen(*type); | k = strlen(*type); | |||
FOREACH_WORD_SEPARATOR(w, l, p, WHITESPACE, state) { | FOREACH_WORD_SEPARATOR(word, l, p, WHITESPACE, state) { | |||
if (l == k && memcmp(w, *type, l) == 0) | if (l == k && memcmp(word, *type, l) == 0) | |||
return true; | return true; | |||
if (l == k + 2 && w[0] == '[' && memcmp(w + 1, *typ | if (l == k + 2 && | |||
e, l - 2) == 0 && w[l-1] == ']') | word[0] == '[' && | |||
memcmp(word + 1, *type, l - 2) == 0 && | ||||
word[l-1] == ']') | ||||
return true; | return true; | |||
} | } | |||
} | } | |||
return false; | return false; | |||
} | } | |||
#define HIBERNATION_SWAP_THRESHOLD 0.98 | #define HIBERNATION_SWAP_THRESHOLD 0.98 | |||
static int hibernation_partition_size(size_t *size, size_t *used) { | static int hibernation_partition_size(size_t *size, size_t *used) { | |||
End of changes. 8 change blocks. | ||||
25 lines changed or deleted | 16 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |