0022-do-not-disable-buffer-in-writing-files.patch 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. From 414e2f97008a1f3c26a260a6dc4d51a8c1fa6900 Mon Sep 17 00:00:00 2001
  2. From: Chen Qi <Qi.Chen@windriver.com>
  3. Date: Fri, 1 Mar 2019 15:22:15 +0800
  4. Subject: [PATCH] do not disable buffer in writing files
  5. Do not disable buffer in writing files, otherwise we get
  6. failure at boot for musl like below.
  7. [!!!!!!] Failed to allocate manager object.
  8. And there will be other failures, critical or not critical.
  9. This is specific to musl.
  10. Upstream-Status: Inappropriate [musl]
  11. Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
  12. [Rebased for v242]
  13. Signed-off-by: Andrej Valek <andrej.valek@siemens.com>
  14. [rebased for systemd 243]
  15. Signed-off-by: Scott Murray <scott.murray@konsulko.com>
  16. ---
  17. src/basic/cgroup-util.c | 12 ++++++------
  18. src/basic/namespace-util.c | 4 ++--
  19. src/basic/procfs-util.c | 4 ++--
  20. src/basic/sysctl-util.c | 2 +-
  21. src/basic/process-util.c | 2 +-
  22. src/binfmt/binfmt.c | 6 +++---
  23. src/core/cgroup.c | 2 +-
  24. src/core/main.c | 4 ++--
  25. src/core/smack-setup.c | 8 ++++----
  26. src/hibernate-resume/hibernate-resume.c | 2 +-
  27. src/home/homework.c | 2 +-
  28. src/libsystemd/sd-device/sd-device.c | 2 +-
  29. src/nspawn/nspawn-cgroup.c | 2 +-
  30. src/nspawn/nspawn.c | 6 +++---
  31. src/shared/binfmt-util.c | 2 +-
  32. src/shared/cgroup-setup.c | 4 ++--
  33. src/shared/coredump-util.c | 2 +-
  34. src/shared/smack-util.c | 2 +-
  35. src/sleep/sleep.c | 8 ++++----
  36. src/udev/udev-rules.c | 1 -
  37. src/vconsole/vconsole-setup.c | 2 +-
  38. 21 files changed, 39 insertions(+), 40 deletions(-)
  39. --- a/src/basic/cgroup-util.c
  40. +++ b/src/basic/cgroup-util.c
  41. @@ -399,7 +399,7 @@ int cg_kill_kernel_sigkill(const char *c
  42. if (r < 0)
  43. return r;
  44. - r = write_string_file(killfile, "1", WRITE_STRING_FILE_DISABLE_BUFFER);
  45. + r = write_string_file(killfile, "1", 0);
  46. if (r < 0)
  47. return r;
  48. @@ -805,7 +805,7 @@ int cg_install_release_agent(const char
  49. sc = strstrip(contents);
  50. if (isempty(sc)) {
  51. - r = write_string_file(fs, agent, WRITE_STRING_FILE_DISABLE_BUFFER);
  52. + r = write_string_file(fs, agent, 0);
  53. if (r < 0)
  54. return r;
  55. } else if (!path_equal(sc, agent))
  56. @@ -823,7 +823,7 @@ int cg_install_release_agent(const char
  57. sc = strstrip(contents);
  58. if (streq(sc, "0")) {
  59. - r = write_string_file(fs, "1", WRITE_STRING_FILE_DISABLE_BUFFER);
  60. + r = write_string_file(fs, "1", 0);
  61. if (r < 0)
  62. return r;
  63. @@ -850,7 +850,7 @@ int cg_uninstall_release_agent(const cha
  64. if (r < 0)
  65. return r;
  66. - r = write_string_file(fs, "0", WRITE_STRING_FILE_DISABLE_BUFFER);
  67. + r = write_string_file(fs, "0", 0);
  68. if (r < 0)
  69. return r;
  70. @@ -860,7 +860,7 @@ int cg_uninstall_release_agent(const cha
  71. if (r < 0)
  72. return r;
  73. - r = write_string_file(fs, "", WRITE_STRING_FILE_DISABLE_BUFFER);
  74. + r = write_string_file(fs, "", 0);
  75. if (r < 0)
  76. return r;
  77. @@ -1730,7 +1730,7 @@ int cg_set_attribute(const char *control
  78. if (r < 0)
  79. return r;
  80. - return write_string_file(p, value, WRITE_STRING_FILE_DISABLE_BUFFER);
  81. + return write_string_file(p, value, 0);
  82. }
  83. int cg_get_attribute(const char *controller, const char *path, const char *attribute, char **ret) {
  84. --- a/src/basic/namespace-util.c
  85. +++ b/src/basic/namespace-util.c
  86. @@ -220,12 +220,12 @@ int userns_acquire(const char *uid_map,
  87. freeze();
  88. xsprintf(path, "/proc/" PID_FMT "/uid_map", pid);
  89. - r = write_string_file(path, uid_map, WRITE_STRING_FILE_DISABLE_BUFFER);
  90. + r = write_string_file(path, uid_map, 0);
  91. if (r < 0)
  92. return log_error_errno(r, "Failed to write UID map: %m");
  93. xsprintf(path, "/proc/" PID_FMT "/gid_map", pid);
  94. - r = write_string_file(path, gid_map, WRITE_STRING_FILE_DISABLE_BUFFER);
  95. + r = write_string_file(path, gid_map, 0);
  96. if (r < 0)
  97. return log_error_errno(r, "Failed to write GID map: %m");
  98. --- a/src/basic/procfs-util.c
  99. +++ b/src/basic/procfs-util.c
  100. @@ -64,13 +64,13 @@ int procfs_tasks_set_limit(uint64_t limi
  101. * decrease it, as threads-max is the much more relevant sysctl. */
  102. if (limit > pid_max-1) {
  103. sprintf(buffer, "%" PRIu64, limit+1); /* Add one, since PID 0 is not a valid PID */
  104. - r = write_string_file("/proc/sys/kernel/pid_max", buffer, WRITE_STRING_FILE_DISABLE_BUFFER);
  105. + r = write_string_file("/proc/sys/kernel/pid_max", buffer, 0);
  106. if (r < 0)
  107. return r;
  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. --- a/src/core/smack-setup.c
  115. +++ b/src/core/smack-setup.c
  116. @@ -320,17 +320,17 @@ int mac_smack_setup(bool *loaded_policy)
  117. }
  118. #if HAVE_SMACK_RUN_LABEL
  119. - r = write_string_file("/proc/self/attr/current", SMACK_RUN_LABEL, WRITE_STRING_FILE_DISABLE_BUFFER);
  120. + r = write_string_file("/proc/self/attr/current", SMACK_RUN_LABEL, 0);
  121. if (r < 0)
  122. log_warning_errno(r, "Failed to set SMACK label \"" SMACK_RUN_LABEL "\" on self: %m");
  123. - r = write_string_file("/sys/fs/smackfs/ambient", SMACK_RUN_LABEL, WRITE_STRING_FILE_DISABLE_BUFFER);
  124. + r = write_string_file("/sys/fs/smackfs/ambient", SMACK_RUN_LABEL, 0);
  125. if (r < 0)
  126. log_warning_errno(r, "Failed to set SMACK ambient label \"" SMACK_RUN_LABEL "\": %m");
  127. r = write_string_file("/sys/fs/smackfs/netlabel",
  128. - "0.0.0.0/0 " SMACK_RUN_LABEL, WRITE_STRING_FILE_DISABLE_BUFFER);
  129. + "0.0.0.0/0 " SMACK_RUN_LABEL, 0);
  130. if (r < 0)
  131. log_warning_errno(r, "Failed to set SMACK netlabel rule \"0.0.0.0/0 " SMACK_RUN_LABEL "\": %m");
  132. - r = write_string_file("/sys/fs/smackfs/netlabel", "127.0.0.1 -CIPSO", WRITE_STRING_FILE_DISABLE_BUFFER);
  133. + r = write_string_file("/sys/fs/smackfs/netlabel", "127.0.0.1 -CIPSO", 0);
  134. if (r < 0)
  135. log_warning_errno(r, "Failed to set SMACK netlabel rule \"127.0.0.1 -CIPSO\": %m");
  136. #endif
  137. --- a/src/hibernate-resume/hibernate-resume.c
  138. +++ b/src/hibernate-resume/hibernate-resume.c
  139. @@ -40,7 +40,7 @@ int main(int argc, char *argv[]) {
  140. return EXIT_FAILURE;
  141. }
  142. - r = write_string_file("/sys/power/resume", FORMAT_DEVNUM(st.st_rdev), WRITE_STRING_FILE_DISABLE_BUFFER);
  143. + r = write_string_file("/sys/power/resume", FORMAT_DEVNUM(st.st_rdev), 0);
  144. if (r < 0) {
  145. log_error_errno(r, "Failed to write '" DEVNUM_FORMAT_STR "' to /sys/power/resume: %m", DEVNUM_FORMAT_VAL(st.st_rdev));
  146. return EXIT_FAILURE;
  147. --- a/src/home/homework.c
  148. +++ b/src/home/homework.c
  149. @@ -278,7 +278,7 @@ static void drop_caches_now(void) {
  150. * for details. We write "2" into /proc/sys/vm/drop_caches to ensure dentries/inodes are flushed, but
  151. * not more. */
  152. - r = write_string_file("/proc/sys/vm/drop_caches", "2\n", WRITE_STRING_FILE_DISABLE_BUFFER);
  153. + r = write_string_file("/proc/sys/vm/drop_caches", "2\n", 0);
  154. if (r < 0)
  155. log_warning_errno(r, "Failed to drop caches, ignoring: %m");
  156. else
  157. --- a/src/libsystemd/sd-device/sd-device.c
  158. +++ b/src/libsystemd/sd-device/sd-device.c
  159. @@ -2444,7 +2444,7 @@ _public_ int sd_device_set_sysattr_value
  160. if (!value)
  161. return -ENOMEM;
  162. - r = write_string_file(path, value, WRITE_STRING_FILE_DISABLE_BUFFER | WRITE_STRING_FILE_NOFOLLOW);
  163. + r = write_string_file(path, value, 0 | WRITE_STRING_FILE_NOFOLLOW);
  164. if (r < 0) {
  165. /* On failure, clear cache entry, as we do not know how it fails. */
  166. device_remove_cached_sysattr_value(device, sysattr);
  167. --- a/src/nspawn/nspawn-cgroup.c
  168. +++ b/src/nspawn/nspawn-cgroup.c
  169. @@ -123,7 +123,7 @@ int sync_cgroup(pid_t pid, CGroupUnified
  170. fn = strjoina(tree, cgroup, "/cgroup.procs");
  171. sprintf(pid_string, PID_FMT, pid);
  172. - r = write_string_file(fn, pid_string, WRITE_STRING_FILE_DISABLE_BUFFER|WRITE_STRING_FILE_MKDIR_0755);
  173. + r = write_string_file(fn, pid_string, WRITE_STRING_FILE_MKDIR_0755);
  174. if (r < 0) {
  175. log_error_errno(r, "Failed to move process: %m");
  176. goto finish;
  177. --- a/src/nspawn/nspawn.c
  178. +++ b/src/nspawn/nspawn.c
  179. @@ -2762,7 +2762,7 @@ static int reset_audit_loginuid(void) {
  180. if (streq(p, "4294967295"))
  181. return 0;
  182. - r = write_string_file("/proc/self/loginuid", "4294967295", WRITE_STRING_FILE_DISABLE_BUFFER);
  183. + r = write_string_file("/proc/self/loginuid", "4294967295", 0);
  184. if (r < 0) {
  185. log_error_errno(r,
  186. "Failed to reset audit login UID. This probably means that your kernel is too\n"
  187. @@ -4187,7 +4187,7 @@ static int setup_uid_map(
  188. return log_oom();
  189. xsprintf(uid_map, "/proc/" PID_FMT "/uid_map", pid);
  190. - r = write_string_file(uid_map, s, WRITE_STRING_FILE_DISABLE_BUFFER);
  191. + r = write_string_file(uid_map, s, 0);
  192. if (r < 0)
  193. return log_error_errno(r, "Failed to write UID map: %m");
  194. @@ -4197,7 +4197,7 @@ static int setup_uid_map(
  195. return log_oom();
  196. xsprintf(uid_map, "/proc/" PID_FMT "/gid_map", pid);
  197. - r = write_string_file(uid_map, s, WRITE_STRING_FILE_DISABLE_BUFFER);
  198. + r = write_string_file(uid_map, s, 0);
  199. if (r < 0)
  200. return log_error_errno(r, "Failed to write GID map: %m");
  201. --- a/src/shared/binfmt-util.c
  202. +++ b/src/shared/binfmt-util.c
  203. @@ -26,7 +26,7 @@ int disable_binfmt(void) {
  204. if (r < 0)
  205. return log_warning_errno(r, "Failed to determine whether binfmt_misc is mounted: %m");
  206. - r = write_string_file("/proc/sys/fs/binfmt_misc/status", "-1", WRITE_STRING_FILE_DISABLE_BUFFER);
  207. + r = write_string_file("/proc/sys/fs/binfmt_misc/status", "-1", 0);
  208. if (r < 0)
  209. return log_warning_errno(r, "Failed to unregister binfmt_misc entries: %m");
  210. --- a/src/shared/cgroup-setup.c
  211. +++ b/src/shared/cgroup-setup.c
  212. @@ -350,7 +350,7 @@ int cg_attach(const char *controller, co
  213. xsprintf(c, PID_FMT "\n", pid);
  214. - r = write_string_file(fs, c, WRITE_STRING_FILE_DISABLE_BUFFER);
  215. + r = write_string_file(fs, c, 0);
  216. if (r == -EOPNOTSUPP && cg_is_threaded(controller, path) > 0)
  217. /* When the threaded mode is used, we cannot read/write the file. Let's return recognizable error. */
  218. return -EUCLEAN;
  219. @@ -887,7 +887,7 @@ int cg_enable_everywhere(
  220. return log_debug_errno(errno, "Failed to open cgroup.subtree_control file of %s: %m", p);
  221. }
  222. - r = write_string_stream(f, s, WRITE_STRING_FILE_DISABLE_BUFFER);
  223. + r = write_string_stream(f, s, 0);
  224. if (r < 0) {
  225. log_debug_errno(r, "Failed to %s controller %s for %s (%s): %m",
  226. FLAGS_SET(mask, bit) ? "enable" : "disable", n, p, fs);
  227. --- a/src/shared/coredump-util.c
  228. +++ b/src/shared/coredump-util.c
  229. @@ -70,5 +70,5 @@ int set_coredump_filter(uint64_t value)
  230. sprintf(t, "0x%"PRIx64, value);
  231. return write_string_file("/proc/self/coredump_filter", t,
  232. - WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_DISABLE_BUFFER);
  233. + WRITE_STRING_FILE_VERIFY_ON_FAILURE);
  234. }
  235. --- a/src/shared/smack-util.c
  236. +++ b/src/shared/smack-util.c
  237. @@ -115,7 +115,7 @@ int mac_smack_apply_pid(pid_t pid, const
  238. return 0;
  239. p = procfs_file_alloca(pid, "attr/current");
  240. - r = write_string_file(p, label, WRITE_STRING_FILE_DISABLE_BUFFER);
  241. + r = write_string_file(p, label, 0);
  242. if (r < 0)
  243. return r;
  244. --- a/src/sleep/sleep.c
  245. +++ b/src/sleep/sleep.c
  246. @@ -50,7 +50,7 @@ static int write_hibernate_location_info
  247. assert(hibernate_location->swap);
  248. xsprintf(resume_str, "%u:%u", major(hibernate_location->devno), minor(hibernate_location->devno));
  249. - r = write_string_file("/sys/power/resume", resume_str, WRITE_STRING_FILE_DISABLE_BUFFER);
  250. + r = write_string_file("/sys/power/resume", resume_str, 0);
  251. if (r < 0)
  252. return log_debug_errno(r, "Failed to write partition device to /sys/power/resume for '%s': '%s': %m",
  253. hibernate_location->swap->device, resume_str);
  254. @@ -77,7 +77,7 @@ static int write_hibernate_location_info
  255. }
  256. xsprintf(offset_str, "%" PRIu64, hibernate_location->offset);
  257. - r = write_string_file("/sys/power/resume_offset", offset_str, WRITE_STRING_FILE_DISABLE_BUFFER);
  258. + r = write_string_file("/sys/power/resume_offset", offset_str, 0);
  259. if (r < 0)
  260. return log_debug_errno(r, "Failed to write swap file offset to /sys/power/resume_offset for '%s': '%s': %m",
  261. hibernate_location->swap->device, offset_str);
  262. @@ -93,7 +93,7 @@ static int write_mode(char **modes) {
  263. STRV_FOREACH(mode, modes) {
  264. int k;
  265. - k = write_string_file("/sys/power/disk", *mode, WRITE_STRING_FILE_DISABLE_BUFFER);
  266. + k = write_string_file("/sys/power/disk", *mode, 0);
  267. if (k >= 0)
  268. return 0;
  269. @@ -114,7 +114,7 @@ static int write_state(FILE **f, char **
  270. STRV_FOREACH(state, states) {
  271. int k;
  272. - k = write_string_stream(*f, *state, WRITE_STRING_FILE_DISABLE_BUFFER);
  273. + k = write_string_stream(*f, *state, 0);
  274. if (k >= 0)
  275. return 0;
  276. log_debug_errno(k, "Failed to write '%s' to /sys/power/state: %m", *state);
  277. --- a/src/udev/udev-rules.c
  278. +++ b/src/udev/udev-rules.c
  279. @@ -2354,7 +2354,6 @@ static int udev_rule_apply_token_to_even
  280. log_rule_debug(dev, rules, "ATTR '%s' writing '%s'", buf, value);
  281. r = write_string_file(buf, value,
  282. WRITE_STRING_FILE_VERIFY_ON_FAILURE |
  283. - WRITE_STRING_FILE_DISABLE_BUFFER |
  284. WRITE_STRING_FILE_AVOID_NEWLINE |
  285. WRITE_STRING_FILE_VERIFY_IGNORE_NEWLINE);
  286. if (r < 0)
  287. --- a/src/vconsole/vconsole-setup.c
  288. +++ b/src/vconsole/vconsole-setup.c
  289. @@ -108,7 +108,7 @@ static int toggle_utf8_vc(const char *na
  290. static int toggle_utf8_sysfs(bool utf8) {
  291. int r;
  292. - r = write_string_file("/sys/module/vt/parameters/default_utf8", one_zero(utf8), WRITE_STRING_FILE_DISABLE_BUFFER);
  293. + r = write_string_file("/sys/module/vt/parameters/default_utf8", one_zero(utf8), 0);
  294. if (r < 0)
  295. return log_warning_errno(r, "Failed to %s sysfs UTF-8 flag: %m", enable_disable(utf8));