Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenBSD Fix. #404

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/boost/process/v2/posix/default_launcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <unistd.h>


#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__MACH__)
#if defined(__APPLE__) || defined(__MACH__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
extern "C" { extern char **environ; }
#endif

Expand Down
4 changes: 2 additions & 2 deletions src/ext/cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,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 vec;}
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 **cmd = kvm_getargv(kd.get(), proc_info, 0);
Expand All @@ -354,7 +354,7 @@ shell cmd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
kvm_close(kd);
kvm_close(kd.get());
return {};
}

Expand Down
53 changes: 8 additions & 45 deletions src/ext/cwd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@
#endif

#if defined(__DragonFly__)
#include <climits>
#include <cstring>
#include <cstdio>
#include <sys/types.h>
#include <sys/sysctl.h>
#endif

#ifdef BOOST_PROCESS_USE_STD_FS
Expand Down Expand Up @@ -152,53 +154,14 @@ filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code

filesystem::path cwd(boost::process::v2::pid_type pid, boost::system::error_code & ec)
{
/*
filesystem::path path;
// Official API (broken OS-level) - including code from DragonFly's fstat(1)
// command line interface utility currently requires way too much code FWIW.
std::size_t sz = 4, len = 0;
char buffer[PATH_MAX];
std::size_t sz = 4, len = sizeof(buffer);
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_CWD, pid};
if (sysctl(mib, sz, nullptr, &len, nullptr, 0) == 0)
{
std::vector<char> vecbuff;
vecbuff.resize(len);
if (sysctl(mib, sz, &vecbuff[0], &len, nullptr, 0) == 0)
{
path = filesystem::canonical(&vecbuff[0], ec);
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
return path;
*/

filesystem::path path;
/* Probably the hackiest thing ever we are doing here, because the official API is broken OS-level. */
FILE *fp = popen(("pos=`ans=\\`/usr/bin/fstat -w -p " + std::to_string(pid) + " | /usr/bin/sed -n 1p\\`; " +
"/usr/bin/awk -v ans=\"$ans\" 'BEGIN{print index(ans, \"INUM\")}'`; str=`/usr/bin/fstat -w -p " +
std::to_string(pid) + " | /usr/bin/sed -n 3p`; /usr/bin/awk -v str=\"$str\" -v pos=\"$pos\" " +
"'BEGIN{print substr(str, 0, pos + 4)}' | /usr/bin/awk 'NF{NF--};1 {$1=$2=$3=$4=\"\"; print" +
" substr($0, 5)'}").c_str(), "r");
if (fp)
if (sysctl(mib, sz, buffer, &len, nullptr, 0) == 0)
{
char buffer[PATH_MAX];
if (fgets(buffer, sizeof(buffer), fp))
{
std::string str = buffer;
std::size_t pos = str.find("\n", strlen(buffer) - 1);
if (pos != std::string::npos)
{
str.replace(pos, 1, "");
}
path = filesystem::canonical(str.c_str(), ec);
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
if (pclose(fp) == -1)
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
}
path = filesystem::canonical(buffer, ec);
}
else
BOOST_PROCESS_V2_ASSIGN_LAST_ERROR(ec)
return path;
Expand Down
4 changes: 2 additions & 2 deletions src/pid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,9 @@ std::vector<pid_type> all_pids(boost::system::error_code & ec)
vec.reserve(cntp);
for (int i = cntp - 1; i >= 0; i--)
{
if (proc_info[i].kp_pid >= 0)
if (proc_info[i].p_pid >= 0)
{
vec.push_back(proc_info[i].kp_pid);
vec.push_back(proc_info[i].p_pid);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/posix/close_handles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
// linux has close_range since 5.19


#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#if defined(__FreeBSD__)

// https://www.freebsd.org/cgi/man.cgi?query=close_range&apropos=0&sektion=0&manpath=FreeBSD+13.1-RELEASE+and+Ports&arch=default&format=html
// https://man.netbsd.org/closefrom.3
// __FreeBSD__
//
// gives us
Expand Down
6 changes: 3 additions & 3 deletions src/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#if defined(BOOST_PROCESS_V2_WINDOWS)
#include <windows.h>
#include <shellapi.h>
#else
#elif !defined(__OpenBSD__)
#include <wordexp.h>
#endif

Expand All @@ -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
{
Expand Down Expand Up @@ -92,7 +92,7 @@ auto shell::args() const-> args_type
return input_.c_str();
}

#else
#elif !defined(__OpenBSD__)

void shell::parse_()
{
Expand Down
3 changes: 3 additions & 0 deletions test/v2/Jamfile.jam
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ project : requirements
<target-os>freebsd:<linkflags>-lkvm
<target-os>freebsd:<linkflags>-lprocstat
<target-os>bsd:<linkflags>-lkvm
<target-os>netbsd:<linkflags>-lkvm
<target-os>openbsd:<linkflags>-lkvm
<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
Expand Down
Loading