Kernel+LibC: Add sys$set_process_name() for changing the process name

This commit is contained in:
Andreas Kling 2020-07-27 18:42:10 +02:00
parent 0b287c18b9
commit b5f54d4153
Notes: sideshowbarker 2024-07-19 04:33:36 +09:00
5 changed files with 22 additions and 1 deletions

View file

@ -192,7 +192,8 @@ namespace Kernel {
__ENUMERATE_SYSCALL(minherit) \ __ENUMERATE_SYSCALL(minherit) \
__ENUMERATE_SYSCALL(sendfd) \ __ENUMERATE_SYSCALL(sendfd) \
__ENUMERATE_SYSCALL(recvfd) \ __ENUMERATE_SYSCALL(recvfd) \
__ENUMERATE_SYSCALL(sysconf) __ENUMERATE_SYSCALL(sysconf) \
__ENUMERATE_SYSCALL(set_process_name)
namespace Syscall { namespace Syscall {

View file

@ -4489,6 +4489,18 @@ int Process::sys$get_process_name(char* buffer, int buffer_size)
return 0; 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 // 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 // random source like Linux, unlike the OpenBSD equivalent. However, if we
// do, we should be able of the caveats that Linux has dealt with. // do, we should be able of the caveats that Linux has dealt with.

View file

@ -185,6 +185,7 @@ public:
int sys$sync(); int sys$sync();
int sys$beep(); int sys$beep();
int sys$get_process_name(char* buffer, int buffer_size); 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$watch_file(const char* path, size_t path_length);
int sys$dbgputch(u8); int sys$dbgputch(u8);
int sys$dbgputstr(const u8*, int length); int sys$dbgputstr(const u8*, int length);

View file

@ -683,6 +683,12 @@ int get_process_name(char* buffer, int buffer_size)
__RETURN_WITH_ERRNO(rc, rc, -1); __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) int chroot(const char* path)
{ {
return chroot_with_mount_flags(path, -1); return chroot_with_mount_flags(path, -1);

View file

@ -55,6 +55,7 @@ __BEGIN_DECLS
extern char** environ; extern char** environ;
int get_process_name(char* buffer, int buffer_size); int get_process_name(char* buffer, int buffer_size);
int set_process_name(const char* name, size_t name_length);
void dump_backtrace(); void dump_backtrace();
int fsync(int fd); int fsync(int fd);
void sysbeep(); void sysbeep();