]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/common/code_environment.cc
update sources to v12.1.0
[ceph.git] / ceph / src / common / code_environment.cc
index 662fa36c9bdf0937179c8a9e71e8b6c83eebb61c..7b106d585fb4c14872d0f7fdbaf42d8bb12517bf 100644 (file)
  * Foundation.  See file COPYING.
  *
  */
-#include "acconfig.h"
 
 #include "common/code_environment.h"
 
-#include <errno.h>
 #include <iostream>
-#include <stdlib.h>
-#include <string.h>
-#include <string>
 
 #ifdef HAVE_SYS_PRCTL_H
 #include <sys/prctl.h>
@@ -41,7 +36,7 @@ extern "C" const char *code_environment_to_str(enum code_environment_t e)
   }
 }
 
-std::ostream &operator<<(std::ostream &oss, enum code_environment_t e)
+std::ostream &operator<<(std::ostream &oss, const enum code_environment_t e)
 {
   oss << code_environment_to_str(e);
   return oss;
@@ -61,6 +56,24 @@ int get_process_name(char *buf, int len)
   return prctl(PR_GET_NAME, buf);
 }
 
+#elif defined(HAVE_GETPROGNAME)
+
+int get_process_name(char *buf, int len)
+{
+  if (len <= 0) {
+    return -EINVAL;
+  }
+
+  const char *progname = getprogname();
+  if (progname == nullptr || *progname == '\0') {
+    return -ENOSYS;
+  }
+
+  strncpy(buf, progname, len - 1);
+  buf[len - 1] = '\0';
+  return 0;
+}
+
 #else
 
 int get_process_name(char *buf, int len)