diffs for uname (posix!) system call, provided by John Brezak <brezak@osf.org>

This commit is contained in:
cgd 1993-05-06 10:46:12 +00:00
parent c7796f288f
commit c5d886aff7
16 changed files with 370 additions and 18 deletions

View File

@ -28,7 +28,7 @@ ASM= accept.o access.o acct.o adjtime.o async_daemon.o bind.o chdir.o \
shutdown.o sigaction.o sigstack.o socket.o socketpair.o stat.o \
statfs.o swapon.o symlink.o sync.o truncate.o umask.o unlink.o \
unmount.o utimes.o vadvise.o wait4.o write.o writev.o getdomainname.o \
setdomainname.o
setdomainname.o uname.o
PSEUDO= _exit.o _getlogin.o
@ -81,7 +81,7 @@ MAN2+= accept.0 access.0 acct.0 adjtime.0 async_daemon.0 bind.0 brk.0 \
shutdown.0 sigaction.0 sigprocmask.0 sigreturn.0 sigstack.0 \
sigsuspend.0 socket.0 socketpair.0 stat.0 statfs.0 swapon.0 \
symlink.0 sync.0 syscall.0 truncate.0 umask.0 unlink.0 utimes.0 \
vfork.0 wait.0 write.0 getdomainname.0
vfork.0 wait.0 write.0 getdomainname.0 uname.0
MLINKS+=brk.2 sbrk.2
MLINKS+=dup.2 dup2.2

99
lib/libc/sys/uname.2 Normal file
View File

@ -0,0 +1,99 @@
.\" Copyright (c) 1983, 1991 The Regents of the University of California.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)uname.2 6.6 (Berkeley) 3/10/91
.\"
.Dd March 29, 1993
.Dt UNAME 2
.Os Posix
.Sh NAME
.Nm uname
.Nd get host information
.Sh SYNOPSIS
.Fd #include <sys/utsname.h>
.Ft int
.Fn uname "struct utsname *name"
.Sh DESCRIPTION
.Fn Uname
returns the information identifying the current UNIX system
in the structure pointed to by
.Fa name.
.Pp
.Fn Uname
uses the structure defined in
.Aq Pa sys/utsname.h
whose members are:
.Bd -literal
struct utsname {
char sysname[SYS_NMLN];
char nodename[SYS_NMLN];
char release[SYS_NMLN];
char version[SYS_NMLN];
char machine[SYS_NMLN];
};
.Ed
.Pp
.Fn Uname
returns a null-terminated character string naming the
current UNIX system in the character array
.Fa sysname .
Similarly,
.Fa nodename
contains the name that the system is known by on a
communication network.
.Fa Release
and
.Fa version
further identify the operating system.
.Fa Machine
contains the standard name that identifies the hardware
that the UNIX system is running on.
.Sn ERRORS
.Bl -tag -width ENAMETOOLONGAA
.It Bq Er EFAULT
.Fn Uname
will fail if
.Fa name
points to an invalid address.
.Sh RETURN VALUE
Upon successful completion a value of 0 is returned.
Otherwise, a value of -1 is returned and
.Va errno
is set to indicate the error.
.Sh SEE ALSO
.Xr hostname 1 ,
.Xr machine 1 ,
.Xr gethostname 2
.Sh HISTORY
The
.Nm uname
function call appeared in
System V.2 AT&T UNIX.

View File

@ -35,7 +35,7 @@
*
* @(#)genassym.c 5.11 (Berkeley) 5/10/91
*/
static char rcsid[] = "$Header: /cvsroot/src/sys/arch/i386/i386/Attic/genassym.c,v 1.1.1.1 1993/03/21 09:45:37 cgd Exp $";
static char rcsid[] = "$Header: /cvsroot/src/sys/arch/i386/i386/Attic/genassym.c,v 1.2 1993/05/06 10:48:11 cgd Exp $";
#ifndef lint
static char sccsid[] = "@(#)genassym.c 5.11 (Berkeley) 5/10/91";
@ -160,5 +160,7 @@ main()
printf("#define\tENOENT %d\n", ENOENT);
printf("#define\tEFAULT %d\n", EFAULT);
printf("#define\tENAMETOOLONG %d\n", ENAMETOOLONG);
printf("#define\tCPU_386 %d\n", CPU_386);
printf("#define\tCPU_486 %d\n", CPU_486);
exit(0);
}

View File

