devcam: exec child binaries when possible

Change-Id: I56d56d9f7416e3d5958e736762063a48dcd8e9f9
This commit is contained in:
Brad Fitzpatrick 2013-09-01 11:37:09 -07:00
parent 3a26c433db
commit 9ae1a64c38
6 changed files with 53 additions and 33 deletions

View File

@ -95,15 +95,7 @@ func (c *gaeCmd) RunCommand(args []string) error {
}
cmdArgs = append(cmdArgs, args...)
cmdArgs = append(cmdArgs, c.applicationDir)
cmd := exec.Command(devAppServerBin, cmdArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {
return fmt.Errorf("Could not start dev_appserver.py: %v", err)
}
go handleSignals(cmd.Process)
cmd.Wait()
return nil
return runExec(devAppServerBin, cmdArgs)
}
func (c *gaeCmd) checkFlags(args []string) error {

View File

@ -99,14 +99,7 @@ func (c *getCmd) RunCommand(args []string) error {
cmdArgs = append(cmdArgs, "-server="+blobserver)
}
cmdArgs = append(cmdArgs, args...)
cmd := exec.Command(cmdBin, cmdArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {
return fmt.Errorf("Could not run camget: %v", err)
}
go handleSignals(cmd.Process)
return cmd.Wait()
return runExec(cmdBin, cmdArgs)
}
func (c *getCmd) checkFlags(args []string) error {

View File

@ -98,14 +98,7 @@ func (c *putCmd) RunCommand(args []string) error {
"-server=" + blobserver,
}
cmdArgs = append(cmdArgs, args...)
cmd := exec.Command(cmdBin, cmdArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {
return fmt.Errorf("Could not run camput: %v", err)
}
go handleSignals(cmd.Process)
return cmd.Wait()
return runExec(cmdBin, cmdArgs)
}
func (c *putCmd) checkFlags(args []string) error {

View File

@ -21,6 +21,7 @@ import (
"io"
"log"
"os"
"os/exec"
"os/signal"
"path/filepath"
"strings"
@ -29,6 +30,26 @@ import (
"camlistore.org/pkg/cmdmain"
)
// sysExec is set to syscall.Exec on platforms that support it.
var sysExec func(argv0 string, argv []string, envv []string) (err error)
// runExec execs bin. If the platform doesn't support exec, it runs it and waits
// for it to finish.
func runExec(bin string, args []string) error {
if sysExec != nil {
sysExec(bin, append([]string{filepath.Base(bin)}, args...), os.Environ())
}
cmd := exec.Command(bin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {
return fmt.Errorf("Could not run camput: %v", err)
}
go handleSignals(cmd.Process)
return cmd.Wait()
}
func setenv(key, value string) {
err := os.Setenv(key, value)
if err != nil {

27
dev/devcam/exec.go Normal file
View File

@ -0,0 +1,27 @@
// +build !windows
/*
Copyright 2013 The Camlistore Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main
import (
"syscall"
)
func init() {
sysExec = syscall.Exec
}

View File

@ -383,13 +383,7 @@ func (c *serverCmd) RunCommand(args []string) error {
cmdArgs := []string{
"-configfile=" + filepath.Join(c.camliSrcRoot, "config", "dev-server-config.json"),
"-listen=" + c.listen,
"-openbrowser=" + strconv.FormatBool(c.openBrowser)}
cmd := exec.Command(camliBin, cmdArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {
return fmt.Errorf("Could not start camlistored: %v", err)
"-openbrowser=" + strconv.FormatBool(c.openBrowser),
}
go handleSignals(cmd.Process)
return cmd.Wait()
return runExec(camliBin, cmdArgs)
}