Skip to content

Commit 9f4947c

Browse files
jesson1jiasheng.yu
andauthored
fix: avoid SIGSEGV in read_proc_io during static initialization (#3184)
Signed-off-by: jiasheng.yu <[email protected]> Co-authored-by: jiasheng.yu <[email protected]>
1 parent c7ae57a commit 9f4947c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/bvar/default_variables.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <sys/resource.h> // getrusage
2323
#include <dirent.h> // dirent
2424
#include <iomanip> // setw
25+
#include <stdio.h>
26+
#include <errno.h>
2527
#if defined(__APPLE__)
2628
#include <libproc.h>
2729
#include <sys/resource.h>
@@ -430,7 +432,12 @@ static bool read_proc_io(ProcIO* s) {
430432
#if defined(OS_LINUX)
431433
butil::ScopedFILE fp("/proc/self/io", "r");
432434
if (NULL == fp) {
433-
PLOG_ONCE(WARNING) << "Fail to open /proc/self/io";
435+
static bool ever_printed_io_err = false;
436+
if (!ever_printed_io_err) {
437+
fprintf(stderr, "WARNING: Fail to open /proc/self/io, errno=%d. "
438+
"I/O related bvars will be unavailable.\n", errno);
439+
ever_printed_io_err = true;
440+
}
434441
return false;
435442
}
436443
errno = 0;

0 commit comments

Comments
 (0)