diff options
author | Andreas Kling <kling@serenityos.org> | 2020-08-04 13:51:11 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-04 18:17:16 +0200 |
commit | 7de831efc65993c44c9e87342a08f6a122250794 (patch) | |
tree | c13e3ae3fa83693eec89be1a1414ebd7ef582b9d /Kernel | |
parent | 83a4fbf5481322989e2e4a83a13a3fc570130c9a (diff) | |
download | serenity-7de831efc65993c44c9e87342a08f6a122250794.zip |
Kernel+LibC: Add sys$disown() for disowning child processes
This syscall allows a parent process to disown a child process, setting
its parent PID to 0.
Unparented processes are automatically reaped by the kernel upon exit,
and no sys$waitid() is required. This will make it much nicer to do
spawn-and-forget which is common in the GUI environment.
Diffstat (limited to 'Kernel')
-rw-r--r-- | Kernel/API/Syscall.h | 3 | ||||
-rw-r--r-- | Kernel/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Kernel/Process.h | 1 | ||||
-rw-r--r-- | Kernel/Syscalls/disown.cpp | 42 |
4 files changed, 46 insertions, 1 deletions
diff --git a/Kernel/API/Syscall.h b/Kernel/API/Syscall.h index 42a36a3d97..88d0459cb0 100644 --- a/Kernel/API/Syscall.h +++ b/Kernel/API/Syscall.h @@ -194,7 +194,8 @@ namespace Kernel { S(sendfd) \ S(recvfd) \ S(sysconf) \ - S(set_process_name) + S(set_process_name) \ + S(disown) namespace Syscall { diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index b41a0d0403..5cbc14ef0c 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -96,6 +96,7 @@ set(KERNEL_SOURCES Syscalls/chroot.cpp Syscalls/clock.cpp Syscalls/debug.cpp + Syscalls/disown.cpp Syscalls/dup.cpp Syscalls/execve.cpp Syscalls/exit.cpp diff --git a/Kernel/Process.h b/Kernel/Process.h index bbb6031307..c25384f3ff 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -333,6 +333,7 @@ public: int sys$sendfd(int sockfd, int fd); int sys$recvfd(int sockfd); long sys$sysconf(int name); + int sys$disown(pid_t); template<bool sockname, typename Params> int get_sock_or_peer_name(const Params&); diff --git a/Kernel/Syscalls/disown.cpp b/Kernel/Syscalls/disown.cpp new file mode 100644 index 0000000000..f92c8f3b83 --- /dev/null +++ b/Kernel/Syscalls/disown.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <Kernel/Process.h> + +namespace Kernel { + +int Process::sys$disown(pid_t pid) +{ + REQUIRE_PROMISE(proc); + auto process = Process::from_pid(pid); + if (!process) + return -ESRCH; + if (process->ppid() != this->pid()) + return -ECHILD; + process->m_ppid = 0; + return 0; +} +} |