]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: turn off stdio locking for a couple of helper calls
authorLennart Poettering <lennart@poettering.net>
Mon, 11 Dec 2017 19:01:55 +0000 (20:01 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 14 Dec 2017 09:46:19 +0000 (10:46 +0100)
These helper calls are potentially called often, and allocate FILE*
objects internally for a very short period of time, let's turn off
locking for them too.

src/basic/cgroup-util.c
src/basic/fileio.c
src/basic/mount-util.c
src/basic/process-util.c

index 5774d4dea160f85bf40a5d69b0cbbc2e85aaadf3..6dcd53102594b2bbf642dac78a0e7cd8a3a32f41 100644 (file)
@@ -24,6 +24,7 @@
 #include <limits.h>
 #include <signal.h>
 #include <stddef.h>
+#include <stdio_ext.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
@@ -1032,6 +1033,8 @@ int cg_pid_get_path(const char *controller, pid_t pid, char **path) {
         if (!f)
                 return errno == ENOENT ? -ESRCH : -errno;
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
         FOREACH_LINE(line, f, return -errno) {
                 char *e, *p;
 
@@ -2371,6 +2374,8 @@ int cg_kernel_controllers(Set **ret) {
                 return -errno;
         }
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
         /* Ignore the header line */
         (void) read_line(f, (size_t) -1, NULL);
 
index 3ab50bca2f7736d4675e53e293bc23230488eb82..5296f1cff04935b9fca32cf0bf4ebfa192b39f82 100644 (file)
@@ -23,6 +23,7 @@
 #include <limits.h>
 #include <stdarg.h>
 #include <stdint.h>
+#include <stdio_ext.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/mman.h>
@@ -98,6 +99,7 @@ static int write_string_file_atomic(
         if (r < 0)
                 return r;
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
         (void) fchmod_umask(fileno(f), 0644);
 
         r = write_string_stream_ts(f, line, flags, ts);
@@ -167,6 +169,8 @@ int write_string_file_ts(
                 }
         }
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
         if (flags & WRITE_STRING_FILE_DISABLE_BUFFER)
                 setvbuf(f, NULL, _IONBF, 0);
 
@@ -203,6 +207,8 @@ int read_one_line_file(const char *fn, char **line) {
         if (!f)
                 return -errno;
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
         r = read_line(f, LONG_LINE_MAX, line);
         return r < 0 ? r : 0;
 }
@@ -228,6 +234,8 @@ int verify_file(const char *fn, const char *blob, bool accept_extra_nl) {
         if (!f)
                 return -errno;
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
         /* We try to read one byte more than we need, so that we know whether we hit eof */
         errno = 0;
         k = fread(buf, 1, l + accept_extra_nl + 1, f);
@@ -323,6 +331,8 @@ int read_full_file(const char *fn, char **contents, size_t *size) {
         if (!f)
                 return -errno;
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
         return read_full_stream(f, contents, size);
 }
 
@@ -879,7 +889,8 @@ int write_env_file(const char *fname, char **l) {
         if (r < 0)
                 return r;
 
-        fchmod_umask(fileno(f), 0644);
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+        (void) fchmod_umask(fileno(f), 0644);
 
         STRV_FOREACH(i, l)
                 write_env_var(f, *i);
index f8d615dd890488cd07ac730598488cbdd1af2908..455c50fc9f64a0ea45615088f8aaf6afed4bf3ed 100644 (file)
@@ -19,6 +19,7 @@
 ***/
 
 #include <errno.h>
+#include <stdio_ext.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/mount.h>
@@ -337,6 +338,8 @@ int umount_recursive(const char *prefix, int flags) {
                 if (!proc_self_mountinfo)
                         return -errno;
 
+                (void) __fsetlocking(proc_self_mountinfo, FSETLOCKING_BYCALLER);
+
                 for (;;) {
                         _cleanup_free_ char *path = NULL, *p = NULL;
                         int k;
@@ -583,6 +586,8 @@ int bind_remount_recursive(const char *prefix, bool ro, char **blacklist) {
         if (!proc_self_mountinfo)
                 return -errno;
 
+        (void) __fsetlocking(proc_self_mountinfo, FSETLOCKING_BYCALLER);
+
         return bind_remount_recursive_with_mountinfo(prefix, ro, blacklist, proc_self_mountinfo);
 }
 
index 5f001494f039633ac8a59028c596635ed0c573d7..32c3c951a177d0ba0820b9b194bbd687f2bb6c03 100644 (file)
@@ -26,6 +26,7 @@
 #include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
+#include <stdio_ext.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sys/mman.h>
@@ -130,6 +131,8 @@ int get_process_cmdline(pid_t pid, size_t max_length, bool comm_fallback, char *
                 return -errno;
         }
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
         if (max_length == 1) {
 
                 /* If there's only room for one byte, return the empty string */
@@ -406,6 +409,8 @@ int is_kernel_thread(pid_t pid) {
                 return -errno;
         }
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
         count = fread(&c, 1, 1, f);
         eof = feof(f);
         fclose(f);
@@ -487,6 +492,8 @@ static int get_process_id(pid_t pid, const char *field, uid_t *uid) {
                 return -errno;
         }
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
         FOREACH_LINE(line, f, return -errno) {
                 char *l;
 
@@ -565,6 +572,8 @@ int get_process_environ(pid_t pid, char **env) {
                 return -errno;
         }
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
         while ((c = fgetc(f)) != EOF) {
                 if (!GREEDY_REALLOC(outcome, allocated, sz + 5))
                         return -ENOMEM;
@@ -749,6 +758,8 @@ int getenv_for_pid(pid_t pid, const char *field, char **_value) {
                 return -errno;
         }
 
+        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);
+
         l = strlen(field);
         r = 0;