Source-Changes-HG archive

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

[src/trunk]: src/usr.bin fix some error handling.



details:   https://anonhg.NetBSD.org/src/rev/86415c3a0ce8
branches:  trunk
changeset: 809054:86415c3a0ce8
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Jun 16 22:54:10 2015 +0000

description:
fix some error handling.

diffstat:

 usr.bin/cal/cal.c              |   6 +++---
 usr.bin/cksum/cksum.c          |   8 ++++----
 usr.bin/fsplit/fsplit.c        |   4 ++--
 usr.bin/kdump/kdump.c          |   6 +++---
 usr.bin/mkcsmapper/yacc.y      |  17 +++++++----------
 usr.bin/mkdep/mkdep.c          |   6 +++---
 usr.bin/mkesdb/yacc.y          |  15 ++++++---------
 usr.bin/mklocale/mklocaledb.c  |  16 ++++++++--------
 usr.bin/netstat/vtw.c          |   6 +++---
 usr.bin/printf/printf.c        |   6 +++---
 usr.bin/rump_dhcpclient/main.c |  28 ++++++++++++++--------------
 usr.bin/sdpquery/command.c     |   6 +++---
 usr.bin/su/su.c                |   6 +++---
 usr.bin/talk/get_addrs.c       |   6 +++---
 usr.bin/tip/remote.c           |   8 ++++----
 usr.bin/tip/tip.c              |  14 ++++++--------
 usr.bin/utoppya/utoppya.c      |   4 ++--
 17 files changed, 77 insertions(+), 85 deletions(-)

diffs (truncated from 625 to 300 lines):

diff -r b910a733523f -r 86415c3a0ce8 usr.bin/cal/cal.c
--- a/usr.bin/cal/cal.c Tue Jun 16 22:31:08 2015 +0000
+++ b/usr.bin/cal/cal.c Tue Jun 16 22:54:10 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cal.c,v 1.28 2015/01/08 03:56:33 christos Exp $        */
+/*     $NetBSD: cal.c,v 1.29 2015/06/16 22:54:10 christos Exp $        */
 
 /*
  * Copyright (c) 1989, 1993, 1994
@@ -42,7 +42,7 @@
 #if 0
 static char sccsid[] = "@(#)cal.c      8.4 (Berkeley) 4/2/94";
 #else
-__RCSID("$NetBSD: cal.c,v 1.28 2015/01/08 03:56:33 christos Exp $");
+__RCSID("$NetBSD: cal.c,v 1.29 2015/06/16 22:54:10 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -377,7 +377,7 @@
        endmonth = (month + after) % 12;
 
        if (startyear < 0 || endyear > 9999) {
-               errx(1, "year should be in 1-9999\n");
+               errx(1, "year should be in 1-9999");
        }
 
        year = startyear;
diff -r b910a733523f -r 86415c3a0ce8 usr.bin/cksum/cksum.c
--- a/usr.bin/cksum/cksum.c     Tue Jun 16 22:31:08 2015 +0000
+++ b/usr.bin/cksum/cksum.c     Tue Jun 16 22:54:10 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cksum.c,v 1.47 2014/08/31 07:05:33 christos Exp $      */
+/*     $NetBSD: cksum.c,v 1.48 2015/06/16 22:54:10 christos Exp $      */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -81,7 +81,7 @@
 #if 0
 static char sccsid[] = "@(#)cksum.c    8.2 (Berkeley) 4/28/95";
 #endif
-__RCSID("$NetBSD: cksum.c,v 1.47 2014/08/31 07:05:33 christos Exp $");
+__RCSID("$NetBSD: cksum.c,v 1.48 2015/06/16 22:54:10 christos Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -194,7 +194,7 @@
                switch(ch) {
                case 'a':
                        if (hash) {
-                               warnx("illegal use of -a option\n");
+                               warnx("illegal use of -a option");
                                usage();
                        }
                        i = 0;
@@ -305,7 +305,7 @@
                            argc>0?argv[0]:"stdin");
                
                while(fgets(buf, sizeof(buf), f) != NULL) {
-                       s=strrchr(buf, '\n');
+                       s = strrchr(buf, '\n');
                        if (s)
                                *s = '\0';
 
diff -r b910a733523f -r 86415c3a0ce8 usr.bin/fsplit/fsplit.c
--- a/usr.bin/fsplit/fsplit.c   Tue Jun 16 22:31:08 2015 +0000
+++ b/usr.bin/fsplit/fsplit.c   Tue Jun 16 22:54:10 2015 +0000
@@ -40,7 +40,7 @@
 #if 0
 static char sccsid[] = "from: @(#)fsplit.c     8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: fsplit.c,v 1.29 2013/01/23 20:39:46 riastradh Exp $");
+__RCSID("$NetBSD: fsplit.c,v 1.30 2015/06/16 22:54:10 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -264,7 +264,7 @@
                        *ptr = '0';
                }
                if (ptr < name + letters) {
-                       errx(1, "Ran out of file names.\n");
+                       errx(1, "Ran out of file names.");
                }
        }
 }
