~zacbrown/signal-fun

73350a28f53bd5aaeba4fd5e7d8576fe2f735a28 — Zac Brown 3 years ago 3c89396
Add a command line argument to ignore SIGTERM.

Signed-off-by: Zac Brown <git@zacbrown.org>
1 files changed, 13 insertions(+), 2 deletions(-)

M main.go
M main.go => main.go +13 -2
@@ 1,6 1,7 @@
package main

import (
	"flag"
	"fmt"
	"os"
	"os/signal"


@@ 9,6 10,11 @@ import (
)

func main() {
	var ignoreTerm bool
	flag.BoolVar(&ignoreTerm, "ignoreterm", false, "tell signalfun to ignore SIGTERM")

	flag.Parse()

	fmt.Printf("my PID is %d\n", os.Getpid())

	c := make(chan os.Signal, 10)


@@ 32,8 38,13 @@ runloop:
			fmt.Println("breaking for SIGKILL")
			break runloop
		case syscall.SIGTERM:
			fmt.Println("breaking for SIGTERM")
			break runloop
			if ignoreTerm {
				fmt.Println("lol ignoring SIGTERM")
				continue runloop
			} else {
				fmt.Println("breaking for SIGTERM")
				break runloop
			}
		default:
			fmt.Printf("continuing despite %+v\n", sig)
			continue runloop