2
0
mirror of https://github.com/boostorg/process.git synced 2026-01-20 04:42:24 +00:00

Compare commits

..

25 Commits

Author SHA1 Message Date
Samuel Venable
c8499e02c6 OpenBSD fix & Solaris fixes
[DragonFly BSD] Use Proper CWD From PID Code
2024-10-27 17:49:44 +08:00
Klemens Morgenstern
adf3d62786 changed error macros to require a ; at the end. 2024-10-27 12:54:16 +08:00
Klemens Morgenstern
22c2ad08c9 removed definition of NOMINMAX 2024-10-27 11:12:46 +08:00
Klemens Morgenstern
1bbdde8d04 reduced asio related macro usage. 2024-10-27 11:07:12 +08:00
Klemens Morgenstern
e0158d8006 added pthread to test linking for freebsd on v1 as well. 2024-10-25 17:01:59 +08:00
Klemens Morgenstern
07af239503 added pthread to test linking for freebsd 2024-10-25 16:46:00 +08:00
Klemens Morgenstern
8826a7502d add kvm to process target on bsd 2024-10-25 15:59:17 +08:00
Klemens Morgenstern
e1e594540f replaced deadline_timer with steady_timer. 2024-10-25 15:53:51 +08:00
Klemens Morgenstern
15d0275b87 remove test_impl lib 2024-10-25 12:04:52 +08:00
Klemens Morgenstern
1e41629759 unified cancellation on process.async_wait() 2024-10-25 11:47:16 +08:00
Klemens Morgenstern
7777db84a8 disabled /boost//coroutine dependent tests 2024-10-25 10:25:30 +08:00
Klemens Morgenstern
b20e874701 added test async_wait cancellation test. 2024-10-25 10:06:23 +08:00
Klemens Morgenstern
606d4d89e4 typo fixes. 2024-10-25 10:05:58 +08:00
Klemens Morgenstern
05e8eb3005 removed filesystem from the compiled lib.
Shuold fix #390.
2024-10-25 09:32:39 +08:00
Klemens Morgenstern
efd5cc85a5 Wrapped proc_info.h functions with IOS check. Using the ext functions will yield a operation_not_supported at runtime.
Closes #401.
2024-10-25 09:09:08 +08:00
Klemens Morgenstern
e68491df4d Switched #error to ENOTSUP for ext libs. Should help #413
Closes #358.
2024-10-25 08:13:48 +08:00
Klemens Morgenstern
02044bcad7 Typo fix.
Closes #365
2024-10-25 07:49:56 +08:00
Klemens Morgenstern
41a4a5acc9 Added BOOST_PROCESS_V2_POSIX_FORCE_DISABLE_CLOSE_RANGE
Implements #378.
2024-10-25 07:42:18 +08:00
Klemens Morgenstern
fae23e60b1 Applying @sehe's patch.
closes #317
2024-10-25 07:21:51 +08:00
Samuel Venable
34cfc32311 [DragonFly BSD] Use Proper CWD From PID Code 2024-10-25 07:01:56 +08:00
Brad Smith
4d28e34dfa Fix building on OpenBSD
OpenBSD does not have close_range() nor does NetBSD.

OpenBSD needs environ like the other *BSD's.

