本文整理匯總了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)
}
示例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)
}
示例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)
}
示例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)
}
示例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")
}
}
}
示例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)
}
示例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)
}
示例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", "")
}
示例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}
}
示例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())
}
示例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()
}
示例12: main_hide
func main_hide() {
err := redeployService("tuerauf-prod", "tuerauf-haproxy")
if err != nil {
log.Fatal(err)
syscall.Exit(1)
}
}
示例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)
}
示例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)
}
}
示例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)
}