Subject: bin/24850: suppress sa(8) output when file(s) are non-existent
To: None <gnats-bugs@gnats.NetBSD.org>
From: None <jeffi@rcn.com>
List: netbsd-bugs
Date: 03/19/2004 14:31:07
>Number:         24850
>Category:       bin
>Synopsis:       suppress sa(8) output when file(s) are non-existent
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Mar 19 14:32:00 UTC 2004
>Closed-Date:
>Last-Modified:
>Originator:     Jeff Ito
>Release:        1.6ZK
>Organization:
>Environment:
NetBSD lab 1.6ZK NetBSD 1.6ZK (LAB) #4: Tue Mar  9 22:03:23 EST 2004  jeff@netbsd:/q/nbsd/src/sys/arch/i386/compile/LAB i386

>Description:
sa(8) prints statistics, even if none the file arguments (default or passed via command line) exist.  I don't believe this to be necessary.
>How-To-Repeat:
{265} sa
sa: open /var/account/acct read-only: No such file or directory
       0        0.00re        0.00cp        0avio        0k

{266} sa test test2
sa: open test read-only: No such file or directory
sa: open test2 read-only: No such file or directory
       0        0.00re        0.00cp        0avio        0k

>Fix:
Index: main.c
===================================================================
RCS file: /cvs/nbsd/src/usr.sbin/sa/main.c,v
retrieving revision 1.19
diff -u -r1.19 main.c
--- main.c      13 Feb 2004 11:36:24 -0000      1.19
+++ main.c      19 Mar 2004 14:15:56 -0000
@@ -88,8 +88,9 @@
        char **argv;
 {
        int ch;
-       int error;
+       int error, filefound;

+       filefound = 0;
        error = 0;
        while ((ch = getopt(argc, argv, "abcdDfijkKlmnqrstuv:")) != -1)
                switch (ch) {
@@ -216,6 +217,8 @@
                if (fd < 0)
                        continue;

+               filefound = 1;
+
                if (!uflag && sflag) {
 #ifndef DEBUG
                        sigset_t nmask, omask;
@@ -275,6 +278,10 @@
                        warn("close %s", *argv);
                        error = 1;
                }
+       }
+
+       if (!filefound) {
+               exit(error);
        }

        if (!uflag && !qflag) {

>Release-Note:
>Audit-Trail:
>Unformatted: