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:
Lennart Poettering
2017-12-11 20:01:55 +01:00
parent 0d53667334
commit 35bbbf85e0
4 changed files with 33 additions and 1 deletions

View 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;