From nobody@FreeBSD.org  Fri Jan 11 23:48:43 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id CB97916A468
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 11 Jan 2008 23:48:43 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 8A2D613C459
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 11 Jan 2008 23:48:43 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m0BNlXxp085209
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 11 Jan 2008 23:47:33 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m0BNlXrK085208;
	Fri, 11 Jan 2008 23:47:33 GMT
	(envelope-from nobody)
Message-Id: <200801112347.m0BNlXrK085208@www.freebsd.org>
Date: Fri, 11 Jan 2008 23:47:33 GMT
From: Alexander Chernikov <admin@su29.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] systat(1): systat -ifstat fails if iface table is `sparse`
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         119581
>Category:       bin
>Synopsis:       [patch] systat(1): systat -ifstat fails if iface table is `sparse`
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    delphij
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 11 23:50:00 UTC 2008
>Closed-Date:    Sat Jan 26 22:02:53 UTC 2008
>Last-Modified:  Sat Jan 26 22:20:01 UTC 2008
>Originator:     Alexander Chernikov
>Release:        6.2-RELEASE
>Organization:
>Environment:
FreeBSD pochta.alo.ru 6.2-RELEASE-p1 FreeBSD 6.2-RELEASE-p1 #1: Sun Mar 25 13:26:51 MSD 2007     root@pochta.alo.ru:/usr/obj/usr/src/sys/POCHTA  amd64
>Description:
systat -ifstat returns 
'systat: sysctl error getting interface data: No such file or directory'
if interface from the 'middle' of interface table is deleted.

The problem resides in an incorrect ifmib(4) sysctl usage.
systat(1) does not handle `sparse` table case correctly and exits instead of skipping row.
>How-To-Repeat:
tcsh# kldload ng_iface
tcsh# ngctl mkpeer iface dummy inet
tcsh# ngctl mkpeer iface dummy inet
tcsh# ngctl mkpeer iface dummy inet
[We now got 3 ngX interfaces, ng0-2]

tcsh# ngctl shutdown ng1:
tcsh# systat -ifstat
systat: sysctl error getting interface data: No such file or directory

>Fix:
Apply the following patch:


Patch attached with submission follows:

--- /usr/src/usr.bin/systat/ifstat.c	2008-01-12 01:14:47.000000000 +0300
+++ /usr/src/usr.bin/systat/ifstat.c	2008-01-12 01:25:22.000000000 +0300
@@ -37,6 +37,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <err.h>
+#include <errno.h>
 
 #include "systat.h"
 #include "extern.h"
@@ -384,8 +385,8 @@
 	datalen = sizeof(*data);
 	name[4] = row;
 
-	if (sysctl(name, 6, (void *)data, (size_t *)&datalen, (void *)NULL,
-	    (size_t)0) != 0)
+	if ((sysctl(name, 6, (void *)data, (size_t *)&datalen, (void *)NULL,
+	    (size_t)0) != 0) && (errno != ENOENT))
 		IFSTAT_ERR(2, "sysctl error getting interface data");
 }
 


>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: delphij 
State-Changed-When: Sat Jan 12 00:11:41 UTC 2008 
State-Changed-Why:  
Patch applied against -HEAD, MFC reminder (two weeks). 


Responsible-Changed-From-To: freebsd-bugs->delphij 
Responsible-Changed-By: delphij 
Responsible-Changed-When: Sat Jan 12 00:11:41 UTC 2008 
Responsible-Changed-Why:  
Take. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=119581 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/119581: commit references a PR
Date: Sat, 12 Jan 2008 00:11:31 +0000 (UTC)

 delphij     2008-01-12 00:11:26 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.bin/systat       ifstat.c 
   Log:
    - Handle the case where interface from "middle" is missing by
      more carefully inspecting the return value from sysctl(3). [1]
    - Use calloc instead of malloc+memset of zero.
   
   Submitted by:   Alexander Chernikov <admin su29 net> [1]
   PR:             bin/119581
   MFC after:      2 weeks
   
   Revision  Changes    Path
   1.7       +4 -4      src/usr.bin/systat/ifstat.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/119581: commit references a PR
Date: Sat, 26 Jan 2008 21:58:36 +0000 (UTC)

 delphij     2008-01-26 21:58:29 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7)
     usr.bin/systat       ifstat.c 
   Log:
   MFC revision 1.7
   date: 2008/01/12 00:11:26;  author: delphij;  state: Exp;  lines: +4 -4
    - Handle the case where interface from "middle" is missing by
      more carefully inspecting the return value from sysctl(3). [1]
    - Use calloc instead of malloc+memset of zero.
   
   Submitted by:   Alexander Chernikov <admin su29 net> [1]
   PR:             bin/119581
   MFC after:      2 weeks
   
   Revision  Changes    Path
   1.6.2.1   +4 -4      src/usr.bin/systat/ifstat.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/119581: commit references a PR
Date: Sat, 26 Jan 2008 21:58:49 +0000 (UTC)

 delphij     2008-01-26 21:58:44 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     usr.bin/systat       ifstat.c 
   Log:
   MFC revision 1.7
   date: 2008/01/12 00:11:26;  author: delphij;  state: Exp;  lines: +4 -4
    - Handle the case where interface from "middle" is missing by
      more carefully inspecting the return value from sysctl(3). [1]
    - Use calloc instead of malloc+memset of zero.
   
   Submitted by:   Alexander Chernikov <admin su29 net> [1]
   PR:             bin/119581
   MFC after:      2 weeks
   
   Revision  Changes    Path
   1.2.8.2   +4 -4      src/usr.bin/systat/ifstat.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/119581: commit references a PR
Date: Sat, 26 Jan 2008 21:59:15 +0000 (UTC)

 delphij     2008-01-26 21:59:10 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_5)
     usr.bin/systat       ifstat.c 
   Log:
   MFC revision 1.7
   date: 2008/01/12 00:11:26;  author: delphij;  state: Exp;  lines: +4 -4
    - Handle the case where interface from "middle" is missing by
      more carefully inspecting the return value from sysctl(3). [1]
    - Use calloc instead of malloc+memset of zero.
   
   Submitted by:   Alexander Chernikov <admin su29 net> [1]
   PR:             bin/119581
   MFC after:      2 weeks
   
   Revision  Changes    Path
   1.2.2.1   +4 -4      src/usr.bin/systat/ifstat.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: delphij 
State-Changed-When: Sat Jan 26 22:02:36 UTC 2008 
State-Changed-Why:  
Patch applied against RELENG_[567]. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=119581 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/119581: commit references a PR
Date: Sat, 26 Jan 2008 22:13:36 +0000 (UTC)

 delphij     2008-01-26 22:13:30 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7_0)
     usr.bin/systat       ifstat.c 
   Log:
   MFC revision 1.7
   date: 2008/01/12 00:11:26;  author: delphij;  state: Exp;  lines: +4 -4
    - Handle the case where interface from "middle" is missing by
      more carefully inspecting the return value from sysctl(3). [1]
    - Use calloc instead of malloc+memset of zero.
   
   Submitted by:   Alexander Chernikov <admin su29 net> [1]
   PR:             bin/119581
   Approved by:    re (kensmith)
   
   Revision  Changes    Path
   1.6.4.1   +4 -4      src/usr.bin/systat/ifstat.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
