]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
global/signal_handler: port get_name_by_pid() to osx
authorKefu Chai <kchai@redhat.com>
Sat, 9 Sep 2017 14:40:12 +0000 (22:40 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 16 Sep 2017 02:43:32 +0000 (10:43 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/global/signal_handler.cc

index d4099e1e201ee73c5a1dad39c5e8ee2044c4adc5..9d57638975beb08379cbacd9844d6362473ce992 100644 (file)
@@ -157,6 +157,22 @@ void install_standard_sighandlers(void)
 #include "common/Thread.h"
 #include <errno.h>
 
+#ifdef __APPLE__
+#include <libproc.h>
+
+string get_name_by_pid(pid_t pid)
+{
+  char buf[PROC_PIDPATHINFO_MAXSIZE];
+  int ret = proc_pidpath(pid, buf, sizeof(buf));
+  if (ret == 0) {
+    derr << "Fail to proc_pidpath(" << pid << ")"
+        << " error = " << cpp_strerror(ret)
+        << dendl;
+    return "<unknown>";
+  }
+  return string(buf, ret);
+}
+#else
 string get_name_by_pid(pid_t pid)
 {
   char proc_pid_path[PATH_MAX] = {0};
@@ -185,7 +201,7 @@ string get_name_by_pid(pid_t pid)
   std::replace(buf, buf + ret, '\0', ' ');
   return string(buf, ret);
 }
-
+#endif
  
 /**
  * safe async signal handler / dispatcher