Skip to content

Commit

Permalink
Inherit parent environment (#3)
Browse files Browse the repository at this point in the history
* Inherit parent environment

* use better var names
  • Loading branch information
osterman authored and goruha committed Mar 10, 2017
1 parent 17f687c commit fb03a08
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ COPYRIGHT_SOFTWARE_DESCRIPTION:=Sudo Shell provides a login shell that can be us
PATH:=$(PATH):$(GOPATH)/bin

include $(shell curl --silent -O "https://raw.githubusercontent.com/cloudposse/build-harness/master/templates/Makefile.build-harness"; echo Makefile.build-harness)
- make travis:docker-tag-and-push

setup:
make init go:deps-build go:deps-dev go:deps go:lint

build:
make go:build

install:
install -m 0755 release/sudosh /usr/local/bin/sudosh
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,16 @@ func main() {
env := os.Environ()

// Lookup path for `sudo`
binary, lookPathErr := exec.LookPath("sudo")
if lookPathErr != nil {
log.Fatalf("error: find to find sudo: %v", lookPathErr)
binary, sudoPathErr := exec.LookPath("sudo")
if sudoPathErr != nil {
log.Fatalf("error: find to find sudo: %v", sudoPathErr)
}

// Prepare `sudo` args
if len(os.Args) <= 2 {
args = []string{"sudo", "-u", user.Username, "-s", shell, "-l"}
if len(os.Args) < 2 {
args = []string{"sudo", "-E", "-u", user.Username, "--", shell, "-l"}
} else {
args = append([]string{"sudo", "-u", user.Username, "--"}, os.Args[1:]...)
args = append([]string{"sudo", "-E", "-u", user.Username, "-s", shell, "-c", "--"}, os.Args[1:]...)
}

execErr := syscall.Exec(binary, args, env)
Expand Down

0 comments on commit fb03a08

Please sign in to comment.