]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/sysctl-util.c
372baa45403fb2c5a5ebfbc4be87dbec8498e94c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2010 Lennart Poettering
16 #include "string-util.h"
17 #include "sysctl-util.h"
19 char *sysctl_normalize(char *s
) {
23 /* If the first separator is a slash, the path is
24 * assumed to be normalized and slashes remain slashes
25 * and dots remains dots. */
29 /* Otherwise, dots become slashes and slashes become
37 n
= strpbrk(n
+ 1, "/.");
43 int sysctl_write(const char *property
, const char *value
) {
45 _cleanup_close_
int fd
= -1;
50 log_debug("Setting '%s' to '%s'", property
, value
);
52 p
= strjoina("/proc/sys/", property
);
53 fd
= open(p
, O_WRONLY
|O_CLOEXEC
);
57 if (!endswith(value
, "\n"))
58 value
= strjoina(value
, "\n");
60 if (write(fd
, value
, strlen(value
)) < 0)
66 int sysctl_read(const char *property
, char **content
) {
72 p
= strjoina("/proc/sys/", property
);
73 return read_full_file(p
, content
, NULL
);