diff --git a/src/shared/sysctl-util.c b/src/shared/sysctl-util.c
index 189580e3ed..0bc81aaa56 100644
--- a/src/shared/sysctl-util.c
+++ b/src/shared/sysctl-util.c
@@ -18,9 +18,13 @@
along with systemd; If not, see .
***/
+#include
+#include
#include
#include
+#include
+#include "fd-util.h"
#include "fileio.h"
#include "log.h"
#include "macro.h"
@@ -53,6 +57,7 @@ char *sysctl_normalize(char *s) {
int sysctl_write(const char *property, const char *value) {
char *p;
+ _cleanup_close_ int fd = -1;
assert(property);
assert(value);
@@ -60,7 +65,17 @@ int sysctl_write(const char *property, const char *value) {
log_debug("Setting '%s' to '%s'", property, value);
p = strjoina("/proc/sys/", property);
- return write_string_file(p, value, WRITE_STRING_FILE_DISABLE_BUFFER);
+ fd = open(p, O_WRONLY|O_CLOEXEC);
+ if (fd < 0)
+ return -errno;
+
+ if (!endswith(value, "\n"))
+ value = strjoina(value, "\n");
+
+ if (write(fd, value, strlen(value)) < 0)
+ return -errno;
+
+ return 0;
}
int sysctl_read(const char *property, char **content) {