@@ -248,7 +248,7 @@ impl Cage {
248248 Socket ( socket_filedesc_obj) => {
249249 // Check if it is a domain socket
250250 let sock_tmp = socket_filedesc_obj. handle . clone ( ) ;
251- let mut sockhandle = sock_tmp. write ( ) ;
251+ let sockhandle = sock_tmp. write ( ) ;
252252 let socket_type = sockhandle. domain ;
253253 //Here we only increment the reference for AF_UNIX socket type
254254 //Since these are the only sockets that have an inode associated with them
@@ -483,33 +483,61 @@ impl Cage {
483483 0
484484 }
485485
486+ /// ### Description
487+ ///
488+ /// The exit function causes normal process(Cage) termination
489+ /// The termination entails unmapping all memory references
490+ /// Removing the cage object from the cage table, closing all open files
491+ /// And decrement all references to files and directories
492+ /// For more information please refer [https://man7.org/linux/man-pages/man3/exit.3.html]
493+ ///
494+ /// ### Arguments
495+ ///
496+ /// The exit function takes only one argument which is `status`
497+ /// `status` : This is a 32 bit integer value that the function returns back
498+ /// upon sucessfully terminating the process
499+ ///
500+ /// ### Returns
501+ ///
502+ /// This function returns a 32 bit integer value - which represents succesful
503+ /// termination of the calling Cage object
504+ ///
505+ /// ### Panics
506+ ///
507+ /// While this syscall does not panic directly - it can panic if the
508+ /// `decref_dir` function panics - which occurs when the working directory
509+ /// passed to it is not a valid directory or the directory did not exist at all.
510+ /// or if the cage_id passed to the remove function is not a valid cage id.
511+ ///
512+ /// ### Errors
513+ ///
514+ /// This function has no scenario where it returns an error
486515 pub fn exit_syscall ( & self , status : i32 ) -> i32 {
487- //flush anything left in stdout
516+ //Clear all values in stdout stream
488517 interface:: flush_stdout ( ) ;
489-
518+ //Unmap all memory mappings for the current cage object
490519 self . unmap_shm_mappings ( ) ;
491520
492- // close fds
521+ //For all file descriptors that the cage holds
493522 for fd in 0 ..MAXFD {
523+ // Close the file pointed to by the file descriptor
494524 self . _close_helper ( fd) ;
495525 }
496526
497- //get file descriptor table into a vector
498- let cwd_container = self . cwd . read ( ) ;
499-
500- //may not be removable in case of lindrustfinalize, we don't unwrap the remove
501- // result
527+ //Remove the current cage object from the cage table
502528 interface:: cagetable_remove ( self . cageid ) ;
503529
504- // Trigger SIGCHLD
530+ // Check if Lind is being run as a test suite or not
531+ // We do this since we only want to
505532 if !interface:: RUSTPOSIX_TESTSUITE . load ( interface:: RustAtomicOrdering :: Relaxed ) {
506- // dont trigger SIGCHLD for test suite
533+ // Trigger SIGCHILD if LIND is not run as a test suite
534+ // SIGCHILD is simply a response that the parent recieves when it's child process terminates
507535 if self . cageid != self . parent {
508536 interface:: lind_kill_from_id ( self . parent , SIGCHLD ) ;
509537 }
510538 }
511539
512- //fdtable will be dropped at end of dispatcher scope because of Arc
540+ // Return the status integer back to the calling function
513541 status
514542 }
515543
0 commit comments