From d2bf1e6bd4df4c0baf4a1e6650a31db8abcd458e Mon Sep 17 00:00:00 2001 From: GH <47375452+VlkrS@users.noreply.github.com> Date: Fri, 10 Apr 2026 19:03:04 +0200 Subject: [PATCH 1/2] Add OpenBSD Support OpenBSD does not have wordexp, therefore we need to add a reasonable approximation of mango's standard behavior when spawning commands. --- src/dispatch/bind_define.h | 42 ++++++++++++++++++++++++++++++++++++++ src/mango.c | 4 ++++ 2 files changed, 46 insertions(+) diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index f5992e29..89772e16 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -1,3 +1,8 @@ +#ifdef __OpenBSD__ +#define SPAWN_MAX_ARGS 64 +#define SPAWN_MAX_TOKENS (SPAWN_MAX_ARGS - 1) +#endif + int32_t bind_to_view(const Arg *arg) { if (!selmon) return 0; @@ -875,6 +880,7 @@ int32_t spawn(const Arg *arg) { dup2(STDERR_FILENO, STDOUT_FILENO); setsid(); +#ifndef __OpenBSD__ // 2. 对整个参数字符串进行单词展开 wordexp_t p; if (wordexp(arg->v, &p, 0) != 0) { @@ -889,6 +895,42 @@ int32_t spawn(const Arg *arg) { wlr_log(WLR_DEBUG, "mango: execvp '%s' failed: %s\n", p.we_wordv[0], strerror(errno)); wordfree(&p); // 释放 wordexp 分配的内存 +#else + int argc = 0; + char *last; + char *argv[SPAWN_MAX_ARGS]; + + char *token = strtok_r((char *)arg->v, " ", &last); + + while (token != NULL && argc < SPAWN_MAX_TOKENS) { + glob_t p; + if (glob(token, GLOB_DOOFFS, NULL, &p) == 0 && p.gl_pathc > 0) { + argv[argc] = strdup(p.gl_pathv[0]); + globfree(&p); + } else { + argv[argc] = strdup(token); + } + argc++; + token = strtok(NULL, " "); + } + + if (argc == 0) { + return 0; + } + + argv[argc] = NULL; + + execvp(argv[0], argv); + + wlr_log(WLR_ERROR, "mango: execvp '%s' failed: %s\n", + argv[0] ? argv[0] : "NULL", strerror(errno)); + + /* Cleanup */ + for (int i = 0; i < argc; i++) { + free(argv[i]); + } + +#endif _exit(EXIT_FAILURE); } return 0; diff --git a/src/mango.c b/src/mango.c index 8fdff709..cf077875 100644 --- a/src/mango.c +++ b/src/mango.c @@ -85,7 +85,11 @@ #include #include #include +#ifndef __OpenBSD__ #include +#else +#include +#endif #include #ifdef XWAYLAND #include From bdcfe21aceb195e19bf580f2e7faf2609b6912fe Mon Sep 17 00:00:00 2001 From: GH <47375452+VlkrS@users.noreply.github.com> Date: Fri, 10 Apr 2026 19:16:26 +0200 Subject: [PATCH 2/2] Use strtok_r consistently --- src/dispatch/bind_define.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dispatch/bind_define.h b/src/dispatch/bind_define.h index 89772e16..1c79ec1b 100644 --- a/src/dispatch/bind_define.h +++ b/src/dispatch/bind_define.h @@ -911,7 +911,7 @@ int32_t spawn(const Arg *arg) { argv[argc] = strdup(token); } argc++; - token = strtok(NULL, " "); + token = strtok_r(NULL, " ", &last); } if (argc == 0) {