Esempio n. 1
0
File: fod.go Progetto: ykanda/fod
// entry point
func main() {
	cpus := runtime.NumCPU()
	runtime.GOMAXPROCS(cpus)

	var exitStatus int
	if os.Getenv("FOD_ENABLE_PANIC_LOG") != "" {
		_exitStatus, _ := panicwrap.BasicWrap(panicHandler)
		exitStatus = _exitStatus
	}

	InitDebug()
	app := cli.NewApp()
	app.Name = "vcd"
	app.Version = Version()
	app.Usage = "interactive file/directory selector"
	app.Author = "Yasuhiro KANDA"
	app.Email = "*****@*****.**"
	app.Action = doMain
	app.Flags = Flags
	app.Run(os.Args)
	CloseDebug()

	if os.Getenv("FOD_ENABLE_PANIC_LOG") != "" {
		if exitStatus > 0 {
			os.Exit(exitStatus)
		}
	}
}
Esempio n. 2
0
func main() {
	// panicwrap works by re-executing the running program (retaining arguments,
	// environmental variables, etc.) and monitoring the stderr of the program.
	exitStatus, err := panicwrap.BasicWrap(
		func(output string) {
			logPanic(output)
			exit(nil)
		})
	if err != nil {
		// Something went wrong setting up the panic wrapper. This won't be
		// captured by panicwrap
		// At this point, continue execution without panicwrap support. There
		// are known cases where panicwrap will fail to fork, such as Windows
		// GUI app
		log.Errorf("Error setting up panic wrapper: %v", err)
	} else {
		// If exitStatus >= 0, then we're the parent process.
		if exitStatus >= 0 {
			os.Exit(exitStatus)
		}
	}

	parseFlags()

	showui = !*headless

	if showui {
		runOnSystrayReady(_main)
	} else {
		log.Debug("Running headless")
		_main()
	}
}
Esempio n. 3
0
File: main.go Progetto: 2722/lantern
func main() {
	// panicwrap works by re-executing the running program (retaining arguments,
	// environmental variables, etc.) and monitoring the stderr of the program.
	exitStatus, err := panicwrap.BasicWrap(
		func(output string) {
			logPanic(output)
			exit(nil)
		})
	if err != nil {
		// Something went wrong setting up the panic wrapper. This won't be
		// captured by panicwrap
		// At this point, continue execution without panicwrap support. There
		// are known cases where panicwrap will fail to fork, such as Windows
		// GUI app
		log.Errorf("Error setting up panic wrapper: %v", err)
	} else {
		// If exitStatus >= 0, then we're the parent process.
		if exitStatus >= 0 {
			os.Exit(exitStatus)
		}
	}

	parseFlags()

	if *pprofAddr != "" {
		go func() {
			log.Debugf("Starting pprof page at http://%s/debug/pprof", *pprofAddr)
			if err := http.ListenAndServe(*pprofAddr, nil); err != nil {
				log.Error(err)
			}
		}()
	}

	client.ForceChainedProxyAddr = *forceProxyAddr
	client.ForceAuthToken = *forceAuthToken

	showui = !*headless

	if showui {
		runOnSystrayReady(_main)
	} else {
		log.Debug("Running headless")
		_main()
	}
}
Esempio n. 4
0
// main reads the command line flag -f, runs the Check specified in the JSON,
// and exits with the appropriate message and exit code.
func main() {
	// Set up global panic handling
	exitStatus, err := panicwrap.BasicWrap(panicHandler)
	if err != nil {
		reportURL := "https://github.com/mitchellh/panicwrap"
		log.WithFields(log.Fields{
			"err": err.Error(),
		}).Fatal("Please report this error to " + reportURL)
	}
	// If exitStatus >= 0, then we're the parent process and the panicwrap
	// re-executed ourselves and completed. Just exit with the proper status.
	if exitStatus >= 0 {
		os.Exit(exitStatus)
	}
	// Otherwise, exitStatus < 0 means we're the child. Continue executing as
	// normal...

	// Set up and parse flags
	log.Debug("Parsing flags")
	file, URL, directory, stdin := getFlags()
	log.Debug("Validating flags")
	validateFlags(file, URL, directory)
	// add workers to workers, parameterLength
	log.Debug("Running checklists")
	exitCode := 0
	for _, chklst := range getChecklists(file, directory, URL, stdin) {
		anyFailed, report := chklst.MakeReport()
		if anyFailed {
			exitCode = 1
		}
		log.WithFields(log.Fields{
			"checklist": chklst.Name,
			"report":    report,
		}).Info("Report from checklist")
	}
	os.Exit(exitCode)
}