st-externalpipe-0.8.5.diff - sites - public wiki contents of suckless.org | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
st-externalpipe-0.8.5.diff (2296B) | |
--- | |
1 diff --git a/st.c b/st.c | |
2 index 034954d..98f2589 100644 | |
3 --- a/st.c | |
4 +++ b/st.c | |
5 @@ -718,8 +718,14 @@ sigchld(int a) | |
6 if ((p = waitpid(pid, &stat, WNOHANG)) < 0) | |
7 die("waiting for pid %hd failed: %s\n", pid, strerror(e… | |
8 | |
9 - if (pid != p) | |
10 + if (pid != p) { | |
11 + if (p == 0 && wait(&stat) < 0) | |
12 + die("wait: %s\n", strerror(errno)); | |
13 + | |
14 + /* reinstall sigchld handler */ | |
15 + signal(SIGCHLD, sigchld); | |
16 return; | |
17 + } | |
18 | |
19 if (WIFEXITED(stat) && WEXITSTATUS(stat)) | |
20 die("child exited with status %d\n", WEXITSTATUS(stat)); | |
21 @@ -803,7 +809,7 @@ ttynew(const char *line, char *cmd, const char *out,… | |
22 break; | |
23 default: | |
24 #ifdef __OpenBSD__ | |
25 - if (pledge("stdio rpath tty proc", NULL) == -1) | |
26 + if (pledge("stdio rpath tty proc exec", NULL) == -1) | |
27 die("pledge\n"); | |
28 #endif | |
29 close(s); | |
30 @@ -1991,6 +1997,59 @@ strparse(void) | |
31 } | |
32 } | |
33 | |
34 +void | |
35 +externalpipe(const Arg *arg) | |
36 +{ | |
37 + int to[2]; | |
38 + char buf[UTF_SIZ]; | |
39 + void (*oldsigpipe)(int); | |
40 + Glyph *bp, *end; | |
41 + int lastpos, n, newline; | |
42 + | |
43 + if (pipe(to) == -1) | |
44 + return; | |
45 + | |
46 + switch (fork()) { | |
47 + case -1: | |
48 + close(to[0]); | |
49 + close(to[1]); | |
50 + return; | |
51 + case 0: | |
52 + dup2(to[0], STDIN_FILENO); | |
53 + close(to[0]); | |
54 + close(to[1]); | |
55 + execvp(((char **)arg->v)[0], (char **)arg->v); | |
56 + fprintf(stderr, "st: execvp %s\n", ((char **)arg->v)[0]… | |
57 + perror("failed"); | |
58 + exit(0); | |
59 + } | |
60 + | |
61 + close(to[0]); | |
62 + /* ignore sigpipe for now, in case child exists early */ | |
63 + oldsigpipe = signal(SIGPIPE, SIG_IGN); | |
64 + newline = 0; | |
65 + for (n = 0; n < term.row; n++) { | |
66 + bp = term.line[n]; | |
67 + lastpos = MIN(tlinelen(n) + 1, term.col) - 1; | |
68 + if (lastpos < 0) | |
69 + break; | |
70 + end = &bp[lastpos + 1]; | |
71 + for (; bp < end; ++bp) | |
72 + if (xwrite(to[1], buf, utf8encode(bp->u, buf)) … | |
73 + break; | |
74 + if ((newline = term.line[n][lastpos].mode & ATTR_WRAP)) | |
75 + continue; | |
76 + if (xwrite(to[1], "\n", 1) < 0) | |
77 + break; | |
78 + newline = 0; | |
79 + } | |
80 + if (newline) | |
81 + (void)xwrite(to[1], "\n", 1); | |
82 + close(to[1]); | |
83 + /* restore */ | |
84 + signal(SIGPIPE, oldsigpipe); | |
85 +} | |
86 + | |
87 void | |
88 strdump(void) | |
89 { | |
90 diff --git a/st.h b/st.h | |
91 index fd3b0d8..754cd08 100644 | |
92 --- a/st.h | |
93 +++ b/st.h | |
94 @@ -81,6 +81,7 @@ void die(const char *, ...); | |
95 void redraw(void); | |
96 void draw(void); | |
97 | |
98 +void externalpipe(const Arg *); | |
99 void printscreen(const Arg *); | |
100 void printsel(const Arg *); | |
101 void sendbreak(const Arg *); | |
102 -- | |
103 2.42.0 | |
104 |