Skip to content

Commit aec3bf5

Browse files
use new binary
1 parent f20e85c commit aec3bf5

File tree

4 files changed

+29
-74
lines changed

4 files changed

+29
-74
lines changed

src/helpers/MiscFunctions.cpp

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -662,50 +662,39 @@ std::vector<pid_t> getAllPIDOf(const std::string& name) {
662662
return results;
663663
}
664664

665-
std::string getProcNameOf(pid_t pid) {
666-
#if defined(KERN_PROC_PID)
665+
std::expected<std::string, std::string> binaryNameForPid(pid_t pid) {
666+
if (pid <= 0)
667+
return std::unexpected("No pid for client");
668+
669+
#if defined(KERN_PROC_PATHNAME)
667670
int mib[] = {
668-
CTL_KERN, KERN_PROC, KERN_PROC_PID, (int)pid,
669-
#if defined(__NetBSD__) || defined(__OpenBSD__)
670-
sizeof(KINFO_PROC), 1,
671+
CTL_KERN,
672+
#if defined(__NetBSD__)
673+
KERN_PROC_ARGS,
674+
pid,
675+
KERN_PROC_PATHNAME,
676+
#else
677+
KERN_PROC,
678+
KERN_PROC_PATHNAME,
679+
pid,
671680
#endif
672681
};
673-
u_int miblen = sizeof(mib) / sizeof(mib[0]);
674-
KINFO_PROC kp;
675-
size_t sz = sizeof(KINFO_PROC);
676-
677-
if (sysctl(mib, miblen, &kp, &sz, NULL, 0) != -1) {
678-
#if defined(__DragonFly__)
679-
return std::string(kp.kp_comm);
680-
#elif defined(__FreeBSD__)
681-
return std::string(kp.ki_comm);
682-
#elif defined(__NetBSD__)
683-
return std::string(kp.p_comm);
684-
#elif defined(__OpenBSD__)
685-
return std::string(kp.p_comm);
686-
#endif
687-
}
688-
689-
return {};
682+
u_int miblen = sizeof(mib) / sizeof(mib[0]);
683+
char exe[PATH_MAX] = "/nonexistent";
684+
size_t sz = sizeof(exe);
685+
sysctl(mib, miblen, &exe, &sz, NULL, 0);
686+
std::string path = exe;
690687
#else
691-
const std::string commPath = "/proc/" + std::to_string(pid) + "/comm";
692-
CFileDescriptor fd{open(commPath.c_str(), O_RDONLY | O_CLOEXEC)};
693-
694-
if (!fd.isValid())
695-
return {};
696-
697-
char buffer[256] = {0};
698-
const auto bytesRead = read(fd.get(), buffer, sizeof(buffer) - 1);
688+
std::string path = std::format("/proc/{}/exe", (uint64_t)pid);
689+
#endif
690+
std::error_code ec;
699691

700-
if (bytesRead <= 0)
701-
return {};
692+
std::string fullPath = std::filesystem::canonical(path, ec);
702693

703-
std::string name{buffer};
704-
if (!name.empty() && name.back() == '\n')
705-
name.pop_back();
694+
if (ec)
695+
return std::unexpected("canonical failed");
706696

707-
return name;
708-
#endif
697+
return fullPath;
709698
}
710699

711700
std::expected<int64_t, std::string> configStringToInt(const std::string& VALUE) {

src/helpers/MiscFunctions.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ float vecToRectDistanceSquared(const Vector2D& vec
2929
void logSystemInfo();
3030
std::string execAndGet(const char*);
3131
pid_t getPPIDof(pid_t pid);
32-
std::string getProcNameOf(pid_t pid);
32+
std::expected<std::string, std::string> binaryNameForPid(pid_t pid) {
3333
std::vector<pid_t> getAllPIDOf(const std::string& name);
3434
std::expected<int64_t, std::string> configStringToInt(const std::string&);
3535
Vector2D configStringToVector2D(const std::string&);

src/managers/KeybindManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ pid_t CKeybindManager::spawnWithRules(std::string args, PHLWORKSPACE pInitialWor
949949
global = true;
950950
else {
951951
if (global)
952-
for (const auto& pid : getAllPIDOf(getProcNameOf(PROC)))
952+
for (const auto& pid : getAllPIDOf(binaryNameForPid(PROC)))
953953
g_pConfigManager->addExecRule({r, (unsigned long)pid});
954954
else
955955
g_pConfigManager->addExecRule({r, (unsigned long)PROC});

src/managers/permissions/DynamicPermissionManager.cpp

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <filesystem>
77
#include "../../Compositor.hpp"
88
#include "../../config/ConfigValue.hpp"
9+
#include "../../helpers/MiscFunctions.hpp"
910

1011
#include <hyprutils/string/String.hpp>
1112
using namespace Hyprutils::String;
@@ -69,41 +70,6 @@ static const char* permissionToHumanString(eDynamicPermissionType type) {
6970
return "error";
7071
}
7172

72-
static std::expected<std::string, std::string> binaryNameForPid(pid_t pid) {
73-
if (pid <= 0)
74-
return std::unexpected("No pid for client");
75-
76-
#if defined(KERN_PROC_PATHNAME)
77-
int mib[] = {
78-
CTL_KERN,
79-
#if defined(__NetBSD__)
80-
KERN_PROC_ARGS,
81-
pid,
82-
KERN_PROC_PATHNAME,
83-
#else
84-
KERN_PROC,
85-
KERN_PROC_PATHNAME,
86-
pid,
87-
#endif
88-
};
89-
u_int miblen = sizeof(mib) / sizeof(mib[0]);
90-
char exe[PATH_MAX] = "/nonexistent";
91-
size_t sz = sizeof(exe);
92-
sysctl(mib, miblen, &exe, &sz, NULL, 0);
93-
std::string path = exe;
94-
#else
95-
std::string path = std::format("/proc/{}/exe", (uint64_t)pid);
96-
#endif
97-
std::error_code ec;
98-
99-
std::string fullPath = std::filesystem::canonical(path, ec);
100-
101-
if (ec)
102-
return std::unexpected("canonical failed");
103-
104-
return fullPath;
105-
}
106-
10773
static std::expected<std::string, std::string> binaryNameForWlClient(wl_client* client) {
10874
pid_t pid = 0;
10975
wl_client_get_credentials(client, &pid, nullptr, nullptr);

0 commit comments

Comments
 (0)