diff options
author | peter <peter@FreeBSD.org> | 2001-03-24 04:40:49 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 2001-03-24 04:40:49 +0000 |
commit | 8de1f8b9b5ad238cf0a9754e92d09f719f81ef03 (patch) | |
tree | 8775ee28f9284ae7ffe716c67b5f3f80e03d2f91 /lib/libc | |
parent | f9d1d96367a9e1830ed904b9e98409637499361c (diff) | |
download | FreeBSD-src-8de1f8b9b5ad238cf0a9754e92d09f719f81ef03.zip FreeBSD-src-8de1f8b9b5ad238cf0a9754e92d09f719f81ef03.tar.gz |
This is kind of a hack, but it should work. Currently, world is broken
because libc/rpc/key_call.c references uname(), and ps/print.c also
defines uname(), and ps is linked statically. This leads to a symbol
clash. The userland uname(3) kinda sucked anyway as the hostname
etc was too short. And since the libc rpc interface now uses
the utsname.nodename which gets truncated, I was tempted into doing
something about it. Create a new userland uname function, called
__xuname() which takes an extra argument that allows you to change
the size of the fields. uname() becomes a static inline function
in sys/utsname.h that passes the extra argument in. struct utsname
has its field members expanded by default now in userland.
We still provide a 'uname' externally linkable function for things
that either think that they ``know'' the utsname format and assume
32 character strings and bypass the include file, or objects that
are linked against old libcs. ie: just about every plausible
case that I can think of is covered. Should we ever change the
default lengths again, a libc major bump should not be required
as the size is now passed to the function.
XXX the uname(2) in the kernel is for FreeBSD 1.1 binary compatability!
All the uname(3) functions that are exported to userland are actually
implemented in libc with sysctl. uname(1) uses sysctl directly and
does not call uname(3).
PR: bin/4688
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/gen/Makefile.inc | 2 | ||||
-rw-r--r-- | lib/libc/gen/__xuname.c | 11 | ||||
-rw-r--r-- | lib/libc/gen/uname.c | 82 |
3 files changed, 14 insertions, 81 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index 93d62a1..9bc51fd 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -4,7 +4,7 @@ # machine-independent gen sources .PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/gen ${.CURDIR}/../libc/gen -SRCS+= _pthread_stubs.c _rand48.c _spinlock_stub.c _thread_init.c \ +SRCS+= __xuname.c _pthread_stubs.c _rand48.c _spinlock_stub.c _thread_init.c \ alarm.c arc4random.c assert.c basename.c \ clock.c closedir.c confstr.c \ crypt.c ctermid.c daemon.c devname.c dirname.c disklabel.c \ diff --git a/lib/libc/gen/__xuname.c b/lib/libc/gen/__xuname.c index 944c2dc..d97c4ad 100644 --- a/lib/libc/gen/__xuname.c +++ b/lib/libc/gen/__xuname.c @@ -43,14 +43,21 @@ static const char rcsid[] = #include <errno.h> int -uname(name) - struct utsname *name; +__xuname(int namesize, void *namebuf) { int mib[2], rval; size_t len; char *p; int oerrno; + struct xutsname { + char sysname[namesize]; /* Name of this OS. */ + char nodename[namesize]; /* Name of this network node. */ + char release[namesize]; /* Release level. */ + char version[namesize]; /* Version level. */ + char machine[namesize]; /* Hardware type. */ + } *name; + name = (struct xutsname *)namebuf; rval = 0; mib[0] = CTL_KERN; diff --git a/lib/libc/gen/uname.c b/lib/libc/gen/uname.c index 944c2dc..75a3f189 100644 --- a/lib/libc/gen/uname.c +++ b/lib/libc/gen/uname.c @@ -37,89 +37,15 @@ static const char rcsid[] = "$FreeBSD$"; #endif /* LIBC_SCCS and not lint */ +#define uname wrapped_uname #include <sys/param.h> #include <sys/sysctl.h> #include <sys/utsname.h> #include <errno.h> +#undef uname int -uname(name) - struct utsname *name; +uname(struct utsname *name) { - int mib[2], rval; - size_t len; - char *p; - int oerrno; - - rval = 0; - - mib[0] = CTL_KERN; - mib[1] = KERN_OSTYPE; - len = sizeof(name->sysname); - oerrno = errno; - if (sysctl(mib, 2, &name->sysname, &len, NULL, 0) == -1) { - if(errno == ENOMEM) - errno = oerrno; - else - rval = -1; - } - name->sysname[sizeof(name->sysname) - 1] = '\0'; - - mib[0] = CTL_KERN; - mib[1] = KERN_HOSTNAME; - len = sizeof(name->nodename); - oerrno = errno; - if (sysctl(mib, 2, &name->nodename, &len, NULL, 0) == -1) { - if(errno == ENOMEM) - errno = oerrno; - else - rval = -1; - } - name->nodename[sizeof(name->nodename) - 1] = '\0'; - - mib[0] = CTL_KERN; - mib[1] = KERN_OSRELEASE; - len = sizeof(name->release); - oerrno = errno; - if (sysctl(mib, 2, &name->release, &len, NULL, 0) == -1) { - if(errno == ENOMEM) - errno = oerrno; - else - rval = -1; - } - name->release[sizeof(name->release) - 1] = '\0'; - - /* The version may have newlines in it, turn them into spaces. */ - mib[0] = CTL_KERN; - mib[1] = KERN_VERSION; - len = sizeof(name->version); - oerrno = errno; - if (sysctl(mib, 2, &name->version, &len, NULL, 0) == -1) { - if (errno == ENOMEM) - errno = oerrno; - else - rval = -1; - } - name->version[sizeof(name->version) - 1] = '\0'; - for (p = name->version; len--; ++p) { - if (*p == '\n' || *p == '\t') { - if (len > 1) - *p = ' '; - else - *p = '\0'; - } - } - - mib[0] = CTL_HW; - mib[1] = HW_MACHINE; - len = sizeof(name->machine); - oerrno = errno; - if (sysctl(mib, 2, &name->machine, &len, NULL, 0) == -1) { - if (errno == ENOMEM) - errno = oerrno; - else - rval = -1; - } - name->machine[sizeof(name->machine) - 1] = '\0'; - return (rval); + return __xuname(32, name); } |