This is an automated email from the ASF dual-hosted git repository.
chenBright pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new 457e22a6 Fix avoid SIGSEGV in read_proc_status during static
initialization (#3282)
457e22a6 is described below
commit 457e22a6c4ce1fc332fb3e7d43e993be7ed2c72b
Author: Zhou <[email protected]>
AuthorDate: Sun Apr 26 17:29:44 2026 +0800
Fix avoid SIGSEGV in read_proc_status during static initialization (#3282)
read_proc_status can be sampled while default bvars are initialized before
main().
If reading /proc/self/stat fails at that time, logging through glog may
access
uninitialized glog state and crash.
Print the warning to stderr instead, matching the read_proc_io fallback.
Signed-off-by: zhoulei <[email protected]>
Co-authored-by: zhoulei <[email protected]>
---
src/bvar/default_variables.cpp | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/bvar/default_variables.cpp b/src/bvar/default_variables.cpp
index 1d600635..40d30c56 100644
--- a/src/bvar/default_variables.cpp
+++ b/src/bvar/default_variables.cpp
@@ -81,7 +81,12 @@ static bool read_proc_status(ProcStat &stat) {
// see http://man7.org/linux/man-pages/man5/proc.5.html
butil::ScopedFILE fp("/proc/self/stat", "r");
if (NULL == fp) {
- PLOG_ONCE(WARNING) << "Fail to open /proc/self/stat";
+ static bool ever_printed_stat_err = false;
+ if (!ever_printed_stat_err) {
+ fprintf(stderr, "WARNING: Fail to open /proc/self/stat, errno=%d. "
+ "Process status related bvars will be
unavailable.\n", errno);
+ ever_printed_stat_err = true;
+ }
return false;
}
if (fscanf(fp, "%d %*s %c "
@@ -94,7 +99,8 @@ static bool read_proc_status(ProcStat &stat) {
&stat.flags, &stat.minflt, &stat.cminflt, &stat.majflt,
&stat.cmajflt, &stat.utime, &stat.stime, &stat.cutime,
&stat.cstime,
&stat.priority, &stat.nice, &stat.num_threads) != 19) {
- PLOG(WARNING) << "Fail to fscanf";
+ fprintf(stderr, "WARNING: Fail to fscanf /proc/self/stat, errno=%d. "
+ "Process status related bvars will be unavailable.\n",
errno);
return false;
}
return true;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]