aboutsummaryrefslogtreecommitdiff
path: root/swaynag
diff options
context:
space:
mode:
authorBrian Ashworth <bosrsf04@gmail.com>2019-04-14 00:27:47 -0400
committerSimon Ser <contact@emersion.fr>2019-04-14 12:41:59 +0300
commit6961bf2e4ce2c116e41a8db158691f6c993707ce (patch)
treea381146599a5f19e565006cafeb23edc04247d2b /swaynag
parent8c69da11bbe70caa2f5db1665e9d60387604c5e4 (diff)
Spawn swaynag as a wayland client
This spawns swaynag as a wayland client similar to how swaybar and swaybg are already done
Diffstat (limited to 'swaynag')
-rw-r--r--swaynag/swaynag.c23
1 files changed, 17 insertions, 6 deletions
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,