mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 13:02:45 +00:00 
			
		
		
		
	ProcFS: make procfs$pid_fds always returns a valid JSON array.
Previously, procfs$pid_fds would return nothing when called for a process that had either no open files or a non-existent handle. This could cause problems when a userspace program expected a valid Json response. Procfs$pid_fs now returns an empty array in the aforementioned cases.
This commit is contained in:
		
							parent
							
								
									d063734f69
								
							
						
					
					
						commit
						3014fdf3bd
					
				
					 1 changed files with 12 additions and 7 deletions
				
			
		|  | @ -198,15 +198,20 @@ ProcFS::~ProcFS() | |||
| 
 | ||||
| Optional<KBuffer> procfs$pid_fds(InodeIdentifier identifier) | ||||
| { | ||||
|     auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); | ||||
|     if (!handle) | ||||
|         return {}; | ||||
|     auto& process = handle->process(); | ||||
|     if (process.number_of_open_file_descriptors() == 0) | ||||
|         return {}; | ||||
| 
 | ||||
|     KBufferBuilder builder; | ||||
|     JsonArraySerializer array { builder }; | ||||
| 
 | ||||
|     auto handle = ProcessInspectionHandle::from_pid(to_pid(identifier)); | ||||
|     if (!handle) { | ||||
|         array.finish(); | ||||
|         return builder.build(); | ||||
|     } | ||||
|     auto& process = handle->process(); | ||||
|     if (process.number_of_open_file_descriptors() == 0) { | ||||
|         array.finish(); | ||||
|         return builder.build(); | ||||
|     } | ||||
| 
 | ||||
|     for (int i = 0; i < process.max_open_file_descriptors(); ++i) { | ||||
|         auto* description = process.file_description(i); | ||||
|         if (!description) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Drew Stratford
						Drew Stratford