Skip to content

Commit

Permalink
Merge pull request openshift#717 from runcom/attach-stdin
Browse files Browse the repository at this point in the history
pkg/daemon: attach stdin directly
  • Loading branch information
openshift-merge-robot authored May 14, 2019
2 parents 3a8b656 + f8bb0b5 commit dddc8ad
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions pkg/daemon/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"os"
"os/exec"
"os/user"
Expand Down Expand Up @@ -821,10 +820,10 @@ func (dn *Daemon) storePendingState(pending *mcfgv1.MachineConfig, isPending int
logger := exec.Command("logger", "--journald")

var pendingState bytes.Buffer
pendingState.Write([]byte(fmt.Sprintf(`MESSAGE_ID=%s
pendingState.WriteString(fmt.Sprintf(`MESSAGE_ID=%s
MESSAGE=%s
BOOT_ID=%s
PENDING=%d`, pendingStateMessageID, pending.GetName(), dn.bootID, isPending)))
PENDING=%d`, pendingStateMessageID, pending.GetName(), dn.bootID, isPending))

logger.Stdin = &pendingState
return logger.CombinedOutput()
Expand All @@ -839,21 +838,13 @@ func (dn *Daemon) logSystem(format string, a ...interface{}) {
// subprocess rather than talking to journald in process since
// I worry about the golang library having a connection pre-chroot.
logger := exec.Command("logger")
stdin, err := logger.StdinPipe()
if err != nil {
glog.Errorf("failed to get stdin pipe: %v", err)
return
}

go func() {
defer stdin.Close()
io.WriteString(stdin, fmt.Sprintf("machine-config-daemon[%d]: ", os.Getpid()))
io.WriteString(stdin, message)
}()
err = logger.Run()
if err != nil {
var log bytes.Buffer
log.WriteString(fmt.Sprintf("machine-config-daemon[%d]: %s", os.Getpid(), message))

logger.Stdin = &log
if err := logger.Run(); err != nil {
glog.Errorf("failed to invoke logger: %v", err)
return
}
}

Expand Down

0 comments on commit dddc8ad

Please sign in to comment.