File tree Expand file tree Collapse file tree 1 file changed +14
-6
lines changed
Expand file tree Collapse file tree 1 file changed +14
-6
lines changed Original file line number Diff line number Diff line change @@ -71,12 +71,12 @@ fn start_monitoring(params: AuthMonitorParams) -> ExitCode {
7171 }
7272}
7373
74- const SYSTEMCTL_COMMAND : & str = "systemctl " ;
75- const POWER_OFF_ARGS : [ & str ; 1 ] = [ "poweroff" ] ;
74+ const SUDO_COMMAND : & str = "sudo " ;
75+ const SYSTEMCTL_POWER_OFF_ARGS : [ & str ; 2 ] = [ "systemctl" , "poweroff" ] ;
7676
7777fn shutdown ( ) {
78- let output = match Command :: new ( SYSTEMCTL_COMMAND )
79- . args ( POWER_OFF_ARGS )
78+ let output = match Command :: new ( SUDO_COMMAND )
79+ . args ( SYSTEMCTL_POWER_OFF_ARGS )
8080 . output ( )
8181 {
8282 Ok ( output) => output,
@@ -85,8 +85,16 @@ fn shutdown() {
8585 return ;
8686 }
8787 } ;
88- match String :: from_utf8 ( output. stdout ) {
89- Ok ( stdout) => println ! ( "Shutdown output: {}" , stdout) ,
88+ let output_data = if output. status . success ( ) {
89+ output. stdout
90+ } else {
91+ output. stderr
92+ } ;
93+ if output_data. is_empty ( ) {
94+ return ;
95+ }
96+ match String :: from_utf8 ( output_data) {
97+ Ok ( output_message) => println ! ( "Shutdown output: {}" , output_message) ,
9098 Err ( error) => eprintln ! ( "Error converting command output to string: {}" , error) ,
9199 } ;
92100}
You can’t perform that action at this time.
0 commit comments