From 9ae159169a6ee7a5abfaf222881c23a6d43a63ae Mon Sep 17 00:00:00 2001 From: Garrett Wollman Date: Wed, 10 Aug 1994 06:25:07 +0000 Subject: [PATCH] Make it easier for programs to figure out what revision of FreeBSD they are running under. Here's how to bootstrap (order is important): 1) Re-compile gcc (just the driver is all you need). 2) Re-compile libc. 3) Re-compile your kernel. Reboot. 4) cd /usr/src/include; make install You can now detect the compilation environment with the following code: #if !defined(__FreeBSD__) #define __FreeBSD_version 199401 #elif __FreeBSD__ == 1 #define __FreeBSD_version 199405 #else #include #endif You can determine the run-time environment by calling the new C library function getosreldate(), or by examining the MIB variable kern.osreldate. For the time being, the release date is defined as 199409, which we have already established as our target. --- include/Makefile | 7 ++++++- lib/libc/gen/Makefile.inc | 8 ++++---- sys/conf/newvers.sh | 3 ++- sys/kern/kern_sysctl.c | 3 +++ sys/sys/sysctl.h | 6 ++++-- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/include/Makefile b/include/Makefile index d8fd2d23c473..1fc89792ab80 100644 --- a/include/Makefile +++ b/include/Makefile @@ -1,5 +1,5 @@ # From: @(#)Makefile 8.2 (Berkeley) 1/4/94 -# $Id: Makefile,v 1.7 1994/08/04 20:49:28 wollman Exp $ +# $Id: Makefile,v 1.8 1994/08/07 22:29:20 wollman Exp $ # # Doing a make install builds /usr/include # @@ -43,6 +43,11 @@ beforeinstall: ${SHARED} install -c -o ${BINOWN} -g ${BINGRP} -m 444 $$i \ ${DESTDIR}/usr/include/$$i; \ done + @echo creating osreldate.h + @rm -f ${DESTDIR}/usr/include/osreldate.h + @echo \#'undef __FreeBSD_version' > ${DESTDIR}/usr/include/osreldate.h + @echo \#'define __FreeBSD_version '`sysctl -n kern.osreldate` \ + >> ${DESTDIR}/usr/include/osreldate.h @echo installing ${DIRS} @-for i in ${DIRS}; do \ if [ ! -d ${DESTDIR}/usr/include/$$i ]; \ diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index d9420b33f4c2..776fa971e7fd 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -7,10 +7,10 @@ SRCS+= alarm.c assert.c clock.c closedir.c confstr.c crypt.c ctermid.c \ ctime.c daemon.c devname.c difftime.c disklabel.c err.c errlst.c \ exec.c fnmatch.c frexp.c fstab.c fts.c getbsize.c getcap.c getcwd.c \ getdomainname.c getgrent.c getgrouplist.c gethostname.c getloadavg.c \ - getlogin.c getmntinfo.c getnetgrent.c getpagesize.c getpass.c \ - getpwent.c getttyent.c getusershell.c glob.c initgroups.c isatty.c \ - nice.c nlist.c opendir.c pause.c popen.c psignal.c pwcache.c raise.c \ - readdir.c rewinddir.c scandir.c seekdir.c setdomainname.c \ + getlogin.c getmntinfo.c getnetgrent.c getosreldate.c getpagesize.c \ + getpass.c getpwent.c getttyent.c getusershell.c glob.c initgroups.c \ + isatty.c nice.c nlist.c opendir.c pause.c popen.c psignal.c pwcache.c \ + raise.c readdir.c rewinddir.c scandir.c seekdir.c setdomainname.c \ sethostname.c setjmperr.c setmode.c siginterrupt.c siglist.c signal.c \ sigsetjmp.c sigsetops.c sleep.c sysconf.c sysctl.c syslog.c telldir.c \ termios.c time.c times.c timezone.c ttyname.c ttyslot.c ualarm.c \ diff --git a/sys/conf/newvers.sh b/sys/conf/newvers.sh index 6ee1edaa3978..adc2a27a1ee2 100644 --- a/sys/conf/newvers.sh +++ b/sys/conf/newvers.sh @@ -32,7 +32,7 @@ # SUCH DAMAGE. # # @(#)newvers.sh 8.1 (Berkeley) 4/20/94 -# $Id$ +# $Id: newvers.sh,v 1.3 1994/08/02 07:38:27 davidg Exp $ if [ ! -r version ] then @@ -43,6 +43,7 @@ touch version v=`cat version` u=${USER-root} d=`pwd` h=`hostname` t=`date` echo "char ostype[] = \"FreeBSD\";" > vers.c echo "char osrelease[] = \"2.0.0 (Development)\";" >> vers.c +echo "int osreldate = 199409;" >> vers.c echo "char sccs[4] = { '@', '(', '#', ')' };" >>vers.c echo "char version[] = \"FreeBSD 2.0.0 (Development) #${v}: ${t}\\n ${u}@${h}:${d}\\n\";" >>vers.c diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index ae7f7b988685..0896ebfe1e84 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -182,6 +182,7 @@ long hostid; int securelevel = -1; extern int vfs_update_wakeup; extern int vfs_update_interval; +extern int osreldate; /* * kernel related system variables. @@ -212,6 +213,8 @@ kern_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) return (sysctl_rdint(oldp, oldlenp, newp, BSD)); case KERN_VERSION: return (sysctl_rdstring(oldp, oldlenp, newp, version)); + case KERN_OSRELDATE: + return (sysctl_rdint(oldp, oldlenp, newp, osreldate)); case KERN_MAXVNODES: return(sysctl_int(oldp, oldlenp, newp, newlen, &desiredvnodes)); case KERN_MAXPROC: diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 590e579369f5..acad92526dd9 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * @(#)sysctl.h 8.1 (Berkeley) 6/2/93 - * $Id: sysctl.h,v 1.3 1994/08/08 00:30:12 wollman Exp $ + * $Id: sysctl.h,v 1.4 1994/08/08 15:41:08 wollman Exp $ */ #ifndef _SYS_SYSCTL_H_ @@ -130,7 +130,8 @@ struct ctlname { #define KERN_BOOTTIME 21 /* struct: time kernel was booted */ #define KERN_DOMAINNAME 22 /* string: YP domain name */ #define KERN_UPDATEINTERVAL 23 /* int: update process sleep time */ -#define KERN_MAXID 24 /* number of valid kern ids */ +#define KERN_OSRELDATE 24 /* int: OS release date */ +#define KERN_MAXID 25 /* number of valid kern ids */ #define CTL_KERN_NAMES { \ { 0, 0 }, \ @@ -157,6 +158,7 @@ struct ctlname { { "boottime", CTLTYPE_STRUCT }, \ { "domainname", CTLTYPE_STRING }, \ { "update", CTLTYPE_INT }, \ + { "osreldate", CTLTYPE_INT }, \ } /*