Esempio n. 1
0
func main() {
	flag.Parse()

	if *showVersion {
		fmt.Println(version)
		os.Exit(1)
	}

	if *deviceID == "" || !(flag.NArg() > 0) {
		logger.Logger.Print(usage)
		log.Fatal(usage)
	}

	gofaxlib.LoadConfig(*configFile)

	var err error
	returned := 1 // Exit code

	devicefifo := filepath.Join(gofaxlib.Config.Hylafax.Spooldir, fifoPrefix+*deviceID)
	gofaxlib.SendFIFO(devicefifo, "SB")

	for _, qfilename := range flag.Args() {
		returned, err = SendQfile(qfilename)

		if err != nil {
			logger.Logger.Printf("Error processing qfile %v: %v", qfilename, err)
			break
		}
	}

	gofaxlib.SendFIFO(devicefifo, "SR")

	logger.Logger.Print("Exiting with status ", returned)
	os.Exit(returned)
}
Esempio n. 2
0
func main() {
	flag.Parse()

	if *showVersion {
		fmt.Println(version)
		os.Exit(1)
	}

	logger.Logger.Printf("%v gofaxd %v starting", productName, version)
	gofaxlib.LoadConfig(*configFile)

	if err := os.Chdir(gofaxlib.Config.Hylafax.Spooldir); err != nil {
		logger.Logger.Print(err)
		log.Fatal(err)
	}

	// Shut down receiving lines when killed
	sigchan := make(chan os.Signal, 1)
	signal.Notify(sigchan, syscall.SIGTERM, syscall.SIGINT)

	// Start modem device manager
	var err error
	devmanager, err = newManager(modemPrefix, gofaxlib.Config.Hylafax.Modems)
	if err != nil {
		logger.Logger.Fatal(err)
	}

	// Start event socket server to handle incoming calls
	server := NewEventSocketServer()
	server.Start()

	// Block until something happens
	select {
	case err := <-server.Errors():
		logger.Logger.Fatal(err)
	case sig := <-sigchan:
		logger.Logger.Print("Received ", sig, ", killing all channels")
		server.Kill()
		devmanager.SetAllDown()
		time.Sleep(3 * time.Second)
		logger.Logger.Print("Terminating")
		os.Exit(1)
	}

}