Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 07 Jun 2001 20:08:37 -0700
From:      Dima Dorfman <dima@unixfreak.org>
To:        Poul-Henning Kamp <phk@critter.freebsd.dk>
Cc:        Jim Pirzyk <Jim.Pirzyk@disney.com>, freebsd-arch@FreeBSD.ORG
Subject:   Re: sysctl interger type max 
Message-ID:  <20010608030837.DC9373E0B@bazooka.unixfreak.org>
In-Reply-To: <65709.991720741@critter>; from phk@critter.freebsd.dk on "Tue, 05 Jun 2001 07:59:01 %2B0200"

next in thread | previous in thread | raw e-mail | index | archive | help
Poul-Henning Kamp <phk@critter.freebsd.dk> writes:
> In message <01060412491406.00744@snoopy>, Jim Pirzyk writes:
> >On Monday 04 June 2001 12:43 pm, Poul-Henning Kamp wrote:
> >> In message <01060412361804.00744@snoopy>, Jim Pirzyk writes:
> >> >On Monday 04 June 2001 12:26 pm, Poul-Henning Kamp wrote:
> >> >> In message <01060412242703.00744@snoopy>, Jim Pirzyk writes:
> >> >> >In sysctl(8), you can set an integer type, but the max value
> >> >> >an int can be is 2 * N-1 where N is the size of int.  This leads
> >> >> >to a problem when trying to set kern.hostid and the number is
> >> >> >greater that 2GB on an IA32 system.  So my question is should

The kern.hostid sysctl is defined as a signed integer, and the
variable itself is a signed long, so I don't think you're supposed to
be able to set it to greater than 2GB.  Perhaps this is a bug.

> >> >> >CTLTYPE_INT be treated as a long or some other larger numeric
> >> >> >number?  Or should we declare some CLTYPE_UINT type?
> >> >>
> >> >> We do have an SYSCTL_UINT these days.
> >> >
> >> >Yes for establishing the oid in the kernel, but sysctl command
> >> >line is limited to 2 * 31 bits even if the variable is set to
> >> >CLTYPE_{UINT|LONG|ULONG}. This means you cannot set the variables
> >> >to a possible range of values.
> >>
> >> Then sysctl(8) is obviously broken...
> >
> >Yes, so how should it be fixed?  Add another CTLTYPE_* or make
> >CTLTYPE_INT handle say up to 'long long'?
> 
> CTLTYPE_UINT should be fixed in sysctl(8) to handle [0..2^32-1]

CTLTYPE_UINT doesn't exist.  SYSCTL_(U)(INT|LONG) set the format
argument to indicate the type.  Currently, sysctl(8) ignores this
format and treats everything that's a CTLTYPE_INT as being a signed
integer, which is obviously wrong.  Attached is a patch which makes it
look up the format to determine how to deal with it.  This seems a
little too simple to me, but it seems to work.  Did I miss anything?

Thanks,

					Dima Dorfman
					dima@unixfreak.org

Index: sysctl.c
===================================================================
RCS file: /stl/src/FreeBSD/src/sbin/sysctl/sysctl.c,v
retrieving revision 1.35
diff -u -r1.35 sysctl.c
--- sysctl.c	2001/06/01 02:58:09	1.35
+++ sysctl.c	2001/06/08 03:00:25
@@ -143,10 +143,14 @@
 {
 	int len, i, j;
 	void *newval = 0;
-	int intval, newsize = 0;
+	int newsize = 0;
+	int intval;
+	unsigned int uintval;
+	long longval;
+	unsigned long ulongval;
 	quad_t quadval;
 	int mib[CTL_MAXNAME];
-	char *cp, *bufp, buf[BUFSIZ];
+	char *cp, *bufp, buf[BUFSIZ], ofmt[BUFSIZ];
 	u_int kind;
 
 	bufp = buf;
@@ -164,7 +168,7 @@
 	if (len < 0) 
 		errx(1, "unknown oid '%s'", bufp);
 
-	if (oidfmt(mib, len, 0, &kind))
+	if (oidfmt(mib, len, ofmt, &kind))
 		err(1, "couldn't find format of oid '%s'", bufp);
 
 	if (newval == NULL) {
@@ -184,10 +188,24 @@
 	
 		switch (kind & CTLTYPE) {
 			case CTLTYPE_INT:
-				intval = (int) strtol(newval, NULL, 0);
-				newval = &intval;
-				newsize = sizeof intval;
-				break;
+				if (strcmp(ofmt, "I") == 0) {
+					intval = (int)strtol(newval, NULL, 0);
+					newval = &intval;
+					newsize = sizeof(intval);
+				} else if (strcmp(ofmt, "IU") == 0) {
+					uintval = (unsigned int)strtoul(newval,
+					    NULL, 0);
+					newval = &uintval;
+					newsize = sizeof(uintval);
+				} else if (strcmp(ofmt, "L") == 0) {
+					longval = strtol(newval, NULL, 0);
+					newval = &longval;
+					newsize = sizeof(longval);
+				} else if (strcmp(ofmt, "LU") == 0) {
+					ulongval = strtoul(newval, NULL, 0);
+					newval = &ulongval;
+					newsize = sizeof(ulongval);
+				}					
 				break;
 			case CTLTYPE_STRING:
 				break;

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010608030837.DC9373E0B>