aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-04-18 17:49:23 -0400
committerGitHub <noreply@github.com>2017-04-18 17:49:23 -0400
commit35603b2341e2e96f3f6cb53092f53bafcfe916d9 (patch)
tree61dbdc83a7353f5347d3843443b87c1c2ee28eff
parent17593ac5593c3bf2de824f26060aae90266f38bb (diff)
parentcee26500a86ccc6b508ae927136beadc4279de14 (diff)
downloadsway-35603b2341e2e96f3f6cb53092f53bafcfe916d9.zip
sway-35603b2341e2e96f3f6cb53092f53bafcfe916d9.tar.gz
sway-35603b2341e2e96f3f6cb53092f53bafcfe916d9.tar.bz2
Merge pull request #1178 from 4e554c4c/fork
Prevent sway from duplicating on a failed fork
-rw-r--r--sway/config.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/sway/config.c b/sway/config.c
index c8432a2..ae09d4f 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -912,8 +912,16 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
}
static void invoke_swaybar(struct bar_config *bar) {
+ // Pipe to communicate errors
+ int filedes[2];
+ if (pipe(filedes) == -1) {
+ sway_log(L_ERROR, "Pipe setup failed! Cannot fork into bar");
+ return;
+ }
+
bar->pid = fork();
if (bar->pid == 0) {
+ close(filedes[0]);
if (!bar->swaybar_command) {
char *const cmd[] = {
"swaybar",
@@ -922,14 +930,20 @@ static void invoke_swaybar(struct bar_config *bar) {
NULL,
};
+ close(filedes[1]);
execvp(cmd[0], cmd);
+ _exit(EXIT_SUCCESS);
} else {
// run custom swaybar
int len = strlen(bar->swaybar_command) + strlen(bar->id) + 5;
char *command = malloc(len * sizeof(char));
if (!command) {
- sway_log(L_ERROR, "Unable to allocate swaybar command string");
- return;
+ const char msg[] = "Unable to allocate swaybar command string";
+ int len = sizeof(msg);
+ write(filedes[1], &len, sizeof(int));
+ write(filedes[1], msg, len);
+ close(filedes[1]);
+ _exit(EXIT_FAILURE);
}
snprintf(command, len, "%s -b %s", bar->swaybar_command, bar->id);
@@ -940,10 +954,26 @@ static void invoke_swaybar(struct bar_config *bar) {
NULL,
};
+ close(filedes[1]);
execvp(cmd[0], cmd);
free(command);
+ _exit(EXIT_SUCCESS);
+ }
+ }
+ close(filedes[0]);
+ int len;
+ if(read(filedes[1], &len, sizeof(int)) == sizeof(int)) {
+ char *buf = malloc(len);
+ if(!buf) {
+ sway_log(L_ERROR, "Cannot allocate error string");
+ return;
+ }
+ if(read(filedes[1], buf, len)) {
+ sway_log(L_ERROR, "%s", buf);
}
+ free(buf);
}
+ close(filedes[1]);
}
static void terminate_swaybar(pid_t pid) {