summaryrefslogtreecommitdiffstats
path: root/src/coredump
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-12-11 19:50:30 +0100
committerLennart Poettering <lennart@poettering.net>2017-12-14 10:42:25 +0100
commit0d5366733428b657e1b5b7700b461e878e00b578 (patch)
treee2bcdb9f85e01c79221a9f4797e11fae60166c48 /src/coredump
parentMerge pull request #7625 from thom311/th/const-strlen (diff)
downloadsystemd-0d5366733428b657e1b5b7700b461e878e00b578.tar.xz
systemd-0d5366733428b657e1b5b7700b461e878e00b578.zip
tree-wide: use __fsetlocking() instead of fxyz_unlocked()
Let's replace usage of fputc_unlocked() and friends by __fsetlocking(f, FSETLOCKING_BYCALLER). This turns off locking for the entire FILE*, instead of doing individual per-call decision whether to use normal calls or _unlocked() calls. This has various benefits: 1. It's easier to read and easier not to forget 2. It's more comprehensive, as fprintf() and friends are covered too (as these functions have no _unlocked() counterpart) 3. Philosophically, it's a bit more correct, because it's more a property of the file handle really whether we ever pass it on to another thread, not of the operations we then apply to it. This patch reworks all pieces of codes that so far used fxyz_unlocked() calls to use __fsetlocking() instead. It also reworks all places that use open_memstream(), i.e. use stdio FILE* for string manipulations. Note that this in some way a revert of 4b61c8751135c58be043d86b9fef4c8ec7aadf18.
Diffstat (limited to 'src/coredump')
-rw-r--r--src/coredump/coredump.c7
-rw-r--r--src/coredump/stacktrace.c5
2 files changed, 9 insertions, 3 deletions
diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c
index c7dd61f077..e6063cc980 100644
--- a/src/coredump/coredump.c
+++ b/src/coredump/coredump.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <stdio.h>
+#include <stdio_ext.h>
#include <sys/prctl.h>
#include <sys/xattr.h>
#include <unistd.h>
@@ -540,6 +541,8 @@ static int compose_open_fds(pid_t pid, char **open_fds) {
if (!stream)
return -ENOMEM;
+ (void) __fsetlocking(stream, FSETLOCKING_BYCALLER);
+
FOREACH_DIRENT(dent, proc_fd_dir, return -errno) {
_cleanup_fclose_ FILE *fdinfo = NULL;
_cleanup_free_ char *fdname = NULL;
@@ -560,12 +563,12 @@ static int compose_open_fds(pid_t pid, char **open_fds) {
fdinfo = fdopen(fd, "re");
if (!fdinfo) {
- close(fd);
+ safe_close(fd);
continue;
}
FOREACH_LINE(line, fdinfo, break) {
- fputs_unlocked(line, stream);
+ fputs(line, stream);
if (!endswith(line, "\n"))
fputc('\n', stream);
}
diff --git a/src/coredump/stacktrace.c b/src/coredump/stacktrace.c
index d37ffae020..95fd27b79a 100644
--- a/src/coredump/stacktrace.c
+++ b/src/coredump/stacktrace.c
@@ -20,6 +20,7 @@
#include <dwarf.h>
#include <elfutils/libdwfl.h>
+#include <stdio_ext.h>
#include "alloc-util.h"
#include "fd-util.h"
@@ -108,7 +109,7 @@ static int thread_callback(Dwfl_Thread *thread, void *userdata) {
return DWARF_CB_ABORT;
if (c->n_thread != 0)
- fputc_unlocked('\n', c->f);
+ fputc('\n', c->f);
c->n_frame = 0;
@@ -145,6 +146,8 @@ int coredump_make_stack_trace(int fd, const char *executable, char **ret) {
if (!c.f)
return -ENOMEM;
+ (void) __fsetlocking(c.f, FSETLOCKING_BYCALLER);
+
elf_version(EV_CURRENT);
c.elf = elf_begin(fd, ELF_C_READ_MMAP, NULL);