View | Details | Raw Unified | Return to bug 226899 | Differences between
and this patch

Collapse All | Expand All

(-)/tmp/diff (-34 / +133 lines)
Lines 1-5 Link Here
1
--- Sysctl.xs.orig	2014-01-21 23:02:47 UTC
1
--- Sysctl.xs.orig	2014-01-22 00:02:47.000000000 +0100
2
+++ Sysctl.xs
2
+++ Sysctl.xs	2018-05-11 10:26:40.364491000 +0200
3
@@ -14,6 +14,7 @@
3
@@ -14,6 +14,7 @@
4
 
4
 
5
 #include <stdio.h>
5
 #include <stdio.h>
Lines 48-59 Link Here
48
-    SV **clenp;
48
-    SV **clenp;
49
-    int cmplen;
49
-    int cmplen;
50
-    int j;
50
-    int j;
51
+_iterator_next(HV *self)
51
-
52
+{
53
+	SV *nextp, **len0p, *namep;
54
+	int *next, name1[CTL_MAXNAME + 2], name2[CTL_MAXNAME + 2];
55
+	size_t len0, next_len, len1, len2;
56
 
57
-    qoid[0] = 0;
52
-    qoid[0] = 0;
58
-    qoid[1] = 2;
53
-    qoid[1] = 2;
59
-    if (valid) {
54
-    if (valid) {
Lines 90-98 Link Here
90
-        SvREFCNT_inc(clen);
85
-        SvREFCNT_inc(clen);
91
-        hv_store(self, "_len", 4, clen, 0);
86
-        hv_store(self, "_len", 4, clen, 0);
92
-    }
87
-    }
93
+	if (! hv_exists(self, "_len0", 5))
88
-
94
+		_iterator_first(self);
95
 
96
-    /*
89
-    /*
97
-    printf( "next: " );
90
-    printf( "next: " );
98
-    for (j = 0; j < qoidlen; ++j) {
91
-    for (j = 0; j < qoidlen; ++j) {
Lines 100-116 Link Here
100
-    }
93
-    }
101
-    printf("\n");
94
-    printf("\n");
102
-    */
95
-    */
103
+	len0p = hv_fetch(self, "_len0", 5, 0);
96
-
104
+	if (len0p == NULL || *len0p == NULL)
105
+		croak("hv_fetch(_len0) failed in _iterator_next\n");
106
+	len0 = SvIV(*len0p);
107
+	
108
+	nextp = hv_delete(self, "_next", 5, 0);
109
+	if (nextp == NULL)
110
+		return 0;
111
+	next = (int *) SvPV(nextp, next_len);
112
+	next_len /= sizeof(int);
113
 
114
-    /* load the mib */
97
-    /* load the mib */
115
-    if (sysctl(qoid, qoidlen, mib, (size_t*)miblenp, 0, 0) == -1) {
98
-    if (sysctl(qoid, qoidlen, mib, (size_t*)miblenp, 0, 0) == -1) {
116
-        return 0;
99
-        return 0;
Lines 119-134 Link Here
119
-    if (*miblenp < cmplen) {
102
-    if (*miblenp < cmplen) {
120
-        return 0 ;
103
-        return 0 ;
121
-    }
104
-    }
122
+	namep = hv_delete(self, "_name", 5, 0);
105
-
123
+	if (namep == NULL)
124
+		return 0;
125
 
126
-    for (j = 0; j < cmplen; ++j) {
106
-    for (j = 0; j < cmplen; ++j) {
127
-        if (mib[j] != qoid[j+2]) {
107
-        if (mib[j] != qoid[j+2]) {
128
-            return 0;
108
-            return 0;
129
-        }
109
-        }
130
-    }
110
-    }
131
-    return 1;
111
-    return 1;
112
+_iterator_next(HV *self)
113
+{
114
+	SV *nextp, **len0p, *namep;
115
+	int *next, name1[CTL_MAXNAME + 2], name2[CTL_MAXNAME + 2];
116
+	size_t len0, next_len, len1, len2;
117
+
118
+	if (! hv_exists(self, "_len0", 5))
119
+		_iterator_first(self);
120
+
121
+	len0p = hv_fetch(self, "_len0", 5, 0);
122
+	if (len0p == NULL || *len0p == NULL)
123
+		croak("hv_fetch(_len0) failed in _iterator_next\n");
124
+	len0 = SvIV(*len0p);
125
+	
126
+	nextp = hv_delete(self, "_next", 5, 0);
127
+	if (nextp == NULL)
128
+		return 0;
129
+	next = (int *) SvPV(nextp, next_len);
130
+	next_len /= sizeof(int);
131
+
132
+	namep = hv_delete(self, "_name", 5, 0);
133
+	if (namep == NULL)
134
+		return 0;
135
+
132
+	/*
136
+	/*
133
+	 * Get next (after _next): name1 = [ 0, 2, next ]
137
+	 * Get next (after _next): name1 = [ 0, 2, next ]
134
+	 */
138
+	 */
Lines 188-194 Link Here
188
 MODULE = BSD::Sysctl   PACKAGE = BSD::Sysctl
192
 MODULE = BSD::Sysctl   PACKAGE = BSD::Sysctl
189
 
193
 
190
 PROTOTYPES: ENABLE
194
 PROTOTYPES: ENABLE
191
@@ -127,67 +164,18 @@ PROTOTYPES: ENABLE
195
@@ -127,67 +164,18 @@
192
 SV *
196
 SV *
193
 next (SV *refself)
197
 next (SV *refself)
194
     INIT:
198
     INIT:
Lines 212-218 Link Here
212
-            p = (int *)SvPVX(*ctxp);
216
-            p = (int *)SvPVX(*ctxp);
213
-            miblen = *p++;
217
-            miblen = *p++;
214
-            memcpy(mib, p, miblen * sizeof(int));
218
-            memcpy(mib, p, miblen * sizeof(int));
215
 
219
-
216
-            if (!_init_iterator(self, mib, (int*)&miblen, 1)) {
220
-            if (!_init_iterator(self, mib, (int*)&miblen, 1)) {
217
-                XSRETURN_UNDEF;
221
-                XSRETURN_UNDEF;
218
-            }
222
-            }
Lines 253-259 Link Here
253
-        ctx = newSVpvn((const char *)qoid, (miblen+1) * sizeof(int));
257
-        ctx = newSVpvn((const char *)qoid, (miblen+1) * sizeof(int));
254
-        SvREFCNT_inc(ctx);
258
-        SvREFCNT_inc(ctx);
255
-        hv_store(self, "_ctx", 4, ctx, 0);
259
-        hv_store(self, "_ctx", 4, ctx, 0);
256
-
260
 
257
+	if (_iterator_next(self) == 0)
261
+	if (_iterator_next(self) == 0)
258
+		XSRETURN_UNDEF;
262
+		XSRETURN_UNDEF;
259
+	
263
+	
Lines 263-269 Link Here
263
     OUTPUT:
267
     OUTPUT:
264
         RETVAL
268
         RETVAL
265
 
269
 
266
@@ -878,6 +866,10 @@ _mib_set(const char *arg, const char *value)
270
@@ -583,25 +571,79 @@
271
         }
272
         case FMT_DEVSTAT: {
273
             HV *c = (HV *)sv_2mortal((SV *)newHV());
274
-            struct devstat *inf = (struct devstat *)buf;
275
+            struct devstat *inf = (struct devstat *)(buf + sizeof(buf));
276
             RETVAL = newRV((SV *)c);
277
-            hv_store(c, "devno",           5, newSViv(inf->device_number), 0);
278
-            hv_store(c, "unitno",          6, newSViv(inf->unit_number), 0);
279
+            char *p = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
280
+            do {
281
+                char name[BUFSIZ];
282
+                strcpy(name, "#.devno"); name[0] = *p;
283
+                hv_store(c, name, strlen(name), newSViv(inf->device_number), 0);
284
+                strcpy(name, "#.device_name"); name[0] = *p;
285
+                hv_store(c, name, strlen(name), newSVpvn(inf->device_name, strlen(inf->device_name)), 0);
286
+                strcpy(name, "#.unitno"); name[0] = *p;
287
+                hv_store(c, name, strlen(name), newSViv(inf->unit_number), 0);
288
 #if __FreeBSD_version < 500000
289
-            hv_store(c, "sequence",        8, newSVpvn("", 0), 0);
290
-            hv_store(c, "allocated",       9, newSVpvn("", 0), 0);
291
-            hv_store(c, "startcount",     10, newSVpvn("", 0), 0);
292
-            hv_store(c, "endcount",        8, newSVpvn("", 0), 0);
293
-            hv_store(c, "busyfromsec",    11, newSVpvn("", 0), 0);
294
-            hv_store(c, "busyfromfrac",   12, newSVpvn("", 0), 0);
295
+                strcpy(name, "#.sequence"); name[0] = *p;
296
+                hv_store(c, name, strlen(name), newSVpvn("", 0)), 0);
297
+                strcpy(name, "#.allocated"); name[0] = *p;
298
+                hv_store(c, name, strlen(name), newSVpvn("", 0)), 0);
299
+                strcpy(name, "#.startcount"); name[0] = *p;
300
+                hv_store(c, name, strlen(name), newSVpvn("", 0)), 0);
301
+                strcpy(name, "#.endcount"); name[0] = *p;
302
+                hv_store(c, name, strlen(name), newSVpvn("", 0)), 0);
303
+                strcpy(name, "#.busyfromsec"); name[0] = *p;
304
+                hv_store(c, name, strlen(name), newSVpvn("", 0)), 0);
305
+                strcpy(name, "#.busyfromfrac"); name[0] = *p;
306
+                hv_store(c, name, strlen(name), newSVpvn("", 0)), 0);
307
+                strcpy(name, "#.bytes_no_data"); name[0] = *p;
308
+                hv_store(c, name, strlen(name), newSVpvn("", 0)), 0);
309
+                strcpy(name, "#.bytes_read"); name[0] = *p;
310
+                hv_store(c, name, strlen(name), newSVpvn("", 0)), 0);
311
+                strcpy(name, "#.bytes_write"); name[0] = *p;
312
+                hv_store(c, name, strlen(name), newSVpvn("", 0)), 0);
313
+                strcpy(name, "#.bytes_free"); name[0] = *p;
314
+                hv_store(c, name, strlen(name), newSVpvn("", 0)), 0);
315
+                strcpy(name, "#.operations_no_data"); name[0] = *p;
316
+                hv_store(c, name, strlen(name), newSVpvn("", 0)), 0);
317
+                strcpy(name, "#.operations_read"); name[0] = *p;
318
+                hv_store(c, name, strlen(name), newSVpvn("", 0)), 0);
319
+                strcpy(name, "#.operations_write"); name[0] = *p;
320
+                hv_store(c, name, strlen(name), newSVpvn("", 0)), 0);
321
+                strcpy(name, "#.operations_free"); name[0] = *p;
322
+                hv_store(c, name, strlen(name), newSVpvn("", 0)), 0);
323
 #else
