lib/modules/core: implement exec command using syscall.exec
This change replaces the currently running process with the command
specified by the user.
Change-Id: Id030791a32d598e85ff1b79977febcbe10c83dde
diff --git a/lib/modules/core/core_test.go b/lib/modules/core/core_test.go
index 09dc291..14ab572 100644
--- a/lib/modules/core/core_test.go
+++ b/lib/modules/core/core_test.go
@@ -200,7 +200,7 @@
func TestExec(t *testing.T) {
sh, cleanup := newShell(t)
defer cleanup()
- h, err := sh.Start(core.ExecCommand, nil, []string{"echo", "-n", "hello world"}...)
+ h, err := sh.Start(core.ExecCommand, nil, []string{"/bin/sh", "-c", "echo -n hello world"}...)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
@@ -216,7 +216,7 @@
func TestExecWithEnv(t *testing.T) {
sh, cleanup := newShell(t)
defer cleanup()
- h, err := sh.Start(core.ExecCommand, []string{"BLAH=hello world"}, "printenv", "BLAH")
+ h, err := sh.Start(core.ExecCommand, []string{"BLAH=hello world"}, "/bin/sh", "-c", "printenv BLAH")
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
diff --git a/lib/modules/core/exec.go b/lib/modules/core/exec.go
index d0e5556..be41d0d 100644
--- a/lib/modules/core/exec.go
+++ b/lib/modules/core/exec.go
@@ -2,7 +2,7 @@
import (
"io"
- "os/exec"
+ "syscall"
"v.io/core/veyron/lib/modules"
)
@@ -12,15 +12,9 @@
}
func execCommand(stdin io.Reader, stdout, stderr io.Writer, env map[string]string, args ...string) error {
- cmd := exec.Command(args[1], args[2:]...)
envSlice := []string{}
for key, value := range env {
envSlice = append(envSlice, key+"="+value)
}
-
- cmd.Env = envSlice
- cmd.Stdin = stdin
- cmd.Stdout = stdout
- cmd.Stderr = stderr
- return cmd.Run()
+ return syscall.Exec(args[1], args[1:], envSlice)
}