@ -289,6 +289,8 @@ begin: /* now running relocated at SYSTEM where the system is linked to run */
lea 7*NBPG(%esi),%esi # skip past stack.
pushl %esi
call _set_cpu_type # get kind of cpu
call _init386 # wire 386 chip for unix operation
movl $0,_PTD
@ -1594,6 +1596,30 @@ IDTVEC(syscall)
popfl
lret
ALIGN32
ENTRY(set_cpu_type)
pushfl
popl %eax
movl %eax, %ecx
xorl $0x40000, %eax
pushl %eax
popfl
pushfl
popl %eax
xorl %ecx, %eax
shrl $18, %eax
andl $1, %eax
push %ecx
popfl
movl $_cpu, %ecx
cmpl $0, %eax
jne 1f
movl $CPU_386, (%ecx)
ret
1: movl $CPU_486, (%ecx)
ret
ALIGN32
ENTRY(htonl)
ENTRY(ntohl)

View File

@ -1 +1 @@
revision 1.2 intentionally removed
revision 1.3 intentionally removed

View File

@ -1 +1 @@
revision 1.8 intentionally removed
revision 1.9 intentionally removed

View File

@ -160,6 +160,7 @@ int getfh();
#endif
int getdomainname();
int setdomainname();
int uname();
#ifdef SYSVSHM
int shmsys();
#else
@ -404,7 +405,7 @@ struct sysent sysent[] = {
#endif
2, getdomainname, /* 162 = getdomainname */
2, setdomainname, /* 163 = setdomainname */
0, nosys, /* 164 = nosys */
1, uname, /* 164 = uname */
0, nosys, /* 165 = nosys */
0, nosys, /* 166 = nosys */
0, nosys, /* 167 = nosys */

View File

@ -38,6 +38,7 @@
#include "kernel.h"
#include "proc.h"
#include "reboot.h"
#include "utsname.h"
/* ARGSUSED */
gethostid(p, uap, retval)
@ -137,6 +138,19 @@ setdomainname(p, uap, retval)
return (error);
}
/* ARGSUSED */
uname(p, uap, retval)
struct proc *p;
struct args {
struct utsname *name;
} *uap;
int *retval;
{
bcopy(hostname, utsname.nodename, sizeof(utsname.nodename));
utsname.nodename[sizeof(utsname.nodename)-1] = '\0';
return (copyout((caddr_t)&utsname, (caddr_t)uap->name, sizeof(struct utsname)));
}
/* ARGSUSED */
reboot(p, uap, retval)
struct proc *p;

View File

