Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/dispatch/bind_define.h
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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_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);
}
return 0;
Expand Down
4 changes: 4 additions & 0 deletions src/mango.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@
#include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/log.h>
#include <wlr/util/region.h>
#ifndef __OpenBSD__
#include <wordexp.h>
#else
#include <glob.h>
#endif
#include <xkbcommon/xkbcommon.h>
#ifdef XWAYLAND
#include <X11/Xlib.h>
Expand Down