github.com/iDigitalFlame/xmt@v0.5.4/c2/task/yv_unix.go (about) 1 //go:build !windows && !plan9 && !js && !linux && !android && !aix && !illumos && !solaris 2 // +build !windows,!plan9,!js,!linux,!android,!aix,!illumos,!solaris 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 x := uintptr(0x4000) 46 if v&1 != 0 { 47 x = 0 48 } 49 if t > 0 { 50 time.Sleep(time.Second * time.Duration(t)) 51 } 52 if o, _, err := syscall.Syscall6(syscall.SYS_REBOOT, x, 0, 0, 0, 0, 0); o != 0 { 53 return err 54 } 55 return nil 56 }