This commit is contained in:
Volker Schlecht 2026-06-18 22:54:31 -07:00 committed by GitHub
commit d92045cf8c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 1 deletions

View file

@ -1,3 +1,7 @@
#ifdef __OpenBSD__
#define SPAWN_MAX_ARGS 64
#endif
int32_t bind_to_view(const Arg *arg) { int32_t bind_to_view(const Arg *arg) {
if (!selmon) if (!selmon)
return 0; return 0;
@ -962,6 +966,7 @@ int32_t spawn(const Arg *arg) {
dup2(STDERR_FILENO, STDOUT_FILENO); dup2(STDERR_FILENO, STDOUT_FILENO);
setsid(); setsid();
#ifndef __OpenBSD__
wordexp_t p; wordexp_t p;
if (wordexp(arg->v, &p, 0) != 0) { if (wordexp(arg->v, &p, 0) != 0) {
wlr_log(WLR_DEBUG, "mango: wordexp failed for '%s'\n", wlr_log(WLR_DEBUG, "mango: wordexp failed for '%s'\n",
@ -974,6 +979,42 @@ int32_t spawn(const Arg *arg) {
wlr_log(WLR_DEBUG, "mango: execvp '%s' failed: %s\n", p.we_wordv[0], wlr_log(WLR_DEBUG, "mango: execvp '%s' failed: %s\n", p.we_wordv[0],
strerror(errno)); strerror(errno));
wordfree(&p); wordfree(&p);
#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_ARGS - 1) {
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_r(NULL, " ", &last);
}
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); _exit(EXIT_FAILURE);
} }
return 0; return 0;
@ -2042,4 +2083,4 @@ int32_t focusid(const Arg *arg) {
Client *c = arg->tc; Client *c = arg->tc;
client_active(c); client_active(c);
return 0; return 0;
} }

View file

@ -88,7 +88,11 @@
#include <wlr/types/wlr_xdg_shell.h> #include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include <wlr/util/region.h> #include <wlr/util/region.h>
#ifndef __OpenBSD__
#include <wordexp.h> #include <wordexp.h>
#else
#include <glob.h>
#endif
#include <xkbcommon/xkbcommon.h> #include <xkbcommon/xkbcommon.h>
#ifdef XWAYLAND #ifdef XWAYLAND
#include <X11/Xlib.h> #include <X11/Xlib.h>