324
-            hv_store(c, "sequence",        8, newSVuv(inf->sequence0), 0);
325
-            hv_store(c, "allocated",       9, newSViv(inf->allocated), 0);
326
-            hv_store(c, "startcount",     10, newSViv(inf->start_count), 0);
327
-            hv_store(c, "endcount",        8, newSViv(inf->end_count), 0);
328
-            hv_store(c, "busyfromsec",    11, newSViv(inf->busy_from.sec), 0);
329
-            hv_store(c, "busyfromfrac",   12, newSVuv(inf->busy_from.frac), 0);
330
+                strcpy(name, "#.sequence"); name[0] = *p;
331
+                hv_store(c, name, strlen(name), newSVuv(inf->sequence0), 0);
332
+                strcpy(name, "#.allocated"); name[0] = *p;
333
+                hv_store(c, name, strlen(name), newSViv(inf->allocated), 0);
334
+                strcpy(name, "#.startcount"); name[0] = *p;
335
+                hv_store(c, name, strlen(name), newSViv(inf->start_count), 0);
336
+                strcpy(name, "#.endcount"); name[0] = *p;
337
+                hv_store(c, name, strlen(name), newSViv(inf->end_count), 0);
338
+                strcpy(name, "#.busyfromsec"); name[0] = *p;
339
+                hv_store(c, name, strlen(name), newSViv(inf->busy_from.sec), 0);
340
+                strcpy(name, "#.busyfromfrac"); name[0] = *p;
341
+                hv_store(c, name, strlen(name), newSVuv(inf->busy_from.frac), 0);
342
+                strcpy(name, "#.bytes_no_data"); name[0] = *p;
343
+                hv_store(c, name, strlen(name), newSVuv(inf->bytes[DEVSTAT_NO_DATA]), 0);
344
+                strcpy(name, "#.bytes_read"); name[0] = *p;
345
+                hv_store(c, name, strlen(name), newSVuv(inf->bytes[DEVSTAT_READ]), 0);
346
+                strcpy(name, "#.bytes_write"); name[0] = *p;
347
+                hv_store(c, name, strlen(name), newSVuv(inf->bytes[DEVSTAT_WRITE]), 0);
348
+                strcpy(name, "#.bytes_free"); name[0] = *p;
349
+                hv_store(c, name, strlen(name), newSVuv(inf->bytes[DEVSTAT_FREE]), 0);
350
+                strcpy(name, "#.operations_no_data"); name[0] = *p;
351
+                hv_store(c, name, strlen(name), newSVuv(inf->operations[DEVSTAT_NO_DATA]), 0);
352
+                strcpy(name, "#.operations_read"); name[0] = *p;
353
+                hv_store(c, name, strlen(name), newSVuv(inf->operations[DEVSTAT_READ]), 0);
354
+                strcpy(name, "#.operations_write"); name[0] = *p;
355
+                hv_store(c, name, strlen(name), newSVuv(inf->operations[DEVSTAT_WRITE]), 0);
356
+                strcpy(name, "#.operations_free"); name[0] = *p;
357
+                hv_store(c, name, strlen(name), newSVuv(inf->operations[DEVSTAT_FREE]), 0);
358
 #endif
