<commit_before>package main

import (
	log "github.com/Sirupsen/logrus"
	"github.com/TrilliumIT/docker-arp-ipam/driver"
	"github.com/docker/go-plugins-helpers/ipam"
	"github.com/urfave/cli"
	"os"
	"os/signal"
	"sync"
	"syscall"
)

func main() {

	app := cli.NewApp()
	app.Name = "docker-arp-ipam"
	app.Usage = "Docker ARP IPAM Plugin"
	app.Version = "0.13"
	app.Flags = []cli.Flag{
		cli.BoolFlag{
			Name:  "debug, d",
			Usage: "Enable debugging.",
		},
		cli.StringFlag{
			Name:  "plugin-name, name",
			Value: "arp-ipam",
			Usage: "Plugin Name. Useful if you want to run multiple instances of the plugin.",
		},
		cli.StringFlag{
			Name:  "address, addr",
			Value: ":8080",
			Usage: "TCP Address to bind the plugin on.",
		},
	}
	app.Action = Run
	app.Run(os.Args)
}

// Run initializes the driver
func Run(ctx *cli.Context) error {
	if ctx.Bool("debug") {
		log.SetLevel(log.DebugLevel)
	}
	log.SetFormatter(&log.TextFormatter{
		ForceColors:      false,
		DisableColors:    true,
		DisableTimestamp: false,
		FullTimestamp:    true,
	})

	quit := make(chan struct{}) // tells other goroutines to quit
	var wg sync.WaitGroup       // waits for goroutines to quit
	done := make(chan struct{}) // tells main that we're done
	ech := make(chan error)     // catches an error from serveTCP
	var err error               // holds the final return value

	c := make(chan os.Signal)
	defer close(c)
	signal.Notify(c, os.Interrupt)
	signal.Notify(c, syscall.SIGTERM)
	go func() {
		select {
		case _ = <-c:
			log.Debugf("Sigterm caught. Closing")
		case err = <-ech:
			log.Error(err)
		}
		close(quit)
		wg.Wait()
		close(done)
	}()

	d, err := driver.NewDriver(quit, wg)
	if err != nil {
		log.Error("Error initializing driver")
		ech <- err
	}

	h := ipam.NewHandler(d)
	go func() {
		ech <- h.ServeTCP(ctx.String("plugin-name"), ctx.String("address"), nil)
	}()

	<-done
	return nil
}
<commit_msg>if debug is enabled, dump stacktrace on ctrl+c<commit_after>package main

import (
	log "github.com/Sirupsen/logrus"
	"github.com/TrilliumIT/docker-arp-ipam/driver"
	"github.com/docker/go-plugins-helpers/ipam"
	"github.com/urfave/cli"
	"os"
	"os/signal"
	"runtime/pprof"
	"sync"
	"syscall"
)

func main() {

	app := cli.NewApp()
	app.Name = "docker-arp-ipam"
	app.Usage = "Docker ARP IPAM Plugin"
	app.Version = "0.14"
	app.Flags = []cli.Flag{
		cli.BoolFlag{
			Name:  "debug, d",
			Usage: "Enable debugging.",
		},
		cli.StringFlag{
			Name:  "plugin-name, name",
			Value: "arp-ipam",
			Usage: "Plugin Name. Useful if you want to run multiple instances of the plugin.",
		},
		cli.StringFlag{
			Name:  "address, addr",
			Value: ":8080",
			Usage: "TCP Address to bind the plugin on.",
		},
	}
	app.Action = Run
	app.Run(os.Args)
}

// Run initializes the driver
func Run(ctx *cli.Context) error {
	if ctx.Bool("debug") {
		log.SetLevel(log.DebugLevel)
	}
	log.SetFormatter(&log.TextFormatter{
		ForceColors:      false,
		DisableColors:    true,
		DisableTimestamp: false,
		FullTimestamp:    true,
	})

	quit := make(chan struct{}) // tells other goroutines to quit
	var wg sync.WaitGroup       // waits for goroutines to quit
	done := make(chan struct{}) // tells main that we're done
	ech := make(chan error)     // catches an error from serveTCP
	var err error               // holds the final return value

	c := make(chan os.Signal)
	defer close(c)
	signal.Notify(c, os.Interrupt)
	signal.Notify(c, syscall.SIGTERM)
	go func() {
		select {
		case _ = <-c:
			log.Debugf("Sigterm caught. Closing")
			if log.GetLevel() == log.DebugLevel {
				log.Debug("Dumping stack traces for all goroutines")
				pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
			}
		case err = <-ech:
			log.Error(err)
		}
		close(quit)
		wg.Wait()
		close(done)
	}()

	d, err := driver.NewDriver(quit, wg)
	if err != nil {
		log.Error("Error initializing driver")
		ech <- err
	}

	h := ipam.NewHandler(d)
	go func() {
		ech <- h.ServeTCP(ctx.String("plugin-name"), ctx.String("address"), nil)
	}()

	<-done
	return nil
}

{'fraction_non_alphanumeric': 0.15215764529807932, 'fraction_numerical': 0.0037415814417560487, 'mean_word_length': 3.146845915201655, 'pattern_counts': {'":': 2, '<': 13, '<?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': '267277', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1491, 'n_words': 375}