aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin J. Pohly <djpohly@gmail.com>2021-04-14 11:15:26 -0500
committerDevin J. Pohly <djpohly@gmail.com>2021-04-14 11:23:23 -0500
commitb372d4b55e256b96fe926c512499ed90c460d66f (patch)
tree6cfb23e17e2709401dea5e084991f327b0f432b4
parent9071ce6c848ce214939fb84f85ae77de86de88d7 (diff)
pipe status info into -s command
Unlike with X window managers, the display socket in Wayland isn't set up prior to starting the compositor. Because of this, you can't pipe the compositor's output directly into a program which needs access to $WAYLAND_DISPLAY, which is a typical setup for this purpose. Existing scripts have been forced to create a pipe/FIFO or a temporary file as an intermediary. Instead, send the status info directly to stdin of the -s command, which *does* have access to $WAYLAND_DISPLAY. Fixes #103.
-rw-r--r--dwl.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/dwl.c b/dwl.c
index d463985..f4b9b3a 100644
--- a/dwl.c
+++ b/dwl.c
@@ -1805,15 +1805,22 @@ run(char *startup_cmd)
setenv("WAYLAND_DISPLAY", socket, 1);
if (startup_cmd) {
+ int piperw[2];
+ pipe(piperw);
startup_pid = fork();
if (startup_pid < 0)
EBARF("startup: fork");
if (startup_pid == 0) {
- dup2(STDERR_FILENO, STDOUT_FILENO);
+ dup2(piperw[0], STDIN_FILENO);
+ close(piperw[1]);
execl("/bin/sh", "/bin/sh", "-c", startup_cmd, NULL);
EBARF("startup: execl");
}
+ dup2(piperw[1], STDOUT_FILENO);
+ close(piperw[0]);
}
+ /* If nobody is reading the status output, don't terminate */
+ signal(SIGPIPE, SIG_IGN);
/* Run the Wayland event loop. This does not return until you exit the
* compositor. Starting the backend rigged up all of the necessary event