Kernel: Convert hostname to KString
This commit is contained in:
parent
6402840670
commit
50d6a6a186
Notes:
sideshowbarker
2024-07-17 21:01:09 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/50d6a6a1864 Pull-request: https://github.com/SerenityOS/serenity/pull/11848 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/bgianfo ✅
4 changed files with 8 additions and 8 deletions
|
@ -45,9 +45,9 @@ static Atomic<pid_t> next_pid;
|
|||
static Singleton<SpinlockProtected<Process::List>> s_all_instances;
|
||||
READONLY_AFTER_INIT Memory::Region* g_signal_trampoline_region;
|
||||
|
||||
static Singleton<MutexProtected<String>> s_hostname;
|
||||
static Singleton<MutexProtected<OwnPtr<KString>>> s_hostname;
|
||||
|
||||
MutexProtected<String>& hostname()
|
||||
MutexProtected<OwnPtr<KString>>& hostname()
|
||||
{
|
||||
return *s_hostname;
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ UNMAP_AFTER_INIT void Process::initialize()
|
|||
|
||||
// Note: This is called before scheduling is initialized, and before APs are booted.
|
||||
// So we can "safely" bypass the lock here.
|
||||
reinterpret_cast<String&>(hostname()) = "courage";
|
||||
reinterpret_cast<OwnPtr<KString>&>(hostname()) = KString::must_create("courage"sv);
|
||||
|
||||
create_signal_trampoline();
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
MutexProtected<String>& hostname();
|
||||
MutexProtected<OwnPtr<KString>>& hostname();
|
||||
Time kgettimeofday();
|
||||
|
||||
#define ENUMERATE_PLEDGE_PROMISES \
|
||||
|
|
|
@ -15,9 +15,9 @@ ErrorOr<FlatPtr> Process::sys$gethostname(Userspace<char*> buffer, size_t size)
|
|||
if (size > NumericLimits<ssize_t>::max())
|
||||
return EINVAL;
|
||||
return hostname().with_shared([&](const auto& name) -> ErrorOr<FlatPtr> {
|
||||
if (size < (name.length() + 1))
|
||||
if (size < (name->length() + 1))
|
||||
return ENAMETOOLONG;
|
||||
TRY(copy_to_user(buffer, name.characters(), name.length() + 1));
|
||||
TRY(copy_to_user(buffer, name->characters(), name->length() + 1));
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ ErrorOr<FlatPtr> Process::sys$sethostname(Userspace<const char*> buffer, size_t
|
|||
return ENAMETOOLONG;
|
||||
auto new_name = TRY(try_copy_kstring_from_user(buffer, length));
|
||||
hostname().with_exclusive([&](auto& name) {
|
||||
name = new_name->view();
|
||||
name = move(new_name);
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ ErrorOr<FlatPtr> Process::sys$uname(Userspace<utsname*> user_buf)
|
|||
#endif
|
||||
|
||||
hostname().with_shared([&](const auto& name) {
|
||||
memcpy(buf.nodename, name.characters(), name.length() + 1);
|
||||
memcpy(buf.nodename, name->characters(), name->length() + 1);
|
||||
});
|
||||
|
||||
TRY(copy_to_user(user_buf, &buf));
|
||||
|
|
Loading…
Add table
Reference in a new issue