diff --git a/include/boost/process/v2/posix/default_launcher.hpp b/include/boost/process/v2/posix/default_launcher.hpp index 625be154..42a9d6f8 100644 --- a/include/boost/process/v2/posix/default_launcher.hpp +++ b/include/boost/process/v2/posix/default_launcher.hpp @@ -29,7 +29,7 @@ #include -#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__MACH__) +#if defined(__APPLE__) || defined(__MACH__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) extern "C" { extern char **environ; } #endif diff --git a/src/ext/cmd.cpp b/src/ext/cmd.cpp index a96fd4bb..fca5d1b5 100644 --- a/src/ext/cmd.cpp +++ b/src/ext/cmd.cpp @@ -357,7 +357,6 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) } else BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); - kvm_close(kd); return {}; } @@ -368,7 +367,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) char **cmd = nullptr; proc *proc_info = nullptr; user *proc_user = nullptr; - kd = kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr); + kvm_t *kd = kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr); if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {};} if ((proc_info = kvm_getproc(kd, pid))) { @@ -379,9 +378,11 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec) int argc = 0; for (int i = 0; cmd[i] != nullptr; i++) argc ++; - return make_cmd_shell_::make( + shell res = make_cmd_shell_::make( {}, argc, cmd, +[](int, char ** argv) {::free(argv);}) + kvm_close(kd); + return res; } else BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); diff --git a/src/ext/cwd.cpp b/src/ext/cwd.cpp index 2bbc4dc8..6aee83de 100644 --- a/src/ext/cwd.cpp +++ b/src/ext/cwd.cpp @@ -187,7 +187,7 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code { std::vector vecbuff; vecbuff.resize(len); - if (sysctl(mib, 4, &vecbuff[0], &len, nullptr, 0) == 0) + if (sysctl(mib, sz, &vecbuff[0], &len, nullptr, 0) == 0) { path = filesystem::canonical(&vecbuff[0], ec); } diff --git a/src/ext/env.cpp b/src/ext/env.cpp index e7861c6d..ee797880 100644 --- a/src/ext/env.cpp +++ b/src/ext/env.cpp @@ -42,6 +42,13 @@ #include #endif +#if defined(__OpenBSD__) +#include +#include +#include +#include +#endif + BOOST_PROCESS_V2_BEGIN_NAMESPACE namespace detail { @@ -98,7 +105,7 @@ const environment::char_type * dereference(native_env_iterator iterator) return iterator; } -#elif (defined(__APPLE___) || defined(__MACH__)) +#elif (defined(__APPLE___) || defined(__MACH__)) || defined(__OpenBSD__) void native_env_handle_deleter::operator()(native_env_handle_type h) const { @@ -393,7 +400,48 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return ev; } +#elif defined(__OpenBSD__) +env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec) +{ + std::vector vec; + int cntp = 0; + kinfo_proc *proc_info = nullptr; + + struct closer + { + void operator()(kvm_t * kd) + { + kvm_close(kd); + } + }; + + std::unique_ptr kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)}; + if (!kd.get()) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {};} + if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &cntp))) + { + char **env = kvm_getenvv(kd.get(), proc_info, 0); + if (env) + { + for (int i = 0; env[i] != nullptr; i++) + { + for (int j = 0; j < strlen(env[i]); j++) + vec.push_back(env[i][j]); + vec.push_back('\0'); + } + vec.push_back('\0'); + } + else + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); + } + else + BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); + + env_view ev; + ev.handle_.reset(new char[vec.size()]()); + std::copy(vec.begin(), vec.end(), ev.handle_.get()); + return ev; +} #endif env_view env(boost::process::v2::pid_type pid) diff --git a/src/shell.cpp b/src/shell.cpp index b563819e..ec0548d0 100644 --- a/src/shell.cpp +++ b/src/shell.cpp @@ -19,7 +19,7 @@ #if defined(BOOST_PROCESS_V2_WINDOWS) #include #include -#else +#elif !defined(__OpenBSD__) #include #endif @@ -30,7 +30,7 @@ BOOST_PROCESS_V2_DECL const error_category& get_shell_category() { return system_category(); } -#else +#elif !defined(__OpenBSD__) struct shell_category_t final : public error_category { @@ -66,6 +66,13 @@ BOOST_PROCESS_V2_DECL const error_category& get_shell_category() return instance; } +#else + +const error_category& get_shell_category() +{ + return system_category(); +} + #endif #if defined (BOOST_PROCESS_V2_WINDOWS) @@ -92,7 +99,7 @@ auto shell::args() const-> args_type return input_.c_str(); } -#else +#elif !defined(__OpenBSD__) void shell::parse_() { @@ -135,6 +142,22 @@ auto shell::args() const -> args_type return const_cast(argv()); } +#else + +void shell::parse_() +{ + error_code ec; + BOOST_PROCESS_V2_ASSIGN_EC(ec, ENOTSUP, system_category()); + throw system_error(ec, "shell::parse"); +} + +shell::~shell() = default; + +auto shell::args() const -> args_type +{ + return nullptr; +} + #endif BOOST_PROCESS_V2_END_NAMESPACE diff --git a/test/v2/Jamfile.jam b/test/v2/Jamfile.jam index 7c6715a1..86774c6a 100644 --- a/test/v2/Jamfile.jam +++ b/test/v2/Jamfile.jam @@ -20,8 +20,18 @@ project : requirements windows:WIN32_LEAN_AND_MEAN windows:_WIN32_WINNT=0x0601 linux:-lpthread - freebsd:-lutil freebsd:-lpthread + freebsd:-lutil + freebsd:-lkvm + freebsd:-lprocstat + bsd:-lpthread + bsd:-lkvm + netbsd:-lpthread + netbsd:-lkvm + openbsd:-lpthread + openbsd:-lkvm + solaris:-lpthread + solaris:-lkvm NT,cw:ws2_32 NT,gcc:ws2_32 NT,gcc:Bcrypt