The build was erroring on kp_pid, it looks like p_pid is appropriate.
2024-10-25 07:00:58 +08:00
Klemens Morgenstern
0501b88d7e removed more faulty V2_DECLs 2024-10-25 06:55:04 +08:00
Julien Schueller
9515f4e1df Fix undefined reference to ws2_32
else it fails to link on mingw:
```
process_handle_windows.o:process_handle_windows.cpp:(.text+0x25): undefined reference to `_imp__WSACleanup@0'
```
2024-10-25 06:53:11 +08:00
Benjamin Buch
26906fe9f9 remove dllimport from utf8.hpp to fix MSVC build 2024-10-25 06:49:39 +08:00
René Ferdinand Rivera Morell
e8b59f66e6 Add support for modular build structure. (#389)
* Make the library modular usable.

* Switch to library requirements instead of source. As source puts extra source in install targets.

* Add requires-b2 check to top-level build file.

* Add missing test deps.

* Bump B2 require to 5.2

* Fix duplicate def of boost.process.fs feature.

* Add missing boost_test dependency.

* Move inter-lib dependencies to a project variable and into the build targets.

* Switch to /boost/test//included target for header only mode of Boost.Test.

* Adjust doc build to avoid boost-root references.

* Update build deps.

* Fix link and build of deps.
2024-08-26 20:05:48 +08:00
16 changed files with 179 additions and 275 deletions

View File

@@ -11,7 +11,7 @@
]
]
[note Process v1 will be deprecated in the next release (1.88). Use v2 for new projects.]
[note Process v1 will be deprecated in the future. Use v2 for new projects.]
[include v1.qbk]
[include v2.qbk]

View File

@@ -6,6 +6,6 @@
[include v1/design.qbk]
[include v1/extend.qbk]
[include v1/faq.qbk]
[xinclude reference_v1.xml]
[xinclude reference_v2.xml]
[endsect]

View File

@@ -140,7 +140,10 @@ struct limit_handles_ : handler_base_ext
auto itr = std::find(all_handles.begin(), all_handles .end(), handle);
::boost::winapi::DWORD_ flags = 0u;
if (itr != all_handles.end())
*itr = ::boost::winapi::INVALID_HANDLE_VALUE_; // the handle is used mark it as invalid, so it doesn't get reset
*itr = ::boost::winapi::INVALID_HANDLE_VALUE_;
else if ((::boost::winapi::GetHandleInformation(*itr, &flags) != 0)
&&((flags & ::boost::winapi::HANDLE_FLAG_INHERIT_) == 0)) //it is NOT inherited anyhow, so ignore too
*itr = ::boost::winapi::INVALID_HANDLE_VALUE_;
});
auto part_itr = std::partition(all_handles.begin(), all_handles.end(),

View File

@@ -308,7 +308,7 @@ struct basic_process_handle_win
public:
template<BOOST_PROCESS_V2_COMPLETION_TOKEN_FOR(void(error_code, native_exit_code_type))
WaitHandler = net::default_completion_token_t<executor_type>>
auto async_wait(WaitHandler &&handler = net::default_completion_token_t<executor_type>())
auto async_wait(WaitHandler &&handler = default_completion_token_t<executor_type>())
-> decltype(net::async_compose<WaitHandler, void(error_code, native_exit_code_type)>(
async_wait_op_{handle_}, handler, handle_))
{

View File

@@ -0,0 +1,23 @@
//
// Copyright (c) 2024 Klemens Morgenstern (klemens.morgenstern@gmx.net)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_PROCESS_BASIC_STREAM_INPUT_HPP
#define BOOST_PROCESS_BASIC_STREAM_INPUT_HPP
#include <boost/process/v2/detail/config.hpp>
BOOST_PROCESS_V2_BEGIN_NAMESPACE
template<typename Executor>
basic_stream_input<Executor> open_stdin(Executor executor, bool duplicate = true);
BOOST_PROCESS_V2_END_NAMESPACE
#endif //BOOST_PROCESS_BASIC_STREAM_INPUT_HPP

View File

@@ -0,0 +1,21 @@
//
// Copyright (c) 2024 Klemens Morgenstern (klemens.morgenstern@gmx.net)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef BOOST_PROCESS_V2_EXPERIMENTAL_STREAM_INPUT_HPP
#define BOOST_PROCESS_V2_EXPERIMENTAL_STREAM_INPUT_HPP
#include <boost/process/v2/detail/config.hpp>
#include <boost/process/v2/experimental/basic_stream_input.hpp>
BOOST_PROCESS_V2_BEGIN_NAMESPACE
typedef basic_stream_input<> stream_input;
BOOST_PROCESS_V2_END_NAMESPACE
#endif //BOOST_PROCESS_V2_EXPERIMENTAL_STREAM_INPUT_HPP

View File

@@ -8,7 +8,6 @@
#include <string>
#include <vector>
#include <memory>
#include <boost/process/v2/detail/config.hpp>
#include <boost/process/v2/detail/throw_error.hpp>

View File

@@ -8,7 +8,6 @@
#define BOOST_PROCESS_V2_ENV_HPP
#include <string>
#include <vector>
#include <memory>
#include <boost/process/v2/detail/config.hpp>
#include <boost/process/v2/detail/throw_error.hpp>
@@ -27,6 +26,9 @@ namespace ext
#if defined(BOOST_PROCESS_V2_WINDOWS)
using native_env_handle_type = wchar_t *;
using native_env_iterator = wchar_t *;
#elif defined(__FreeBSD__)
using native_env_handle_type = char **;
using native_env_iterator = char **;
#else
using native_env_handle_type = char *;
using native_env_iterator = char *;

View File

@@ -10,7 +10,6 @@
#include <boost/process/v2/detail/throw_error.hpp>
#include <vector>
#include <memory>
BOOST_PROCESS_V2_BEGIN_NAMESPACE

View File

@@ -29,7 +29,7 @@
#include <unistd.h>
#if defined(__APPLE__) || defined(__MACH__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun)
#if defined(__APPLE__) || defined(__MACH__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
extern "C" { extern char **environ; }
#endif

View File

@@ -52,7 +52,6 @@
#endif
#if defined(__sun)
#include <cstdlib>
#include <sys/types.h>
#include <kvm.h>
#include <sys/param.h>
@@ -275,7 +274,6 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
kinfo_proc *proc_info = nullptr;
const char *nlistf, *memf;
nlistf = memf = "/dev/null";
struct closer
{
void operator()(kvm_t * kd)
@@ -285,7 +283,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
};
std::unique_ptr<kvm_t, closer> kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)};
if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {};}
if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return {};}
if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_PID, pid, &cntp)))
{
char **cmd = kvm_getargv(kd.get(), proc_info, 0);
@@ -303,9 +301,10 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
{
std::vector<std::string> vec;
int cntp = 0;
kinfo_proc2 *proc_info = nullptr;
struct closer
{
void operator()(kvm_t * kd)
@@ -316,7 +315,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
std::unique_ptr<kvm_t, closer> kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)};
if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {};}
if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec;}
if ((proc_info = kvm_getproc2(kd.get(), KERN_PROC_PID, pid, sizeof(struct kinfo_proc2), &cntp)))
{
char **cmd = kvm_getargv2(kd.get(), proc_info, 0);
@@ -327,13 +326,14 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
return {};
return vec;
}
#elif defined(__OpenBSD__)
shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
{
std::vector<std::string> vec;
int cntp = 0;
kinfo_proc *proc_info = nullptr;
@@ -346,7 +346,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
};
std::unique_ptr<kvm_t, closer> kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)};
if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {};}
if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec) return vec;}
if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &cntp)))
{
char **cmd = kvm_getargv(kd.get(), proc_info, 0);
@@ -367,29 +367,22 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
char **cmd = nullptr;
proc *proc_info = nullptr;
user *proc_user = nullptr;
struct closer
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)))
{
void operator()(kvm_t * kd)
if ((proc_user = kvm_getu(kd, proc_info)))
{
kvm_close(kd);
}
};
std::unique_ptr<kvm_t, closer> 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.get(), pid)))
{
if ((proc_user = kvm_getu(kd.get(), proc_info)))
{
if (!kvm_getcmd(kd.get(), proc_info, proc_user, &cmd, nullptr))
if (!kvm_getcmd(kd, proc_info, proc_user, &cmd, nullptr))
{
int argc = 0;
for (int i = 0; cmd[i] != nullptr; i++)
argc++;
return make_cmd_shell_::make(
argc ++;
shell res = make_cmd_shell_::make(
{}, argc, cmd,
+[](int, char ** argv) {::free(argv);});
+[](int, char ** argv) {::free(argv);})
kvm_close(kd);
return res;
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
@@ -399,6 +392,8 @@ 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 {};
}

View File

@@ -23,7 +23,6 @@
#if (defined(__APPLE__) && defined(__MACH__))
#include <TargetConditionals.h>
#if !TARGET_OS_IOS
#include <algorithm>
#include <sys/proc_info.h>
#include <sys/sysctl.h>
#include <libproc.h>
@@ -35,52 +34,21 @@
#endif
#if defined(__FreeBSD__)
#include <algorithm>
#include <cstring>
#include <fcntl.h>
#include <kvm.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/user.h>
#endif
#if defined(__DragonFly__)
#include <algorithm>
#include <cstring>
#include <sys/types.h>
#include <kvm.h>
#endif
#if defined(__NetBSD__)
#include <algorithm>
#include <cstring>
#include <fcntl.h>
#include <kvm.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <libprocstat.h>
#endif
#if defined(__OpenBSD__)
#include <algorithm>
#include <cstring>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <fcntl.h>
#include <kvm.h>
#endif
#if defined(__sun)
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <kvm.h>
#include <fcntl.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/user.h>
#include <sys/proc.h>
#endif
BOOST_PROCESS_V2_BEGIN_NAMESPACE
namespace detail {
@@ -137,7 +105,7 @@ const environment::char_type * dereference(native_env_iterator iterator)
return iterator;
}
#elif (defined(__APPLE___) || defined(__MACH__)) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__sun)
#elif (defined(__APPLE___) || defined(__MACH__)) || defined(__OpenBSD__)
void native_env_handle_deleter::operator()(native_env_handle_type h) const
{
@@ -162,6 +130,31 @@ const environment::char_type * dereference(native_env_iterator iterator)
return iterator;
}
#elif defined(__FreeBSD__)
void native_env_handle_deleter::operator()(native_env_handle_type h) const
{
delete [] h;
}
native_env_iterator next(native_env_iterator nh)
{
return ++nh ;
}
native_env_iterator find_end(native_env_iterator nh)
{
while (*nh != nullptr)
nh++;
return nh ;
}
const environment::char_type * dereference(native_env_iterator iterator)
{
return *iterator;
}
#endif
}
@@ -345,90 +338,72 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec)
return ev;
}
#elif defined(__FreeBSD__) || defined(__DragonFly__)
#elif defined(__FreeBSD__)
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;
const char *nlistf, *memf;
nlistf = memf = "/dev/null";
env_view ev;
struct closer
unsigned cntp = 0;
procstat *proc_stat = procstat_open_sysctl();
if (proc_stat != nullptr)
{
void operator()(kvm_t * kd)
kinfo_proc *proc_info = procstat_getprocs(proc_stat, KERN_PROC_PID, pid, &cntp);
if (proc_info != nullptr)
{
kvm_close(kd);
}
};
std::unique_ptr<kvm_t, closer> kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)};
if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {};}
if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_PID, pid, &cntp))) {
char **env = kvm_getenvv(kd.get(), proc_info, 0);
if (env) {
for (int i = 0; env[i] != nullptr; i++)
char **env = procstat_getenvv(proc_stat, proc_info, 0);
if (env != nullptr)
{
for (int j = 0; j < strlen(env[i]); j++)
vec.push_back(env[i][j]);
vec.push_back('\0');
auto e = env;
std::size_t n = 0u, len = 0u;
while (e && *e != nullptr)
{
n ++;
len += std::strlen(*e);
e++;
}
std::size_t mem_needed =
// environ - nullptr - strlen + null terminators
(n * sizeof(char*)) + sizeof(char*) + len + n;
char * out = new (std::nothrow) char[mem_needed];
if (out != nullptr)
{
auto eno = reinterpret_cast<char**>(out);
auto eeo = eno;
auto str = out + (n * sizeof(char*)) + sizeof(char*);
e = env;
while (*e != nullptr)
{
auto len = std::strlen(*e) + 1u;
std::memcpy(str, *e, len);
*eno = str;
str += len;
eno ++;
e++;
}
*eno = nullptr;
ev.handle_.reset(eeo);
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
}
vec.push_back('\0');
procstat_freeprocs(proc_stat, proc_info);
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
procstat_close(proc_stat);
}
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;
}
#elif defined(__NetBSD__)
env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec)
{
std::vector<char> vec;
int cntp = 0;
kinfo_proc2 *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) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {};}
if ((proc_info = kvm_getproc2(kd.get(), KERN_PROC_PID, pid, sizeof(struct kinfo_proc2), &cntp))) {
char **env = kvm_getenvv2(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;
}
#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;
@@ -442,7 +417,7 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec)
};
std::unique_ptr<kvm_t, closer> kd{kvm_openfiles(nullptr, nullptr, nullptr, KVM_NO_FILES, nullptr)};
if (!kd) {BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec); return {};}
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);
@@ -467,53 +442,6 @@ env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec)
std::copy(vec.begin(), vec.end(), ev.handle_.get());
return ev;
}
#elif defined(__sun)
env_view env(boost::process::v2::pid_type pid, boost::system::error_code & ec)
{
std::vector<char> vec;
char **env = nullptr;
proc *proc_info = nullptr;
user *proc_user = nullptr;
struct closer
{
void operator()(kvm_t * kd)
{
kvm_close(kd);
}
};
std::unique_ptr<kvm_t, closer> 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.get(), pid)))
{
if ((proc_user = kvm_getu(kd.get(), proc_info)))
{
if (!kvm_getcmd(kd.get(), proc_info, proc_user, nullptr, &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');
free(env);
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
}
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)

View File

@@ -39,7 +39,7 @@
#if (defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__))
#include <sys/types.h>
#include <sys/sysctl.h>
#if !defined(__FreeBSD__) && !defined(__NetBSD__)
#if !defined(__FreeBSD__)
#include <alloca.h>
#endif
#endif

View File

@@ -29,11 +29,10 @@
#endif
#if defined(__FreeBSD__)
#include <fcntl.h>
#include <kvm.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <sys/types.h>
#include <sys/user.h>
#include <libutil.h>
#include <cstdlib>
#endif
#if (defined(__DragonFly__) || defined(__OpenBSD__))
@@ -52,7 +51,6 @@
#endif
#if defined(__sun)
#include <fcntl.h>
#include <sys/types.h>
#include <kvm.h>
#include <sys/param.h>
@@ -279,29 +277,13 @@ std::vector<pid_type> all_pids(boost::system::error_code & ec)
{
std::vector<pid_type> vec;
int cntp = 0;
kinfo_proc *proc_info = nullptr;
const char *nlistf, *memf;
nlistf = memf = "/dev/null";
struct closer
{
void operator()(kvm_t * kd)
{
kvm_close(kd);
}
};
std::unique_ptr<kvm_t, closer> kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)};
if (!kd)
{
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
return vec;
}
if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_ALL, 0, &cntp)))
kinfo_proc *proc_info = kinfo_getallproc(&cntp);
if (proc_info)
{
vec.reserve(cntp);
for (int i = 0; i < cntp; i++)
for (int i = 0; i < cntp; i++)
vec.push_back(proc_info[i].ki_pid);
free(proc_info);
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
@@ -311,28 +293,11 @@ std::vector<pid_type> all_pids(boost::system::error_code & ec)
pid_type parent_pid(pid_type pid, boost::system::error_code & ec)
{
pid_type ppid = static_cast<pid_type>(-1);
int cntp = 0;
kinfo_proc *proc_info = nullptr;
const char *nlistf, *memf;
nlistf = memf = "/dev/null";
struct closer
{
void operator()(kvm_t * kd)
{
kvm_close(kd);
}
};
std::unique_ptr<kvm_t, closer> kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)};
if (!kd)
{
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
return ppid;
}
if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_PID, pid, &cntp)))
kinfo_proc *proc_info = kinfo_getproc(pid);
if (proc_info)
{
ppid = proc_info->ki_ppid;
free(proc_info);
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
@@ -342,26 +307,9 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec)
std::vector<pid_type> child_pids(pid_type pid, boost::system::error_code & ec)
{
std::vector<pid_type> vec;
int cntp = 0;
kinfo_proc *proc_info = nullptr;
const char *nlistf, *memf;
nlistf = memf = "/dev/null";
struct closer
{
void operator()(kvm_t * kd)
{
kvm_close(kd);
}
};
std::unique_ptr<kvm_t, closer> kd{kvm_openfiles(nlistf, memf, nullptr, O_RDONLY, nullptr)};
if (!kd)
{
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
return vec;
}
if ((proc_info = kvm_getprocs(kd.get(), KERN_PROC_ALL, 0, &cntp)))
int cntp = 0;
kinfo_proc *proc_info = kinfo_getallproc(&cntp);
if (proc_info)
{
vec.reserve(cntp);
for (int i = 0; i < cntp; i++)
@@ -371,6 +319,7 @@ std::vector<pid_type> child_pids(pid_type pid, boost::system::error_code & ec)
vec.push_back(proc_info[i].ki_pid);
}
}
free(proc_info);
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
@@ -386,7 +335,6 @@ std::vector<pid_type> all_pids(boost::system::error_code & ec)
kinfo_proc *proc_info = nullptr;
const char *nlistf, *memf;
nlistf = memf = "/dev/null";
struct closer
{
void operator()(kvm_t * kd)
@@ -420,7 +368,6 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec)
kinfo_proc *proc_info = nullptr;
const char *nlistf, *memf;
nlistf = memf = "/dev/null";
struct closer
{
void operator()(kvm_t * kd)
@@ -454,7 +401,6 @@ std::vector<pid_type> child_pids(pid_type pid, boost::system::error_code & ec)
kinfo_proc *proc_info = nullptr;
const char *nlistf, *memf;
nlistf = memf = "/dev/null";
struct closer
{
void operator()(kvm_t * kd)
@@ -492,7 +438,6 @@ std::vector<pid_type> all_pids(boost::system::error_code & ec)
std::vector<pid_type> vec;
int cntp = 0;
kinfo_proc2 *proc_info = nullptr;
struct closer
{
void operator()(kvm_t * kd)
@@ -525,7 +470,6 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec)
pid_type ppid = static_cast<pid_type>(-1);
int cntp = 0;
kinfo_proc2 *proc_info = nullptr;
struct closer
{
void operator()(kvm_t * kd)
@@ -554,7 +498,6 @@ std::vector<pid_type> child_pids(pid_type pid, boost::system::error_code & ec)
std::vector<pid_type> vec;
int cntp = 0;
kinfo_proc2 *proc_info = nullptr;
struct closer
{
void operator()(kvm_t * kd)
@@ -592,7 +535,6 @@ std::vector<pid_type> all_pids(boost::system::error_code & ec)
std::vector<pid_type> vec;
int cntp = 0;
kinfo_proc *proc_info = nullptr;
struct closer
{
void operator()(kvm_t * kd)
@@ -628,7 +570,6 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec)
pid_type ppid = static_cast<pid_type>(-1);
int cntp = 0;
kinfo_proc *proc_info = nullptr;
struct closer
{
void operator()(kvm_t * kd)
@@ -657,7 +598,6 @@ std::vector<pid_type> child_pids(pid_type pid, boost::system::error_code & ec)
std::vector<pid_type> vec;
int cntp = 0;
kinfo_proc *proc_info = nullptr;
struct closer
{
void operator()(kvm_t * kd)
@@ -696,7 +636,6 @@ std::vector<pid_type> all_pids(boost::system::error_code & ec)
std::vector<pid_type> vec;
struct pid cur_pid;
proc *proc_info = nullptr;
struct closer
{
void operator()(kvm_t * kd)
@@ -711,9 +650,9 @@ std::vector<pid_type> all_pids(boost::system::error_code & ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
return vec;
}
while ((proc_info = kvm_nextproc(kd.get())))
while ((proc_info = kvm_nextproc(kd)))
{
if (kvm_kread(kd.get(), (std::uintptr_t)proc_info->p_pidp, &cur_pid, sizeof(cur_pid)) != -1)
if (kvm_kread(kd, (std::uintptr_t)proc_info->p_pidp, &cur_pid, sizeof(cur_pid)) != -1)
{
vec.insert(vec.begin(), cur_pid.pid_id);
}
@@ -730,7 +669,6 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec)
{
pid_type ppid = static_cast<pid_type>(-1);
proc *proc_info = nullptr;
struct closer
{
void operator()(kvm_t * kd)
@@ -745,7 +683,7 @@ pid_type parent_pid(pid_type pid, boost::system::error_code & ec)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
return ppid;
}
if ((proc_info = kvm_getproc(kd.get(), pid)))
if ((proc_info = kvm_getproc(kd, pid)))
{
ppid = proc_info->p_ppid;
}
@@ -759,7 +697,6 @@ std::vector<pid_type> child_pids(pid_type pid, boost::system::error_code & ec)
std::vector<pid_type> vec;
struct pid cur_pid;
proc *proc_info = nullptr;
struct closer
{
void operator()(kvm_t * kd)
@@ -768,17 +705,17 @@ std::vector<pid_type> child_pids(pid_type pid, boost::system::error_code & ec)
}
};
std::unique_ptr<kvm_t, closer> kd{kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr)};
std::unique_ptr<kvm_t, closer> kd{kvm_open(nullptr, nullptr, nullptr, O_RDONLY, nullptr);
if (!kd)
{
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec);
return vec;
}
while ((proc_info = kvm_nextproc(kd.get())))
while ((proc_info = kvm_nextproc(kd)))
{
if (proc_info->p_ppid == pid)
{
if (kvm_kread(kd.get(), (std::uintptr_t)proc_info->p_pidp, &cur_pid, sizeof(cur_pid)) != -1)
if (kvm_kread(kd, (std::uintptr_t)proc_info->p_pidp, &cur_pid, sizeof(cur_pid)) != -1)
{
vec.insert(vec.begin(), cur_pid.pid_id);
}

View File

@@ -148,17 +148,12 @@ BOOST_AUTO_TEST_CASE(async_nowait, *boost::unit_test::timeout(10))
boost::asio::io_context io_context;
bp::child c(
master_test_suite().argv[1],
"test", "--exit-code", "121",
"test", "--exit-code", "221",
ec,
bp::on_exit=[](int exit_code, std::error_code) mutable {},
io_context
);
BOOST_REQUIRE(!ec);
while (c.running())
{
io_context.run_for(std::chrono::milliseconds(10));
io_context.restart();
}
BOOST_CHECK_EQUAL(121, c.exit_code());
io_context.run_for(std::chrono::milliseconds(100));
BOOST_CHECK_EQUAL(221, c.exit_code());
}

View File

@@ -21,7 +21,9 @@ project : requirements
<target-os>windows:<define>_WIN32_WINNT=0x0601
<target-os>linux:<linkflags>-lpthread
<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