spawm支持~

This commit is contained in:
DreamMaoMao 2025-02-16 21:38:31 +08:00
parent 57d4775e73
commit 4bfcf11619

View file

@ -3,6 +3,7 @@
*/ */
#include <getopt.h> #include <getopt.h>
#include <libinput.h> #include <libinput.h>
#include <wordexp.h>
#include <signal.h> #include <signal.h>
#include <execinfo.h> #include <execinfo.h>
#include <limits.h> #include <limits.h>
@ -4735,7 +4736,6 @@ void sigchld(int unused) {
} }
void spawn(const Arg *arg) { void spawn(const Arg *arg) {
if (fork() == 0) { if (fork() == 0) {
dup2(STDERR_FILENO, STDOUT_FILENO); dup2(STDERR_FILENO, STDOUT_FILENO);
setsid(); setsid();
@ -4745,7 +4745,13 @@ void spawn(const Arg *arg) {
int argc = 0; int argc = 0;
char *token = strtok((char *)arg->v, " "); char *token = strtok((char *)arg->v, " ");
while (token != NULL && argc < 63) { while (token != NULL && argc < 63) {
argv[argc++] = token; // 扩展 ~ 为家目录路径
wordexp_t p;
if (wordexp(token, &p, 0) == 0) {
argv[argc++] = p.we_wordv[0];
} else {
argv[argc++] = token; // 如果扩展失败,使用原始 token
}
token = strtok(NULL, " "); token = strtok(NULL, " ");
} }
argv[argc] = NULL; // execvp 需要以 NULL 结尾的数组 argv[argc] = NULL; // execvp 需要以 NULL 结尾的数组