1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:07:35 +00:00

Add sys$gethostname and /bin/hostname

This commit is contained in:
Andreas Kling 2018-10-26 09:54:29 +02:00
parent 3faaa3e04a
commit 53abfa7ea1
16 changed files with 77 additions and 40 deletions

View file

@ -100,6 +100,8 @@ DWORD handle(DWORD function, DWORD arg1, DWORD arg2, DWORD arg3)
return (dword)current->sys$mmap((void*)arg1, (size_t)arg2);
case Syscall::PosixMunmap:
return current->sys$munmap((void*)arg1, (size_t)arg2);
case Syscall::PosixGethostname:
return current->sys$gethostname((char*)arg1, (size_t)arg2);
case Syscall::PosixExit:
cli();
locker.unlock();

View file

@ -30,6 +30,7 @@ enum Function {
PosixLstat = 0x1998,
PosixGetcwd = 0x1999,
PosixGettimeofday = 0x2000,
PosixGethostname = 0x2001,
};
void initialize();

View file

@ -24,6 +24,13 @@ Task* s_kernelTask;
static pid_t next_pid;
static InlineLinkedList<Task>* s_tasks;
static InlineLinkedList<Task>* s_deadTasks;
static String* s_hostname;
static String& hostname(InterruptDisabler&)
{
ASSERT(s_hostname);
return *s_hostname;
}
static bool contextSwitch(Task*);
@ -61,6 +68,7 @@ void Task::initialize()
s_tasks = new InlineLinkedList<Task>;
s_deadTasks = new InlineLinkedList<Task>;
s_kernelTask = Task::createKernelTask(nullptr, "colonel");
s_hostname = new String("birx");
redoKernelTaskTSS();
loadTaskRegister(s_kernelTask->selector());
}
@ -167,6 +175,18 @@ int Task::sys$munmap(void* addr, size_t size)
return 0;
}
int Task::sys$gethostname(char* buffer, size_t size)
{
String hn;
{
InterruptDisabler disabler;
hn = hostname(disabler).isolatedCopy();
}
if (size < (hn.length() + 1))
return -ENAMETOOLONG;
memcpy(buffer, hn.characters(), size);
}
int Task::sys$spawn(const char* path)
{
int error = 0;

View file

@ -100,6 +100,7 @@ public:
int sys$getcwd(char*, size_t);
int sys$sleep(unsigned seconds);
int sys$gettimeofday(timeval*);
int sys$gethostname(char* name, size_t length);
static void initialize();

Binary file not shown.

View file

@ -34,5 +34,6 @@
#define EPIPE 32 // Broken pipe
#define EDOM 33 // Math argument out of domain of func
#define ERANGE 34 // Math result not representable
#define ENAMETOOLONG 36 // Name too long
#define EOVERFLOW 75 // Value too large for defined data type
#define EOVERFLOW 75 // Value too large for defined data type

View file

@ -9,5 +9,6 @@ cp ../Userland/sleep mnt/bin/sleep
cp ../Userland/date mnt/bin/date
cp ../Userland/true mnt/bin/true
cp ../Userland/false mnt/bin/false
cp ../Userland/hostname mnt/bin/hostname
umount mnt
sync