func()

in pkg/platform/updog/updog.go [44:79]


func (e *executable) runOk(cmd *exec.Cmd) (bool, error) {
	cmd.SysProcAttr = bottlerocket.ProcessAttrs()

	var buf bytes.Buffer
	writer := bufio.NewWriter(&buf)
	cmd.Stdout = writer
	cmd.Stderr = writer

	log := e.log.WithField("cmd", cmd.String())
	log.Debug("running command")
	if err := cmd.Start(); err != nil {
		log.WithError(err).Error("failed to start command")
		if logging.Debuggable {
			log.WithField("output", buf.String()).Debugf("command output")
		}
		return false, err
	}
	err := cmd.Wait()
	if err != nil {
		log.WithError(err).Error("error during command run")
		if logging.Debuggable {
			log.WithField("output", buf.String()).Debug("command output")
		}
		return false, err
	}
	log.Debug("command completed successfully")
	if logging.Debuggable {
		log.WithField("output", buf.String()).Debug("command output")
	}
	// Boolean currently only used by ListUpdate. Returns true if the
	// command yielded output, which indicates an update is available.
	//
	// TODO: Use richer interface data once provided by host integration.
	updateEmitted := len(buf.String()) > 0
	return updateEmitted, err
}