mirror of
https://github.com/DreamMaoMao/maomaowm.git
synced 2026-05-02 06:46:29 -04:00
Add OpenBSD Support
OpenBSD does not have wordexp, therefore we need to add a reasonable approximation of mango's standard behavior when spawning commands.
This commit is contained in:
parent
e83a9dff82
commit
d2bf1e6bd4
2 changed files with 46 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue