2020-08-04 13:51:11 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-08-04 13:51:11 +02:00
|
|
|
*/
|
|
|
|
|
2023-02-24 19:45:37 +02:00
|
|
|
#include <Kernel/Tasks/Process.h>
|
2020-08-04 13:51:11 +02:00
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
2021-11-08 00:51:39 +01:00
|
|
|
ErrorOr<FlatPtr> Process::sys$disown(ProcessID pid)
|
2020-08-04 13:51:11 +02:00
|
|
|
{
|
2023-04-03 13:24:20 +02:00
|
|
|
VERIFY_NO_PROCESS_BIG_LOCK(this);
|
2021-12-29 01:11:45 -08:00
|
|
|
TRY(require_promise(Pledge::proc));
|
2022-11-02 22:26:02 +02:00
|
|
|
auto process = Process::from_pid_in_same_jail(pid);
|
2020-08-04 13:51:11 +02:00
|
|
|
if (!process)
|
2021-03-01 13:49:16 +01:00
|
|
|
return ESRCH;
|
2023-04-03 13:24:20 +02:00
|
|
|
TRY(process->with_mutable_protected_data([this](auto& protected_data) -> ErrorOr<void> {
|
|
|
|
if (protected_data.ppid != this->pid())
|
|
|
|
return ECHILD;
|
2022-08-21 12:18:26 +02:00
|
|
|
protected_data.ppid = 0;
|
2023-04-03 13:24:20 +02:00
|
|
|
return {};
|
|
|
|
}));
|
2020-12-08 19:04:05 -07:00
|
|
|
process->disowned_by_waiter(*this);
|
2020-08-04 13:51:11 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|