File tree Expand file tree Collapse file tree 4 files changed +36
-2
lines changed
Expand file tree Collapse file tree 4 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ sd_journal_sources = files(
1212 ' sd-journal/journal-file.h' ,
1313 ' sd-journal/journal-internal.h' ,
1414 ' sd-journal/journal-send.c' ,
15+ ' sd-journal/journal-send.h' ,
1516 ' sd-journal/journal-vacuum.c' ,
1617 ' sd-journal/journal-vacuum.h' ,
1718 ' sd-journal/journal-verify.c' ,
Original file line number Diff line number Diff line change 66#include <stddef.h>
77#include <sys/un.h>
88#include <unistd.h>
9+ #if HAVE_VALGRIND_VALGRIND_H
10+ #include <valgrind/valgrind.h>
11+ #endif
912
1013#define SD_JOURNAL_SUPPRESS_LOCATION
1114
1417#include "alloc-util.h"
1518#include "errno-util.h"
1619#include "fd-util.h"
17- #include "io-util.h"
1820#include "fileio.h"
21+ #include "io-util.h"
22+ #include "journal-send.h"
1923#include "memfd-util.h"
2024#include "socket-util.h"
2125#include "stdio-util.h"
3943 * all its threads, and all its subprocesses. This means we need to
4044 * initialize it atomically, and need to operate on it atomically
4145 * never assuming we are the only user */
46+ static int fd_plus_one = 0 ;
4247
4348static int journal_fd (void ) {
4449 int fd ;
45- static int fd_plus_one = 0 ;
4650
4751retry :
4852 if (fd_plus_one > 0 )
@@ -62,6 +66,24 @@ static int journal_fd(void) {
6266 return fd ;
6367}
6468
69+ #if VALGRIND
70+ void close_journal_fd (void ) {
71+ /* Be nice to valgrind. This is not atomic. This must be used only in tests. */
72+
73+ if (!RUNNING_ON_VALGRIND )
74+ return ;
75+
76+ if (getpid () != gettid ())
77+ return ;
78+
79+ if (fd_plus_one <= 0 )
80+ return ;
81+
82+ safe_close (fd_plus_one - 1 );
83+ fd_plus_one = 0 ;
84+ }
85+ #endif
86+
6587_public_ int sd_journal_print (int priority , const char * format , ...) {
6688 int r ;
6789 va_list ap ;
Original file line number Diff line number Diff line change 1+ /* SPDX-License-Identifier: LGPL-2.1-or-later */
2+ #pragma once
3+
4+ #if VALGRIND
5+ void close_journal_fd (void );
6+ #else
7+ static inline void close_journal_fd (void ) {}
8+ #endif
Original file line number Diff line number Diff line change 55#include <unistd.h>
66
77#include "sd-journal.h"
8+
89#include "fileio.h"
10+ #include "journal-send.h"
911#include "macro.h"
1012#include "memory-util.h"
1113
@@ -103,5 +105,6 @@ int main(int argc, char *argv[]) {
103105 /* Sleep a bit to make it easy for journald to collect metadata. */
104106 sleep (1 );
105107
108+ close_journal_fd ();
106109 return 0 ;
107110}
You can’t perform that action at this time.
0 commit comments