diff options
author | Andreas Kling <kling@serenityos.org> | 2020-07-27 18:42:10 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-27 19:10:18 +0200 |
commit | b5f54d4153dba430f92c8f4e6fe729b31793964a (patch) | |
tree | 6db6e01ce412d182caf22f02799dc824153659d8 | |
parent | 0b287c18b939a89bd5c6884a71a832b091cbe74b (diff) | |
download | serenity-b5f54d4153dba430f92c8f4e6fe729b31793964a.zip |
Kernel+LibC: Add sys$set_process_name() for changing the process name
-rw-r--r-- | Kernel/API/Syscall.h | 3 | ||||
-rw-r--r-- | Kernel/Process.cpp | 12 | ||||
-rw-r--r-- | Kernel/Process.h | 1 | ||||
-rw-r--r-- | Libraries/LibC/unistd.cpp | 6 | ||||
-rw-r--r-- | Libraries/LibC/unistd.h | 1 |
5 files changed, 22 insertions, 1 deletions
diff --git a/Kernel/API/Syscall.h b/Kernel/API/Syscall.h index 8412971bf6..91cd72b960 100644 --- a/Kernel/API/Syscall.h +++ b/Kernel/API/Syscall.h @@ -192,7 +192,8 @@ namespace Kernel { __ENUMERATE_SYSCALL(minherit) \ __ENUMERATE_SYSCALL(sendfd) \ __ENUMERATE_SYSCALL(recvfd) \ - __ENUMERATE_SYSCALL(sysconf) + __ENUMERATE_SYSCALL(sysconf) \ + __ENUMERATE_SYSCALL(set_process_name) namespace Syscall { diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 9fb82f20a5..0d4f1110e9 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -4489,6 +4489,18 @@ int Process::sys$get_process_name(char* buffer, int buffer_size) return 0; } +int Process::sys$set_process_name(const char* user_name, size_t user_name_length) +{ + REQUIRE_PROMISE(proc); + if (user_name_length > 256) + return -ENAMETOOLONG; + auto name = validate_and_copy_string_from_user(user_name, user_name_length); + if (name.is_null()) + return -EFAULT; + m_name = move(name); + return 0; +} + // We don't use the flag yet, but we could use it for distinguishing // random source like Linux, unlike the OpenBSD equivalent. However, if we // do, we should be able of the caveats that Linux has dealt with. diff --git a/Kernel/Process.h b/Kernel/Process.h index ebec0c73ea..4aa172dc98 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -185,6 +185,7 @@ public: int sys$sync(); int sys$beep(); int sys$get_process_name(char* buffer, int buffer_size); + int sys$set_process_name(const char* user_name, size_t user_name_length); int sys$watch_file(const char* path, size_t path_length); int sys$dbgputch(u8); int sys$dbgputstr(const u8*, int length); diff --git a/Libraries/LibC/unistd.cpp b/Libraries/LibC/unistd.cpp index 76c0427031..1bebaf9032 100644 --- a/Libraries/LibC/unistd.cpp +++ b/Libraries/LibC/unistd.cpp @@ -683,6 +683,12 @@ int get_process_name(char* buffer, int buffer_size) __RETURN_WITH_ERRNO(rc, rc, -1); } +int set_process_name(const char* name, size_t name_length) +{ + int rc = syscall(SC_set_process_name, name, name_length); + __RETURN_WITH_ERRNO(rc, rc, -1); +} + int chroot(const char* path) { return chroot_with_mount_flags(path, -1); diff --git a/Libraries/LibC/unistd.h b/Libraries/LibC/unistd.h index 5836018975..b496bbdaa5 100644 --- a/Libraries/LibC/unistd.h +++ b/Libraries/LibC/unistd.h @@ -55,6 +55,7 @@ __BEGIN_DECLS extern char** environ; int get_process_name(char* buffer, int buffer_size); +int set_process_name(const char* name, size_t name_length); void dump_backtrace(); int fsync(int fd); void sysbeep(); |