commands/exec: redirect child stdio to /dev/null

Children spawned via exec inherit sway's stdio pointing to the launch
TTY. wlroots puts the TTY in KD_GRAPHICS mode, where writes block,
causing programs that write to stdout/stderr on startup (e.g. Electron
apps) to hang.
This commit is contained in:
Sungjoon Moon 2026-02-08 01:17:47 +09:00
parent fa497964fd
commit bd81e3c71f

View file

@ -1,3 +1,4 @@
#include <fcntl.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
@ -53,6 +54,14 @@ struct cmd_results *cmd_exec_process(int argc, char **argv) {
if (child == 0) { if (child == 0) {
setsid(); setsid();
int devnull = open("/dev/null", O_RDWR);
if (devnull > STDERR_FILENO) {
dup2(devnull, STDIN_FILENO);
dup2(devnull, STDOUT_FILENO);
dup2(devnull, STDERR_FILENO);
close(devnull);
}
if (ctx) { if (ctx) {
const char *token = launcher_ctx_get_token_name(ctx); const char *token = launcher_ctx_get_token_name(ctx);
setenv("XDG_ACTIVATION_TOKEN", token, 1); setenv("XDG_ACTIVATION_TOKEN", token, 1);