basic: turn off stdio locking for a couple of helper calls
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.
This commit is contained in:
parent
0d53667334
commit
35bbbf85e0
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue