mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:02:45 +00:00 
			
		
		
		
	LibC: Make system() behave according to POSIX
- system(nullptr) returns non-zero to indicate the presence of a shell - Failure to fork() returns -1 - Failure to exec() in the child returns 127
This commit is contained in:
		
							parent
							
								
									676af444ca
								
							
						
					
					
						commit
						b009f8522c
					
				
					 1 changed files with 9 additions and 3 deletions
				
			
		|  | @ -263,12 +263,18 @@ void srandom(unsigned seed) | ||||||
| 
 | 
 | ||||||
| int system(const char* command) | int system(const char* command) | ||||||
| { | { | ||||||
|  |     if (!command) | ||||||
|  |         return 1; | ||||||
|  | 
 | ||||||
|     auto child = fork(); |     auto child = fork(); | ||||||
|  |     if (child < 0) | ||||||
|  |         return -1; | ||||||
|  | 
 | ||||||
|     if (!child) { |     if (!child) { | ||||||
|         int rc = execl("/bin/sh", "sh", "-c", command, nullptr); |         int rc = execl("/bin/sh", "sh", "-c", command, nullptr); | ||||||
|         if (rc < 0) |         ASSERT(rc < 0); | ||||||
|             perror("execl"); |         perror("execl"); | ||||||
|         exit(0); |         exit(127); | ||||||
|     } |     } | ||||||
|     int wstatus; |     int wstatus; | ||||||
|     waitpid(child, &wstatus, 0); |     waitpid(child, &wstatus, 0); | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling