ehds commented on code in PR #3602:
URL: https://github.com/apache/brpc/pull/3602#discussion_r4267954927


##########
src/bvar/default_variables.cpp:
##########
@@ -350,29 +401,24 @@ static int get_fd_count(int limit) {
     for (; dr.Next() && count <= limit + 3; ++count) {}
     return count - 3 /* skipped ., .. and the fd in dr*/;
 #elif defined(OS_MACOSX)
-    // TODO(zhujiashun): following code will cause core dump with some 
-    // probability under mac when program exits. Fix it.
-    /* 
-    static pid_t pid = getpid();
-    std::ostringstream oss;
-    char cmdbuf[128];
-    snprintf(cmdbuf, sizeof(cmdbuf),
-            "lsof -p %ld | grep -v \"txt\" | wc -l", (long)pid);
-    if (butil::read_command_output(oss, cmdbuf) != 0) {
-        LOG(ERROR) << "Fail to read open files";
+    if (limit <= 0) {
+        return 0;
+    }
+    std::vector<proc_fdinfo> fds(limit);
+    errno = 0;
+    // This query opens no additional FD.
+    const int bytes = proc_pidinfo(getpid(), PROC_PIDLISTFDS, 0,
+                                  fds.data(), fds.size() * 
sizeof(proc_fdinfo));

Review Comment:
   Changed to a thread_local std::vector to reuse the allocation while keeping 
each thread’s buffer separate.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to