sleep-config.c revision c8a202b7d47f9d6bba3100a208abdadfc383499e
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2013 Zbigniew Jędrzejewski-Szmek
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <stdio.h>
#include "conf-parser.h"
#include "sleep-config.h"
#include "fileio.h"
#include "log.h"
#include "strv.h"
#include "util.h"
_cleanup_strv_free_ char
const ConfigTableItem items[] = {
{}};
int r;
FILE _cleanup_fclose_ *f;
if (!f)
else {
if (r < 0)
}
/* empty by default */
if (suspend_state)
else
if (hibernate_mode)
else
if (hibernate_state)
else
if (hybrid_mode)
else
if (hybrid_state)
else
} else
assert_not_reached("what verb");
return log_oom();
}
return 0;
}
int can_sleep_state(char **types) {
int r;
_cleanup_free_ char *p = NULL;
if (strv_isempty(types))
return true;
/* If /sys is read-only we cannot sleep */
return false;
r = read_one_line_file("/sys/power/state", &p);
if (r < 0)
return false;
size_t l, k;
return true;
}
return false;
}
int can_sleep_disk(char **types) {
int r;
_cleanup_free_ char *p = NULL;
if (strv_isempty(types))
return true;
/* If /sys is read-only we cannot sleep */
return false;
r = read_one_line_file("/sys/power/disk", &p);
if (r < 0)
return false;
size_t l, k;
return true;
return true;
}
}
return false;
}
#define HIBERNATION_SWAP_THRESHOLD 0.98
_cleanup_fclose_ FILE *f;
int i;
if (!f) {
return -errno;
}
(void) fscanf(f, "%*s %*s %*s %*s %*s\n");
for (i = 1;; i++) {
int k;
k = fscanf(f,
"%ms " /* type of swap */
"%zd " /* swap size */
"%zd " /* used */
"%*i\n", /* priority */
if (k != 4) {
if (k == EOF)
break;
log_warning("Failed to parse /proc/swaps:%u", i);
continue;
}
continue;
}
*size = size_field;
*used = used_field;
return 0;
}
log_debug("No swap partitions were found.");
return -ENOSYS;
}
static bool enough_memory_for_hibernation(void) {
unsigned long long act;
int r;
if (r < 0)
return false;
if (r < 0) {
return false;
}
if (r < 0) {
return false;
}
log_debug("Hibernation is %spossible, Active(anon)=%llu kB, size=%zu kB, used=%zu kB, threshold=%.2g%%",
return r;
}
int r;
if (r < 0)
return false;
return false;
}