@ -195,7 +195,7 @@ char *syscallnames[] = {
#endif
"getdomainname", /* 162 = getdomainname */
"setdomainname", /* 163 = setdomainname */
"#164", /* 164 = nosys */
"uname", /* 164 = uname */
"#165", /* 165 = nosys */
"#166", /* 166 = nosys */
"#167", /* 167 = nosys */

View File

@ -219,7 +219,7 @@
#endif
162 STD 2 getdomainname
163 STD 2 setdomainname
164 UNIMPL 0 nosys
164 STD 1 uname
165 UNIMPL 0 nosys
166 UNIMPL 0 nosys
167 UNIMPL 0 nosys

View File

@ -5,9 +5,6 @@
* created from @(#)syscalls.master 7.26 (Berkeley) 3/25/91
*/
#ifndef _SYS_SYSCALL_H_
#define _SYS_SYSCALL_H_
#define SYS_exit 1
#define SYS_fork 2
#define SYS_read 3
@ -165,9 +162,8 @@
#define SYS_getfh 161
#define SYS_getdomainname 162
#define SYS_setdomainname 163
#define SYS_uname 164
#define SYS_shmsys 171
#define SYS_setgid 181
#define SYS_setegid 182
#define SYS_seteuid 183
#endif /* !_SYS_SYSCALL_H_ */

60
sys/sys/utsname.h Normal file
View File

@ -0,0 +1,60 @@
/*
* Copyright (c) 1982, 1986, 1991 The Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)utsname.h 1.0 (Berkeley) 43/29/93
*/
#ifndef _UTSNAME_H_
#define _UTSNAME_H_
#define SYS_NMLN 32
struct utsname {
char sysname[SYS_NMLN];
char nodename[SYS_NMLN];
char release[SYS_NMLN];
char version[SYS_NMLN];
char machine[SYS_NMLN];
};
#ifndef KERNEL
#ifdef __STDC__
extern int uname(struct utsname *);
#else
extern int uname();
#endif
#else
extern struct utsname utsname;
#endif /* KERNEL */
#endif /* _UTSNAME_H_ */

View File

@ -1,6 +1,6 @@
# @(#)Makefile 5.8.1.1 (Berkeley) 5/8/91
#
# $Header: /cvsroot/src/usr.bin/Makefile,v 1.17 1993/04/30 08:04:14 glass Exp $
# $Header: /cvsroot/src/usr.bin/Makefile,v 1.18 1993/05/06 10:46:12 cgd Exp $
SUBDIR= ar biff basename cal calendar \
checknr chpass cksum cmp col colcrt colrm column comm compress \
@ -14,9 +14,9 @@ SUBDIR= ar biff basename cal calendar \
rdist ref renice rlogin rpcgen rpcinfo rsh ruptime rwall rwho \
sccs script sed shar showmount size soelim split strings \
strip su symorder tail talk tcopy tee telnet tftp time \
tip tn3270 touch tput tr true tset tsort tty ul unexpand unifdef uniq \
unvis users uudecode uuencode vacation vgrind vis vmstat \
w wall wc what whereis which who whoami whois window \
write xargs xinstall xstr yacc yes
tip tn3270 touch tput tr true tset tsort tty ul uname unexpand \
unifdef uniq unvis users uudecode uuencode vacation vgrind vis \
vmstat w wall wc what whereis which who whoami whois window write \
xargs xinstall xstr yacc yes
.include <bsd.subdir.mk>

5
usr.bin/uname/Makefile Normal file
View File

@ -0,0 +1,5 @@
# @(#)Makefile 5.3 (Berkeley) 5/11/90
PROG= uname
.include <bsd.prog.mk>

77
usr.bin/uname/uname.1 Normal file
View File

@ -0,0 +1,77 @@
.\" Copyright (c) 1990 The Regents of the University of California.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)du.1 6.13 (Berkeley) 6/20/91
.\"
.Dd March 29, 1992
.Dt UNAME 1
.Os Posix
.Sh NAME
.Nm uname
.Nd Print name of current UNIX system
.Sh SYNOPSIS
.Nm uname
.Op Fl snrvma
.Sh DESCRIPTION
The
.Nm uname
prints the current system name of the UNIX system on
the standard output file. It is mainly useful to determine
which system one is using.
.Pp
The following options are available:
.Bl -tag -width indent
.It Fl s
print the system name (default).
.It Fl n
print the nodename (the nodename may be a name
that the system is known by to a communications
network).
.It Fl r
print the operating system release.
.It Fl v
print the operating system version.
.It Fl m
print the machine hardware name.
.It Fl a
print all the above information.
.Sh SEE ALSO
.Xr hostname 1 ,
.Xr machine 1 ,
.Xr uname 2
.Sh STANDARDS
The
.Nm uname
utility is expected to be
.St -p1003.2
compatible.

72
usr.bin/uname/uname.c Normal file
View File

@ -0,0 +1,72 @@
/*
* uname - print system information. Jeff Comstock - Bloomington, MN USA 1992
* Usage: uname [-asnrvm]
* -s prints system name
* -n prints nodename
* -r prints software release
* -v prints os version
* -m prints machine name
* -a prinst all the above information
*/
#include <stdio.h>
#include <unistd.h>
#include <sys/utsname.h>
#define SYSNAME 0
#define NODENAME 1
#define RELEASE 2
#define VERSION 3
#define MACHINE 4
struct utsname u;
struct utstab {
char *str;
int requested;
} uttab[] = {
{ u.sysname, 0 },
{ u.nodename, 0 },
{ u.release, 0 },
{ u.version, 0 },
{ u.machine, 0 }
};
main(int argc, char **argv) {
char *opts="amnrsv";
register int c,space, all=0;
if ( ! uname(&u) ) {
if ( argc == 1 ) {
puts(u.sysname);
} else {
while ( (c = getopt(argc,argv,opts)) != -1 ) {
switch ( c ) {
case 'a' : all++;
break;
case 'm' : uttab[MACHINE].requested++;
break;
case 'n' : uttab[NODENAME].requested++;
break;
case 'r' : uttab[RELEASE].requested++;
break;
case 's' : uttab[SYSNAME].requested++;
break;
case 'v' : uttab[VERSION].requested++;
break;
}
}
space=0;
for(c=0; c <= MACHINE; c++) {
if ( uttab[c].requested || all ) {
if ( space )
putchar(' ');
printf("%s", uttab[c].str);
space++;
}
}
puts("");
}
}
else
perror("uname");
}