Support to execute a symlink file
This commit is contained in:
		
							parent
							
								
									655869711a
								
							
						
					
					
						commit
						f54abc78a2
					
				
							
								
								
									
										2
									
								
								deps/sefs
									
									
									
									
										vendored
									
									
								
							
							
								
								
								
								
								
									
									
								
							
						
						
									
										2
									
								
								deps/sefs
									
									
									
									
										vendored
									
									
								
							| @ -1 +1 @@ | |||||||
| Subproject commit b3565f22b547dac487b46a1fb4d6c8c5d1b3162e | Subproject commit 1d173f103626d4771e120456f8960a7ff3157583 | ||||||
| @ -80,16 +80,37 @@ impl FsView { | |||||||
| 
 | 
 | ||||||
|     /// Lookup INode from the cwd of the process
 |     /// Lookup INode from the cwd of the process
 | ||||||
|     pub fn lookup_inode(&self, path: &str) -> Result<Arc<dyn INode>> { |     pub fn lookup_inode(&self, path: &str) -> Result<Arc<dyn INode>> { | ||||||
|         debug!("lookup_inode: cwd: {:?}, path: {:?}", self.cwd(), path); |         self.lookup_inode_follow_with_max_times(path, 0) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     /// Lookup INode from the cwd of the process, follow symlinks
 | ||||||
|  |     pub fn lookup_inode_follow(&self, path: &str) -> Result<Arc<dyn INode>> { | ||||||
|  |         // Linux uses 40 as the upper limit for resolving symbolic links,
 | ||||||
|  |         // so Occlum use it as a reasonable value
 | ||||||
|  |         const MAX_SYMLINKS: usize = 40; | ||||||
|  |         self.lookup_inode_follow_with_max_times(path, MAX_SYMLINKS) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fn lookup_inode_follow_with_max_times( | ||||||
|  |         &self, | ||||||
|  |         path: &str, | ||||||
|  |         max_times: usize, | ||||||
|  |     ) -> Result<Arc<dyn INode>> { | ||||||
|  |         debug!( | ||||||
|  |             "lookup_inode_follow_with_max_times: cwd: {:?}, path: {:?}, max_times: {}", | ||||||
|  |             self.cwd(), | ||||||
|  |             path, | ||||||
|  |             max_times | ||||||
|  |         ); | ||||||
|         if path.len() > 0 && path.as_bytes()[0] == b'/' { |         if path.len() > 0 && path.as_bytes()[0] == b'/' { | ||||||
|             // absolute path
 |             // absolute path
 | ||||||
|             let abs_path = path.trim_start_matches('/'); |             let abs_path = path.trim_start_matches('/'); | ||||||
|             let inode = ROOT_INODE.lookup(abs_path)?; |             let inode = ROOT_INODE.lookup_follow(abs_path, max_times)?; | ||||||
|             Ok(inode) |             Ok(inode) | ||||||
|         } else { |         } else { | ||||||
|             // relative path
 |             // relative path
 | ||||||
|             let cwd = self.cwd().trim_start_matches('/'); |             let cwd = self.cwd().trim_start_matches('/'); | ||||||
|             let inode = ROOT_INODE.lookup(cwd)?.lookup(path)?; |             let inode = ROOT_INODE.lookup(cwd)?.lookup_follow(path, max_times)?; | ||||||
|             Ok(inode) |             Ok(inode) | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -206,7 +206,7 @@ fn load_elf_to_vec(elf_path: &str, current_ref: &ThreadRef) -> Result<Vec<u8>> { | |||||||
|         .fs() |         .fs() | ||||||
|         .lock() |         .lock() | ||||||
|         .unwrap() |         .unwrap() | ||||||
|         .lookup_inode(elf_path) |         .lookup_inode_follow(elf_path) | ||||||
|         .map_err(|e| errno!(e.errno(), "cannot find the ELF"))?; |         .map_err(|e| errno!(e.errno(), "cannot find the ELF"))?; | ||||||
|     let file_mode = { |     let file_mode = { | ||||||
|         let info = inode.metadata()?; |         let info = inode.metadata()?; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user