From 4c5d61709d4e46043e148a1a7fa1cd1246ceed03 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 10 Dec 2013 14:12:00 -0800 Subject: [PATCH] packer/plugin: catch interrupts for every server --- packer/plugin/plugin.go | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/packer/plugin/plugin.go b/packer/plugin/plugin.go index 91aa91274..8012ffc4f 100644 --- a/packer/plugin/plugin.go +++ b/packer/plugin/plugin.go @@ -92,28 +92,19 @@ func Server() (*packrpc.Server, error) { return nil, err } - // Serve a single connection - log.Println("Serving a plugin connection...") - return packrpc.NewServer(conn), nil -} - -// Registers a signal handler to swallow and count interrupts so that the -// plugin isn't killed. The main host Packer process is responsible -// for killing the plugins when interrupted. -func countInterrupts() { + // Eat the interrupts ch := make(chan os.Signal, 1) signal.Notify(ch, os.Interrupt) - go func() { + var count int32 = 0 for { <-ch - newCount := atomic.AddInt32(&Interrupts, 1) + newCount := atomic.AddInt32(&count, 1) log.Printf("Received interrupt signal (count: %d). Ignoring.", newCount) } }() -} -// Tests whether or not the plugin was interrupted or not. -func Interrupted() bool { - return atomic.LoadInt32(&Interrupts) > 0 + // Serve a single connection + log.Println("Serving a plugin connection...") + return packrpc.NewServer(conn), nil }