diff options
author | Vaxry <[email protected]> | 2024-12-13 22:36:35 +0000 |
---|---|---|
committer | Vaxry <[email protected]> | 2024-12-13 22:36:42 +0000 |
commit | 3cba4ba44e7ba3cc8bb67ac71bc61245b5aca347 (patch) | |
tree | 5f3e5149ffa14bc0adcee59a1109b1b7f60f87ee | |
parent | 8237627f3a7255e0dbae61a8090a81596d0cba8a (diff) | |
download | Hyprland-3cba4ba44e7ba3cc8bb67ac71bc61245b5aca347.tar.gz Hyprland-3cba4ba44e7ba3cc8bb67ac71bc61245b5aca347.zip |
hyprctl: avoid crash on null pwuid
fixes #8693
-rw-r--r-- | hyprctl/main.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 4ee2d598..4092bca0 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -52,11 +52,17 @@ void log(const std::string& str) { std::println("{}", str); } +static int getUID() { + const auto UID = getuid(); + const auto PWUID = getpwuid(UID); + return PWUID ? PWUID->pw_uid : UID; +} + std::string getRuntimeDir() { const auto XDG = getenv("XDG_RUNTIME_DIR"); if (!XDG) { - const std::string USERID = std::to_string(getpwuid(getuid())->pw_uid); + const std::string USERID = std::to_string(getUID()); return "/run/user/" + USERID + "/hypr"; } @@ -168,7 +174,7 @@ int request(std::string arg, int minArgs = 0, bool needRoll = false) { return 2; } - const std::string USERID = std::to_string(getpwuid(getuid())->pw_uid); + const std::string USERID = std::to_string(getUID()); sockaddr_un serverAddress = {0}; serverAddress.sun_family = AF_UNIX; @@ -238,7 +244,7 @@ int requestHyprpaper(std::string arg) { sockaddr_un serverAddress = {0}; serverAddress.sun_family = AF_UNIX; - const std::string USERID = std::to_string(getpwuid(getuid())->pw_uid); + const std::string USERID = std::to_string(getUID()); std::string socketPath = getRuntimeDir() + "/" + instanceSignature + "/.hyprpaper.sock"; |