View | Details | Raw Unified | Return to bug 33150
Collapse All | Expand All

(-)sysctl.c (-2 / +32 lines)
Lines 49-54 Link Here
49
#include <sys/stat.h>
49
#include <sys/stat.h>
50
#include <sys/sysctl.h>
50
#include <sys/sysctl.h>
51
#include <sys/resource.h>
51
#include <sys/resource.h>
52
#include <sys/param.h>
52
53
53
#include <ctype.h>
54
#include <ctype.h>
54
#include <err.h>
55
#include <err.h>
Lines 66-71 Link Here
66
static int	sysctl_all (int *oid, int len);
67
static int	sysctl_all (int *oid, int len);
67
static int	name2oid(char *, int *);
68
static int	name2oid(char *, int *);
68
69
70
static void	set_T_dev_t (char *, void **, int *);
71
69
static void
72
static void
70
usage(void)
73
usage(void)
71
{
74
{
Lines 153-159 Link Here
153
	size_t newsize = 0;
156
	size_t newsize = 0;
154
	quad_t quadval;
157
	quad_t quadval;
155
	int mib[CTL_MAXNAME];
158
	int mib[CTL_MAXNAME];
156
	char *cp, *bufp, buf[BUFSIZ];
159
	char *cp, *bufp, buf[BUFSIZ], fmt[BUFSIZ];
157
	u_int kind;
160
	u_int kind;
158
161
159
	bufp = buf;
162
	bufp = buf;
Lines 171-177 Link Here
171
	if (len < 0) 
174
	if (len < 0) 
172
		errx(1, "unknown oid '%s'", bufp);
175
		errx(1, "unknown oid '%s'", bufp);
173
176
174
	if (oidfmt(mib, len, 0, &kind))
177
	if (oidfmt(mib, len, fmt, &kind))
175
		err(1, "couldn't find format of oid '%s'", bufp);
178
		err(1, "couldn't find format of oid '%s'", bufp);
176
179
177
	if (newval == NULL) {
180
	if (newval == NULL) {
Lines 217-222 Link Here
217
				newval = &quadval;
220
				newval = &quadval;
218
				newsize = sizeof(quadval);
221
				newsize = sizeof(quadval);
219
				break;
222
				break;
223
			case CTLTYPE_OPAQUE:
224
				if (strcmp(fmt, "T,dev_t") == 0) {
225
					set_T_dev_t ((char*)newval, &newval, &newsize);
226
					break;
227
				}
228
				/* FALLTHROUGH */
220
			default:
229
			default:
221
				errx(1, "oid '%s' is type %d,"
230
				errx(1, "oid '%s' is type %d,"
222
					" cannot set that", bufp,
231
					" cannot set that", bufp,
Lines 316-321 Link Here
316
				major(*d), minor(*d));
325
				major(*d), minor(*d));
317
	}
326
	}
318
	return (0);
327
	return (0);
328
}
329
330
static void
331
set_T_dev_t (char *path, void **val, int *size)
332
{
333
	static struct stat statb;
334
335
	if (strcmp(path, "none") && strcmp(path, "off")) {
336
		int rc = stat (path, &statb);
337
		if (rc) {
338
			err(1, "cannot stat %s", path);
339
		}
340
341
		if (!S_ISCHR(statb.st_mode)) {
342
			errx(1, "must specify a device special file.");
343
		}
344
	} else {
345
		statb.st_rdev = NODEV;
346
	}
347
	*val = (char*) &statb.st_rdev;
348
	*size = sizeof statb.st_rdev;
319
}
349
}
320
350
321
/*
351
/*

Return to bug 33150