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