Browse Source

onefork now runs properly. palin and widefork do not. changed exit to update child procs to point to NULL parents if the parent exits

tarfeef101 6 years ago
parent
commit
6146aaa5c4

BIN
kern/compile/ASST2/kernel


+ 1 - 1
kern/compile/ASST2/vers.c

@@ -1,3 +1,3 @@
 /* This file is automatically generated. Edits will be lost.*/
-const int buildversion = 59;
+const int buildversion = 62;
 const char buildconfig[] = "ASST2";

+ 1 - 1
kern/compile/ASST2/version

@@ -1 +1 @@
-59
+62

+ 1 - 0
kern/include/list.h

@@ -20,5 +20,6 @@ int listsert(struct list * l, int x);
 void listemove(struct list * l, int x);
 void listelete(struct list * l);
 int listearch(struct list * l, int x);
+int listpop(struct list * l);
 
 #endif /* _LIST_H_ */

+ 16 - 0
kern/lib/list.c

@@ -82,3 +82,19 @@ int listearch(list * l, int x)
   
   return 0;
 }
+
+int listpop(list * l)
+{
+  node * temp = l->front;
+  
+  if (temp)
+  {
+    int x = temp->val;
+    l->front = temp->next;
+    --l->len;
+    kfree(temp);
+    return x;
+  }
+  
+  return 0;
+}

+ 0 - 11
kern/proc/proc.c

@@ -213,7 +213,6 @@ void proc_destroy(struct proc * proc)
 	 * reference to this structure. (Otherwise it would be
 	 * incorrect to destroy it.)
 	 */
-  kprintf("TRYING TO DESTROY CWD\n");
 	/* VFS fields */
 	if (proc->p_cwd)
 	{
@@ -221,7 +220,6 @@ void proc_destroy(struct proc * proc)
 		proc->p_cwd = NULL;
 	}
 
-  kprintf("DESTROYED CWD\n");
 #ifndef UW  // in the UW version, space destruction occurs in sys_exit, not here
 	if (proc->p_addrspace)
 	{
@@ -242,8 +240,6 @@ void proc_destroy(struct proc * proc)
 		as_destroy(as);
 	}
 #endif // UW
-
-  kprintf("DESTROYED AS AGAIN\n");
 /*
 #ifdef UW
 	if (proc->console)
@@ -252,21 +248,16 @@ void proc_destroy(struct proc * proc)
 	}
 #endif // UW*/
 
-  kprintf("DESTROYED VFS\n");
 	//threadarray_cleanup(&proc->p_threads);
 	//spinlock_cleanup(&proc->p_lock);
-  kprintf("CLEANUP DONE\n");
   lock_acquire(proclock);
   processes->pids[proc->pid] = NULL; // update available PIDs
   lock_release(proclock);
-  kprintf("PID RELEASED\n");
   //listelete(proc->kids);
   lock_destroy(proc->waitlock);
   cv_destroy(proc->waiting);
-  kprintf("CV DESTROYED\n");
 	kfree(proc->p_name);
 	kfree(proc);
-	kprintf("KFREES DONE\n");
 
 #ifdef UW
 	/* decrement the process count */
@@ -284,8 +275,6 @@ void proc_destroy(struct proc * proc)
 	}
 	V(proc_count_mutex);
 #endif // UW
-	
-  kprintf("DESTROYS DONE\n");
 }
 
 /*

+ 8 - 11
kern/syscall/proc_syscalls.c

@@ -96,7 +96,6 @@ void sys__exit(int exitcode)
   p->exitcode = exitcode;
   DEBUG(DB_SYSCALL,"Syscall: _exit(%d)\n",exitcode);
   KASSERT(curproc->p_addrspace != NULL);
-  kprintf("TRYING TO DESTROY CWD\n");
 	/* VFS fields */
 	if (p->p_cwd)
 	{
@@ -104,7 +103,6 @@ void sys__exit(int exitcode)
 		p->p_cwd = NULL;
 	}
 
-  kprintf("DESTROYED CWD\n");
   as_deactivate();
   as = curproc_setas(NULL);
   as_destroy(as);
@@ -118,6 +116,13 @@ void sys__exit(int exitcode)
   /* note: curproc cannot be used after this call */
   proc_remthread(curthread);
 
+  int x = listpop(p->kids);
+  while (x)
+  {
+    processes->pids[x]->parent = NULL;
+    x = listpop(p->kids);
+  }
+  
   listelete(p->kids);
   threadarray_cleanup(&p->p_threads);
 	spinlock_cleanup(&p->p_lock);
@@ -126,23 +131,15 @@ void sys__exit(int exitcode)
   cv_broadcast(p->waiting, p->waitlock);
   lock_release(p->waitlock);
   
-  kprintf("This is the parent: %p\n", p->parent);
-  if (p->parent)
-  {
-    kprintf("This is the exitcode: %d\n", p->parent->exitcode);
-  }
   if (!(p->parent)) proc_destroy(p);
-  else if (p->parent->exitcode != -1)
+  else if (p->parent->exitcode >= 0)
   {
-    kprintf("This is the exitcode: %d\n", p->parent->exitcode);
     proc_destroy(p);
   }
   
   /* if this is the last user process in the system, proc_destroy()
      will wake up the kernel menu thread */
   //proc_destroy(p);
-  
-  kprintf("Exiting\n");
   thread_exit();
   /* thread_exit() does not return, so we should never get here */
   panic("return from thread_exit in sys_exit\n");