diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-04-14 00:27:47 -0400 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2019-04-14 12:41:59 +0300 |
commit | 6961bf2e4ce2c116e41a8db158691f6c993707ce (patch) | |
tree | a381146599a5f19e565006cafeb23edc04247d2b /swaynag/swaynag.c | |
parent | swaynag: fix pointer management (diff) | |
download | sway-6961bf2e4ce2c116e41a8db158691f6c993707ce.tar.gz sway-6961bf2e4ce2c116e41a8db158691f6c993707ce.tar.zst sway-6961bf2e4ce2c116e41a8db158691f6c993707ce.zip |
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/swaynag.c')
-rw-r--r-- | swaynag/swaynag.c | 23 |
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, | |||
45 | swaynag->details.visible = !swaynag->details.visible; | 45 | swaynag->details.visible = !swaynag->details.visible; |
46 | render_frame(swaynag); | 46 | render_frame(swaynag); |
47 | } else { | 47 | } else { |
48 | if (fork() == 0) { | 48 | pid_t pid = fork(); |
49 | if (pid < 0) { | ||
50 | sway_log_errno(SWAY_DEBUG, "Failed to fork"); | ||
51 | return; | ||
52 | } else if (pid == 0) { | ||
49 | // Child process. Will be used to prevent zombie processes | 53 | // Child process. Will be used to prevent zombie processes |
50 | setsid(); | 54 | pid = fork(); |
51 | if (fork() == 0) { | 55 | if (pid < 0) { |
56 | sway_log_errno(SWAY_DEBUG, "Failed to fork"); | ||
57 | return; | ||
58 | } else if (pid == 0) { | ||
52 | // Child of the child. Will be reparented to the init process | 59 | // Child of the child. Will be reparented to the init process |
53 | char *terminal = getenv("TERMINAL"); | 60 | char *terminal = getenv("TERMINAL"); |
54 | if (button->terminal && terminal && strlen(terminal)) { | 61 | if (button->terminal && terminal && strlen(terminal)) { |
55 | sway_log(SWAY_DEBUG, "Found $TERMINAL: %s", terminal); | 62 | sway_log(SWAY_DEBUG, "Found $TERMINAL: %s", terminal); |
56 | if (!terminal_execute(terminal, button->action)) { | 63 | if (!terminal_execute(terminal, button->action)) { |
57 | swaynag_destroy(swaynag); | 64 | swaynag_destroy(swaynag); |
58 | exit(EXIT_FAILURE); | 65 | _exit(EXIT_FAILURE); |
59 | } | 66 | } |
60 | } else { | 67 | } else { |
61 | if (button->terminal) { | 68 | if (button->terminal) { |
@@ -63,12 +70,16 @@ static void swaynag_button_execute(struct swaynag *swaynag, | |||
63 | "$TERMINAL not found. Running directly"); | 70 | "$TERMINAL not found. Running directly"); |
64 | } | 71 | } |
65 | execl("/bin/sh", "/bin/sh", "-c", button->action, NULL); | 72 | execl("/bin/sh", "/bin/sh", "-c", button->action, NULL); |
73 | sway_log_errno(SWAY_DEBUG, "execl failed"); | ||
74 | _exit(EXIT_FAILURE); | ||
66 | } | 75 | } |
67 | } | 76 | } |
68 | exit(EXIT_SUCCESS); | 77 | _exit(EXIT_SUCCESS); |
78 | } | ||
79 | if (waitpid(pid, NULL, 0) < 0) { | ||
80 | sway_log_errno(SWAY_DEBUG, "waitpid failed"); | ||
69 | } | 81 | } |
70 | } | 82 | } |
71 | wait(0); | ||
72 | } | 83 | } |
73 | 84 | ||
74 | static void layer_surface_configure(void *data, | 85 | static void layer_surface_configure(void *data, |