diff options
-rw-r--r-- | Base/usr/share/man/man2/disown.md | 25 | ||||
-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 | ||||
-rw-r--r-- | Libraries/LibC/serenity.cpp | 6 | ||||
-rw-r--r-- | Libraries/LibC/serenity.h | 2 |
7 files changed, 79 insertions, 1 deletions
diff --git a/Base/usr/share/man/man2/disown.md b/Base/usr/share/man/man2/disown.md new file mode 100644 index 0000000000..8416029865 --- /dev/null +++ b/Base/usr/share/man/man2/disown.md @@ -0,0 +1,25 @@ +## Name + +disown - disown a child process + +## Synopsis + +```**c++ +#include <serenity.h> + +int disown(pid_t pid); +``` + +## Description + +`disown()` unparents a child process of the calling process. The child's parent PID is set to zero, which allows the kernel to automatically reap it upon death. + +## Pledge + +In pledged programs, the `proc` promise is required for this system call. + +## Errors + +* `ESRCH`: No process with PID `pid` was found. +* `ECHILD`: The target process is not a child of the calling process. + 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; +} +} diff --git a/Libraries/LibC/serenity.cpp b/Libraries/LibC/serenity.cpp index 68e10accb0..5837aee15f 100644 --- a/Libraries/LibC/serenity.cpp +++ b/Libraries/LibC/serenity.cpp @@ -30,6 +30,12 @@ extern "C" { +int disown(pid_t pid) +{ + int rc = syscall(SC_disown, pid); + __RETURN_WITH_ERRNO(rc, rc, -1); +} + int module_load(const char* path, size_t path_length) { int rc = syscall(SC_module_load, path, path_length); diff --git a/Libraries/LibC/serenity.h b/Libraries/LibC/serenity.h index 6ed6bba428..55423f13c2 100644 --- a/Libraries/LibC/serenity.h +++ b/Libraries/LibC/serenity.h @@ -31,6 +31,8 @@ __BEGIN_DECLS +int disown(pid_t); + int shbuf_create(int, void** buffer); int shbuf_allow_pid(int, pid_t peer_pid); int shbuf_allow_all(int); |