Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libedit Disable attempts to handle EINTR and non-blockin...



details:   https://anonhg.NetBSD.org/src/rev/280ade96d0ff
branches:  trunk
changeset: 1022933:280ade96d0ff
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Aug 15 10:08:41 2021 +0000

description:
Disable attempts to handle EINTR and non-blocking I/O by default. It is
confusing to other programs and unexpected behavior. Reported by Ingo Schwarze.
This behavior is now controlled with EL_SAFEREAD.

diffstat:

 lib/libedit/editline.3 |  18 ++++++++++++++++--
 lib/libedit/el.c       |  17 +++++++++++++++--
 lib/libedit/el.h       |  15 ++++++++-------
 lib/libedit/eln.c      |   6 ++++--
 lib/libedit/histedit.h |   3 ++-
 lib/libedit/read.c     |   6 +++---
 6 files changed, 48 insertions(+), 17 deletions(-)

diffs (198 lines):

diff -r c1ff606c97d4 -r 280ade96d0ff lib/libedit/editline.3
--- a/lib/libedit/editline.3    Sun Aug 15 10:06:32 2021 +0000
+++ b/lib/libedit/editline.3    Sun Aug 15 10:08:41 2021 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: editline.3,v 1.99 2018/11/18 17:09:39 christos Exp $
+.\"    $NetBSD: editline.3,v 1.100 2021/08/15 10:08:41 christos Exp $
 .\"
 .\" Copyright (c) 1997-2014 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -26,7 +26,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd November 9, 2018
+.Dd August 15, 2021
 .Dt EDITLINE 3
 .Os
 .Sh NAME
@@ -507,6 +507,16 @@
 In unbuffered mode,
 .Fn el_gets
 will return immediately after processing a single character.
+.It Dv EL_SAFEREAD , Fa "int flag"
+If
+.Fa flag
+argument non zero, then
+.Nm editline
+attempts to recover from read errors, ignoring the first interrrupted
+error, and trying to reset the input file descriptor to reset non-blocking I/O.
+This is disabled by default, and desirable only when
+.Nm editline
+is used in shell-like applications.
 .It Dv EL_GETCFN , Fa "el_rfunc_t f"
 Whenever reading a character, use the function
 .Bd -ragged -offset indent -compact
@@ -634,6 +644,10 @@
 Set
 .Fa c
 to non-zero if unbuffered mode is enabled.
+.It Dv EL_SAFEREAD , Fa "int *c"
+Set
+.Fa c
+to non-zero if safe read is set.
 .It Dv EL_GETFP , Fa "int fd", Fa "FILE **fp"
 Set
 .Fa fp
diff -r c1ff606c97d4 -r 280ade96d0ff lib/libedit/el.c
--- a/lib/libedit/el.c  Sun Aug 15 10:06:32 2021 +0000
+++ b/lib/libedit/el.c  Sun Aug 15 10:08:41 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: el.c,v 1.99 2019/07/23 10:18:52 christos Exp $ */
+/*     $NetBSD: el.c,v 1.100 2021/08/15 10:08:41 christos Exp $        */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)el.c       8.2 (Berkeley) 1/3/94";
 #else
-__RCSID("$NetBSD: el.c,v 1.99 2019/07/23 10:18:52 christos Exp $");
+__RCSID("$NetBSD: el.c,v 1.100 2021/08/15 10:08:41 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -300,6 +300,14 @@
                break;
        }
 
+       case EL_SAFEREAD:
+               if (va_arg(ap, int))
+                       el->el_flags |= FIXIO;
+               else
+                       el->el_flags &= ~FIXIO;
+               rv = 0;
+               break;
+
        case EL_EDITMODE:
                if (va_arg(ap, int))
                        el->el_flags &= ~EDIT_DISABLED;
@@ -429,6 +437,11 @@
                rv = 0;
                break;
 
+       case EL_SAFEREAD:
+               *va_arg(ap, int *) = (el->el_flags & FIXIO);
+               rv = 0;
+               break;
+
        case EL_TERMINAL:
                terminal_get(el, va_arg(ap, const char **));
                rv = 0;
diff -r c1ff606c97d4 -r 280ade96d0ff lib/libedit/el.h
--- a/lib/libedit/el.h  Sun Aug 15 10:06:32 2021 +0000
+++ b/lib/libedit/el.h  Sun Aug 15 10:08:41 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: el.h,v 1.45 2019/07/23 10:18:52 christos Exp $ */
+/*     $NetBSD: el.h,v 1.46 2021/08/15 10:08:41 christos Exp $ */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -51,12 +51,13 @@
 
 #define        EL_BUFSIZ       ((size_t)1024)  /* Maximum line size            */
 