359
+                ++p;
360
+                ++inf;
361
+            } while (inf < (struct devstat *)(buf + buflen));
362
             break;
363
         }
364
 #if __FreeBSD_version >= 500000
365
@@ -878,6 +920,10 @@
267
         SV **oidp;
366
         SV **oidp;
268
         SV *oid;
367
         SV *oid;
269
         char *oid_data;
368
         char *oid_data;
Lines 274-284 Link Here
274
         int oid_fmt;
373
         int oid_fmt;
275
         int oid_len;
374
         int oid_len;
276
         int intval;
375
         int intval;
277
@@ -954,6 +946,42 @@ _mib_set(const char *arg, const char *value)
376
@@ -955,6 +1001,42 @@
278
             }
279
             newval  = &ulongval;
377
             newval  = &ulongval;
280
             newsize = sizeof(ulongval);
378
             newsize = sizeof(ulongval);
281
+            break;
379
             break;
282
+
380
+
283
+        case FMT_64:
381
+        case FMT_64:
284
+            llval = strtoll(value, &endconvptr, 0);
382
+            llval = strtoll(value, &endconvptr, 0);
Lines 314-319 Link Here
314
+                uint64val = (uint64_t)ullval;
412
+                uint64val = (uint64_t)ullval;
315
+            newval  = &uint64val;
413
+            newval  = &uint64val;
316
+            newsize = sizeof(uint64val);
414
+            newsize = sizeof(uint64val);
317
             break;
415
+            break;
318
         }
416
         }
319
         
417
         
418
         if (sysctl((int *)oid_data, oid_len, 0, 0, newval, newsize) == -1) {

Return to bug 226899