From: Zbigniew Jędrzejewski-Szmek Date: Sat, 3 Dec 2022 10:27:40 +0000 (+0100) Subject: manager: do not append '\n' when writing sysctl settings X-Git-Tag: v253-rc1~378^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b47e0fac0356308cf34aa235ba9328c0c9de51bd;p=thirdparty%2Fsystemd.git manager: do not append '\n' when writing sysctl settings When booting with debug logs, we print: Setting '/proc/sys/fs/file-max' to '9223372036854775807 ' Setting '/proc/sys/fs/nr_open' to '2147483640 ' Couldn't write fs.nr_open as 2147483640, halving it. Setting '/proc/sys/fs/nr_open' to '1073741816 ' Successfully bumped fs.nr_open to 1073741816 The strange formatting is because we explicitly appended a newline in those two places. It seems that the kernel doesn't care. In fact, we have a few dozen other writes to sysctl where we don't append a newline. So let's just drop those here too, to make the code a bit simpler and avoid strange output in the logs. --- diff --git a/src/core/main.c b/src/core/main.c index 119c518664f..ffe5c1688aa 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1184,9 +1184,10 @@ static void bump_file_max_and_nr_open(void) { #if BUMP_PROC_SYS_FS_FILE_MAX /* The maximum the kernel allows for this since 5.2 is LONG_MAX, use that. (Previously things were * different, but the operation would fail silently.) */ - r = sysctl_writef("fs/file-max", "%li\n", LONG_MAX); + r = sysctl_writef("fs/file-max", "%li", LONG_MAX); if (r < 0) - log_full_errno(IN_SET(r, -EROFS, -EPERM, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, "Failed to bump fs.file-max, ignoring: %m"); + log_full_errno(IN_SET(r, -EROFS, -EPERM, -EACCES) ? LOG_DEBUG : LOG_WARNING, + r, "Failed to bump fs.file-max, ignoring: %m"); #endif #if BUMP_PROC_SYS_FS_NR_OPEN @@ -1218,7 +1219,7 @@ static void bump_file_max_and_nr_open(void) { break; } - r = sysctl_writef("fs/nr_open", "%i\n", v); + r = sysctl_writef("fs/nr_open", "%i", v); if (r == -EINVAL) { log_debug("Couldn't write fs.nr_open as %i, halving it.", v); v /= 2;