Author: pfg
Date: Mon Jul  9 15:31:05 2012
New Revision: 238299
URL: http://svn.freebsd.org/changeset/base/238299

Log:
  MFC   r238173:
  
  Fix issue resizing bin/sh
  
  This partially reverts some changes from r237448 that are causing
  breakage when resizing under bin/sh .
  
  Reverted changes from NetBSD are:
  
  Mar 10 20:46:15 2009 - editline.3 read.c
  make el_gets set the count to -1 on error to distinguish between EOF and
  error.
  
  Feb 19 15:20:22 2009 - read.c sig.c sig.h
  reset and redraw on sigcont. From Anon Ymous.
  
  Feb 15 21:24:13 2009
  don't restart on EINTR, instead return NULL immediately. From Anon Ymous
  
  Approved by:  re

Modified:
  stable/8/lib/libedit/editline.3
  stable/8/lib/libedit/el.h
  stable/8/lib/libedit/read.c
  stable/8/lib/libedit/sig.c
  stable/8/lib/libedit/sig.h
Directory Properties:
  stable/8/lib/libedit/   (props changed)

Modified: stable/8/lib/libedit/editline.3
==============================================================================
--- stable/8/lib/libedit/editline.3     Mon Jul  9 14:16:49 2012        
(r238298)
+++ stable/8/lib/libedit/editline.3     Mon Jul  9 15:31:05 2012        
(r238299)
@@ -165,11 +165,6 @@ is modified to contain the number of cha
 Returns the line read if successful, or
 .Dv NULL
 if no characters were read or if an error occurred.
-If an error occurred,
-.Fa count
-is set to \-1 and
-.Dv errno
-contains the error code that caused it.
 The return value may not remain valid across calls to
 .Fn el_gets
 and must be copied if the data is to be retained.

