(restart_after)
| 23 | |
| 24 | |
| 25 | def _exec_shutdown(restart_after): |
| 26 | if restart_after: |
| 27 | param = '--reboot' |
| 28 | else: |
| 29 | param = '--poweroff' |
| 30 | |
| 31 | try: |
| 32 | # The command arguments are trusted because they aren't based on user |
| 33 | # input. |
| 34 | result = subprocess.run( # noqa: S603 |
| 35 | ['/usr/bin/sudo', '/sbin/shutdown', param, 'now'], |
| 36 | capture_output=True, |
| 37 | text=True, |
| 38 | check=True) |
| 39 | except subprocess.CalledProcessError as e: |
| 40 | raise ShutdownError(e) from e |
| 41 | if 'failed' in result.stderr.lower(): |
| 42 | raise ShutdownError(result.stdout + result.stderr) |
| 43 | |
| 44 | if result.stdout: |
| 45 | logger.info(result.stdout) |
| 46 | if result.stderr: |
| 47 | logger.info(result.stderr) |
| 48 | return True |
no test coverage detected