示例#1
0
// spawnChild creates a new child process and stores it on the runner object.
func (r *Runner) spawnChild() error {
	p := shellwords.NewParser()
	p.ParseEnv = true
	p.ParseBacktick = true
	args, err := p.Parse(r.config.Exec.Command)
	if err != nil {
		return err
	}

	child, err := child.New(&child.NewInput{
		Stdin:        r.inStream,
		Stdout:       r.outStream,
		Stderr:       r.errStream,
		Command:      args[0],
		Args:         args[1:],
		ReloadSignal: r.config.Exec.ReloadSignal,
		KillSignal:   r.config.Exec.KillSignal,
		KillTimeout:  r.config.Exec.KillTimeout,
		Splay:        r.config.Exec.Splay,
	})
	if err != nil {
		return fmt.Errorf("error creating child: %s", err)
	}
	r.child = child

	if err := r.child.Start(); err != nil {
		return fmt.Errorf("error starting child: %s", err)
	}
	return nil
}
示例#2
0
// spawnChild spawns a child process with the given inputs and returns the
// resulting child.
func spawnChild(i *spawnChildInput) (*child.Child, error) {
	p := shellwords.NewParser()
	p.ParseEnv = true
	p.ParseBacktick = true
	args, err := p.Parse(i.Command)
	if err != nil {
		return nil, errors.Wrap(err, "failed parsing command")
	}

	child, err := child.New(&child.NewInput{
		Stdin:        i.Stdin,
		Stdout:       i.Stdout,
		Stderr:       i.Stderr,
		Command:      args[0],
		Args:         args[1:],
		Env:          i.Env,
		Timeout:      i.Timeout,
		ReloadSignal: i.ReloadSignal,
		KillSignal:   i.KillSignal,
		KillTimeout:  i.KillTimeout,
		Splay:        i.Splay,
	})
	if err != nil {
		return nil, errors.Wrap(err, "error creating child")
	}

	if err := child.Start(); err != nil {
		return nil, errors.Wrap(err, "child")
	}
	return child, nil
}