Modified: stable/8/lib/libedit/el.h
==============================================================================
--- stable/8/lib/libedit/el.h   Mon Jul  9 14:16:49 2012        (r238298)
+++ stable/8/lib/libedit/el.h   Mon Jul  9 15:31:05 2012        (r238299)
@@ -115,7 +115,6 @@ struct editline {
        FILE             *el_errfile;   /* Stdio stuff                  */
        int               el_infd;      /* Input file descriptor        */
        int               el_flags;     /* Various flags.               */
-       int               el_errno;     /* Local copy of errno          */
        coord_t           el_cursor;    /* Cursor location              */
        char            **el_display;   /* Real screen image = what is there */
        char            **el_vdisplay;  /* Virtual screen image = what we see */

Modified: stable/8/lib/libedit/read.c
==============================================================================
--- stable/8/lib/libedit/read.c Mon Jul  9 14:16:49 2012        (r238298)
+++ stable/8/lib/libedit/read.c Mon Jul  9 15:31:05 2012        (r238299)
@@ -49,7 +49,7 @@ __FBSDID("$FreeBSD$");
 #include <stdlib.h>
 #include "el.h"
 
-#define        OKCMD   -1      /* must be -1! */
+#define        OKCMD   -1
 
 private int    read__fixio(int, int);
 private int    read_preread(EditLine *);
@@ -170,7 +170,7 @@ read__fixio(int fd __unused, int e)
                return (e ? 0 : -1);
 
        case EINTR:
-               return (-1);
+               return (0);
 
        default:
                return (-1);
@@ -235,12 +235,9 @@ read_getcmd(EditLine *el, el_action_t *c
        el_action_t cmd;
        int num;
 
-       el->el_errno = 0;
        do {
-               if ((num = el_getc(el, ch)) != 1) {     /* if EOF or error */
-                       el->el_errno = num == 0 ? 0 : errno;
+               if ((num = el_getc(el, ch)) != 1)       /* if EOF or error */
                        return (num);
-               }
 
 #ifdef KANJI
                if ((*ch & 0200)) {
@@ -292,21 +289,14 @@ read_char(EditLine *el, char *cp)
        ssize_t num_read;
        int tried = 0;
 
- again:
-       el->el_signal->sig_no = 0;
-       while ((num_read = read(el->el_infd, cp, 1)) == -1) {
-               if (el->el_signal->sig_no == SIGCONT) {
-                       sig_set(el);
-                       el_set(el, EL_REFRESH);
-                       goto again;
-               }
+       while ((num_read = read(el->el_infd, cp, 1)) == -1)
                if (!tried && read__fixio(el->el_infd, errno) == 0)
                        tried = 1;
                else {
                        *cp = '\0';
                        return (-1);
                }
-       }
+
        return (int)num_read;
 }
 
@@ -413,20 +403,17 @@ el_gets(EditLine *el, int *nread)
        int num;                /* how many chars we have read at NL */
        char ch;
        int crlf = 0;
-       int nrb;
 #ifdef FIONREAD
        c_macro_t *ma = &el->el_chared.c_macro;
 #endif /* FIONREAD */
 
-       if (nread == NULL)
-               nread = &nrb;
        *nread = 0;
 
        if (el->el_flags & NO_TTY) {
                char *cp = el->el_line.buffer;
                size_t idx;
 
-               while ((num = (*el->el_read.read_char)(el, cp)) == 1) {
+               while ((*el->el_read.read_char)(el, cp) == 1) {
                        /* make sure there is space for next character */
                        if (cp + 1 >= el->el_line.limit) {
                                idx = (cp - el->el_line.buffer);
@@ -440,16 +427,12 @@ el_gets(EditLine *el, int *nread)
                        if (cp[-1] == '\r' || cp[-1] == '\n')
                                break;
                }
-               if (num == -1) {
-                       if (errno == EINTR)
-                               cp = el->el_line.buffer;
-                       el->el_errno = errno;
-               }
 
                el->el_line.cursor = el->el_line.lastchar = cp;
                *cp = '\0';
-               *nread = (int)(el->el_line.cursor - el->el_line.buffer);
-               goto done;
+               if (nread)
+                       *nread = (int)(el->el_line.cursor - el->el_line.buffer);
+               return (*nread ? el->el_line.buffer : NULL);
        }
 
 
@@ -460,8 +443,8 @@ el_gets(EditLine *el, int *nread)
                (void) ioctl(el->el_infd, FIONREAD, (ioctl_t) & chrs);
                if (chrs == 0) {
                        if (tty_rawmode(el) < 0) {
-                               errno = 0;
-                               *nread = 0;
+                               if (nread)
+                                       *nread = 0;
                                return (NULL);
                        }
                }
@@ -474,7 +457,6 @@ el_gets(EditLine *el, int *nread)
        if (el->el_flags & EDIT_DISABLED) {
                char *cp;
                size_t idx;
-
                if ((el->el_flags & UNBUFFERED) == 0)
                        cp = el->el_line.buffer;
                else
@@ -482,7 +464,7 @@ el_gets(EditLine *el, int *nread)
 
                term__flush(el);
 
-               while ((num = (*el->el_read.read_char)(el, cp)) == 1) {
+               while ((*el->el_read.read_char)(el, cp) == 1) {
                        /* make sure there is space next character */
                        if (cp + 1 >= el->el_line.limit) {
                                idx = (cp - el->el_line.buffer);
@@ -498,15 +480,11 @@ el_gets(EditLine *el, int *nread)
                                break;
                }
 
-               if (num == -1) {
-                       if (errno == EINTR)
-                               cp = el->el_line.buffer;
-                       el->el_errno = errno;
-               }
-
                el->el_line.cursor = el->el_line.lastchar = cp;
                *cp = '\0';
-               goto done;
+               if (nread)
+                       *nread = (int)(el->el_line.cursor - el->el_line.buffer);
+               return (*nread ? el->el_line.buffer : NULL);
        }
 
        for (num = OKCMD; num == OKCMD;) {      /* while still editing this
@@ -522,12 +500,6 @@ el_gets(EditLine *el, int *nread)
 #endif /* DEBUG_READ */
                        break;
                }
-               if (el->el_errno == EINTR) {
-                       el->el_line.buffer[0] = '\0';
-                       el->el_line.lastchar =
-                           el->el_line.cursor = el->el_line.buffer;
-                       break;
-               }
                if ((unsigned int)cmdnum >= (unsigned int)el->el_map.nfunc) {   
/* BUG CHECK command */
 #ifdef DEBUG_EDIT
                        (void) fprintf(el->el_errfile,
@@ -645,17 +617,12 @@ el_gets(EditLine *el, int *nread)
        /* make sure the tty is set up correctly */
        if ((el->el_flags & UNBUFFERED) == 0) {
                read_finish(el);
-               *nread = num != -1 ? num : 0;
+               if (nread)
+                       *nread = num;
        } else {
-               *nread = (int)(el->el_line.lastchar - el->el_line.buffer);
+               if (nread)
+                       *nread =
+                           (int)(el->el_line.lastchar - el->el_line.buffer);
        }
-done:
-       if (*nread == 0) {
-               if (num == -1) {
-                       *nread = -1;
-                       errno = el->el_errno;
-               }
-               return NULL;
-       } else
-               return el->el_line.buffer;
+       return (num ? el->el_line.buffer : NULL);
 }

Modified: stable/8/lib/libedit/sig.c
==============================================================================
--- stable/8/lib/libedit/sig.c  Mon Jul  9 14:16:49 2012        (r238298)
+++ stable/8/lib/libedit/sig.c  Mon Jul  9 15:31:05 2012        (r238299)
@@ -29,7 +29,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     $NetBSD: sig.c,v 1.15 2009/02/19 15:20:22 christos Exp $
+ *     $NetBSD: sig.c,v 1.14 2009/02/18 15:04:40 christos Exp $
  */
 
 #if !defined(lint) && !defined(SCCSID)
@@ -73,8 +73,6 @@ sig_handler(int signo)
        (void) sigaddset(&nset, signo);
        (void) sigprocmask(SIG_BLOCK, &nset, &oset);
 
-       sel->el_signal->sig_no = signo;
-
        switch (signo) {
        case SIGCONT:
                tty_rawmode(sel);
@@ -160,12 +158,12 @@ sig_set(EditLine *el)
        struct sigaction osa, nsa;
 
        nsa.sa_handler = sig_handler;
-       nsa.sa_flags = 0;
        sigemptyset(&nsa.sa_mask);
 
        (void) sigprocmask(SIG_BLOCK, &el->el_signal->sig_set, &oset);
 
        for (i = 0; sighdl[i] != -1; i++) {
+               nsa.sa_flags = SIGINT ? 0 : SA_RESTART;
                /* This could happen if we get interrupted */
                if (sigaction(sighdl[i], &nsa, &osa) != -1 &&
                    osa.sa_handler != sig_handler)

Modified: stable/8/lib/libedit/sig.h
==============================================================================
--- stable/8/lib/libedit/sig.h  Mon Jul  9 14:16:49 2012        (r238298)
+++ stable/8/lib/libedit/sig.h  Mon Jul  9 15:31:05 2012        (r238299)
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  *
  *     @(#)sig.h       8.1 (Berkeley) 6/4/93
- *     $NetBSD: sig.h,v 1.5 2003/08/07 16:44:33 agc Exp $
+ *     $NetBSD: sig.h,v 1.7 2009/02/15 21:25:01 christos Exp $
  * $FreeBSD$
  */
 
@@ -61,7 +61,6 @@
 typedef struct {
        struct sigaction sig_action[ALLSIGSNO];
        sigset_t sig_set;
-       volatile sig_atomic_t sig_no;
 } *el_signal_t;
 
 protected void sig_end(EditLine*);
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to