From owner-svn-ports-head@freebsd.org Fri May 11 11:50:18 2018 Return-Path: Delivered-To: svn-ports-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id EF01EFCF17A; Fri, 11 May 2018 11:50:17 +0000 (UTC) (envelope-from pi@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id A01566F259; Fri, 11 May 2018 11:50:17 +0000 (UTC) (envelope-from pi@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 81FD5714C; Fri, 11 May 2018 11:50:17 +0000 (UTC) (envelope-from pi@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w4BBoHOU078955; Fri, 11 May 2018 11:50:17 GMT (envelope-from pi@FreeBSD.org) Received: (from pi@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w4BBoHg6078954; Fri, 11 May 2018 11:50:17 GMT (envelope-from pi@FreeBSD.org) Message-Id: <201805111150.w4BBoHg6078954@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pi set sender to pi@FreeBSD.org using -f From: Kurt Jaeger Date: Fri, 11 May 2018 11:50:17 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r469629 - in head/sysutils/p5-BSD-Sysctl: . files X-SVN-Group: ports-head X-SVN-Commit-Author: pi X-SVN-Commit-Paths: in head/sysutils/p5-BSD-Sysctl: . files X-SVN-Commit-Revision: 469629 X-SVN-Commit-Repository: ports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the ports tree for head List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 May 2018 11:50:18 -0000 Author: pi Date: Fri May 11 11:50:16 2018 New Revision: 469629 URL: https://svnweb.freebsd.org/changeset/ports/469629 Log: sysutils/p5-BSD-Sysctl: fix access to kern.devstat - see the PR for a few nice examples on how to use it PR: 226899 Submitted by: Helge Oldach Approved by: david@landgren.net (maintainer timeout) Modified: head/sysutils/p5-BSD-Sysctl/Makefile head/sysutils/p5-BSD-Sysctl/files/patch-Sysctl.xs Modified: head/sysutils/p5-BSD-Sysctl/Makefile ============================================================================== --- head/sysutils/p5-BSD-Sysctl/Makefile Fri May 11 11:23:42 2018 (r469628) +++ head/sysutils/p5-BSD-Sysctl/Makefile Fri May 11 11:50:16 2018 (r469629) @@ -3,7 +3,7 @@ PORTNAME= BSD-Sysctl PORTVERSION= 0.11 -PORTREVISION= 2 +PORTREVISION= 3 CATEGORIES= sysutils perl5 MASTER_SITES= CPAN PKGNAMEPREFIX= p5- Modified: head/sysutils/p5-BSD-Sysctl/files/patch-Sysctl.xs ============================================================================== --- head/sysutils/p5-BSD-Sysctl/files/patch-Sysctl.xs Fri May 11 11:23:42 2018 (r469628) +++ head/sysutils/p5-BSD-Sysctl/files/patch-Sysctl.xs Fri May 11 11:50:16 2018 (r469629) @@ -1,5 +1,5 @@ ---- Sysctl.xs.orig 2014-01-21 23:02:47 UTC -+++ Sysctl.xs +--- Sysctl.xs.orig 2014-01-22 00:02:47.000000000 +0100 ++++ Sysctl.xs 2018-05-11 10:26:40.364491000 +0200 @@ -14,6 +14,7 @@ #include @@ -48,12 +48,7 @@ - SV **clenp; - int cmplen; - int j; -+_iterator_next(HV *self) -+{ -+ SV *nextp, **len0p, *namep; -+ int *next, name1[CTL_MAXNAME + 2], name2[CTL_MAXNAME + 2]; -+ size_t len0, next_len, len1, len2; - +- - qoid[0] = 0; - qoid[1] = 2; - if (valid) { @@ -90,9 +85,7 @@ - SvREFCNT_inc(clen); - hv_store(self, "_len", 4, clen, 0); - } -+ if (! hv_exists(self, "_len0", 5)) -+ _iterator_first(self); - +- - /* - printf( "next: " ); - for (j = 0; j < qoidlen; ++j) { @@ -100,17 +93,7 @@ - } - printf("\n"); - */ -+ len0p = hv_fetch(self, "_len0", 5, 0); -+ if (len0p == NULL || *len0p == NULL) -+ croak("hv_fetch(_len0) failed in _iterator_next\n"); -+ len0 = SvIV(*len0p); -+ -+ nextp = hv_delete(self, "_next", 5, 0); -+ if (nextp == NULL) -+ return 0; -+ next = (int *) SvPV(nextp, next_len); -+ next_len /= sizeof(int); - +- - /* load the mib */ - if (sysctl(qoid, qoidlen, mib, (size_t*)miblenp, 0, 0) == -1) { - return 0; @@ -119,16 +102,37 @@ - if (*miblenp < cmplen) { - return 0 ; - } -+ namep = hv_delete(self, "_name", 5, 0); -+ if (namep == NULL) -+ return 0; - +- - for (j = 0; j < cmplen; ++j) { - if (mib[j] != qoid[j+2]) { - return 0; - } - } - return 1; ++_iterator_next(HV *self) ++{ ++ SV *nextp, **len0p, *namep; ++ int *next, name1[CTL_MAXNAME + 2], name2[CTL_MAXNAME + 2]; ++ size_t len0, next_len, len1, len2; ++ ++ if (! hv_exists(self, "_len0", 5)) ++ _iterator_first(self); ++ ++ len0p = hv_fetch(self, "_len0", 5, 0); ++ if (len0p == NULL || *len0p == NULL) ++ croak("hv_fetch(_len0) failed in _iterator_next\n"); ++ len0 = SvIV(*len0p); ++ ++ nextp = hv_delete(self, "_next", 5, 0); ++ if (nextp == NULL) ++ return 0; ++ next = (int *) SvPV(nextp, next_len); ++ next_len /= sizeof(int); ++ ++ namep = hv_delete(self, "_name", 5, 0); ++ if (namep == NULL) ++ return 0; ++ + /* + * Get next (after _next): name1 = [ 0, 2, next ] + */ @@ -188,7 +192,7 @@ MODULE = BSD::Sysctl PACKAGE = BSD::Sysctl PROTOTYPES: ENABLE -@@ -127,67 +164,18 @@ PROTOTYPES: ENABLE +@@ -127,67 +164,18 @@ SV * next (SV *refself) INIT: @@ -212,7 +216,7 @@ - p = (int *)SvPVX(*ctxp); - miblen = *p++; - memcpy(mib, p, miblen * sizeof(int)); - +- - if (!_init_iterator(self, mib, (int*)&miblen, 1)) { - XSRETURN_UNDEF; - } @@ -253,7 +257,7 @@ - ctx = newSVpvn((const char *)qoid, (miblen+1) * sizeof(int)); - SvREFCNT_inc(ctx); - hv_store(self, "_ctx", 4, ctx, 0); -- + + if (_iterator_next(self) == 0) + XSRETURN_UNDEF; + @@ -263,7 +267,102 @@ OUTPUT: RETVAL -@@ -878,6 +866,10 @@ _mib_set(const char *arg, const char *value) +@@ -583,25 +571,79 @@ + } + case FMT_DEVSTAT: { + HV *c = (HV *)sv_2mortal((SV *)newHV()); +- struct devstat *inf = (struct devstat *)buf; ++ struct devstat *inf = (struct devstat *)(buf + sizeof(buf)); + RETVAL = newRV((SV *)c); +- hv_store(c, "devno", 5, newSViv(inf->device_number), 0); +- hv_store(c, "unitno", 6, newSViv(inf->unit_number), 0); ++ char *p = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; ++ do { ++ char name[BUFSIZ]; ++ strcpy(name, "#.devno"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSViv(inf->device_number), 0); ++ strcpy(name, "#.device_name"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVpvn(inf->device_name, strlen(inf->device_name)), 0); ++ strcpy(name, "#.unitno"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSViv(inf->unit_number), 0); + #if __FreeBSD_version < 500000 +- hv_store(c, "sequence", 8, newSVpvn("", 0), 0); +- hv_store(c, "allocated", 9, newSVpvn("", 0), 0); +- hv_store(c, "startcount", 10, newSVpvn("", 0), 0); +- hv_store(c, "endcount", 8, newSVpvn("", 0), 0); +- hv_store(c, "busyfromsec", 11, newSVpvn("", 0), 0); +- hv_store(c, "busyfromfrac", 12, newSVpvn("", 0), 0); ++ strcpy(name, "#.sequence"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVpvn("", 0)), 0); ++ strcpy(name, "#.allocated"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVpvn("", 0)), 0); ++ strcpy(name, "#.startcount"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVpvn("", 0)), 0); ++ strcpy(name, "#.endcount"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVpvn("", 0)), 0); ++ strcpy(name, "#.busyfromsec"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVpvn("", 0)), 0); ++ strcpy(name, "#.busyfromfrac"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVpvn("", 0)), 0); ++ strcpy(name, "#.bytes_no_data"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVpvn("", 0)), 0); ++ strcpy(name, "#.bytes_read"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVpvn("", 0)), 0); ++ strcpy(name, "#.bytes_write"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVpvn("", 0)), 0); ++ strcpy(name, "#.bytes_free"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVpvn("", 0)), 0); ++ strcpy(name, "#.operations_no_data"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVpvn("", 0)), 0); ++ strcpy(name, "#.operations_read"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVpvn("", 0)), 0); ++ strcpy(name, "#.operations_write"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVpvn("", 0)), 0); ++ strcpy(name, "#.operations_free"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVpvn("", 0)), 0); + #else +- hv_store(c, "sequence", 8, newSVuv(inf->sequence0), 0); +- hv_store(c, "allocated", 9, newSViv(inf->allocated), 0); +- hv_store(c, "startcount", 10, newSViv(inf->start_count), 0); +- hv_store(c, "endcount", 8, newSViv(inf->end_count), 0); +- hv_store(c, "busyfromsec", 11, newSViv(inf->busy_from.sec), 0); +- hv_store(c, "busyfromfrac", 12, newSVuv(inf->busy_from.frac), 0); ++ strcpy(name, "#.sequence"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVuv(inf->sequence0), 0); ++ strcpy(name, "#.allocated"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSViv(inf->allocated), 0); ++ strcpy(name, "#.startcount"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSViv(inf->start_count), 0); ++ strcpy(name, "#.endcount"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSViv(inf->end_count), 0); ++ strcpy(name, "#.busyfromsec"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSViv(inf->busy_from.sec), 0); ++ strcpy(name, "#.busyfromfrac"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVuv(inf->busy_from.frac), 0); ++ strcpy(name, "#.bytes_no_data"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVuv(inf->bytes[DEVSTAT_NO_DATA]), 0); ++ strcpy(name, "#.bytes_read"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVuv(inf->bytes[DEVSTAT_READ]), 0); ++ strcpy(name, "#.bytes_write"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVuv(inf->bytes[DEVSTAT_WRITE]), 0); ++ strcpy(name, "#.bytes_free"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVuv(inf->bytes[DEVSTAT_FREE]), 0); ++ strcpy(name, "#.operations_no_data"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVuv(inf->operations[DEVSTAT_NO_DATA]), 0); ++ strcpy(name, "#.operations_read"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVuv(inf->operations[DEVSTAT_READ]), 0); ++ strcpy(name, "#.operations_write"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVuv(inf->operations[DEVSTAT_WRITE]), 0); ++ strcpy(name, "#.operations_free"); name[0] = *p; ++ hv_store(c, name, strlen(name), newSVuv(inf->operations[DEVSTAT_FREE]), 0); + #endif ++ ++p; ++ ++inf; ++ } while (inf < (struct devstat *)(buf + buflen)); + break; + } + #if __FreeBSD_version >= 500000 +@@ -878,6 +920,10 @@ SV **oidp; SV *oid; char *oid_data; @@ -274,11 +373,10 @@ int oid_fmt; int oid_len; int intval; -@@ -954,6 +946,42 @@ _mib_set(const char *arg, const char *value) - } +@@ -955,6 +1001,42 @@ newval = &ulongval; newsize = sizeof(ulongval); -+ break; + break; + + case FMT_64: + llval = strtoll(value, &endconvptr, 0); @@ -314,6 +412,7 @@ + uint64val = (uint64_t)ullval; + newval = &uint64val; + newsize = sizeof(uint64val); - break; ++ break; } + if (sysctl((int *)oid_data, oid_len, 0, 0, newval, newsize) == -1) {