mirror of
https://github.com/boostorg/process.git
synced 2026-01-19 04:22:15 +00:00
OpenBSD fix & Solaris fixes
[DragonFly BSD] Use Proper CWD From PID Code
This commit is contained in:
committed by
Klemens Morgenstern
parent
817128108a
commit
8a8ca8b7ab
@@ -29,7 +29,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#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
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -187,7 +187,7 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code
|
||||
{
|
||||
std::vector<char> 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);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,13 @@
|
||||
#include <libprocstat.h>
|
||||
#endif
|
||||
|
||||
#if defined(__OpenBSD__)
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <kvm.h>
|
||||
#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<char> vec;
|
||||
int cntp = 0;
|
||||
kinfo_proc *proc_info = nullptr;
|
||||
|
||||
struct closer
|
||||
{
|
||||
void operator()(kvm_t * kd)
|
||||
{
|
||||
kvm_close(kd);
|
||||
}
|
||||
};
|
||||
|
||||
std::unique_ptr<kvm_t, closer> 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)
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#if defined(BOOST_PROCESS_V2_WINDOWS)
|
||||
#include <windows.h>
|
||||
#include <shellapi.h>
|
||||
#else
|
||||
#elif !defined(__OpenBSD__)
|
||||
#include <wordexp.h>
|
||||
#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<const char**>(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
|
||||
|
||||
@@ -20,8 +20,18 @@ project : requirements
|
||||
<target-os>windows:<define>WIN32_LEAN_AND_MEAN
|
||||
<target-os>windows:<define>_WIN32_WINNT=0x0601
|
||||
<target-os>linux:<linkflags>-lpthread
|
||||
<target-os>freebsd:<linkflags>-lutil
|
||||
<target-os>freebsd:<linkflags>-lpthread
|
||||
<target-os>freebsd:<linkflags>-lutil
|
||||
<target-os>freebsd:<linkflags>-lkvm
|
||||
<target-os>freebsd:<linkflags>-lprocstat
|
||||
<target-os>bsd:<linkflags>-lpthread
|
||||
<target-os>bsd:<linkflags>-lkvm
|
||||
<target-os>netbsd:<linkflags>-lpthread
|
||||
<target-os>netbsd:<linkflags>-lkvm
|
||||
<target-os>openbsd:<linkflags>-lpthread
|
||||
<target-os>openbsd:<linkflags>-lkvm
|
||||
<target-os>solaris:<linkflags>-lpthread
|
||||
<target-os>solaris:<linkflags>-lkvm
|
||||
<os>NT,<toolset>cw:<library>ws2_32
|
||||
<os>NT,<toolset>gcc:<library>ws2_32
|
||||
<os>NT,<toolset>gcc:<library>Bcrypt
|
||||
|
||||
Reference in New Issue
Block a user