diff --git a/src/kernel/emulation/linux/CMakeLists.txt b/src/kernel/emulation/linux/CMakeLists.txt index 8cc4a4049..2836f92fb 100644 --- a/src/kernel/emulation/linux/CMakeLists.txt +++ b/src/kernel/emulation/linux/CMakeLists.txt @@ -64,6 +64,7 @@ set(emulation_sources misc/thread_selfid.c misc/sysctl.c misc/getrlimit.c + misc/gethostuuid.c fcntl/open.c fcntl/fcntl.c network/socket.c diff --git a/src/kernel/emulation/linux/misc/gethostuuid.c b/src/kernel/emulation/linux/misc/gethostuuid.c new file mode 100644 index 000000000..09640f867 --- /dev/null +++ b/src/kernel/emulation/linux/misc/gethostuuid.c @@ -0,0 +1,61 @@ +#include "gethostuuid.h" +#include "../base.h" +#include "../errno.h" +#include +#include "../../../../libc/include/fcntl.h" +#include "../../../../../platform-include/sys/errno.h" +#include "../fcntl/open.h" +#include "../unistd/close.h" +#include "../unistd/read.h" + +static int hex2bin(const char* str, unsigned char* uuid_buf); + +long sys_gethostuuid(unsigned char* uuid_buf, void* timeout) +{ + int ret, fd; + char buf[32]; + + fd = sys_open("/etc/machine-id", O_RDONLY, 0); + if (fd < 0) + return fd; + + ret = sys_read(fd, buf, sizeof(buf)); + sys_close(fd); + + if (ret < 0) + return ret; + if (ret != sizeof(buf)) + return -ENOSYS; + + return hex2bin(buf, uuid_buf); +} + +static inline unsigned char hvalue(char c) +{ + if (c >= '0' && c <= '9') + return c - '0'; + else if (c >= 'A' && c <= 'F') + return 10 + (c - 'A'); + else if (c >= 'a' && c <= 'f') + return 10 + (c - 'a'); + else + return 0; +} + +static int hex2bin(const char* str, unsigned char* uuid_buf) +{ + int i; + + for (i = 0; i < 16; i++) + { + unsigned char v; + + v = hvalue(str[i*2]) << 4; + v |= hvalue(str[i*2+1]); + + uuid_buf[i] = v; + } + + return 0; +} + diff --git a/src/kernel/emulation/linux/misc/gethostuuid.h b/src/kernel/emulation/linux/misc/gethostuuid.h new file mode 100644 index 000000000..6548f5612 --- /dev/null +++ b/src/kernel/emulation/linux/misc/gethostuuid.h @@ -0,0 +1,7 @@ +#ifndef LINUX_GETHOSTUUID_H +#define LINUX_GETHOSTUUID_H + +long sys_gethostuuid(unsigned char* uuid_buf, void* timeout); + +#endif + diff --git a/src/kernel/emulation/linux/syscalls.c b/src/kernel/emulation/linux/syscalls.c index 16e0cdea0..0bea68432 100644 --- a/src/kernel/emulation/linux/syscalls.c +++ b/src/kernel/emulation/linux/syscalls.c @@ -49,6 +49,7 @@ #include "misc/getrlimit.h" #include "misc/thread_selfid.h" #include "misc/sysctl.h" +#include "misc/gethostuuid.h" #include "fcntl/open.h" #include "fcntl/fcntl.h" #include "network/socket.h" @@ -130,6 +131,7 @@ void* __bsd_syscall_table[512] = { [137] = sys_rmdir, [138] = sys_utimes, [139] = sys_futimes, + [142] = sys_gethostuuid, [147] = sys_setsid, [153] = sys_pread, [154] = sys_pwrite,