~snappy-dev/snappy/trunk-github

« back to all changes in this revision

Viewing changes to classic/run.go

  • Committer: Michael Vogt
  • Date: 2016-01-07 17:21:26 UTC
  • mfrom: (997.3.10)
  • Revision ID: git-v1:1282a183c69d8ff2b3a5b3a5ac9624023feb2c01
Merge pull request #266 from mvo5/bugfix/classic-sudo

Bugfix/classic sudo

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
        return fmt.Sprintf("snappy-classic_%s_%s.scope", ti, helpers.MakeRandomString(5))
55
55
}
56
56
 
57
 
// RunShell runs a shell in the classic environment
58
 
func RunShell() error {
 
57
func runInClassicEnv(cmdStr ...string) error {
59
58
        // setup the bind mounts
60
59
        for _, m := range bindMountDirs {
61
60
                if err := bindmount(m.src, m.dst, m.remount); err != nil {
63
62
                }
64
63
        }
65
64
 
66
 
        // drop to the calling user
67
 
        sudoUser := os.Getenv("SUDO_USER")
68
 
        if sudoUser == "" {
69
 
                sudoUser = "root"
70
 
        }
71
 
 
72
65
        // run chroot shell inside a systemd "scope"
73
66
        unitName := genClassicScopeName()
74
 
        cmd := exec.Command("systemd-run", "--quiet", "--scope", fmt.Sprintf("--unit=%s", unitName), "--description=Snappy Classic shell", "chroot", dirs.ClassicDir, "sudo", "debian_chroot=classic", "-u", sudoUser, "-i")
 
67
        args := []string{"systemd-run", "--quiet", "--scope", fmt.Sprintf("--unit=%s", unitName), "--description=Snappy Classic shell", "chroot", dirs.ClassicDir}
 
68
        args = append(args, cmdStr...)
 
69
        cmd := exec.Command(args[0], args[1:]...)
75
70
        cmd.Stdin = os.Stdin
76
71
        cmd.Stdout = os.Stdout
77
72
        cmd.Stderr = os.Stderr
78
 
        cmd.Run()
 
73
        return cmd.Run()
 
74
}
 
75
 
 
76
// RunShell runs a shell in the classic environment
 
77
func RunShell() error {
 
78
        // drop to the calling user
 
79
        sudoUser := os.Getenv("SUDO_USER")
 
80
        if sudoUser == "" {
 
81
                sudoUser = "root"
 
82
        }
 
83
        runInClassicEnv("sudo", "debian_chroot=classic", "-u", sudoUser, "-i")
79
84
 
80
85
        // We could inform the user here that
81
86
        //  "systemctl stop $unitName"