mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-29 13:48:21 +00:00
handle /etc/hostname, sethostname(2), gethostname(2) and uname(2)
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
#include <kernel/syscalls.h>
|
||||
#include <kernel/abi.h>
|
||||
#include <spinlock.h>
|
||||
#include <util.h>
|
||||
|
||||
static spinlock_t lock;
|
||||
static char buffer[HOST_NAME_MAX];
|
||||
static size_t bufferlen;
|
||||
|
||||
void hostname_get(char *buf) {
|
||||
bool intstatus = interrupt_set(false);
|
||||
spinlock_acquire(&lock);
|
||||
|
||||
memcpy(buf, buffer, bufferlen);
|
||||
buf[bufferlen] = '\0';
|
||||
|
||||
spinlock_release(&lock);
|
||||
interrupt_set(intstatus);
|
||||
}
|
||||
|
||||
syscallret_t syscall_hostname(context_t *, char *unew, size_t newsize, char *uold, size_t oldsize) {
|
||||
syscallret_t ret = {
|
||||
.ret = -1
|
||||
};
|
||||
|
||||
if ((unew && newsize > HOST_NAME_MAX) || (uold && oldsize == 0)) {
|
||||
ret.errno = EINVAL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
char new[HOST_NAME_MAX];
|
||||
char old[HOST_NAME_MAX + 1];
|
||||
|
||||
if (unew)
|
||||
memcpy(new, unew, newsize);
|
||||
|
||||
interrupt_set(false);
|
||||
spinlock_acquire(&lock);
|
||||
|
||||
if (uold) {
|
||||
size_t copysize = min(oldsize - 1, bufferlen);
|
||||
|
||||
memcpy(old, buffer, copysize);
|
||||
old[copysize] = '\0';
|
||||
}
|
||||
|
||||
if (unew) {
|
||||
bufferlen = newsize;
|
||||
strcpy(buffer, new);
|
||||
}
|
||||
|
||||
spinlock_release(&lock);
|
||||
interrupt_set(true);
|
||||
|
||||
if (uold)
|
||||
strcpy(uold, old);
|
||||
|
||||
ret.errno = 0;
|
||||
ret.ret = 0;
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#include <kernel/syscalls.h>
|
||||
#include <build.h>
|
||||
|
||||
typedef struct {
|
||||
char sysname[65];
|
||||
char nodename[65];
|
||||
char release[65];
|
||||
char version[65];
|
||||
char machine[65];
|
||||
char domainname[65];
|
||||
} utsname_t;
|
||||
|
||||
void hostname_get(char *buf);
|
||||
|
||||
syscallret_t syscall_uname(context_t *, utsname_t *utsname) {
|
||||
syscallret_t ret = {0};
|
||||
|
||||
char hostname[HOST_NAME_MAX + 1];
|
||||
hostname_get(hostname);
|
||||
|
||||
strcpy(utsname->sysname, "Astral");
|
||||
strcpy(utsname->nodename, hostname);
|
||||
strcpy(utsname->release, "Astral");
|
||||
strcpy(utsname->version, BUILD_DATE);
|
||||
strcpy(utsname->machine, BUILD_TARGET);
|
||||
strcpy(utsname->domainname, hostname);
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user