]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/sysctl-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2010 Lennart Poettering
18 #include "string-util.h"
19 #include "sysctl-util.h"
21 char *sysctl_normalize(char *s
) {
25 /* If the first separator is a slash, the path is
26 * assumed to be normalized and slashes remain slashes
27 * and dots remains dots. */
31 /* Otherwise, dots become slashes and slashes become
39 n
= strpbrk(n
+ 1, "/.");
45 int sysctl_write(const char *property
, const char *value
) {
47 _cleanup_close_
int fd
= -1;
52 log_debug("Setting '%s' to '%s'", property
, value
);
54 p
= strjoina("/proc/sys/", property
);
55 fd
= open(p
, O_WRONLY
|O_CLOEXEC
);
59 if (!endswith(value
, "\n"))
60 value
= strjoina(value
, "\n");
62 if (write(fd
, value
, strlen(value
)) < 0)
68 int sysctl_read(const char *property
, char **content
) {
74 p
= strjoina("/proc/sys/", property
);
75 return read_full_file(p
, content
, NULL
);