<commit_before>package main

import (
	"github.com/mitchellh/packer/packer"
	"github.com/mitchellh/packer/packer/plugin"
	"log"
	"os"
	"os/signal"
)

// Prepares the signal handlers so that we handle interrupts properly.
// The signal handler exists in a goroutine.
func setupSignalHandlers(env packer.Environment) {
	ch := make(chan os.Signal, 1)
	signal.Notify(ch, os.Interrupt)

	go func() {
		// First interrupt. We mostly ignore this because it allows the
		// plugins time to cleanup.
		<-ch
		log.Println("First interrupt. Ignoring to allow plugins to clean up.")

		// Second interrupt. Go down hard.
		<-ch
		log.Println("Second interrupt. Exiting now.")

		env.Ui().Error("Interrupt signal received twice. Forcefully exiting now.")

		// Force kill all the plugins, but mark that we're killing them
		// first so that we don't get panics everywhere.
		plugin.CleanupClients()
		os.Exit(1)
	}()
}<commit_msg>packer/plugin: confirm cleanup at first signal received<commit_after>package main

import (
	"github.com/mitchellh/packer/packer"
	"github.com/mitchellh/packer/packer/plugin"
	"log"
	"os"
	"os/signal"
)

// Prepares the signal handlers so that we handle interrupts properly.
// The signal handler exists in a goroutine.
func setupSignalHandlers(env packer.Environment) {
	ch := make(chan os.Signal, 1)
	signal.Notify(ch, os.Interrupt)

	go func() {
		// First interrupt. We mostly ignore this because it allows the
		// plugins time to cleanup.
		<-ch
		log.Println("First interrupt. Ignoring to allow plugins to clean up.")

		env.Ui().Error("Interrupt signal received. Cleaning up...")

		// Second interrupt. Go down hard.
		<-ch
		log.Println("Second interrupt. Exiting now.")

		env.Ui().Error("Interrupt signal received twice. Forcefully exiting now.")

		// Force kill all the plugins, but mark that we're killing them
		// first so that we don't get panics everywhere.
		plugin.CleanupClients()
		os.Exit(1)
	}()
}
{'fraction_non_alphanumeric': 0.11552346570397112, 'fraction_numerical': 0.0020629190304280558, 'mean_word_length': 3.619047619047619, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7672602', 'n_tokens_mistral': 655, 'n_tokens_neox': 603, 'n_words': 207}