diff options
author | tsxv478 <vt0451@yandex.ru> | 2022-07-17 04:33:36 +0300 |
---|---|---|
committer | tsxv478 <vt0451@yandex.ru> | 2022-07-17 04:33:36 +0300 |
commit | b8ecd1869e364f4f7fed2c819240d7de30b97721 (patch) | |
tree | 3548be793a6a01937fd200b5a2686cf3b3a9c45e /st.c | |
parent | 32d72cf9b50ba1c28803e641cbd87df4f421476c (diff) |
newterm orphan patch
Diffstat (limited to 'st.c')
-rw-r--r-- | st.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -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); @@ -1090,6 +1091,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) { term.c = (TCursor){ { .mode = ATTR_NULL, .fg = defaultfg, .bg = defaultbg }, |