]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/sysctl-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
13 #include "string-util.h"
14 #include "sysctl-util.h"
16 char *sysctl_normalize(char *s
) {
20 /* If the first separator is a slash, the path is
21 * assumed to be normalized and slashes remain slashes
22 * and dots remains dots. */
26 /* Otherwise, dots become slashes and slashes become
34 n
= strpbrk(n
+ 1, "/.");
40 int sysctl_write(const char *property
, const char *value
) {
42 _cleanup_close_
int fd
= -1;
47 log_debug("Setting '%s' to '%.*s'.", property
, (int) strcspn(value
, NEWLINE
), value
);
49 p
= strjoina("/proc/sys/", property
);
50 fd
= open(p
, O_WRONLY
|O_CLOEXEC
);
54 if (!endswith(value
, "\n"))
55 value
= strjoina(value
, "\n");
57 if (write(fd
, value
, strlen(value
)) < 0)
63 int sysctl_read(const char *property
, char **content
) {
69 p
= strjoina("/proc/sys/", property
);
70 return read_full_file(p
, content
, NULL
);