From 1528c772fd9b9848d0e6d8ac1b45701eef9a155c Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 4 Sep 2023 11:43:11 +0200 Subject: [PATCH] kernel: Store the full command line of a process --- kernel/src/sys/exec.cpp | 6 ++++-- kernel/src/sys/pstat.cpp | 2 +- kernel/src/thread/Scheduler.cpp | 8 ++++---- kernel/src/thread/Thread.h | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/kernel/src/sys/exec.cpp b/kernel/src/sys/exec.cpp index f9a25e4e..f9dfeb95 100644 --- a/kernel/src/sys/exec.cpp +++ b/kernel/src/sys/exec.cpp @@ -59,6 +59,8 @@ Result sys_execve(Registers* regs, SyscallArgs args) Vector envp; if (args[2]) envp = TRY(copy_string_vector_from_userspace(args[2])); + String cmdline = TRY(String::join(argv, " ")); + if ((calculate_userspace_stack_size(argv) + calculate_userspace_stack_size(envp)) > MAX_ARGV_STACK_SIZE) return err(E2BIG); @@ -115,7 +117,7 @@ Result sys_execve(Registers* regs, SyscallArgs args) if (is_setuid) current->auth.euid = current->auth.suid = inode->metadata().uid; if (is_setgid) current->auth.egid = current->auth.sgid = inode->metadata().gid; - current->name = path.chars(); + current->cmdline = cmdline.chars(); image->apply(current); @@ -159,7 +161,7 @@ Result sys_fork(Registers* regs, SyscallArgs) thread->state = ThreadState::Runnable; thread->is_kernel = false; thread->fp_data.save(); - thread->name = current->name; + thread->cmdline = current->cmdline; thread->auth = current->auth; thread->current_directory = current->current_directory; thread->current_directory_path = move(current_directory_path); diff --git a/kernel/src/sys/pstat.cpp b/kernel/src/sys/pstat.cpp index dbb7947d..a402eb14 100644 --- a/kernel/src/sys/pstat.cpp +++ b/kernel/src/sys/pstat.cpp @@ -35,7 +35,7 @@ Result sys_pstat(Registers*, SyscallArgs args) set_timespec(proc.ps_time, thread->user_ticks_self + thread->kernel_ticks_self); set_timespec(proc.ps_ktime, thread->kernel_ticks_self); set_timespec(proc.ps_utime, thread->kernel_ticks_children); - strlcpy(proc.ps_name, thread->name.chars(), sizeof(proc.ps_name)); + strlcpy(proc.ps_name, thread->cmdline.chars(), sizeof(proc.ps_name)); strlcpy(proc.ps_cwd, thread->current_directory_path.is_empty() ? "/" : thread->current_directory_path.chars(), sizeof(proc.ps_cwd)); diff --git a/kernel/src/thread/Scheduler.cpp b/kernel/src/thread/Scheduler.cpp index cbab9a91..bc4ea632 100644 --- a/kernel/src/thread/Scheduler.cpp +++ b/kernel/src/thread/Scheduler.cpp @@ -27,7 +27,7 @@ namespace Scheduler g_idle.state = ThreadState::Idle; g_idle.is_kernel = true; g_idle.parent = nullptr; - g_idle.name = "[idle]"; + g_idle.cmdline = "[idle]"; g_idle.active_directory = nullptr; g_idle.ticks_left = 1; @@ -96,7 +96,7 @@ namespace Scheduler thread->stack = thread_stack; - thread->name = name; + thread->cmdline = name; thread->is_kernel = true; thread->active_directory = MMU::kernel_page_directory(); @@ -148,7 +148,7 @@ namespace Scheduler thread->is_kernel = false; thread->id = 1; thread->pgid = 1; - thread->name = name; + thread->cmdline = name; thread->auth = Credentials { .uid = 0, .euid = 0, .suid = 0, .gid = 0, .egid = 0, .sgid = 0 }; Vector args; @@ -374,7 +374,7 @@ namespace Scheduler { kdbgln("%p %c [%-20s] %4d, parent = (%-18p,%d), state = %d, ticks: (k:%04zu,u:%04zu), status = " "%d, cwd = %s", - thread, thread->is_kernel ? 'k' : 'u', thread->name.chars(), thread->id, thread->parent, + thread, thread->is_kernel ? 'k' : 'u', thread->cmdline.chars(), thread->id, thread->parent, thread->parent ? thread->parent->id : 0, (int)thread->state, thread->kernel_ticks_self, thread->user_ticks_self, thread->status, thread->current_directory_path.is_empty() ? "/" : thread->current_directory_path.chars()); diff --git a/kernel/src/thread/Thread.h b/kernel/src/thread/Thread.h index 0f7d4327..0ad2e929 100644 --- a/kernel/src/thread/Thread.h +++ b/kernel/src/thread/Thread.h @@ -123,7 +123,7 @@ struct Thread : public LinkedListNode mode_t umask { 0 }; - StaticString<128> name; + StaticString<128> cmdline; String current_directory_path = {}; SharedPtr current_directory = {};