diff -r b910a733523f -r 86415c3a0ce8 usr.bin/kdump/kdump.c
--- a/usr.bin/kdump/kdump.c     Tue Jun 16 22:31:08 2015 +0000
+++ b/usr.bin/kdump/kdump.c     Tue Jun 16 22:54:10 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kdump.c,v 1.118 2014/04/30 11:51:51 njoly Exp $        */
+/*     $NetBSD: kdump.c,v 1.119 2015/06/16 22:54:10 christos Exp $     */
 
 /*-
  * Copyright (c) 1988, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)kdump.c    8.4 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: kdump.c,v 1.118 2014/04/30 11:51:51 njoly Exp $");
+__RCSID("$NetBSD: kdump.c,v 1.119 2015/06/16 22:54:10 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -436,7 +436,7 @@
                                break;
                        default:
                        badversion:
-                               err(1, "Unsupported ktrace version %x\n",
+                               err(1, "Unsupported ktrace version %x",
                                    kth->ktr_version);
                        }
                }
diff -r b910a733523f -r 86415c3a0ce8 usr.bin/mkcsmapper/yacc.y
--- a/usr.bin/mkcsmapper/yacc.y Tue Jun 16 22:31:08 2015 +0000
+++ b/usr.bin/mkcsmapper/yacc.y Tue Jun 16 22:54:10 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: yacc.y,v 1.9 2011/09/16 15:39:27 joerg Exp $   */
+/*     $NetBSD: yacc.y,v 1.10 2015/06/16 22:54:10 christos Exp $       */
 
 %{
 /*-
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: yacc.y,v 1.9 2011/09/16 15:39:27 joerg Exp $");
+__RCSID("$NetBSD: yacc.y,v 1.10 2015/06/16 22:54:10 christos Exp $");
 #endif /* not lint */
 
 #include <assert.h>
@@ -659,7 +659,7 @@
        else
                out = stdout;
 
-       if (out==NULL)
+       if (out == NULL)
                err(EXIT_FAILURE, "fopen");
 
        ret = _pivot_factory_convert(out, in);
@@ -667,18 +667,15 @@
        if (ret && output)
                unlink(output); /* dump failure */
        if (ret)
-               errx(EXIT_FAILURE, "%s\n", strerror(ret));
+               errc(EXIT_FAILURE, ret, "");
 }
 
 __dead static void
 usage(void)
 {
-       warnx("usage: \n"
-             "\t%s [-d] [-o outfile] [infile]\n"
-             "\t%s -m [-d] [-o outfile] [infile]\n"
-             "\t%s -p [-d] [-o outfile] [infile]\n",
-             getprogname(), getprogname(), getprogname());
-       exit(1);
+       fprintf(stderr, "Usage: %s [-m|-p] [-d] [-o outfile] [infile]\n",
+           getprogname());
+       exit(EXIT_FAILURE);
 }
 
 int
diff -r b910a733523f -r 86415c3a0ce8 usr.bin/mkdep/mkdep.c
--- a/usr.bin/mkdep/mkdep.c     Tue Jun 16 22:31:08 2015 +0000
+++ b/usr.bin/mkdep/mkdep.c     Tue Jun 16 22:54:10 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mkdep.c,v 1.43 2013/03/05 21:57:47 christos Exp $ */
+/* $NetBSD: mkdep.c,v 1.44 2015/06/16 22:54:10 christos Exp $ */
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
 #if !defined(lint)
 __COPYRIGHT("@(#) Copyright (c) 1999 The NetBSD Foundation, Inc.\
  All rights reserved.");
-__RCSID("$NetBSD: mkdep.c,v 1.43 2013/03/05 21:57:47 christos Exp $");
+__RCSID("$NetBSD: mkdep.c,v 1.44 2015/06/16 22:54:10 christos Exp $");
 #endif /* not lint */
 
 #include <sys/mman.h>
@@ -472,7 +472,7 @@
 
        exit(EXIT_SUCCESS);
 wrerror:
-       err(EXIT_FAILURE, "unable to %s to file %s\n",
+       err(EXIT_FAILURE, "unable to %s to file %s",
            aflag & O_TRUNC ? "write" : "append", filename);
 }
 
