/* * Copyright (c) 2018-2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include namespace Kernel { ErrorOr Process::sys$gethostname(Userspace buffer, size_t size) { VERIFY_NO_PROCESS_BIG_LOCK(this) TRY(require_promise(Pledge::stdio)); if (size > NumericLimits::max()) return EINVAL; return hostname().with_shared([&](const auto& name) -> ErrorOr { if (size < (name->length() + 1)) return ENAMETOOLONG; TRY(copy_to_user(buffer, name->characters(), name->length() + 1)); return 0; }); } ErrorOr Process::sys$sethostname(Userspace buffer, size_t length) { VERIFY_NO_PROCESS_BIG_LOCK(this) TRY(require_no_promises()); if (!is_superuser()) return EPERM; if (length > 64) return ENAMETOOLONG; auto new_name = TRY(try_copy_kstring_from_user(buffer, length)); hostname().with_exclusive([&](auto& name) { name = move(new_name); }); return 0; } }