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) }
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) }
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) }
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) }
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") } } }
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) }
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) }
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", "") }
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} }
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()) }
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() }
func main_hide() { err := redeployService("tuerauf-prod", "tuerauf-haproxy") if err != nil { log.Fatal(err) syscall.Exit(1) } }
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) }
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) } }
// 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) }
func setupCommFile() ([]byte, FD, FD) { mem, err := syscall.Mmap(3, 0, CoverSize+MaxInputSize+SonarRegionSize, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED) if err != nil { println("failed to mmap fd = 3 errno =", err.(syscall.Errno)) syscall.Exit(1) } return mem, 4, 5 }
func gracefulShutdown() { log.Println("Graceful Shutdown") svc.RemoveFromConfig() //would prefer to unregister HTTP and RPC handlers //need to figure out how to do that time.Sleep(10e9) // wait 10 seconds for requests to finish #HACK syscall.Exit(0) }
func main() { var useSys = flag.Bool("syscall", false, "Use syscall.Exit() rather than os.Exit()") flag.Parse() if *useSys { syscall.Exit(5) } else { os.Exit(6) } }
func main() { if len(os.Args) < 3 { Usage() return } outputDirectory := os.Args[1] inputFilename := os.Args[2] if !DirectoryExists(outputDirectory) || !FileExists(inputFilename) { Usage() return } println("[*] Initializing Import...") mix, err := hashdb.OpenMix("db", 1) if err != nil { println("Error initializing database:", err) syscall.Exit(1) } resultChan := make(chan bool, 1) passes := make(chan string, 1) go DatabaseImport(mix, passes, resultChan) println("[*] Import started...") if err := ReadFileByLine(inputFilename, passes); err != nil { println("Error while importing:", err) syscall.Exit(1) return } go StatusUpdate(mix) if err := <-resultChan; !err { println("Error while importing to database:", err) syscall.Exit(1) return } println("[X] Done.") }
// read reads little-endian-encoded uint64 from fd. func read(fd FD) uint64 { rd := 0 var buf [8]byte for rd != len(buf) { n, err := fd.read(buf[rd:]) if err == syscall.EINTR { continue } if n == 0 { syscall.Exit(1) } if err != nil { println("failed to read fd =", fd, "errno =", err.(syscall.Errno)) syscall.Exit(1) } rd += n } return deserialize64(buf[:]) }
func main() { // We use a custom FlagSet since golang/glog adds a bunch of flags we // do not want to publish flagset := flag.NewFlagSet("coreinit", flag.ExitOnError) cfgPath := flagset.String("config_file", "", "Path to config file.") err := flagset.Parse(os.Args[1:]) // We do this manually since we're using a custom FlagSet if err == flag.ErrHelp { flag.Usage() syscall.Exit(1) } // Print out to stderr by default (stderr instead of stdout due to glog's choices) flag.Lookup("logtostderr").Value.Set("true") cfg, err := loadConfigFromPath(*cfgPath) if err != nil { glog.Errorf(err.Error()) syscall.Exit(1) } if cfg.Verbosity >= 3 { 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) }
func printUnitAction(c *cli.Context) { r := getRegistry(c) if len(c.Args()) != 1 { fmt.Println("One unit file must be provided.") syscall.Exit(1) } name := path.Base(c.Args()[0]) for _, j := range r.GetAllJobs() { if j.Name == name { fmt.Println(j.Payload.Value) return } } fmt.Println("Unit not found.") syscall.Exit(1) }
func assignProgram(prog string, exec *string) { flag, err := util.IsExistProgram(prog) if err != nil { fmt.Fprintf(os.Stderr, MISSING_PROG, prog, util.ShortHelp) syscall.Exit(127) } if flag { p := reflect.ValueOf(exec) p.Elem().SetString(prog) } }
func runCommand(argv []string, debug bool) { fullCommandPath, pathErr := exec.LookPath(consul) if pathErr != nil { fmt.Fprint(os.Stderr, pathErr.Error()) syscall.Exit(1) } if debug { fmt.Println(fullCommandPath, argv) syscall.Exit(0) } else { envv := os.Environ() execErr := syscall.Exec(fullCommandPath, argv, envv) if execErr != nil { fmt.Fprint(os.Stderr, execErr.Error()) syscall.Exit(1) } } }
func exQuit(a *ExArgs) (interface{}, os.Error) { if !a.force { for b := a.d.bufs; b != nil; b = b.next { if b.dirty { return nil, &DviError{b.name + " has modifications", 0} } } } endscreen() syscall.Exit(0) return nil, nil }
func main() { argument := new(Argument) argument.ParseArgs() if len(argument.filename) > 0 { cmd := NewCommand(argument.filename) next := cmd.Find() existed := false for path := next(); len(path) > 0; path = next() { fmt.Println(path) existed = true if !argument.option_all { break } } if !existed { syscall.Exit(NotFoundStatus) } syscall.Exit(OKStatus) } syscall.Exit(ErrorStatus) }
func Init() (api *Api) { filename := os.ExpandEnv("$BITSTAMP_CONFIG") if filename == "" { fmt.Println("Please set $BITSTAMP_CONFIG to a proper configuration file") syscall.Exit(0) } api, err := NewFromConfig(filename) if err != nil { panic(err) } return }
//export DidInitRun func DidInitRun() bool { select { case x := <-initCh: if x != 42 { // Just in case initCh was not correctly made. println("want init value of 42, got: ", x) syscall.Exit(2) } return true default: return false } }
func main() { flag.Parse() fmt.Println(*directory) file_names, err := ioutil.ReadDir(*directory) if err != nil { fmt.Println(err) syscall.Exit(1) } for i := 0; i < len(file_names); i++ { file_name := file_names[i].Name() if !strings.Contains(file_name, ".good.") { continue } // If string contains ".good.", delete the version of the file that doesn't and rename. // For PartNetwork__Part_7-511A21310-011~8V613__Container_Scrape__Expected_Results.good.xlsx // delete PartNetwork__Part_7-511A21310-011~8V613__Container_Scrape__Expected_Results.xlsx // and rename PartNetwork__Part_7-511A21310-011~8V613__Container_Scrape__Expected_Results.good.xlsx // to PartNetwork__Part_7-511A21310-011~8V613__Container_Scrape__Expected_Results.xlsx original_file_name := strings.Replace(file_name, ".good.", ".", -1) fmt.Println("Removing: " + original_file_name) err = os.Remove(*directory + original_file_name) if err != nil { fmt.Println(err) syscall.Exit(1) } fmt.Println("Renaming: " + file_name + " to: " + original_file_name) os.Rename(*directory+file_name, *directory+original_file_name) if err != nil { fmt.Println(err) syscall.Exit(1) } } }
func watchSignals(c chan os.Signal) { signal.Notify(c, syscall.SIGINT, syscall.SIGKILL, syscall.SIGQUIT, syscall.SIGSEGV, syscall.SIGSTOP, syscall.SIGTERM) for { select { case sig := <-c: switch sig.(syscall.Signal) { // Trap signals for clean shutdown case syscall.SIGINT, syscall.SIGKILL, syscall.SIGQUIT, syscall.SIGSEGV, syscall.SIGSTOP, syscall.SIGTERM: syscall.Exit(0) } } } }