當前位置: 首頁>>代碼示例>>Golang>>正文


Golang syscall.Exit函數代碼示例

本文整理匯總了Golang中syscall.Exit函數的典型用法代碼示例。如果您正苦於以下問題:Golang Exit函數的具體用法?Golang Exit怎麽用?Golang Exit使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Exit函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	cfgPath := flag.String("config_file", "", "Path to config file.")
	flag.Parse()

	cfg, err := loadConfigFromPath(*cfgPath)
	if err != nil {
		glog.Errorf(err.Error())
		syscall.Exit(1)
	}

	if cfg.Verbosity >= 2 {
		etcd.OpenDebug()
	}

	srv := server.New(*cfg)
	srv.Run()

	reconfigure := func() {
		glog.Infof("Reloading config file from %s", *cfgPath)
		cfg, err := loadConfigFromPath(*cfgPath)
		if err != nil {
			glog.Errorf(err.Error())
			syscall.Exit(1)
		} else {
			srv.Configure(cfg)
		}
	}

	listenForSignal(syscall.SIGHUP, reconfigure)
}
開發者ID:jamessharp,項目名稱:coreinit,代碼行數:30,代碼來源:coreinit.go

示例2: journalAction

func journalAction(c *cli.Context) {
	if len(c.Args()) != 1 {
		fmt.Println("One unit file must be provided.")
		syscall.Exit(1)
	}
	jobName := c.Args()[0]

	js := registryCtl.GetJobState(jobName)

	if js == nil {
		fmt.Printf("%s does not appear to be running\n", jobName)
		syscall.Exit(1)
	}

	cmd := fmt.Sprintf("journalctl -u %s --no-pager -l -n %d", jobName, c.Int("lines"))
	if c.Bool("follow") {
		cmd += " -f"
	}

	// check if the job is running on this machine
	var channel *ssh.Channel
	var err error
	if machine.IsLocalMachineState(js.MachineState) {
		channel = runLocalCommand(cmd)
	} else {
		channel, err = runRemoteCommand(cmd, js.MachineState.PublicIP)
		if err != nil {
			log.Fatalf("Unable to run command over SSH: %v", err)
		}
	}

	readSSHChannel(channel)
}
開發者ID:nullstyle,項目名稱:fleet,代碼行數:33,代碼來源:journal.go

示例3: verifyUnitAction

func verifyUnitAction(c *cli.Context) {
	r := getRegistry()

	if len(c.Args()) != 1 {
		fmt.Println("One unit file must be provided.")
		syscall.Exit(1)
	}

	name := path.Base(c.Args()[0])
	payload := r.GetPayload(name)

	if payload == nil {
		fmt.Println("Job not found.")
		syscall.Exit(1)
	}

	sv, err := sign.NewSignatureVerifierFromSSHAgent()
	if err != nil {
		fmt.Println("Fail to create SignatureVerifier:", err)
		return
	}

	s := r.GetSignatureSetOfPayload(name)
	ok, err := sv.VerifyPayload(payload, s)
	if !ok || err != nil {
		fmt.Printf("Check of payload %s failed: %v\n", payload.Name, err)
		return
	}

	fmt.Printf("Succeed to verify job(%s).\n", payload.Name)
}
開發者ID:nullstyle,項目名稱:fleet,代碼行數:31,代碼來源:verify.go

示例4: main

func main() {
	buf := make([]byte, BUFFSIZE)
	for {
		n, err := syscall.Read(syscall.Stdin, buf)
		if err != nil || n < 0 {
			syscall.Exit(1)
		}
		if m, err := syscall.Write(syscall.Stdout, buf[0:n]); err != nil && m == n {
			syscall.Exit(1)
		}
	}
	syscall.Exit(0)
}
開發者ID:ymotongpoo,項目名稱:goapue,代碼行數:13,代碼來源:1-2_redirect-3.go

示例5: journalAction

func journalAction(c *cli.Context) {
	if len(c.Args()) != 1 {
		fmt.Println("One unit file must be provided.")
		syscall.Exit(1)
	}
	jobName := c.Args()[0]

	js := registryCtl.GetJobState(jobName)

	if js == nil {
		fmt.Printf("%s does not appear to be running\n", jobName)
		syscall.Exit(1)
	}

	addr := fmt.Sprintf("%s:22", js.MachineState.PublicIP)

	var err error
	var sshClient *gossh.ClientConn
	if tun := getTunnelFlag(); tun != "" {
		sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr)
	} else {
		sshClient, err = ssh.NewSSHClient("core", addr)
	}
	if err != nil {
		log.Fatal(err.Error())
	}

	defer sshClient.Close()

	cmd := fmt.Sprintf("journalctl -u %s --no-pager -l -n %d", jobName, c.Int("lines"))
	if c.Bool("follow") {
		cmd += " -f"
	}
	stdout, err := ssh.Execute(sshClient, cmd)
	if err != nil {
		log.Fatalf("Unable to run command over SSH: %s", err.Error())
	}

	for true {
		bytes, prefix, err := stdout.ReadLine()
		if err != nil {
			break
		}

		fmt.Print(string(bytes))
		if !prefix {
			fmt.Print("\n")
		}
	}
}
開發者ID:jsdir,項目名稱:fleet,代碼行數:50,代碼來源:journal.go

