1From 0f9422780a569c79a4b28e44c79c70b4a354bd92 Mon Sep 17 00:00:00 2001 2From: Chen Qi <Qi.Chen@windriver.com> 3Date: Fri, 1 Mar 2019 15:22:15 +0800 4Subject: [PATCH] do not disable buffer in writing files 5 6Do not disable buffer in writing files, otherwise we get 7failure at boot for musl like below. 8 9 [!!!!!!] Failed to allocate manager object. 10 11And there will be other failures, critical or not critical. 12This is specific to musl. 13 14Upstream-Status: Inappropriate [musl] 15 16Signed-off-by: Chen Qi <Qi.Chen@windriver.com> 17[Rebased for v242] 18Signed-off-by: Andrej Valek <andrej.valek@siemens.com> 19[rebased for systemd 243] 20Signed-off-by: Scott Murray <scott.murray@konsulko.com> 21 22--- 23 src/basic/cgroup-util.c | 10 +++++----- 24 src/basic/procfs-util.c | 4 ++-- 25 src/basic/sysctl-util.c | 2 +- 26 src/basic/util.c | 2 +- 27 src/binfmt/binfmt.c | 6 +++--- 28 src/core/main.c | 4 ++-- 29 src/core/smack-setup.c | 8 ++++---- 30 src/hibernate-resume/hibernate-resume.c | 2 +- 31 src/libsystemd/sd-device/sd-device.c | 2 +- 32 src/nspawn/nspawn-cgroup.c | 2 +- 33 src/nspawn/nspawn.c | 6 +++--- 34 src/shared/cgroup-setup.c | 4 ++-- 35 src/shared/mount-util.c | 4 ++-- 36 src/shared/smack-util.c | 2 +- 37 src/sleep/sleep.c | 8 ++++---- 38 src/vconsole/vconsole-setup.c | 2 +- 39 16 files changed, 34 insertions(+), 34 deletions(-) 40 41--- a/src/basic/cgroup-util.c 42+++ b/src/basic/cgroup-util.c 43@@ -390,7 +390,7 @@ int cg_kill_kernel_sigkill(const char *c 44 if (r < 0) 45 return r; 46 47- r = write_string_file(killfile, "1", WRITE_STRING_FILE_DISABLE_BUFFER); 48+ r = write_string_file(killfile, "1", 0); 49 if (r < 0) 50 return r; 51 52@@ -803,7 +803,7 @@ int cg_install_release_agent(const char 53 54 sc = strstrip(contents); 55 if (isempty(sc)) { 56- r = write_string_file(fs, agent, WRITE_STRING_FILE_DISABLE_BUFFER); 57+ r = write_string_file(fs, agent, 0); 58 if (r < 0) 59 return r; 60 } else if (!path_equal(sc, agent)) 61@@ -821,7 +821,7 @@ int cg_install_release_agent(const char 62 63 sc = strstrip(contents); 64 if (streq(sc, "0")) { 65- r = write_string_file(fs, "1", WRITE_STRING_FILE_DISABLE_BUFFER); 66+ r = write_string_file(fs, "1", 0); 67 if (r < 0) 68 return r; 69 70@@ -848,7 +848,7 @@ int cg_uninstall_release_agent(const cha 71 if (r < 0) 72 return r; 73 74- r = write_string_file(fs, "0", WRITE_STRING_FILE_DISABLE_BUFFER); 75+ r = write_string_file(fs, "0", 0); 76 if (r < 0) 77 return r; 78 79@@ -858,7 +858,7 @@ int cg_uninstall_release_agent(const cha 80 if (r < 0) 81 return r; 82 83- r = write_string_file(fs, "", WRITE_STRING_FILE_DISABLE_BUFFER); 84+ r = write_string_file(fs, "", 0); 85 if (r < 0) 86 return r; 87 88@@ -1704,7 +1704,7 @@ int cg_set_attribute(const char *control 89 if (r < 0) 90 return r; 91 92- return write_string_file(p, value, WRITE_STRING_FILE_DISABLE_BUFFER); 93+ return write_string_file(p, value, 0); 94 } 95 96 int cg_get_attribute(const char *controller, const char *path, const char *attribute, char **ret) { 97--- a/src/basic/procfs-util.c 98+++ b/src/basic/procfs-util.c 99@@ -64,13 +64,13 @@ int procfs_tasks_set_limit(uint64_t limi 100 * decrease it, as threads-max is the much more relevant sysctl. */ 101 if (limit > pid_max-1) { 102 sprintf(buffer, "%" PRIu64, limit+1); /* Add one, since PID 0 is not a valid PID */ 103- r = write_string_file("/proc/sys/kernel/pid_max", buffer, WRITE_STRING_FILE_DISABLE_BUFFER); 104+ r = write_string_file("/proc/sys/kernel/pid_max", buffer, 0); 105 if (r < 0) 106 return r; 107 } 108 109 sprintf(buffer, "%" PRIu64, limit); 110- r = write_string_file("/proc/sys/kernel/threads-max", buffer, WRITE_STRING_FILE_DISABLE_BUFFER); 111+ r = write_string_file("/proc/sys/kernel/threads-max", buffer, 0); 112 if (r < 0) { 113 uint64_t threads_max; 114 115--- a/src/basic/sysctl-util.c 116+++ b/src/basic/sysctl-util.c 117@@ -58,7 +58,7 @@ int sysctl_write(const char *property, c 118 119 log_debug("Setting '%s' to '%s'", p, value); 120 121- return write_string_file(p, value, WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER | WRITE_STRING_FILE_SUPPRESS_REDUNDANT_VIRTUAL); 122+ return write_string_file(p, value, WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_SUPPRESS_REDUNDANT_VIRTUAL); 123 } 124 125 int sysctl_writef(const char *property, const char *format, ...) { 126--- a/src/basic/util.c 127+++ b/src/basic/util.c 128@@ -168,7 +168,7 @@ void disable_coredumps(void) { 129 if (detect_container() > 0) 130 return; 131 132- r = write_string_file("/proc/sys/kernel/core_pattern", "|/bin/false", WRITE_STRING_FILE_DISABLE_BUFFER); 133+ r = write_string_file("/proc/sys/kernel/core_pattern", "|/bin/false", 0); 134 if (r < 0) 135 log_debug_errno(r, "Failed to turn off coredumps, ignoring: %m"); 136 } 137--- a/src/binfmt/binfmt.c 138+++ b/src/binfmt/binfmt.c 139@@ -29,7 +29,7 @@ static bool arg_unregister = false; 140 141 static int delete_rule(const char *rulename) { 142 const char *fn = strjoina("/proc/sys/fs/binfmt_misc/", rulename); 143- return write_string_file(fn, "-1", WRITE_STRING_FILE_DISABLE_BUFFER); 144+ return write_string_file(fn, "-1", 0); 145 } 146 147 static int apply_rule(const char *filename, unsigned line, const char *rule) { 148@@ -59,7 +59,7 @@ static int apply_rule(const char *filena 149 if (r >= 0) 150 log_debug("%s:%u: Rule '%s' deleted.", filename, line, rulename); 151 152- r = write_string_file("/proc/sys/fs/binfmt_misc/register", rule, WRITE_STRING_FILE_DISABLE_BUFFER); 153+ r = write_string_file("/proc/sys/fs/binfmt_misc/register", rule, 0); 154 if (r < 0) 155 return log_error_errno(r, "%s:%u: Failed to add binary format '%s': %m", 156 filename, line, rulename); 157@@ -226,7 +226,7 @@ static int run(int argc, char *argv[]) { 158 } 159 160 /* Flush out all rules */ 161- r = write_string_file("/proc/sys/fs/binfmt_misc/status", "-1", WRITE_STRING_FILE_DISABLE_BUFFER); 162+ r = write_string_file("/proc/sys/fs/binfmt_misc/status", "-1", 0); 163 if (r < 0) 164 log_warning_errno(r, "Failed to flush binfmt_misc rules, ignoring: %m"); 165 else 166--- a/src/core/main.c 167+++ b/src/core/main.c 168@@ -1466,7 +1466,7 @@ static int bump_unix_max_dgram_qlen(void 169 if (v >= DEFAULT_UNIX_MAX_DGRAM_QLEN) 170 return 0; 171 172- r = write_string_filef("/proc/sys/net/unix/max_dgram_qlen", WRITE_STRING_FILE_DISABLE_BUFFER, 173+ r = write_string_filef("/proc/sys/net/unix/max_dgram_qlen", 0, 174 "%lu", DEFAULT_UNIX_MAX_DGRAM_QLEN); 175 if (r < 0) 176 return log_full_errno(IN_SET(r, -EROFS, -EPERM, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, 177@@ -1737,7 +1737,7 @@ static void initialize_core_pattern(bool 178 if (getpid_cached() != 1) 179 return; 180 181- r = write_string_file("/proc/sys/kernel/core_pattern", arg_early_core_pattern, WRITE_STRING_FILE_DISABLE_BUFFER); 182+ r = write_string_file("/proc/sys/kernel/core_pattern", arg_early_core_pattern, 0); 183 if (r < 0) 184 log_warning_errno(r, "Failed to write '%s' to /proc/sys/kernel/core_pattern, ignoring: %m", 185 arg_early_core_pattern); 186--- a/src/core/smack-setup.c 187+++ b/src/core/smack-setup.c 188@@ -320,17 +320,17 @@ int mac_smack_setup(bool *loaded_policy) 189 } 190 191 #if HAVE_SMACK_RUN_LABEL 192- r = write_string_file("/proc/self/attr/current", SMACK_RUN_LABEL, WRITE_STRING_FILE_DISABLE_BUFFER); 193+ r = write_string_file("/proc/self/attr/current", SMACK_RUN_LABEL, 0); 194 if (r < 0) 195 log_warning_errno(r, "Failed to set SMACK label \"" SMACK_RUN_LABEL "\" on self: %m"); 196- r = write_string_file("/sys/fs/smackfs/ambient", SMACK_RUN_LABEL, WRITE_STRING_FILE_DISABLE_BUFFER); 197+ r = write_string_file("/sys/fs/smackfs/ambient", SMACK_RUN_LABEL, 0); 198 if (r < 0) 199 log_warning_errno(r, "Failed to set SMACK ambient label \"" SMACK_RUN_LABEL "\": %m"); 200 r = write_string_file("/sys/fs/smackfs/netlabel", 201- "0.0.0.0/0 " SMACK_RUN_LABEL, WRITE_STRING_FILE_DISABLE_BUFFER); 202+ "0.0.0.0/0 " SMACK_RUN_LABEL, 0); 203 if (r < 0) 204 log_warning_errno(r, "Failed to set SMACK netlabel rule \"0.0.0.0/0 " SMACK_RUN_LABEL "\": %m"); 205- r = write_string_file("/sys/fs/smackfs/netlabel", "127.0.0.1 -CIPSO", WRITE_STRING_FILE_DISABLE_BUFFER); 206+ r = write_string_file("/sys/fs/smackfs/netlabel", "127.0.0.1 -CIPSO", 0); 207 if (r < 0) 208 log_warning_errno(r, "Failed to set SMACK netlabel rule \"127.0.0.1 -CIPSO\": %m"); 209 #endif 210--- a/src/hibernate-resume/hibernate-resume.c 211+++ b/src/hibernate-resume/hibernate-resume.c 212@@ -45,7 +45,7 @@ int main(int argc, char *argv[]) { 213 return EXIT_FAILURE; 214 } 215 216- r = write_string_file("/sys/power/resume", major_minor, WRITE_STRING_FILE_DISABLE_BUFFER); 217+ r = write_string_file("/sys/power/resume", major_minor, 0); 218 if (r < 0) { 219 log_error_errno(r, "Failed to write '%s' to /sys/power/resume: %m", major_minor); 220 return EXIT_FAILURE; 221--- a/src/libsystemd/sd-device/sd-device.c 222+++ b/src/libsystemd/sd-device/sd-device.c 223@@ -2108,7 +2108,7 @@ _public_ int sd_device_set_sysattr_value 224 if (!value) 225 return -ENOMEM; 226 227- r = write_string_file(path, value, WRITE_STRING_FILE_DISABLE_BUFFER | WRITE_STRING_FILE_NOFOLLOW); 228+ r = write_string_file(path, value, 0 | WRITE_STRING_FILE_NOFOLLOW); 229 if (r < 0) { 230 /* On failure, clear cache entry, as we do not know how it fails. */ 231 device_remove_cached_sysattr_value(device, sysattr); 232--- a/src/nspawn/nspawn-cgroup.c 233+++ b/src/nspawn/nspawn-cgroup.c 234@@ -124,7 +124,7 @@ int sync_cgroup(pid_t pid, CGroupUnified 235 fn = strjoina(tree, cgroup, "/cgroup.procs"); 236 237 sprintf(pid_string, PID_FMT, pid); 238- r = write_string_file(fn, pid_string, WRITE_STRING_FILE_DISABLE_BUFFER|WRITE_STRING_FILE_MKDIR_0755); 239+ r = write_string_file(fn, pid_string, WRITE_STRING_FILE_MKDIR_0755); 240 if (r < 0) { 241 log_error_errno(r, "Failed to move process: %m"); 242 goto finish; 243--- a/src/nspawn/nspawn.c 244+++ b/src/nspawn/nspawn.c 245@@ -2757,7 +2757,7 @@ static int reset_audit_loginuid(void) { 246 if (streq(p, "4294967295")) 247 return 0; 248 249- r = write_string_file("/proc/self/loginuid", "4294967295", WRITE_STRING_FILE_DISABLE_BUFFER); 250+ r = write_string_file("/proc/self/loginuid", "4294967295", 0); 251 if (r < 0) { 252 log_error_errno(r, 253 "Failed to reset audit login UID. This probably means that your kernel is too\n" 254@@ -4163,7 +4163,7 @@ static int setup_uid_map( 255 return log_oom(); 256 257 xsprintf(uid_map, "/proc/" PID_FMT "/uid_map", pid); 258- r = write_string_file(uid_map, s, WRITE_STRING_FILE_DISABLE_BUFFER); 259+ r = write_string_file(uid_map, s, 0); 260 if (r < 0) 261 return log_error_errno(r, "Failed to write UID map: %m"); 262 263@@ -4173,7 +4173,7 @@ static int setup_uid_map( 264 return log_oom(); 265 266 xsprintf(uid_map, "/proc/" PID_FMT "/gid_map", pid); 267- r = write_string_file(uid_map, s, WRITE_STRING_FILE_DISABLE_BUFFER); 268+ r = write_string_file(uid_map, s, 0); 269 if (r < 0) 270 return log_error_errno(r, "Failed to write GID map: %m"); 271 272--- a/src/shared/cgroup-setup.c 273+++ b/src/shared/cgroup-setup.c 274@@ -345,7 +345,7 @@ int cg_attach(const char *controller, co 275 276 xsprintf(c, PID_FMT "\n", pid); 277 278- r = write_string_file(fs, c, WRITE_STRING_FILE_DISABLE_BUFFER); 279+ r = write_string_file(fs, c, 0); 280 if (r < 0) 281 return r; 282 283@@ -877,7 +877,7 @@ int cg_enable_everywhere( 284 return log_debug_errno(errno, "Failed to open cgroup.subtree_control file of %s: %m", p); 285 } 286 287- r = write_string_stream(f, s, WRITE_STRING_FILE_DISABLE_BUFFER); 288+ r = write_string_stream(f, s, 0); 289 if (r < 0) { 290 log_debug_errno(r, "Failed to %s controller %s for %s (%s): %m", 291 FLAGS_SET(mask, bit) ? "enable" : "disable", n, p, fs); 292--- a/src/shared/smack-util.c 293+++ b/src/shared/smack-util.c 294@@ -114,7 +114,7 @@ int mac_smack_apply_pid(pid_t pid, const 295 return 0; 296 297 p = procfs_file_alloca(pid, "attr/current"); 298- r = write_string_file(p, label, WRITE_STRING_FILE_DISABLE_BUFFER); 299+ r = write_string_file(p, label, 0); 300 if (r < 0) 301 return r; 302 303--- a/src/sleep/sleep.c 304+++ b/src/sleep/sleep.c 305@@ -46,7 +46,7 @@ static int write_hibernate_location_info 306 assert(hibernate_location->swap); 307 308 xsprintf(resume_str, "%u:%u", major(hibernate_location->devno), minor(hibernate_location->devno)); 309- r = write_string_file("/sys/power/resume", resume_str, WRITE_STRING_FILE_DISABLE_BUFFER); 310+ r = write_string_file("/sys/power/resume", resume_str, 0); 311 if (r < 0) 312 return log_debug_errno(r, "Failed to write partition device to /sys/power/resume for '%s': '%s': %m", 313 hibernate_location->swap->device, resume_str); 314@@ -73,7 +73,7 @@ static int write_hibernate_location_info 315 } 316 317 xsprintf(offset_str, "%" PRIu64, hibernate_location->offset); 318- r = write_string_file("/sys/power/resume_offset", offset_str, WRITE_STRING_FILE_DISABLE_BUFFER); 319+ r = write_string_file("/sys/power/resume_offset", offset_str, 0); 320 if (r < 0) 321 return log_debug_errno(r, "Failed to write swap file offset to /sys/power/resume_offset for '%s': '%s': %m", 322 hibernate_location->swap->device, offset_str); 323@@ -90,7 +90,7 @@ static int write_mode(char **modes) { 324 STRV_FOREACH(mode, modes) { 325 int k; 326 327- k = write_string_file("/sys/power/disk", *mode, WRITE_STRING_FILE_DISABLE_BUFFER); 328+ k = write_string_file("/sys/power/disk", *mode, 0); 329 if (k >= 0) 330 return 0; 331 332@@ -112,7 +112,7 @@ static int write_state(FILE **f, char ** 333 STRV_FOREACH(state, states) { 334 int k; 335 336- k = write_string_stream(*f, *state, WRITE_STRING_FILE_DISABLE_BUFFER); 337+ k = write_string_stream(*f, *state, 0); 338 if (k >= 0) 339 return 0; 340 log_debug_errno(k, "Failed to write '%s' to /sys/power/state: %m", *state); 341--- a/src/vconsole/vconsole-setup.c 342+++ b/src/vconsole/vconsole-setup.c 343@@ -108,7 +108,7 @@ static int toggle_utf8_vc(const char *na 344 static int toggle_utf8_sysfs(bool utf8) { 345 int r; 346 347- r = write_string_file("/sys/module/vt/parameters/default_utf8", one_zero(utf8), WRITE_STRING_FILE_DISABLE_BUFFER); 348+ r = write_string_file("/sys/module/vt/parameters/default_utf8", one_zero(utf8), 0); 349 if (r < 0) 350 return log_warning_errno(r, "Failed to %s sysfs UTF-8 flag: %m", enable_disable(utf8)); 351 352--- a/src/basic/namespace-util.c 353+++ b/src/basic/namespace-util.c 354@@ -202,12 +202,12 @@ int userns_acquire(const char *uid_map, 355 freeze(); 356 357 xsprintf(path, "/proc/" PID_FMT "/uid_map", pid); 358- r = write_string_file(path, uid_map, WRITE_STRING_FILE_DISABLE_BUFFER); 359+ r = write_string_file(path, uid_map, 0); 360 if (r < 0) 361 return log_error_errno(r, "Failed to write UID map: %m"); 362 363 xsprintf(path, "/proc/" PID_FMT "/gid_map", pid); 364- r = write_string_file(path, gid_map, WRITE_STRING_FILE_DISABLE_BUFFER); 365+ r = write_string_file(path, gid_map, 0); 366 if (r < 0) 367 return log_error_errno(r, "Failed to write GID map: %m"); 368 369--- a/src/core/cgroup.c 370+++ b/src/core/cgroup.c 371@@ -4140,7 +4140,7 @@ int unit_cgroup_freezer_action(Unit *u, 372 else 373 u->freezer_state = FREEZER_THAWING; 374 375- r = write_string_file(path, one_zero(action == FREEZER_FREEZE), WRITE_STRING_FILE_DISABLE_BUFFER); 376+ r = write_string_file(path, one_zero(action == FREEZER_FREEZE), 0); 377 if (r < 0) 378 return r; 379 380--- a/src/home/homework.c 381+++ b/src/home/homework.c 382@@ -284,7 +284,7 @@ static void drop_caches_now(void) { 383 * details. We write "2" into /proc/sys/vm/drop_caches to ensure dentries/inodes are flushed, but not 384 * more. */ 385 386- r = write_string_file("/proc/sys/vm/drop_caches", "2\n", WRITE_STRING_FILE_DISABLE_BUFFER); 387+ r = write_string_file("/proc/sys/vm/drop_caches", "2\n", 0); 388 if (r < 0) 389 log_warning_errno(r, "Failed to drop caches, ignoring: %m"); 390 else 391--- a/src/shared/binfmt-util.c 392+++ b/src/shared/binfmt-util.c 393@@ -26,7 +26,7 @@ int disable_binfmt(void) { 394 if (r < 0) 395 return log_warning_errno(r, "Failed to determine whether binfmt_misc is mounted: %m"); 396 397- r = write_string_file("/proc/sys/fs/binfmt_misc/status", "-1", WRITE_STRING_FILE_DISABLE_BUFFER); 398+ r = write_string_file("/proc/sys/fs/binfmt_misc/status", "-1", 0); 399 if (r < 0) 400 return log_warning_errno(r, "Failed to unregister binfmt_misc entries: %m"); 401 402--- a/src/shared/coredump-util.c 403+++ b/src/shared/coredump-util.c 404@@ -70,5 +70,5 @@ int set_coredump_filter(uint64_t value) 405 sprintf(t, "0x%"PRIx64, value); 406 407 return write_string_file("/proc/self/coredump_filter", t, 408- WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_DISABLE_BUFFER); 409+ WRITE_STRING_FILE_VERIFY_ON_FAILURE); 410 } 411--- a/src/udev/udev-rules.c 412+++ b/src/udev/udev-rules.c 413@@ -2181,7 +2181,6 @@ static int udev_rule_apply_token_to_even 414 log_rule_debug(dev, rules, "ATTR '%s' writing '%s'", buf, value); 415 r = write_string_file(buf, value, 416 WRITE_STRING_FILE_VERIFY_ON_FAILURE | 417- WRITE_STRING_FILE_DISABLE_BUFFER | 418 WRITE_STRING_FILE_AVOID_NEWLINE | 419 WRITE_STRING_FILE_VERIFY_IGNORE_NEWLINE); 420 if (r < 0) 421