From e8f03e205d27dc3f25b4446093b4c11ba7b9a135 Mon Sep 17 00:00:00 2001 From: Willem Jan Withagen Date: Mon, 3 Apr 2017 00:04:01 +0200 Subject: [PATCH] core: Prefix /proc/ with FreeBSD emulation Signed-off-by: Willem Jan Withagen --- src/common/MemoryModel.cc | 9 +++++---- src/common/buffer.cc | 5 +++-- src/common/fd.cc | 3 ++- src/common/util.cc | 5 +++-- src/global/signal_handler.cc | 2 +- src/include/compat.h | 8 ++++++++ src/mds/MDBalancer.cc | 5 +++-- src/mds/MDSDaemon.cc | 5 +++-- 8 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/common/MemoryModel.cc b/src/common/MemoryModel.cc index 99bb1ca35c6..fc14a04389b 100644 --- a/src/common/MemoryModel.cc +++ b/src/common/MemoryModel.cc @@ -1,5 +1,6 @@ #include "acconfig.h" +#include "include/compat.h" #include "include/types.h" #include "MemoryModel.h" #include "common/config.h" @@ -21,9 +22,9 @@ void MemoryModel::_sample(snap *psnap) { ifstream f; - f.open("/proc/self/status"); + f.open(PROCPREFIX "/proc/self/status"); if (!f.is_open()) { - ldout(cct, 0) << "check_memory_usage unable to open /proc/self/status" << dendl; + ldout(cct, 0) << "check_memory_usage unable to open " PROCPREFIX "/proc/self/status" << dendl; return; } while (!f.eof()) { @@ -45,9 +46,9 @@ void MemoryModel::_sample(snap *psnap) } f.close(); - f.open("/proc/self/maps"); + f.open(PROCPREFIX "/proc/self/maps"); if (!f.is_open()) { - ldout(cct, 0) << "check_memory_usage unable to open /proc/self/maps" << dendl; + ldout(cct, 0) << "check_memory_usage unable to open " PROCPREFIX "/proc/self/maps" << dendl; return; } diff --git a/src/common/buffer.cc b/src/common/buffer.cc index 56b5770fa01..790e4551f36 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -12,6 +12,7 @@ * */ +#include "include/compat.h" #include "include/mempool.h" #include "armor.h" #include "common/environment.h" @@ -118,9 +119,9 @@ static simple_spinlock_t buffer_debug_lock = SIMPLE_SPINLOCK_INITIALIZER; int r; std::string err; struct stat stat_result; - if (::stat("/proc/sys/fs/pipe-max-size", &stat_result) == -1) + if (::stat(PROCPREFIX "/proc/sys/fs/pipe-max-size", &stat_result) == -1) return -errno; - r = safe_read_file("/proc/sys/fs/", "pipe-max-size", + r = safe_read_file(PROCPREFIX "/proc/sys/fs/", "pipe-max-size", buf, sizeof(buf) - 1); if (r < 0) return r; diff --git a/src/common/fd.cc b/src/common/fd.cc index 45d6a129b05..19f817daf48 100644 --- a/src/common/fd.cc +++ b/src/common/fd.cc @@ -12,6 +12,7 @@ * */ +#include "include/compat.h" #include "fd.h" #include @@ -24,7 +25,7 @@ void dump_open_fds(CephContext *cct) { - const char *fn = "/proc/self/fd"; + const char *fn = PROCPREFIX "/proc/self/fd"; DIR *d = opendir(fn); if (!d) { lderr(cct) << "dump_open_fds unable to open " << fn << dendl; diff --git a/src/common/util.cc b/src/common/util.cc index 73b457ff541..3cc1c49e78b 100644 --- a/src/common/util.cc +++ b/src/common/util.cc @@ -16,6 +16,7 @@ #include #include +#include "include/compat.h" #include "include/util.h" #include "common/debug.h" #include "common/errno.h" @@ -202,7 +203,7 @@ void collect_sys_info(map *m, CephContext *cct) } // memory - FILE *f = fopen("/proc/meminfo", "r"); + FILE *f = fopen(PROCPREFIX "/proc/meminfo", "r"); if (f) { char buf[100]; while (!feof(f)) { @@ -223,7 +224,7 @@ void collect_sys_info(map *m, CephContext *cct) } // processor - f = fopen("/proc/cpuinfo", "r"); + f = fopen(PROCPREFIX "/proc/cpuinfo", "r"); if (f) { char buf[100]; while (!feof(f)) { diff --git a/src/global/signal_handler.cc b/src/global/signal_handler.cc index 2ddc0149893..d4099e1e201 100644 --- a/src/global/signal_handler.cc +++ b/src/global/signal_handler.cc @@ -160,7 +160,7 @@ void install_standard_sighandlers(void) string get_name_by_pid(pid_t pid) { char proc_pid_path[PATH_MAX] = {0}; - snprintf(proc_pid_path, PATH_MAX, "/proc/%d/cmdline", pid); + snprintf(proc_pid_path, PATH_MAX, PROCPREFIX "/proc/%d/cmdline", pid); int fd = open(proc_pid_path, O_RDONLY); if (fd < 0) { diff --git a/src/include/compat.h b/src/include/compat.h index ecd8a61fe3e..d4120478c88 100644 --- a/src/include/compat.h +++ b/src/include/compat.h @@ -14,8 +14,16 @@ #include "acconfig.h" +#if defined(__linux__) +#define PROCPREFIX +#endif + #if defined(__FreeBSD__) +// FreeBSD supports Linux procfs with its compatibility module +// And all compatibility stuff is standard mounted on this +#define PROCPREFIX "/compat/linux" + /* Make sure that ENODATA is defined in the correct way */ #ifndef ENODATA #define ENODATA ENOATTR diff --git a/src/mds/MDBalancer.cc b/src/mds/MDBalancer.cc index afe4296f179..3e114ddd4b9 100644 --- a/src/mds/MDBalancer.cc +++ b/src/mds/MDBalancer.cc @@ -12,6 +12,7 @@ * */ +#include "include/compat.h" #include "mdstypes.h" #include "MDBalancer.h" @@ -154,11 +155,11 @@ mds_load_t MDBalancer::get_load(utime_t now) load.req_rate = mds->get_req_rate(); load.queue_len = messenger->get_dispatch_queue_len(); - ifstream cpu("/proc/loadavg"); + ifstream cpu(PROCPREFIX "/proc/loadavg"); if (cpu.is_open()) cpu >> load.cpu_load_avg; else - derr << "input file '/proc/loadavg' not found" << dendl; + derr << "input file " PROCPREFIX "'/proc/loadavg' not found" << dendl; dout(15) << "get_load " << load << dendl; return load; diff --git a/src/mds/MDSDaemon.cc b/src/mds/MDSDaemon.cc index 2d24d1bf0fd..273e5eca7c1 100644 --- a/src/mds/MDSDaemon.cc +++ b/src/mds/MDSDaemon.cc @@ -14,6 +14,7 @@ #include +#include "include/compat.h" #include "global/signal_handler.h" #include "include/types.h" @@ -1041,7 +1042,7 @@ void MDSDaemon::respawn() * unlinked. */ char exe_path[PATH_MAX] = ""; - if (readlink("/proc/self/exe", exe_path, PATH_MAX-1) == -1) { + if (readlink(PROCPREFIX "/proc/self/exe", exe_path, PATH_MAX-1) == -1) { /* Print CWD for the user's interest */ char buf[PATH_MAX]; char *cwd = getcwd(buf, sizeof(buf)); @@ -1052,7 +1053,7 @@ void MDSDaemon::respawn() strncpy(exe_path, orig_argv[0], PATH_MAX-1); } else { dout(1) << "respawning with exe " << exe_path << dendl; - strcpy(exe_path, "/proc/self/exe"); + strcpy(exe_path, PROCPREFIX "/proc/self/exe"); } dout(1) << " exe_path " << exe_path << dendl; -- 2.39.5