minix/lib/posix/_uname.c
Philip Homburg e9aabcf2f8 Disabled building rescue driver (no longer needed). Moved allocmem from
library to the memory driver. Always put output from within TTY directly on
the console. Removed second include of driver.h from tty.c. Made tty_inrepcode
bigger. First step to move PM and FS calls that are not regular (API)
system calls out of callnr.h (renumbered them, and removed them from the
table.c files). Imported the Minix-vmd uname implementation. This provides
a more stable ABI than the current implementation. Added a bit of security
checking. Unfortunately not nearly enough to get a secure system. Fixed a
bug related to the sizes of the programs in the image (in PM patch_mem_chunks).
2006-05-19 12:19:37 +00:00

62 lines
1.5 KiB
C
Executable file

/* uname(3) - describe the machine. Author: Kees J. Bot
* 5 Dec 1992
*/
#define uname _uname
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/utsname.h>
#define uts_get(field, string) \
if (sysuname(_UTS_GET, field, name->string, sizeof(name->string)) < 0) \
return -1; \
name->string[sizeof(name->string)-1]= 0;
int uname(name)
struct utsname *name;
{
int hf, n, err;
char *nl;
/* Get each of the strings with a sysuname call. Null terminate them,
* because the buffers in the kernel may grow before this and the
* programs are recompiled.
*/
uts_get(_UTS_SYSNAME, sysname);
uts_get(_UTS_NODENAME, nodename);
uts_get(_UTS_RELEASE, release);
uts_get(_UTS_VERSION, version);
uts_get(_UTS_MACHINE, machine);
uts_get(_UTS_ARCH, arch);
#if 0
uts_get(_UTS_KERNEL, kernel);
uts_get(_UTS_HOSTNAME, hostname);
uts_get(_UTS_BUS, bus);
#endif
/* Try to read the node name from /etc/hostname.file. This information
* should be stored in the kernel.
*/
if ((hf = open("/etc/hostname.file", O_RDONLY)) < 0) {
if (errno != ENOENT) return(-1);
} else {
n = read(hf, name->nodename, sizeof(name->nodename) - 1);
err = errno;
close(hf);
errno = err;
if (n < 0) return(-1);
name->nodename[n] = 0;
if ((nl = strchr(name->nodename, '\n')) != NULL) {
memset(nl, 0, (name->nodename +
sizeof(name->nodename)) - nl);
}
}
return 0;
}
/*
* $PchId: _uname.c,v 1.4 1995/11/27 20:09:08 philip Exp $
*/