mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-08 04:45:59 +01:00
use spawn in config exec
This commit is contained in:
parent
851df11eb5
commit
153c99217d
2 changed files with 3 additions and 56 deletions
|
@ -388,62 +388,7 @@ void CConfigManager::configSetValueSafe(const std::string& COMMAND, const std::s
|
|||
|
||||
void CConfigManager::handleRawExec(const std::string& command, const std::string& args) {
|
||||
// Exec in the background dont wait for it.
|
||||
|
||||
std::string toExec = args;
|
||||
|
||||
if (g_pXWaylandManager->m_sWLRXWayland)
|
||||
toExec = std::string("WAYLAND_DISPLAY=") + std::string(g_pCompositor->m_szWLDisplaySocket) + " DISPLAY=" + std::string(g_pXWaylandManager->m_sWLRXWayland->display_name) + " " + toExec;
|
||||
else
|
||||
toExec = std::string("WAYLAND_DISPLAY=") + std::string(g_pCompositor->m_szWLDisplaySocket) + " " + toExec;
|
||||
|
||||
Debug::log(LOG, "Config executing %s", toExec.c_str());
|
||||
|
||||
int socket[2];
|
||||
if (pipe(socket) != 0) {
|
||||
Debug::log(LOG, "Unable to create pipe for fork");
|
||||
}
|
||||
|
||||
pid_t child, grandchild;
|
||||
child = fork();
|
||||
if (child < 0) {
|
||||
close(socket[0]);
|
||||
close(socket[1]);
|
||||
Debug::log(LOG, "Fail to create the first fork");
|
||||
return;
|
||||
}
|
||||
if (child == 0) {
|
||||
// run in child
|
||||
grandchild = fork();
|
||||
|
||||
sigset_t set;
|
||||
sigemptyset(&set);
|
||||
sigprocmask(SIG_SETMASK, &set, NULL);
|
||||
|
||||
if (grandchild == 0) {
|
||||
// run in grandchild
|
||||
close(socket[0]);
|
||||
close(socket[1]);
|
||||
execl("/bin/sh", "/bin/sh", "-c", toExec.c_str(), nullptr);
|
||||
// exit grandchild
|
||||
_exit(0);
|
||||
}
|
||||
close(socket[0]);
|
||||
write(socket[1], &grandchild, sizeof(grandchild));
|
||||
close(socket[1]);
|
||||
// exit child
|
||||
_exit(0);
|
||||
}
|
||||
// run in parent
|
||||
close(socket[1]);
|
||||
read(socket[0], &grandchild, sizeof(grandchild));
|
||||
close(socket[0]);
|
||||
// clear child and leave child to init
|
||||
waitpid(child, NULL, 0);
|
||||
if (child < 0) {
|
||||
Debug::log(LOG, "Fail to create the second fork");
|
||||
return;
|
||||
}
|
||||
Debug::log(LOG, "Process created with pid %d", grandchild);
|
||||
g_pKeybindManager->spawn(args);
|
||||
}
|
||||
|
||||
void CConfigManager::handleMonitor(const std::string& command, const std::string& args) {
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <functional>
|
||||
|
||||
class CInputManager;
|
||||
class CConfigManager;
|
||||
|
||||
struct SKeybind {
|
||||
std::string key = "";
|
||||
|
@ -125,6 +126,7 @@ private:
|
|||
|
||||
friend class CCompositor;
|
||||
friend class CInputManager;
|
||||
friend class CConfigManager;
|
||||
};
|
||||
|
||||
inline std::unique_ptr<CKeybindManager> g_pKeybindManager;
|
||||
|
|
Loading…
Reference in a new issue