github.com/iDigitalFlame/xmt@v0.5.4/c2/task/yv_nix.go (about) 1 //go:build android || linux 2 // +build android linux 3 4 // Copyright (C) 2020 - 2023 iDigitalFlame 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program. If not, see <https://www.gnu.org/licenses/>. 18 // 19 20 package task 21 22 import ( 23 "context" 24 "syscall" 25 "time" 26 27 "github.com/iDigitalFlame/xmt/data" 28 ) 29 30 func taskShutdown(_ context.Context, r data.Reader, _ data.Writer) error { 31 if _, err := r.StringVal(); err != nil { 32 return err 33 } 34 t, err := r.Uint32() 35 if err != nil { 36 return err 37 } 38 if _, err := r.Uint32(); err != nil { 39 return err 40 } 41 v, err := r.Uint8() 42 if err != nil { 43 return err 44 } 45 if t > 0 { 46 time.Sleep(time.Second * time.Duration(t)) 47 } 48 if syscall.Sync(); v&1 != 0 { 49 return syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART) 50 } 51 return syscall.Reboot(syscall.LINUX_REBOOT_CMD_POWER_OFF) 52 }