Date: Fri, 20 May 2005 14:17:25 -0700 From: Colin Percival <cperciva@freebsd.org> To: John-Mark Gurney <gurney_j@resnet.uoregon.edu> Cc: freebsd-arch@freebsd.org Subject: Re: RFC: Using fixed-length strings for version[] and osrelease[] Message-ID: <428E53E5.7050509@freebsd.org> In-Reply-To: <20050520064929.GC959@funkthat.com> References: <428D26C1.2020201@freebsd.org> <20050520064929.GC959@funkthat.com>
next in thread | previous in thread | raw e-mail | index | archive | help
John-Mark Gurney wrote: > Colin Percival wrote this message on Thu, May 19, 2005 at 16:52 -0700: >>The lengths 512 and 64 are chosen as being considerably more than double the >>likely lengths of these strings; on my system, these two strings are 12 bytes >>and 134 bytes long respectively. > > Nope, but I would say make them just a bit larger than necessary right > now, and add the necessary CTASSERT lines to make sure we don't overflow.. > > I'd say no more than 256 bytes for the VERSION string, since CTASSERT will > prevent the overflow... > > Though you might want to make the fixed size dependent upon the release > kernel and not for custom compiled kernels... No point in penalizing > kernels that don't need this... I don't think there's much point worrying about saving a few hundred bytes, but I've put together a patch which allows the strings to be lengthened if necessary. The lengths are now 256 bytes and 32 bytes. I've also added a BRANCH_OVERRIDE variable which can bs set in the environment; this is probably not going to be useful to many people, but it will allow me to identify the osrelease[] string and avoid distributing a new kernel when the patch number is bumped due to a userland-only fix. Any objections to the following patch? @@ -33,6 +33,9 @@ TYPE="FreeBSD" REVISION="6.0" BRANCH="CURRENT" +if [ "X${BRANCH_OVERRIDE}" != "X" ]; then + BRANCH=${BRANCH_OVERRIDE} +fi RELEASE="${REVISION}-${BRANCH}" VERSION="${TYPE} ${RELEASE}" @@ -85,11 +88,14 @@ v=`cat version` u=${USER:-root} d=`pwd` i=`${MAKE:-make} -V KERN_IDENT` cat << EOF > vers.c $COPYRIGHT +#define VERSTR "${VERSION} #${v}: ${t}\\n ${u}@${h}:${d}\\n" +#define RELSTR "${RELEASE}" + char sccspad[32 - 4 /* sizeof(sccs) */] = { '\\0' }; char sccs[4] = { '@', '(', '#', ')' }; -char version[] = "${VERSION} #${v}: ${t}\\n ${u}@${h}:${d}\\n"; +char version[sizeof(VERSTR) > 256 ? sizeof(VERSTR) : 256] = VERSTR; char ostype[] = "${TYPE}"; -char osrelease[] = "${RELEASE}"; +char osrelease[sizeof(RELSTR) > 32 ? sizeof(RELSTR) : 32] = RELSTR; int osreldate = ${RELDATE}; char kern_ident[] = "${i}"; EOF Colin Percival
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?428E53E5.7050509>