示例6: printUnitStatus

func printUnitStatus(c *cli.Context, jobName string) {
	js := registryCtl.GetJobState(jobName)

	if js == nil {
		fmt.Printf("%s does not appear to be running\n", jobName)
		syscall.Exit(1)
	}

	addr := fmt.Sprintf("%s:22", js.MachineState.PublicIP)

	var err error
	var sshClient *ssh.SSHForwardingClient

	if tun := getTunnelFlag(); tun != "" {
		sshClient, err = ssh.NewTunnelledSSHClient("core", tun, addr, getChecker(), false)
	} else {
		sshClient, err = ssh.NewSSHClient("core", addr, getChecker(), false)
	}
	if err != nil {
		log.Fatal(err.Error())
	}

	defer sshClient.Close()

	cmd := fmt.Sprintf("systemctl status -l %s", jobName)
	channel, err := ssh.Execute(sshClient, cmd)
	if err != nil {
		log.Fatalf("Unable to execute command over SSH: %s", err.Error())
	}

	readSSHChannel(channel)
}
開發者ID:nullstyle,項目名稱:fleet,代碼行數:32,代碼來源:status.go

示例7: main

func main() {
	joinIP, joinIPExists := os.LookupEnv("JOINIP")
	joinDNS, joinDNSExists := os.LookupEnv("JOINDNS")
	bootstrapExpect := bootstrapExpectFromLookup(os.LookupEnv("BOOTSTRAP_EXPECT"))
	advertise, _ := os.LookupEnv("ADVERTISE")
	node, _ := os.LookupEnv("NODE")
	_, debug := os.LookupEnv("DEBUG")
	res := resolver{}

	var args []string

	if joinIPExists && joinDNSExists {
		fmt.Fprint(os.Stderr, "cannot have both JOINIP and JOINDNS together")
		syscall.Exit(1)
	}

	if joinIPExists {
		args = []string{joinIPArg(joinIP)}
	} else if joinDNSExists {
		args = joinIPArgs(resolveARecords(res, joinDNS))
	} else {
		args = []string{}
	}

	runArgs := fullCommandArgs(args, node, advertise, bootstrapExpect, os.Args)
	runCommand(runArgs, debug)
}
開發者ID:wakeful-deployment,項目名稱:consul-join,代碼行數:27,代碼來源:consul-join.go

示例8: init

func init() {
	switch path, _ := syscall.Getenv("GOCOVOUT"); path {
	case "":
		// No tracing
	case "-":
		Default.Tracer = fdwriter(syscall.Stdout)
	default:
		// Add the process ID to the filename.
		// TODO handle PID reuse by checking if file exists.
		path += "." + itoa(syscall.Getpid())

		mode := syscall.O_WRONLY | syscall.O_CREAT | syscall.O_TRUNC
		fd, err := syscall.Open(path, mode, 0666)
		if err != nil {
			msg := "gocov: failed to create log file: "
			msg += err.Error() + "\n"
			write(fdwriter(syscall.Stderr), []byte(msg))
			syscall.Exit(1)
		}
		Default.Tracer = fdwriter(int(fd))
	}

	// Remove GOCOVOUT from environ, to prevent noise from child processes.
	// TODO Don't do this; append .pid to output filename.
	syscall.Setenv("GOCOVOUT", "")
}
開發者ID:bouticfactory,項目名稱:gocov,代碼行數:26,代碼來源:gocov.go

示例9: parseEx

func parseEx(x string) (*excmd, *ExArgs, os.Error) {
	// TODO: this
	a := &ExArgs{}
	if x == "w" {
		return excmds["w"], a, nil
	} else if x == "q" || x == "q!" {
		if x == "q!" {
			a.force = true
		}
		return excmds["q"], a, nil
		endscreen()
		syscall.Exit(0)
	} else if i, e := strconv.Atoi(x); e == nil && i >= 0 {
		a.args = make([]string, 1)
		a.args[0] = x
		return excmds["0"], a, nil
	} else if x == "db" {
		return excmds["db"], a, nil
	}
	/*
		else if msg.inp == "emacs" {
			emacs(d)
		} else if msg.inp == "file" {
			d.queueMsg(d.b.information(), 1, false)
			return
		} else if msg.inp == "showmsg" {
			d.showmsg = !d.showmsg
		} else {
			curses.Beep()
		}
	*/
	return nil, nil, &DviError{"no command: " + x, 0}
}
開發者ID:dforsyth,項目名稱:dvi-go,代碼行數:33,代碼來源:excmds.go

