File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed
Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change 1- use std:: fs:: File ;
2- use std:: io:: { Error , ErrorKind , Write } ;
1+ use std:: io:: { Error , ErrorKind } ;
32use std:: process:: Command ;
43
54use super :: not_implemented;
@@ -53,14 +52,16 @@ pub fn reboot() -> ShutdownResult {
5352 invoke_script ( "tell application \" System Events\" to restart" )
5453}
5554
56- /// Unix specific function to force reboot the machine using the magic SysRq key .
55+ /// macOS specific function to force reboot the system using `shutdown -r now` .
5756pub fn force_reboot ( ) -> ShutdownResult {
58- // Reference: https://www.kernel.org/doc/html/latest/admin-guide/sysrq.html
59- let mut file = File :: create ( "/proc/sys/kernel/sysrq" ) ?;
60- file. write_all ( b"128" ) ?;
61- file = File :: create ( "/proc/sysrq-trigger" ) ?;
62- file. write_all ( b"b" ) ?;
63- Ok ( ( ) )
57+ let output = Command :: new ( "shutdown" ) . args ( [ "-r" , "now" ] ) . output ( ) ?;
58+ if output. status . success ( ) {
59+ return Ok ( ( ) ) ;
60+ }
61+ Err ( Error :: new (
62+ ErrorKind :: Other ,
63+ String :: from_utf8_lossy ( & output. stderr ) . into_owned ( ) ,
64+ ) )
6465}
6566
6667/// macOS specific function to logout with a confirmation dialog using AppleScript and "System Events" call "log out".
You can’t perform that action at this time.
0 commit comments