Source-Changes-HG archive

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

[src/trunk]: src/bin/sh Detect write errors to stdout, and exit(1) from some ...



details:   https://anonhg.NetBSD.org/src/rev/9334f4310b1e
branches:  trunk
changeset: 1026285:9334f4310b1e
user:      kre <kre%NetBSD.org@localhost>
date:      Tue Nov 16 11:27:50 2021 +0000

description:
Detect write errors to stdout, and exit(1) from some built-in
commands which (primarily) are used just to generate output
(or with a particular option combination do so).

diffstat:

 bin/sh/eval.c      |   5 +++--
 bin/sh/miscbltin.c |  17 ++++++++++++++---
 bin/sh/redir.c     |  13 ++++++++-----
 3 files changed, 25 insertions(+), 10 deletions(-)

diffs (119 lines):

diff -r 54d89de7c6fa -r 9334f4310b1e bin/sh/eval.c
--- a/bin/sh/eval.c     Tue Nov 16 11:25:44 2021 +0000
+++ b/bin/sh/eval.c     Tue Nov 16 11:27:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eval.c,v 1.184 2021/11/16 11:25:44 kre Exp $   */
+/*     $NetBSD: eval.c,v 1.185 2021/11/16 11:27:50 kre Exp $   */
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)eval.c     8.9 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: eval.c,v 1.184 2021/11/16 11:25:44 kre Exp $");
+__RCSID("$NetBSD: eval.c,v 1.185 2021/11/16 11:27:50 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -1346,6 +1346,7 @@
                        optreset = 1;
                        optind = 1;
                        builtin_flags = flags;
+                       clr_err(out1);  /* discard previous I/O errors */
                        exitstatus = cmdentry.u.bltin(argc, argv);
                } else {
                        e = exception;
diff -r 54d89de7c6fa -r 9334f4310b1e bin/sh/miscbltin.c
--- a/bin/sh/miscbltin.c        Tue Nov 16 11:25:44 2021 +0000
+++ b/bin/sh/miscbltin.c        Tue Nov 16 11:27:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: miscbltin.c,v 1.45 2021/09/15 18:30:57 kre Exp $       */
+/*     $NetBSD: miscbltin.c,v 1.46 2021/11/16 11:27:50 kre Exp $       */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)miscbltin.c        8.4 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: miscbltin.c,v 1.45 2021/09/15 18:30:57 kre Exp $");
+__RCSID("$NetBSD: miscbltin.c,v 1.46 2021/11/16 11:27:50 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -288,6 +288,11 @@
                        umask(~mask & 0777);
                }
        }
+       flushout(out1);
+       if (io_err(out1)) {
+               out2str("umask: I/O error\n");
+               return 1;
+       }
        return 0;
 }
 
@@ -445,7 +450,7 @@
                                out1fmt("%c", which ? '\t' : '\n');
                        }
                }
-               return 0;
+               goto done;
        }
 
        if (getrlimit(l->cmd, &limit) == -1)
@@ -477,5 +482,11 @@
 #endif
                }
        }
+  done:;
+       flushout(out1);
+       if (io_err(out1)) {
+               out2str("ulimit: I/O error (stdout)\n");
+               return 1;
+       }
        return 0;
 }
diff -r 54d89de7c6fa -r 9334f4310b1e bin/sh/redir.c
--- a/bin/sh/redir.c    Tue Nov 16 11:25:44 2021 +0000
+++ b/bin/sh/redir.c    Tue Nov 16 11:27:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: redir.c,v 1.70 2021/11/10 15:26:34 kre Exp $   */
+/*     $NetBSD: redir.c,v 1.71 2021/11/16 11:27:50 kre Exp $   */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)redir.c    8.2 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: redir.c,v 1.70 2021/11/10 15:26:34 kre Exp $");
+__RCSID("$NetBSD: redir.c,v 1.71 2021/11/16 11:27:50 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -1033,10 +1033,8 @@
 
                for (i = 0; i <= max_user_fd; i++)
                        printone(i, 0, verbose, 1);
-               return 0;
-       }
 
-       while ((num = *argv++) != NULL) {
+       } else while ((num = *argv++) != NULL) {
                int fd = number(num);
 
                while (num[0] == '0' && num[1] != '\0')         /* skip 0's */
@@ -1050,6 +1048,11 @@
                else
                        printone(fd, 1, verbose, argc > 1);
        }
+       flushout(out1);
+       if (io_err(out1)) {
+               out2str("fdflags: I/O error\n");
+               return 1;
+       }
        return 0;
 }
 



Home | Main Index | Thread Index | Old Index