From 4c7eef874d18b0772ed6e0b30bac3cca693aa3ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Mon, 29 Aug 2022 13:57:14 +0200 Subject: Kernel: Read version and git commit hash from baked-in version info ... instead of hard-coding it in the uname syscall. --- Kernel/Syscalls/uname.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'Kernel') diff --git a/Kernel/Syscalls/uname.cpp b/Kernel/Syscalls/uname.cpp index adbe965a5e..276c6c02f9 100644 --- a/Kernel/Syscalls/uname.cpp +++ b/Kernel/Syscalls/uname.cpp @@ -1,10 +1,13 @@ /* * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2022, kleines Filmröllchen * * SPDX-License-Identifier: BSD-2-Clause */ +#include #include +#include namespace Kernel { @@ -13,19 +16,27 @@ ErrorOr Process::sys$uname(Userspace user_buf) VERIFY_NO_PROCESS_BIG_LOCK(this); TRY(require_promise(Pledge::stdio)); - utsname buf {}; - memcpy(buf.sysname, "SerenityOS", 11); - memcpy(buf.release, "1.0-dev", 8); - memcpy(buf.version, "FIXME", 6); + utsname buf + { + "SerenityOS", + {}, // Hostname, filled in below. + {}, // "Release" (1.0-dev), filled in below. + {}, // "Revision" (git commit hash), filled in below. #if ARCH(I386) - memcpy(buf.machine, "i686", 5); + "i686", #elif ARCH(X86_64) - memcpy(buf.machine, "x86_64", 7); + "x86_64", #elif ARCH(AARCH64) - memcpy(buf.machine, "AArch64", 7); + "AArch64", #else # error Unknown architecture #endif + }; + + auto version_string = TRY(KString::formatted("{}.{}-dev", SERENITY_MAJOR_REVISION, SERENITY_MINOR_REVISION)); + AK::TypedTransfer::copy(reinterpret_cast(buf.release), version_string->bytes().data(), min(version_string->length(), UTSNAME_ENTRY_LEN - 1)); + + AK::TypedTransfer::copy(reinterpret_cast(buf.version), SERENITY_VERSION.bytes().data(), min(SERENITY_VERSION.length(), UTSNAME_ENTRY_LEN - 1)); hostname().with_shared([&](auto const& name) { auto length = min(name->length(), UTSNAME_ENTRY_LEN - 1); -- cgit v1.2.3