sleep-config.c revision b5efdb8af40ea759a1ea584c1bc44ecc81dd00ce
/*-*- 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 "alloc-util.h"
#include "conf-parser.h"
#include "fd-util.h"
#include "fileio.h"
#include "log.h"
#include "sleep-config.h"
#include "string-util.h"
#include "strv.h"
#include "util.h"
#include "parse-util.h"
_cleanup_strv_free_ char
const ConfigTableItem items[] = {
{}
};
false, NULL);
/* 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) {
char **type;
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) {
char **type;
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;
if (l == k + 2 &&
word[0] == '[' &&
return true;
}
}
return false;
}
#define HIBERNATION_SWAP_THRESHOLD 0.98
_cleanup_fclose_ FILE *f;
unsigned 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 */
"%zu " /* swap size */
"%zu " /* 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 = 0;
int r;
if (r < 0)
return false;
if (r < 0) {
log_error_errno(r, "Failed to retrieve Active(anon) from /proc/meminfo: %m");
return false;
}
if (r < 0) {
log_error_errno(r, "Failed to parse Active(anon) from /proc/meminfo: %s: %m",
active);
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;
}