st-flexipatch

My st-flexipatch configuration
git clone git://git.ethandl.dev/st-flexipatch
Log | Files | Refs | README | LICENSE

commit 78adbd240620747af25dd54454564a60c1b179f7
parent f0e4dc3bd5a4d5aa91ce6503176bfd965d442717
Author: bakkeby <bakkeby@gmail.com>
Date:   Tue, 24 Aug 2021 14:57:35 +0200

fix a problem that the standard streams are unexpectedly closed

In the current implementation, the slave PTY (assigned to the variable
`s') is always closed after duplicating it to file descriptors of
standard streams (0, 1, and 2). However, when the allocated slave PTY
`s' is already one of 0, 1, or 2, this causes unexpected closing of a
standard stream. The same problem occurs when the file descriptor of
the master PTY (the variable `m') is one of 0, 1, or 2.

In this patch, the original master PTY (m) is closed before it would
be overwritten by duplicated slave PTYs. The original slave PTY (s)
is closed only when it is not one of the standarad streams.

Ref. https://git.suckless.org/st/commit/1d3142da968da7f6f61f1c1708f39ca233eda150.html

Diffstat:
Mst.c | 3+++
1 file changed, 3 insertions(+), 0 deletions(-)

diff --git a/st.c b/st.c @@ -1073,6 +1073,7 @@ ttynew(const char *line, char *cmd, const char *out, char **args) break; case 0: close(iofd); + close(m); setsid(); /* create a new process group */ dup2(s, 0); dup2(s, 1); @@ -1081,6 +1082,8 @@ ttynew(const char *line, char *cmd, const char *out, char **args) die("ioctl TIOCSCTTY failed: %s\n", strerror(errno)); close(s); close(m); + if (s > 2) + close(s); #ifdef __OpenBSD__ if (pledge("stdio getpw proc exec", NULL) == -1) die("pledge\n");