[+] fix exit status for commands
1. fix intercept_output when the process has died
    before select poll has been started;
			
			
This commit is contained in:
		
							parent
							
								
									eb457950d3
								
							
						
					
					
						commit
						a6cdf03523
					
				| @ -132,8 +132,11 @@ def intercept_output( | |||||||
|             break |             break | ||||||
| 
 | 
 | ||||||
|         t2 = t1.poll(100) |         t2 = t1.poll(100) | ||||||
|         if len(t2) == 1 and (t2[0][1] & select.POLLIN) > 0 and \ |         if ( | ||||||
|             not (isinstance(last_data, bytes) and len(last_data) == 0): |             len(t2) == 1 and (t2[0][1] & select.POLLIN) > 0 and \ | ||||||
|  |             not (isinstance(last_data, bytes) and len(last_data) == 0) or | ||||||
|  |             not current_subprocess.poll() is None | ||||||
|  |         ): | ||||||
|             t3 = current_subprocess.stdout.peek() |             t3 = current_subprocess.stdout.peek() | ||||||
| 
 | 
 | ||||||
|             t4: bytes = current_subprocess.stdout.read(len(t3)) |             t4: bytes = current_subprocess.stdout.read(len(t3)) | ||||||
| @ -1557,6 +1560,12 @@ def pass_ssh_osx(argv): | |||||||
|                     last_chunk = chunk |                     last_chunk = chunk | ||||||
|                     break |                     break | ||||||
| 
 | 
 | ||||||
|  |             assert not p.poll() is None | ||||||
|  | 
 | ||||||
|  |             if p.poll() != 0: | ||||||
|  |                 logger.error(p.stderr.read()) | ||||||
|  |                 sys.exit(p.poll()) | ||||||
|  | 
 | ||||||
|             assert not last_chunk is None |             assert not last_chunk is None | ||||||
|             assert last_chunk['returncode'] == 0 |             assert last_chunk['returncode'] == 0 | ||||||
| 
 | 
 | ||||||
| @ -3844,7 +3853,7 @@ class Command(enum.StrEnum): | |||||||
| 
 | 
 | ||||||
| def commands_cli( | def commands_cli( | ||||||
|     argv: Optional[list[str]] = None |     argv: Optional[list[str]] = None | ||||||
| ) -> None: | ) -> int: | ||||||
|     if argv is None: |     if argv is None: | ||||||
|         argv = sys.argv[1:] |         argv = sys.argv[1:] | ||||||
| 
 | 
 | ||||||
| @ -3933,14 +3942,14 @@ def commands_cli( | |||||||
|             else: |             else: | ||||||
|                 raise NotImplementedError |                 raise NotImplementedError | ||||||
|     except SystemExit: |     except SystemExit: | ||||||
|         pass |         raise | ||||||
|     except Exception: |     except Exception: | ||||||
|         msg = 'not implemented\n%s' % traceback.format_exc() |         msg = 'not implemented\n%s' % traceback.format_exc() | ||||||
|         logging.error(msg) |         logging.error(msg) | ||||||
| 
 |     finally: | ||||||
|         if not msg is None: |         if not msg is None: | ||||||
|             custom_notify(msg=msg) |             custom_notify(msg=msg) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||||
|     commands_cli() |     sys.exit(commands_cli()) | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user