Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/systat Fix error handling throughout. First off, it...



details:   https://anonhg.NetBSD.org/src/rev/99e4508c6d35
branches:  trunk
changeset: 479762:99e4508c6d35
user:      jwise <jwise%NetBSD.org@localhost>
date:      Mon Dec 20 23:11:50 1999 +0000

description:
Fix error handling throughout.  First off, it is not true as claimed in swap.c
that `systat doesn't handle errors'.  Second off, errx should not be used directly, since
the terminal should be cleaned up before bailing.  Third off, whatever we do we need
to be consistent.

There, I feel better now.

diffstat:

 usr.bin/systat/bufcache.c |  17 ++++++++++-------
 usr.bin/systat/cmds.c     |   6 +++---
 usr.bin/systat/keyboard.c |  11 +++++------
 usr.bin/systat/swap.c     |  21 +++++++++++----------
 usr.bin/systat/vmstat.c   |  13 +++++++------
 5 files changed, 36 insertions(+), 32 deletions(-)

diffs (188 lines):

diff -r 497eb62d7109 -r 99e4508c6d35 usr.bin/systat/bufcache.c
--- a/usr.bin/systat/bufcache.c Mon Dec 20 23:01:20 1999 +0000
+++ b/usr.bin/systat/bufcache.c Mon Dec 20 23:11:50 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bufcache.c,v 1.4 1999/11/27 05:58:04 mrg Exp $ */
+/*     $NetBSD: bufcache.c,v 1.5 1999/12/20 23:11:50 jwise Exp $       */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: bufcache.c,v 1.4 1999/11/27 05:58:04 mrg Exp $");
+__RCSID("$NetBSD: bufcache.c,v 1.5 1999/12/20 23:11:50 jwise Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -206,9 +206,10 @@
        NREAD(X_BUFPAGES, &bufpages, sizeof(bufpages));
        bufbytes = bufpages * sysconf(_SC_PAGESIZE);
 
-       buf = (struct buf *)malloc(nbuf * sizeof(struct buf));
-       if (buf == NULL)
-               errx(1, "malloc failed\n");
+       if ((buf = malloc(nbuf * sizeof(struct buf))) == NULL) {
+               error("malloc failed");
+               die(0);
+       }
        NREAD(X_BUF, &bufaddr, sizeof(bufaddr));
 
        return(1);
@@ -352,8 +353,10 @@
                                return(&ml->ml_mount);
                }
 
-       if ((ml = malloc(sizeof(struct ml_entry))) == NULL)
-               errx(1, "out of memory\n");
+       if ((ml = malloc(sizeof(struct ml_entry))) == NULL) {
+               error("out of memory");
+               die(0);
+       }
        LIST_INSERT_HEAD(&mount_list, ml, ml_entries);
        ml->ml_count = 1;
        ml->ml_size = size;
diff -r 497eb62d7109 -r 99e4508c6d35 usr.bin/systat/cmds.c
--- a/usr.bin/systat/cmds.c     Mon Dec 20 23:01:20 1999 +0000
+++ b/usr.bin/systat/cmds.c     Mon Dec 20 23:11:50 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cmds.c,v 1.17 1999/12/20 21:46:10 jwise Exp $  */
+/*     $NetBSD: cmds.c,v 1.18 1999/12/20 23:11:50 jwise Exp $  */
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)cmds.c     8.2 (Berkeley) 4/29/95";
 #endif
-__RCSID("$NetBSD: cmds.c,v 1.17 1999/12/20 21:46:10 jwise Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.18 1999/12/20 23:11:50 jwise Exp $");
 #endif /* not lint */
 
 #include <stdlib.h>
@@ -115,7 +115,7 @@
                wnd = (*curmode->c_open)();
                if (wnd == 0) {
                        error("Couldn't change back to previous mode");
-                       exit(1);
+                       die(0);
                }
 
                p = curmode;
diff -r 497eb62d7109 -r 99e4508c6d35 usr.bin/systat/keyboard.c
--- a/usr.bin/systat/keyboard.c Mon Dec 20 23:01:20 1999 +0000
+++ b/usr.bin/systat/keyboard.c Mon Dec 20 23:11:50 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: keyboard.c,v 1.9 1999/12/20 21:59:29 jwise Exp $       */
+/*     $NetBSD: keyboard.c,v 1.10 1999/12/20 23:11:50 jwise Exp $      */
 
 /*-
  * Copyright (c) 1980, 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)keyboard.c 8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: keyboard.c,v 1.9 1999/12/20 21:59:29 jwise Exp $");
+__RCSID("$NetBSD: keyboard.c,v 1.10 1999/12/20 23:11:50 jwise Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -63,10 +63,9 @@
        sigaddset(&set, SIGALRM);
 
        linesz = COLS - 2;              /* XXX does not get updated on SIGWINCH */
-       line = malloc(linesz);
-       if (line == NULL) {
-               error("malloc");
-               exit(1);
+       if ((line = malloc(linesz)) == NULL) {
+               error("malloc failed");
+               die(0);
        }
 
        for (;;) {
diff -r 497eb62d7109 -r 99e4508c6d35 usr.bin/systat/swap.c
--- a/usr.bin/systat/swap.c     Mon Dec 20 23:01:20 1999 +0000
+++ b/usr.bin/systat/swap.c     Mon Dec 20 23:11:50 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: swap.c,v 1.9 1998/12/26 07:05:08 marc Exp $    */
+/*     $NetBSD: swap.c,v 1.10 1999/12/20 23:11:50 jwise Exp $  */
 
 /*-
  * Copyright (c) 1997 Matthew R. Green.  All rights reserved.
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)swap.c     8.3 (Berkeley) 4/29/95";
 #endif
-__RCSID("$NetBSD: swap.c,v 1.9 1998/12/26 07:05:08 marc Exp $");
+__RCSID("$NetBSD: swap.c,v 1.10 1999/12/20 23:11:50 jwise Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -108,15 +108,16 @@
 
        if (swap_devices)
                (void)free(swap_devices);
-       swap_devices = (struct swapent *)malloc(nswap * sizeof(*swap_devices));
-       if (swap_devices == NULL)
-               /* XXX */ ;     /* XXX systat doesn't do errors! */
+       if ((swap_devices = malloc(nswap * sizeof(*swap_devices))) == NULL) {
+               error("malloc failed");
+               die(0);
+       }
 
-       rnswap = swapctl(SWAP_STATS, (void *)swap_devices, nswap);
-       if (nswap < 0)
-               /* XXX */ ;     /* XXX systat doesn't do errors! */
-       if (nswap != rnswap)
-               /* XXX */ ;     /* XXX systat doesn't do errors! */
+       if ((rnswap = swapctl(SWAP_STATS, (void *)swap_devices, nswap)) != nswap) {
+               error("swapctl failed");
+               die(0);
+       }
+               
        if (update_label)
                labelswap();
 }
diff -r 497eb62d7109 -r 99e4508c6d35 usr.bin/systat/vmstat.c
--- a/usr.bin/systat/vmstat.c   Mon Dec 20 23:01:20 1999 +0000
+++ b/usr.bin/systat/vmstat.c   Mon Dec 20 23:11:50 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vmstat.c,v 1.22 1999/12/20 03:45:03 jwise Exp $        */
+/*     $NetBSD: vmstat.c,v 1.23 1999/12/20 23:11:51 jwise Exp $        */
 
 /*-
  * Copyright (c) 1983, 1989, 1992, 1993
@@ -38,7 +38,7 @@
 #if 0
 static char sccsid[] = "@(#)vmstat.c   8.2 (Berkeley) 1/12/94";
 #endif
-__RCSID("$NetBSD: vmstat.c,v 1.22 1999/12/20 03:45:03 jwise Exp $");
+__RCSID("$NetBSD: vmstat.c,v 1.23 1999/12/20 23:11:51 jwise Exp $");
 #endif /* not lint */
 
 /*
@@ -224,7 +224,7 @@
                intrname = calloc(nintr, sizeof (long));
                intrnamebuf = malloc(namelist[X_EINTRNAMES].n_value -
                        namelist[X_INTRNAMES].n_value);
-               if (intrnamebuf == 0 || intrname == 0 || intrloc == 0) {
+               if (intrnamebuf == NULL || intrname == 0 || intrloc == 0) {
                        error("Out of memory\n");
                        if (intrnamebuf)
                                free(intrnamebuf);
@@ -634,9 +634,10 @@
        struct Info *s;
 {
 
-       s->intrcnt = (long *) malloc(nintr * sizeof(long));
-       if (s->intrcnt == NULL)
-               errx(2, "out of memory");
+       if ((s->intrcnt = malloc(nintr * sizeof(long))) == NULL) {
+               error("malloc failed");
+               die(0);
+       }
 }
 
 static void



Home | Main Index | Thread Index | Old Index