From owner-freebsd-arch Thu Jun 7 20: 8:43 2001 Delivered-To: freebsd-arch@freebsd.org Received: from bazooka.unixfreak.org (bazooka.unixfreak.org [63.198.170.138]) by hub.freebsd.org (Postfix) with ESMTP id 8F1D637B406 for ; Thu, 7 Jun 2001 20:08:38 -0700 (PDT) (envelope-from dima@unixfreak.org) Received: from hornet.unixfreak.org (hornet [63.198.170.140]) by bazooka.unixfreak.org (Postfix) with ESMTP id DC9373E0B; Thu, 7 Jun 2001 20:08:37 -0700 (PDT) To: Poul-Henning Kamp Cc: Jim Pirzyk , freebsd-arch@FreeBSD.ORG Subject: Re: sysctl interger type max In-Reply-To: <65709.991720741@critter>; from phk@critter.freebsd.dk on "Tue, 05 Jun 2001 07:59:01 +0200" Date: Thu, 07 Jun 2001 20:08:37 -0700 From: Dima Dorfman Message-Id: <20010608030837.DC9373E0B@bazooka.unixfreak.org> Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Poul-Henning Kamp 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