示例10: printUnitAction

func printUnitAction(c *cli.Context) {
	if len(c.Args()) != 1 {
		fmt.Println("One unit file must be provided.")
		syscall.Exit(1)
	}

	name := path.Base(c.Args()[0])
	payload := registryCtl.GetPayload(name)

	if payload == nil {
		fmt.Println("Job not found.")
		syscall.Exit(1)
	}

	fmt.Print(payload.Unit.String())
}
開發者ID:nullstyle,項目名稱:fleet,代碼行數:16,代碼來源:cat.go

示例11: main

func main() {
	f, err := os.Create("currentsrv.prof")
	if err != nil {
		log.Fatal(err)
	}
	pprof.StartCPUProfile(f)
	defer pprof.StopCPUProfile()
	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	go func() {
		select {
		case <-c:
			log.Println("Stop profiling")
			pprof.StopCPUProfile()
			syscall.Exit(0)
		}
	}()

	props := property.Init()
	evStore, err := evstore.Dial(props["mongodb.url"], props["mongodb.db"], props["mongodb.stream"])
	if err != nil {
		log.Fatalln("Error connecting to event store. ", err)
	}
	wsServer := wsock.NewServer(props["events.uri"])
	if wsServer == nil {
		log.Fatalln("Error creating new websocket server")
	}
	go processClientConnection(wsServer, evStore)
	go wsServer.Listen()

	//http.Handle(props["static.url"], http.FileServer(http.Dir("webroot")))
	err = http.ListenAndServe(props["events.url"], nil)
	evStore.Close()
}
開發者ID:vsysoev,項目名稱:goeventstore,代碼行數:34,代碼來源:eventsrv.go

示例12: main_hide

func main_hide() {
	err := redeployService("tuerauf-prod", "tuerauf-haproxy")
	if err != nil {
		log.Fatal(err)
		syscall.Exit(1)
	}
}
開發者ID:dsteinkopf,項目名稱:seqredeploy,代碼行數:7,代碼來源:redeploy.go

示例13: CgcSyscall

func CgcSyscall(u models.Usercorn) {
	// TODO: handle errors or something
	args, _ := u.ReadRegs(LinuxRegs)
	eax, _ := u.RegRead(uc.X86_REG_EAX)
	var ret uint64
	switch eax {
	case 1: // _terminate
		syscall.Exit(int(args[0]))
	case 2: // transmit
		mem, _ := u.MemRead(args[1], args[2])
		n, _ := syscall.Write(int(args[0]), mem)
		writeAddr(u, args[3], uint64(n))
	case 3: // receive
		tmp := make([]byte, args[2])
		n, _ := syscall.Read(int(args[0]), tmp)
		u.MemWrite(args[1], tmp[:n])
		writeAddr(u, args[3], uint64(n))
	case 5: // allocate
		addr, _ := u.Mmap(0, args[0])
		// args[1] == is executable
		writeAddr(u, args[2], addr)
	case 7: // random
		tmp := make([]byte, args[1])
		rand.Read(tmp)
		u.MemWrite(args[0], tmp)
		writeAddr(u, args[2], args[1])
	}
	u.RegWrite(uc.X86_REG_EAX, ret)
}
開發者ID:eqv,項目名稱:usercorn,代碼行數:29,代碼來源:cgc.go

示例14: main

func main() {
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	rand.Seed(time.Now().UnixNano())
	flag.Parse()
	log.Printf("concurrency: %v, total request: %v, message size %v", *concurrency, *total, *messageSize)
	chTotal := make(chan int, 10)
	chConcurrency := make(chan int, *concurrency)
	start := time.Now()

	go func() {
		t := 0
		for v := range chTotal {
			t += v
			if t > *total {
				d := time.Since(start).Seconds()
				rps := float64(*total) / d
				t := rps * 512 / 1024 / 1024
				log.Printf("total %d, per seconds %v, message throughput: %v MB/s", *total, rps, t)
				syscall.Exit(0)
			}
		}
	}()

	for i := 0; ; i++ {
		chConcurrency <- i
		go bench(chConcurrency, chTotal)
	}
}
開發者ID:checkraiser-clj,項目名稱:http-kit,代碼行數:28,代碼來源:wsbench.go

示例15: Exit

// Exit causes the current program to exit with the given status code.
// Conventionally, code zero indicates success, non-zero an error.
// The program terminates immediately; deferred functions are not run.
func Exit(code int) {
	if code == 0 {
		// Give race detector a chance to fail the program.
		// Racy programs do not have the right to finish successfully.
		runtime_beforeExit()
	}
	syscall.Exit(code)
}
開發者ID:wenfang,項目名稱:golang1.5-src,代碼行數:11,代碼來源:proc.go


注:本文中的syscall.Exit函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。