2022-02-28 20:15:08 +00:00
|
|
|
// +build darwin linux
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-02-19 19:13:52 +00:00
|
|
|
"fmt"
|
2022-02-28 20:15:08 +00:00
|
|
|
"syscall"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
2023-02-19 19:13:52 +00:00
|
|
|
|
|
|
|
rt "github.com/arnodel/golua/runtime"
|
2022-02-28 20:15:08 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func handleSignals() {
|
|
|
|
c := make(chan os.Signal)
|
2023-02-19 19:13:52 +00:00
|
|
|
signal.Ignore(syscall.SIGTTOU, syscall.SIGTTIN)
|
|
|
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGWINCH, syscall.SIGUSR1, syscall.SIGUSR2, syscall.SIGQUIT, syscall.SIGTSTP)
|
2022-02-28 20:15:08 +00:00
|
|
|
|
|
|
|
for s := range c {
|
|
|
|
switch s {
|
2023-02-19 19:13:52 +00:00
|
|
|
case os.Interrupt: hooks.Emit("signal.sigint")
|
|
|
|
case syscall.SIGTERM: exit(0)
|
|
|
|
case syscall.SIGWINCH: hooks.Emit("signal.resize")
|
|
|
|
case syscall.SIGUSR1: hooks.Emit("signal.sigusr1")
|
|
|
|
case syscall.SIGUSR2: hooks.Emit("signal.sigusr2")
|
|
|
|
case syscall.SIGTSTP:
|
|
|
|
suspendHandler := hshMod.Get(rt.StringValue("suspend"))
|
|
|
|
_, err := rt.Call1(l.MainThread(), suspendHandler)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2022-02-28 20:15:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|