github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/pkg/signal/testfiles/main.go (about)

     1  package main
     2  
     3  import (
     4  	"os"
     5  	"syscall"
     6  	"time"
     7  
     8  	"github.com/demonoid81/moby/pkg/signal"
     9  	"github.com/sirupsen/logrus"
    10  )
    11  
    12  func main() {
    13  	sigmap := map[string]os.Signal{
    14  		"TERM": syscall.SIGTERM,
    15  		"QUIT": syscall.SIGQUIT,
    16  		"INT":  os.Interrupt,
    17  	}
    18  	signal.Trap(func() {
    19  		time.Sleep(time.Second)
    20  		os.Exit(99)
    21  	}, logrus.StandardLogger())
    22  	go func() {
    23  		p, err := os.FindProcess(os.Getpid())
    24  		if err != nil {
    25  			panic(err)
    26  		}
    27  		s := os.Getenv("SIGNAL_TYPE")
    28  		multiple := os.Getenv("IF_MULTIPLE")
    29  		switch s {
    30  		case "TERM", "INT":
    31  			if multiple == "1" {
    32  				for {
    33  					p.Signal(sigmap[s])
    34  				}
    35  			} else {
    36  				p.Signal(sigmap[s])
    37  			}
    38  		case "QUIT":
    39  			p.Signal(sigmap[s])
    40  		}
    41  	}()
    42  	time.Sleep(2 * time.Second)
    43  }