diff -r b910a733523f -r 86415c3a0ce8 usr.bin/mkesdb/yacc.y
--- a/usr.bin/mkesdb/yacc.y     Tue Jun 16 22:31:08 2015 +0000
+++ b/usr.bin/mkesdb/yacc.y     Tue Jun 16 22:54:10 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: yacc.y,v 1.6 2011/09/16 15:39:27 joerg Exp $   */
+/*     $NetBSD: yacc.y,v 1.7 2015/06/16 22:54:10 christos Exp $        */
 
 %{
 /*-
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: yacc.y,v 1.6 2011/09/16 15:39:27 joerg Exp $");
+__RCSID("$NetBSD: yacc.y,v 1.7 2015/06/16 22:54:10 christos Exp $");
 #endif /* not lint */
 
 #include <assert.h>
@@ -276,7 +276,7 @@
        else
                out = stdout;
 
-       if (out==NULL)
+       if (out == NULL)
                err(EXIT_FAILURE, "fopen");
 
        ret = _lookup_factory_convert(out, in);
@@ -284,17 +284,14 @@
        if (ret && output)
                unlink(output); /* dump failure */
        if (ret)
-               errx(EXIT_FAILURE, "%s\n", strerror(ret));
+               errc(EXIT_FAILURE, c, "");
 }
 
 __dead static void
 usage(void)
 {
-       errx(EXIT_FAILURE,
-            "usage:\n"
-            "\t%s [-o outfile] [infile]\n"
-            "\t%s -m [-o outfile] [infile]",
-            getprogname(), getprogname());
+       fprintf("Usage: %s [-m] [-o outfile] [infile]\n", getprogname());
+       exit(EXIT_FAILURE);
 }
 
 int
diff -r b910a733523f -r 86415c3a0ce8 usr.bin/mklocale/mklocaledb.c
--- a/usr.bin/mklocale/mklocaledb.c     Tue Jun 16 22:31:08 2015 +0000
+++ b/usr.bin/mklocale/mklocaledb.c     Tue Jun 16 22:54:10 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mklocaledb.c,v 1.3 2013/07/04 11:36:17 joerg Exp $ */
+/* $NetBSD: mklocaledb.c,v 1.4 2015/06/16 22:54:10 christos Exp $ */
 
 /*-
  * Copyright (c)2008 Citrus Project,
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: mklocaledb.c,v 1.3 2013/07/04 11:36:17 joerg Exp $");
+__RCSID("$NetBSD: mklocaledb.c,v 1.4 2015/06/16 22:54:10 christos Exp $");
 #endif /* not lint */
 
 #include <assert.h>
@@ -252,17 +252,17 @@
                /*NOTREACHED*/
        }
        if (_db_factory_create(&df, &_db_hash_std, NULL))
-               errx(1, "can't create db factory.\n");
+               errx(EXIT_FAILURE, "can't create db factory");
        if (_db_factory_add32_by_s(df, category->vers_sym, category->version))
-               errx(1, "can't store db.\n");
+               errx(EXIT_FAILURE, "can't store db");
        token = &category->tokens[0];
        while (token->key != NULL) {
                line = fparseln(reader, NULL,
                    NULL, delim, FPARSELN_UNESCALL);
                if (line == NULL)
-                       errx(1, "can't read line.\n");
+                       errx(EXIT_FAILURE, "can't read line");
                if ((*token->save)(df, token->key, (const char *)line))
-                       errx(1, "can't store db.\n");
+                       errx(EXIT_FAILURE, "can't store db");
                free(line);
                ++token;
        }
@@ -270,11 +270,11 @@
        _DIAGASSERT(size > 0);
        serialized = malloc(size);
        if (serialized == NULL)
-               errx(1, "can't malloc.\n");
+               errx(EXIT_FAILURE, "can't malloc");
        _DIAGASSERT(serialized != NULL);
        _region_init(&r, serialized, size);
        if (_db_factory_serialize(df, category->magic, &r))
-               errx(1, "can't serialize db.\n");
+               errx(EXIT_FAILURE, "can't serialize db");
        fwrite(serialized, size, 1, writer);
        _db_factory_free(df);
 }
diff -r b910a733523f -r 86415c3a0ce8 usr.bin/netstat/vtw.c
--- a/usr.bin/netstat/vtw.c     Tue Jun 16 22:31:08 2015 +0000
+++ b/usr.bin/netstat/vtw.c     Tue Jun 16 22:54:10 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vtw.c,v 1.7 2013/10/18 20:26:45 christos Exp $ */
+/*     $NetBSD: vtw.c,v 1.8 2015/06/16 22:54:10 christos Exp $ */
 
 /*
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@



Home | Main Index | Thread Index | Old Index