From b8ecd1869e364f4f7fed2c819240d7de30b97721 Mon Sep 17 00:00:00 2001 From: tsxv478 Date: Sun, 17 Jul 2022 04:33:36 +0300 Subject: newterm orphan patch --- st.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'st.c') diff --git a/st.c b/st.c index f0d5f8a..a778e61 100644 --- a/st.c +++ b/st.c @@ -181,6 +181,7 @@ typedef struct { } STREscape; static void execsh(char *, char **); +static char *getcwd_by_pid(pid_t pid); static void stty(char **); static void sigchld(int); static void ttywriteraw(const char *, size_t); @@ -1089,6 +1090,37 @@ tcursor(int mode) } } +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: + res = chdir(getcwd_by_pid(pid)); + execlp("st", "./st", NULL); + break; + default: + exit(0); + } + default: + wait(NULL); + } +} + +static char *getcwd_by_pid(pid_t pid) { + char buf[32]; + snprintf(buf, sizeof buf, "/proc/%d/cwd", pid); + return realpath(buf, NULL); +} + void tresetcursor(void) { -- cgit v1.2.3