fixes
This commit is contained in:
parent
84df352751
commit
18d51031e6
5 changed files with 34 additions and 24 deletions
|
@ -7,10 +7,9 @@
|
|||
#include <sys/socket.h> // ucred, getsockopt, SOL_SOCKET, SO_PEERCRED
|
||||
#include <sys/statvfs.h> // statvfs
|
||||
#include <sys/sysctl.h> // sysctlbyname
|
||||
#include <sys/types.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/utsname.h> // utsname, uname
|
||||
#include <unistd.h>
|
||||
#include <sys/un.h> // LOCAL_PEERCRED
|
||||
#include <sys/utsname.h> // uname, utsname
|
||||
#include <unistd.h> // readlink
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
#include <kenv.h> // kenv
|
||||
|
@ -36,14 +35,14 @@ namespace {
|
|||
fn GetPathByPid(pid_t pid) -> Result<String, DracError> {
|
||||
Array<char, PATH_MAX> exePathBuf;
|
||||
usize size = exePathBuf.size();
|
||||
int mib[4];
|
||||
Array<i32, 4> mib;
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROC_ARGS; // Use KERN_PROC_ARGS which includes path
|
||||
mib[2] = pid;
|
||||
mib[3] = KERN_PROC_PATHNAME; // The specific subcommand
|
||||
mib.at(0) = CTL_KERN;
|
||||
mib.at(1) = KERN_PROC_ARGS;
|
||||
mib.at(2) = pid;
|
||||
mib.at(3) = KERN_PROC_PATHNAME;
|
||||
|
||||
if (sysctl(mib, 4, exePathBuf.data(), &size, nullptr, 0) == -1)
|
||||
if (sysctl(mib.data(), 4, exePathBuf.data(), &size, nullptr, 0) == -1)
|
||||
return Err(DracError::withErrno(std::format("sysctl KERN_PROC_PATHNAME failed for pid {}", pid)));
|
||||
|
||||
if (size == 0 || exePathBuf[0] == '\0')
|
||||
|
@ -51,7 +50,7 @@ namespace {
|
|||
DracError(DracErrorCode::NotFound, std::format("sysctl KERN_PROC_PATHNAME returned empty path for pid {}", pid))
|
||||
);
|
||||
|
||||
exePathBuf[std::min(size, exePathBuf.size() - 1)] = '\0';
|
||||
exePathBuf.at(std::min(size, exePathBuf.size() - 1)) = '\0';
|
||||
|
||||
return String(exePathBuf.data());
|
||||
}
|
||||
|
@ -145,7 +144,7 @@ namespace {
|
|||
if (fileDescriptor < 0)
|
||||
return Err(DracError(DracErrorCode::ApiUnavailable, "Failed to get Wayland file descriptor"));
|
||||
|
||||
pid_t peer_pid = -1; // Initialize PID
|
||||
pid_t peerPid = -1; // Initialize PID
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__DragonFly__)
|
||||
struct xucred cred;
|
||||
|
@ -155,10 +154,7 @@ namespace {
|
|||
if (getsockopt(fileDescriptor, SOL_SOCKET, LOCAL_PEERCRED, &cred, &len) == -1)
|
||||
return Err(DracError::withErrno("Failed to get socket credentials (LOCAL_PEERCRED)"));
|
||||
|
||||
if (len != sizeof(cred) || cred.cr_version != XUCRED_VERSION)
|
||||
return Err(DracError(DracErrorCode::PlatformSpecific, "Invalid xucred structure received"));
|
||||
|
||||
peer_pid = cred.cr_pid;
|
||||
peerPid = cred.cr_pid;
|
||||
#elif defined(__NetBSD__)
|
||||
uid_t euid;
|
||||
gid_t egid;
|
||||
|
@ -169,10 +165,10 @@ namespace {
|
|||
return "Wayland Compositor (Unknown Path)";
|
||||
#endif
|
||||
|
||||
if (peer_pid <= 0)
|
||||
if (peerPid <= 0)
|
||||
return Err(DracError(DracErrorCode::PlatformSpecific, "Failed to obtain a valid peer PID"));
|
||||
|
||||
Result<String, DracError> exePathResult = GetPathByPid(peer_pid);
|
||||
Result<String, DracError> exePathResult = GetPathByPid(peerPid);
|
||||
|
||||
if (!exePathResult) {
|
||||
return Err(std::move(exePathResult).error());
|
||||
|
@ -447,14 +443,14 @@ namespace os {
|
|||
if (sysctlbyname("hw.model", buffer.data(), &size, nullptr, 0) == -1)
|
||||
return Err(DracError::withErrno("kenv smbios.system.product failed and sysctl hw.model also failed"));
|
||||
|
||||
buffer[std::min(size, buffer.size() - 1)] = '\0';
|
||||
buffer.at(std::min(size, buffer.size() - 1)) = '\0';
|
||||
return String(buffer.data());
|
||||
}
|
||||
|
||||
if (result > 0)
|
||||
buffer[result] = '\0';
|
||||
buffer.at(result) = '\0';
|
||||
else
|
||||
buffer[0] = '\0';
|
||||
buffer.at(0) = '\0';
|
||||
|
||||
#elif defined(__NetBSD__)
|
||||
if (sysctlbyname("machdep.dmi.system-product", buffer.data(), &size, nullptr, 0) == -1)
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstring>
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
|
||||
// clang-format off
|
||||
#include <cstring>
|
||||
#include <dbus/dbus.h> // DBus Library
|
||||
#include <utility> // std::exchange, std::forward
|
||||
#include <format> // std::format
|
||||
|
@ -384,3 +385,5 @@ namespace dbus {
|
|||
}
|
||||
};
|
||||
} // namespace dbus
|
||||
|
||||
#endif // __linux__ || __FreeBSD__
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
|
||||
// clang-format off
|
||||
#include <wayland-client.h> // Wayland client library
|
||||
|
||||
#include "src/util/defs.hpp"
|
||||
#include "src/util/logging.hpp"
|
||||
#include "src/util/types.hpp"
|
||||
// clang-format on
|
||||
|
||||
struct wl_display;
|
||||
|
||||
|
@ -91,3 +95,5 @@ namespace wl {
|
|||
[[nodiscard]] fn fd() const -> util::types::i32 { return get_fd(m_display); }
|
||||
};
|
||||
} // namespace wl
|
||||
|
||||
#endif // __linux__ || __FreeBSD__
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
|
||||
// clang-format off
|
||||
#include <xcb/xcb.h> // XCB library
|
||||
|
||||
|
@ -31,7 +33,7 @@ namespace xcb {
|
|||
ReqLenExceed = XCB_CONN_CLOSED_REQ_LEN_EXCEED,
|
||||
ParseErr = XCB_CONN_CLOSED_PARSE_ERR,
|
||||
InvalidScreen = XCB_CONN_CLOSED_INVALID_SCREEN,
|
||||
FdPassingFailed = XCB_CONN_CLOSED_FDPASSING_FAILED
|
||||
FdPassingFailed = XCB_CONN_CLOSED_FDPASSING_FAILED,
|
||||
};
|
||||
|
||||
// NOLINTBEGIN(readability-identifier-naming)
|
||||
|
@ -168,3 +170,5 @@ namespace xcb {
|
|||
[[nodiscard]] fn operator*() const->T& { return *m_reply; }
|
||||
};
|
||||
} // namespace xcb
|
||||
|
||||
#endif // __linux__ || __FreeBSD__
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue