1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 05:57:45 +00:00

Add sys$uname() and a /bin/uname utility.

This commit is contained in:
Andreas Kling 2018-10-26 14:56:21 +02:00
parent 384e2f24d4
commit 1c45b28da6
15 changed files with 129 additions and 10 deletions

View file

@ -112,6 +112,8 @@ DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
return current->sys$get_arguments((int*)arg1, (char***)arg2);
case Syscall::PosixChdir:
return current->sys$chdir((const char*)arg1);
case Syscall::PosixUname:
return current->sys$uname((utsname*)arg1);
default:
kprintf("int0x80: Unknown function %x requested {%x, %x, %x}\n", function, arg1, arg2, arg3);
break;

View file

@ -33,6 +33,7 @@ enum Function {
PosixGethostname = 0x2001,
GetArguments = 0x2002,
PosixChdir = 0x2003,
PosixUname = 0x2004,
};
void initialize();

View file

@ -26,12 +26,18 @@ static InlineLinkedList<Task>* s_tasks;
static InlineLinkedList<Task>* s_deadTasks;
static String* s_hostname;
static String& hostname(InterruptDisabler&)
static String& hostnameStorage(InterruptDisabler&)
{
ASSERT(s_hostname);
return *s_hostname;
}
static String getHostname()
{
InterruptDisabler disabler;
return hostnameStorage(disabler).isolatedCopy();
}
static bool contextSwitch(Task*);
static void redoKernelTaskTSS()
@ -177,14 +183,10 @@ int Task::sys$munmap(void* addr, size_t size)
int Task::sys$gethostname(char* buffer, size_t size)
{
String hn;
{
InterruptDisabler disabler;
hn = hostname(disabler).isolatedCopy();
}
if (size < (hn.length() + 1))
auto hostname = getHostname();
if (size < (hostname.length() + 1))
return -ENAMETOOLONG;
memcpy(buffer, hn.characters(), size);
memcpy(buffer, hostname.characters(), size);
return 0;
}
@ -760,6 +762,16 @@ int Task::sys$open(const char* path, size_t pathLength)
return fd;
}
int Task::sys$uname(utsname* buf)
{
strcpy(buf->sysname, "Serenity");
strcpy(buf->release, "1.0-dev");
strcpy(buf->version, "FIXME");
strcpy(buf->machine, "i386");
strcpy(buf->nodename, getHostname().characters());
return 0;
}
int Task::sys$kill(pid_t pid, int sig)
{
(void) sig;

View file

@ -104,6 +104,7 @@ public:
int sys$gettimeofday(timeval*);
int sys$gethostname(char* name, size_t length);
int sys$get_arguments(int* argc, char*** argv);
int sys$uname(utsname*);
static void initialize();

Binary file not shown.

View file

@ -11,5 +11,6 @@ cp ../Userland/true mnt/bin/true
cp ../Userland/false mnt/bin/false
cp ../Userland/hostname mnt/bin/hostname
cp ../Userland/cat mnt/bin/cat
cp ../Userland/uname mnt/bin/uname
umount mnt
sync

View file

@ -31,6 +31,16 @@ struct timeval {
suseconds_t tv_usec;
};
#define UTSNAME_ENTRY_LEN 65
struct utsname {
char sysname[UTSNAME_ENTRY_LEN];
char nodename[UTSNAME_ENTRY_LEN];
char release[UTSNAME_ENTRY_LEN];
char version[UTSNAME_ENTRY_LEN];
char machine[UTSNAME_ENTRY_LEN];
};
struct FarPtr {
DWORD offset { 0 };
WORD selector { 0 };