apply newterm patch

This commit is contained in:
2023-03-19 12:10:05 +01:00
parent 033298508e
commit 3240bec57c
4 changed files with 45 additions and 3 deletions

36
st.c
View File

@ -20,6 +20,8 @@
#include "st.h"
#include "win.h"
extern char *argv0;
#if defined(__linux)
#include <pty.h>
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
@ -162,6 +164,7 @@ typedef struct {
} STREscape;
static void execsh(char *, char **);
static int chdir_by_pid(pid_t pid);
static void stty(char **);
static void sigchld(int);
static void ttywriteraw(const char *, size_t);
@ -831,6 +834,7 @@ ttynew(const char *line, char *cmd, const char *out, char **args)
if (pledge("stdio rpath tty proc", NULL) == -1)
die("pledge\n");
#endif
fcntl(m, F_SETFD, FD_CLOEXEC);
close(s);
cmdfd = m;
signal(SIGCHLD, sigchld);
@ -1082,6 +1086,38 @@ tswapscreen(void)
tfulldirt();
}
void
newterm(const Arg* a)
{
int res;
switch (fork()) {
case -1:
die("fork failed: %s\n", strerror(errno));
break;
case 0:
switch (fork()) {
case -1:
die("fork failed: %s\n", strerror(errno));
break;
case 0:
chdir_by_pid(pid);
execlp("/proc/self/exe", argv0, NULL);
exit(1);
break;
default:
exit(0);
}
default:
wait(NULL);
}
}
static int chdir_by_pid(pid_t pid) {
char buf[32];
snprintf(buf, sizeof buf, "/proc/%ld/cwd", (long)pid);
return chdir(buf);
}
void
kscrolldown(const Arg* a)
{