From 6961bf2e4ce2c116e41a8db158691f6c993707ce Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Sun, 14 Apr 2019 00:27:47 -0400 Subject: Spawn swaynag as a wayland client This spawns swaynag as a wayland client similar to how swaybar and swaybg are already done --- swaynag/swaynag.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'swaynag') diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c index eb31da57..26411ab3 100644 --- a/swaynag/swaynag.c +++ b/swaynag/swaynag.c @@ -45,17 +45,24 @@ static void swaynag_button_execute(struct swaynag *swaynag, swaynag->details.visible = !swaynag->details.visible; render_frame(swaynag); } else { - if (fork() == 0) { + pid_t pid = fork(); + if (pid < 0) { + sway_log_errno(SWAY_DEBUG, "Failed to fork"); + return; + } else if (pid == 0) { // Child process. Will be used to prevent zombie processes - setsid(); - if (fork() == 0) { + pid = fork(); + if (pid < 0) { + sway_log_errno(SWAY_DEBUG, "Failed to fork"); + return; + } else if (pid == 0) { // Child of the child. Will be reparented to the init process char *terminal = getenv("TERMINAL"); if (button->terminal && terminal && strlen(terminal)) { sway_log(SWAY_DEBUG, "Found $TERMINAL: %s", terminal); if (!terminal_execute(terminal, button->action)) { swaynag_destroy(swaynag); - exit(EXIT_FAILURE); + _exit(EXIT_FAILURE); } } else { if (button->terminal) { @@ -63,12 +70,16 @@ static void swaynag_button_execute(struct swaynag *swaynag, "$TERMINAL not found. Running directly"); } execl("/bin/sh", "/bin/sh", "-c", button->action, NULL); + sway_log_errno(SWAY_DEBUG, "execl failed"); + _exit(EXIT_FAILURE); } } - exit(EXIT_SUCCESS); + _exit(EXIT_SUCCESS); + } + if (waitpid(pid, NULL, 0) < 0) { + sway_log_errno(SWAY_DEBUG, "waitpid failed"); } } - wait(0); } static void layer_surface_configure(void *data, -- cgit v1.2.3