-#define        HANDLE_SIGNALS  0x01
-#define        NO_TTY          0x02
-#define        EDIT_DISABLED   0x04
-#define        UNBUFFERED      0x08
-#define        NARROW_HISTORY  0x40
-#define        NO_RESET        0x80
+#define        HANDLE_SIGNALS  0x001
+#define        NO_TTY          0x002
+#define        EDIT_DISABLED   0x004
+#define        UNBUFFERED      0x008
+#define        NARROW_HISTORY  0x040
+#define        NO_RESET        0x080
+#define        FIXIO           0x100
 
 typedef unsigned char el_action_t;     /* Index to command array       */
 
diff -r c1ff606c97d4 -r 280ade96d0ff lib/libedit/eln.c
--- a/lib/libedit/eln.c Sun Aug 15 10:06:32 2021 +0000
+++ b/lib/libedit/eln.c Sun Aug 15 10:08:41 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eln.c,v 1.35 2019/04/26 16:56:57 christos Exp $        */
+/*     $NetBSD: eln.c,v 1.36 2021/08/15 10:08:41 christos Exp $        */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 #include "config.h"
 #if !defined(lint) && !defined(SCCSID)
-__RCSID("$NetBSD: eln.c,v 1.35 2019/04/26 16:56:57 christos Exp $");
+__RCSID("$NetBSD: eln.c,v 1.36 2021/08/15 10:08:41 christos Exp $");
 #endif /* not lint && not SCCSID */
 
 #include <errno.h>
@@ -153,6 +153,7 @@
 
        case EL_SIGNAL:         /* int */
        case EL_EDITMODE:
+       case EL_SAFEREAD:
        case EL_UNBUFFERED:
        case EL_PREP_TERM:
                ret = el_wset(el, op, va_arg(ap, int));
@@ -315,6 +316,7 @@
 
        case EL_SIGNAL:         /* int * */
        case EL_EDITMODE:
+       case EL_SAFEREAD:
        case EL_UNBUFFERED:
        case EL_PREP_TERM:
                ret = el_wget(el, op, va_arg(ap, int *));
diff -r c1ff606c97d4 -r 280ade96d0ff lib/libedit/histedit.h
--- a/lib/libedit/histedit.h    Sun Aug 15 10:06:32 2021 +0000
+++ b/lib/libedit/histedit.h    Sun Aug 15 10:08:41 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: histedit.h,v 1.57 2017/09/01 10:19:10 christos Exp $   */
+/*     $NetBSD: histedit.h,v 1.58 2021/08/15 10:08:41 christos Exp $   */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -157,6 +157,7 @@
 #define        EL_RPROMPT_ESC  22      /* , prompt_func, Char);              set/get */
 #define        EL_RESIZE       23      /* , el_zfunc_t, void *);             set     */
 #define        EL_ALIAS_TEXT   24      /* , el_afunc_t, void *);             set     */
+#define        EL_SAFEREAD     25      /* , int);                            set/get */
 
 #define        EL_BUILTIN_GETCFN       (NULL)
 
diff -r c1ff606c97d4 -r 280ade96d0ff lib/libedit/read.c
--- a/lib/libedit/read.c        Sun Aug 15 10:06:32 2021 +0000
+++ b/lib/libedit/read.c        Sun Aug 15 10:08:41 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: read.c,v 1.106 2019/07/23 10:18:52 christos Exp $      */
+/*     $NetBSD: read.c,v 1.107 2021/08/15 10:08:41 christos Exp $      */
 
 /*-
  * Copyright (c) 1992, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)read.c     8.1 (Berkeley) 6/4/93";
 #else
-__RCSID("$NetBSD: read.c,v 1.106 2019/07/23 10:18:52 christos Exp $");
+__RCSID("$NetBSD: read.c,v 1.107 2021/08/15 10:08:41 christos Exp $");
 #endif
 #endif /* not lint && not SCCSID */
 
@@ -277,7 +277,7 @@
 read_char(EditLine *el, wchar_t *cp)
 {
        ssize_t num_read;
-       int tried = 0;
+       int tried = (el->el_flags & FIXIO) == 0;
        char cbuf[MB_LEN_MAX];
        size_t cbp = 0;
        int save_errno = errno;



Home | Main Index | Thread Index | Old Index