kernel: Store the full command line of a process

This commit is contained in:
apio 2023-09-04 11:43:11 +02:00
parent 39ba4c9087
commit 1528c772fd
Signed by: apio
GPG Key ID: B8A7D06E42258954
4 changed files with 10 additions and 8 deletions

View File

@ -59,6 +59,8 @@ Result<u64> sys_execve(Registers* regs, SyscallArgs args)
Vector<String> 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<u64> 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<u64> 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);

View File

@ -35,7 +35,7 @@ Result<u64> 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));

View File

@ -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<String> 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());

View File

@ -123,7 +123,7 @@ struct Thread : public LinkedListNode<Thread>
mode_t umask { 0 };
StaticString<128> name;
StaticString<128> cmdline;
String current_directory_path = {};
SharedPtr<VFS::Inode> current_directory = {};