From d517f3d39142615ec3db9925f4db848d52817ebf Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 27 Mar 2012 13:38:00 +0200 Subject: userprocess threads should be named by their executable and not their full commandline string --- env.sh | 2 +- userprog/process.c | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/env.sh b/env.sh index 7cf736b..f0251b2 100644 --- a/env.sh +++ b/env.sh @@ -1,3 +1,3 @@ #!/bin/bash -export PATH="$PATH:$(dirname "${BASH_SOURCE[0]}")/utils" +export PATH="$PATH:$(readlink -f "$(dirname "${BASH_SOURCE[0]}")")/utils" export PATH="/opt/bochs/bin:$PATH" diff --git a/userprog/process.c b/userprog/process.c index adb6b66..af7e0b3 100644 --- a/userprog/process.c +++ b/userprog/process.c @@ -21,7 +21,7 @@ /* data structure to communicate with the thread initializing a new process */ struct start_aux_data { - char *filename; + char *args; struct semaphore startup_sem; struct thread *parent_thread; struct process *new_process; @@ -32,7 +32,7 @@ struct lock filesys_lock; /* prototypes */ static thread_func start_process NO_RETURN; -static bool load (char *filename, void (**eip) (void), void **esp); +static bool load (char *args, void (**eip) (void), void **esp); static bool setup_stack (void **esp); static bool init_fd_table (struct fd_table * table); @@ -64,25 +64,27 @@ process_current () and support command strings such as "echo A B C". You will also need to change `load` and `setup_stack`. */ tid_t -process_execute (const char *filename) +process_execute (const char *cmd) { tid_t tid = TID_ERROR; char *fn_copy = NULL; struct start_aux_data *aux_data = NULL; + char *name, *args; /* Setup the auxiliary data for starting up the new process */ fn_copy = palloc_get_page (0); aux_data = palloc_get_page (0); if (aux_data == NULL || fn_copy == NULL) goto done; - strlcpy (fn_copy, filename, PGSIZE); - aux_data->filename = fn_copy; + strlcpy (fn_copy, cmd, PGSIZE); + name = strtok_r (fn_copy, " ", &args); + aux_data->args = args; aux_data->parent_thread = thread_current (); aux_data->new_process = NULL; sema_init (&aux_data->startup_sem, 0); /* Create a new thread to execute FILE_NAME. */ - tid = thread_create (fn_copy, PRI_DEFAULT, start_process, aux_data); + tid = thread_create (name, PRI_DEFAULT, start_process, aux_data); if (tid == TID_ERROR) goto done; @@ -131,7 +133,7 @@ start_process (void *aux) if_.gs = if_.fs = if_.es = if_.ds = if_.ss = SEL_UDSEG; if_.cs = SEL_UCSEG; if_.eflags = FLAG_IF | FLAG_MBS; - if (! load (aux_data->filename, &if_.eip, &if_.esp)) { + if (! load (aux_data->args, &if_.eip, &if_.esp)) { thread->process = NULL; } else { aux_data->new_process = thread->process; @@ -347,13 +349,12 @@ static bool load_segment (struct file *file, off_t ofs, uint8_t *upage, uint32_t read_bytes, uint32_t zero_bytes, bool writable); -/* Loads an ELF executable from file_name (the first word of - cmd) into the current thread. +/* Loads an ELF executable from t->name into the current thread. Stores the executable's entry point into *EIP and its initial stack pointer into *ESP. Returns true if successful, false otherwise. */ bool -load (char *file_name, void (**eip) (void), void **esp) +load (char *args, void (**eip) (void), void **esp) { struct thread *t = thread_current (); struct Elf32_Ehdr ehdr; @@ -372,7 +373,7 @@ load (char *file_name, void (**eip) (void), void **esp) lock_acquire (&filesys_lock); /* Open executable file. */ - file = filesys_open (file_name); + file = filesys_open (t->name); if (file == NULL) goto done; @@ -388,7 +389,7 @@ load (char *file_name, void (**eip) (void), void **esp) || ehdr.e_phentsize != sizeof (struct Elf32_Phdr) || ehdr.e_phnum > 1024) { - printf ("load: %s: error loading executable\n", file_name); + printf ("load: %s: error loading executable\n", t->name); goto done; } -- cgit v1.2.3