Esempio n. 1
0
func main() {
	if state.period > 0 && !shouldrun() {
		os.Exit(10)
	}
	proc := cmd.NewProc(state.cmd.Cmd.Name, state.cmd.Cmd.Args)
	proc.Cmd.Stdout = os.Stdout
	proc.Cmd.Stderr = os.Stderr
	proc.StartExit()
	proc.WaitExit()
}
Esempio n. 2
0
func main() {
	if state.bound != 0 {
		time.Sleep(time.Duration(rand.Int63n(state.bound.Nanoseconds())))
	}
	proc := cmd.NewProc(state.cmd.Cmd.Name, state.cmd.Cmd.Args)
	proc.Cmd.Stdout = os.Stdout
	proc.Cmd.Stderr = os.Stderr
	proc.StartExit()
	proc.WaitExit()
}
Esempio n. 3
0
func main() {
	lc, err := lockfile.LockRm(state.globalname, state.localname)
	if err != nil {
		log.Print(err)
		os.Exit(20)
	}
	defer lc.Unlock()
	proc := cmd.NewProc(state.cmd.Cmd.Name, state.cmd.Cmd.Args)
	proc.Cmd.Stdout = os.Stdout
	proc.Cmd.Stderr = os.Stderr
	proc.StartExit()
	proc.WaitExit()
}
Esempio n. 4
0
func main() {
	proc := cmd.NewProc(state.cmd.Cmd.Name, state.cmd.Cmd.Args)

	// Copy combined output from process into ring buffer.  So in
	// the end, if a lot is written, we'll only be left with the
	// last bits.
	cout := combinedOutput(proc)
	rbuf := ringbuffer.New(maxLogSize)
	go func() {
		_, err := io.Copy(rbuf, cout)
		if err != nil {
			log.Print(err)
			os.Exit(30)
		}
	}()

	lf, lferr := newLogFile(state.logname)
	if lferr != nil {
		log.Print(lferr)
		os.Exit(31)
	}

	if perr := proc.StartError(); perr != nil {
		// There aren't any errors that could be caused by just
		// trying to start the process that we should elide.
		perr.Exit()
	}

	if perr := proc.WaitError(); perr != nil {
		// These are the errors that we'll want to potentially elide.
		exit(lf, perr, rbuf)
	}

	// Success: reset the failure count and not only do we log, but
	// the consolidated output also goes unconditionally to standard
	// error.
	lf.failures = 0
	write(lf, rbuf, true)
}
Esempio n. 5
0
func main() {
	proc := cmd.NewProc(state.cmd.Cmd.Name, state.cmd.Cmd.Args)
	proc.Cmd.Stdout = os.Stdout
	proc.Cmd.Stderr = os.Stderr
	proc.StartExit()

	done := make(chan struct{})
	go func() {
		proc.WaitExit()
		close(done)
	}()

	if state.timelimit > 0 {
		timeout := make(chan struct{})
		go func() {
			time.Sleep(state.timelimit)
			close(timeout)
		}()
		select {
		case <-done:
			// Process exited successfully before timeout.
			// Thus, there's no need to wait on that anymore
			// in combination with the timeout.
			break
		case <-timeout:
			log.Printf("timed out: %s\n", proc)
			if err := proc.Cmd.Process.Kill(); err != nil {
				log.Print(err)
			}
			proc.Wait() // Don't care if this errors.
			os.Exit(40)
		}
	}

	<-done
}