Skip to content

Commit

Permalink
Merge 51331c9 into 9edbcdc
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavosbarreto committed Jun 22, 2018
2 parents 9edbcdc + 51331c9 commit bb0edff
Showing 1 changed file with 0 additions and 37 deletions.
37 changes: 0 additions & 37 deletions cmd/updatehub/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ import (
"encoding/pem"
"net/http"
"os"
"os/exec"
"path"
"path/filepath"
"syscall"

"github.com/pkg/errors"

Expand All @@ -44,37 +42,6 @@ var (
)

func main() {
if !isReexeced() {
/* Reexec updatehub binary to enter in a new mount NS
for isolating changes to the mount table */
if err := syscall.Unshare(syscall.CLONE_NEWNS); err != nil {
log.Fatalf("failed to enter private mount NS: %s", err)
os.Exit(1)
}

cmd := exec.Command("/proc/self/exe", os.Args...)
cmd.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
Pdeathsig: syscall.SIGTERM,
Cloneflags: syscall.CLONE_NEWNS,
}
cmd.Env = append(os.Environ(), []string{"UPDATEHUB_REEXEC=true"}...)
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout

if err := cmd.Run(); err != nil {
if exitError, ok := err.(*exec.ExitError); ok {
ws := exitError.Sys().(syscall.WaitStatus)
os.Exit(ws.ExitStatus())
}

os.Exit(1)
}

os.Exit(0)
}

log.SetLevel(logrus.InfoLevel)

cmd := &cobra.Command{
Expand Down Expand Up @@ -221,7 +188,3 @@ func readPublicKey(fs afero.Fs, settings *updatehub.Settings) (*rsa.PublicKey, e

return key.(*rsa.PublicKey), nil
}

func isReexeced() bool {
return os.Getenv("UPDATEHUB_REEXEC") == "true"
}

0 comments on commit bb0edff

Please sign in to comment.