Related: #56353 - drop workaround for broken terminals over serial port

This commit is contained in:
Kamil Dudka 2017-05-17 13:46:34 +02:00
parent 2524ac4722
commit 16616a0fe1
2 changed files with 4 additions and 79 deletions

View File

@ -1,73 +0,0 @@
Src/builtin.c | 2 +-
Src/init.c | 34 ++++++++++++++++++++++++++++++++--
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/Src/builtin.c b/Src/builtin.c
index 9358e8b..ee14f91 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5859,7 +5859,7 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
if (!zleactive) {
if (SHTTY == -1) {
/* need to open /dev/tty specially */
- if ((SHTTY = open("/dev/tty", O_RDWR|O_NOCTTY)) != -1) {
+ if ((SHTTY = block_open("/dev/tty", O_RDWR|O_NOCTTY)) != -1) {
haso = 1;
oshout = shout;
init_shout();
diff --git a/Src/init.c b/Src/init.c
index 102276a..238f6ed 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -545,7 +545,7 @@ init_io(char *cmd)
if (isatty(0)) {
zsfree(ttystrname);
if ((ttystrname = ztrdup(ttyname(0)))) {
- SHTTY = movefd(open(ttystrname, O_RDWR | O_NOCTTY));
+ SHTTY = movefd(block_open(ttystrname, O_RDWR | O_NOCTTY));
#ifdef TIOCNXCL
/*
* See if the terminal claims to be busy. If so, and fd 0
@@ -586,7 +586,7 @@ init_io(char *cmd)
ttystrname = ztrdup(ttyname(1));
}
if (SHTTY == -1 &&
- (SHTTY = movefd(open("/dev/tty", O_RDWR | O_NOCTTY))) != -1) {
+ (SHTTY = movefd(block_open("/dev/tty", O_RDWR | O_NOCTTY))) != -1) {
zsfree(ttystrname);
ttystrname = ztrdup(ttyname(SHTTY));
}
@@ -1725,3 +1725,33 @@ zsh_main(UNUSED(int argc), char **argv)
: "use 'logout' to logout.");
}
}
+
+/**/
+int
+block_open (const char *tty, int flags)
+{
+ int saved_errno;
+ int fd;
+
+ if ((flags & O_NONBLOCK) == 0) {
+ fd = open (tty, flags | O_NONBLOCK);
+ if (fd == -1)
+ return fd;
+ flags = fcntl(fd, F_GETFL);
+ if (flags == -1)
+ goto bad;
+ flags &= ~O_NONBLOCK;
+ if (fcntl(fd, F_SETFL, flags) == -1)
+ goto bad;
+ }
+ else
+ fd = open (tty, flags);
+
+ return fd;
+
+bad:
+ saved_errno = errno;
+ close (fd);
+ errno = saved_errno;
+ return -1;
+}

View File

@ -3,7 +3,7 @@
Summary: Powerful interactive shell Summary: Powerful interactive shell
Name: zsh Name: zsh
Version: 5.3.1 Version: 5.3.1
Release: 5%{?dist} Release: 6%{?dist}
License: MIT License: MIT
URL: http://zsh.sourceforge.net/ URL: http://zsh.sourceforge.net/
Group: System Environment/Shells Group: System Environment/Shells
@ -16,11 +16,6 @@ Source5: zshenv.rhs
Source6: dotzshrc Source6: dotzshrc
Source7: zshprompt.pl Source7: zshprompt.pl
%if 0%{?epel} != 6
# legacy downstream patches, TODO: either get them upstream or drop them
Patch0: zsh-serial.patch
%endif
BuildRequires: coreutils BuildRequires: coreutils
BuildRequires: gawk BuildRequires: gawk
BuildRequires: gdbm-devel BuildRequires: gdbm-devel
@ -178,6 +173,9 @@ fi
%doc Doc/*.html %doc Doc/*.html
%changelog %changelog
* Wed May 17 2017 Kamil Dudka <kdudka@redhat.com> - 5.3.1-6
- drop workaround for broken terminals over serial port (#56353)
* Thu May 11 2017 Kamil Dudka <kdudka@redhat.com> - 5.3.1-5 * Thu May 11 2017 Kamil Dudka <kdudka@redhat.com> - 5.3.1-5
- compile with -fconserve-stack to prevent stack overflow (#1441092) - compile with -fconserve-stack to prevent stack overflow (#1441092)