X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=st.c;h=3abf1b021258ce2b7f16f24bd1e14aa3247ed595;hb=ddb08dfe82ca196bb4f6e554e7db0fd32da58ba2;hp=324c59805d20e7b9eb15e4d7e76efc196d4cd193;hpb=181c9f3ba9a0d9bb36b372f3dc04c966a95f491e;p=st.git diff --git a/st.c b/st.c index 324c598..3abf1b0 100644 --- a/st.c +++ b/st.c @@ -28,6 +28,9 @@ #elif defined(__FreeBSD__) || defined(__DragonFly__) #include #endif +#if defined(__OpenBSD__) + #include +#endif /* Arbitrary sizes */ #define UTF_INVALID 0xFFFD @@ -157,6 +160,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); @@ -242,6 +246,22 @@ static TCursor c[3]; static inline int rows() { return IS_SET(MODE_ALTSCREEN) ? term.row : buffSize;} static inline int rangeY(int i) { while (i < 0) i += rows(); return i % rows();} +int +subprocwd(char *path) +{ +#if defined(__linux) + if (snprintf(path, PATH_MAX, "/proc/%d/cwd", pid) < 0) + return -1; + return 0; +#elif defined(__OpenBSD__) + size_t sz = PATH_MAX; + int name[3] = {CTL_KERN, KERN_PROC_CWD, pid}; + if (sysctl(name, 3, path, &sz, 0, 0) == -1) + return -1; + return 0; +#endif +} + ssize_t xwrite(int fd, const char *s, size_t len) { @@ -811,7 +831,7 @@ ttynew(char *line, char *cmd, char *out, char **args) break; default: #ifdef __OpenBSD__ - if (pledge("stdio rpath tty proc", NULL) == -1) + if (pledge("stdio rpath tty proc ps exec", NULL) == -1) die("pledge\n"); #endif close(s); @@ -1061,6 +1081,26 @@ tswapscreen(void) tfulldirt(); } +void +newterm(const Arg* a) +{ + switch (fork()) { + case -1: + die("fork failed: %s\n", strerror(errno)); + break; + case 0: + chdir(getcwd_by_pid(pid)); + execlp("st", "./st", NULL); + break; + } +} + +static char *getcwd_by_pid(pid_t pid) { + char buf[32]; + snprintf(buf, sizeof buf, "/proc/%d/cwd", pid); + return realpath(buf, NULL); +} + void tscrolldown(int orig, int n) {