mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-12 17:27:50 +08:00
Add elvish-stub.
This commit is contained in:
parent
56fae84255
commit
ef61fcf234
21
elvish-stub/main.go
Normal file
21
elvish-stub/main.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// TODO Need to learn the semantics handle of SIGHUP and see if it deserves
|
||||
// special treatment.
|
||||
func main() {
|
||||
signalChan := make(chan os.Signal)
|
||||
signal.Notify(signalChan)
|
||||
fmt.Println("ok")
|
||||
os.Stdout.Sync()
|
||||
for sig := range signalChan {
|
||||
fmt.Println(int(sig.(syscall.Signal)))
|
||||
os.Stdout.Sync()
|
||||
}
|
||||
}
|
32
elvish-stub/test.sh
Executable file
32
elvish-stub/test.sh
Executable file
|
@ -0,0 +1,32 @@
|
|||
#!/bin/sh
|
||||
fail() {
|
||||
echo "$*; log left at $log"
|
||||
exit 1
|
||||
}
|
||||
|
||||
log=`mktemp elvishXXXXX`
|
||||
|
||||
# Start elvish-stub.
|
||||
elvish-stub > $log &
|
||||
stub=$!
|
||||
|
||||
sleep 0.1
|
||||
|
||||
# Wait for startup message.
|
||||
test `tail -n1 $log` == ok || {
|
||||
fail "no startup message or startup too slow"
|
||||
}
|
||||
|
||||
# Send a SIGINT.
|
||||
kill -2 $stub
|
||||
ps $stub >/dev/null || {
|
||||
fail "stub killed by SIGTERM"
|
||||
}
|
||||
test `tail -n1 $log` == 2 || {
|
||||
fail "stub didn't record SIGTERM"
|
||||
}
|
||||
|
||||
# Really kill stub.
|
||||
kill -9 $stub
|
||||
|
||||
rm $log
|
Loading…
Reference in New Issue
Block a user