]> Cypherpunks.ru repositories - goredo.git/blobdiff - run.go
Remove shebang parsing, let the kernel do this
[goredo.git] / run.go
diff --git a/run.go b/run.go
index 93c837d9fb458dca6c4bffbe62c120da60aa387f..6a38d5abdf7b735e15beb7023ae43d459cf3e2d3 100644 (file)
--- a/run.go
+++ b/run.go
@@ -63,7 +63,7 @@ var (
        StderrPrefix string
        Jobs         sync.WaitGroup
 
-       flagTrace        = flag.Bool("x", false, fmt.Sprintf("trace current target (sh -x) (set %s=1 for others too)", EnvTrace))
+       flagTrace        = flag.Bool("x", false, fmt.Sprintf("trace current target (sh -x) (set %s=1 for all others)", EnvTrace))
        flagStderrKeep   = flag.Bool("logs", false, fmt.Sprintf("keep job's stderr (%s=1)", EnvStderrKeep))
        flagStderrSilent = flag.Bool("silent", false, fmt.Sprintf("do not print job's stderr (%s=1)", EnvStderrSilent))
 )
@@ -275,10 +275,6 @@ func runScript(tgtOrig string, errs chan error, traced bool) error {
                cleanup()
                return TgtErr{tgtOrig, errors.New("no .do found")}
        }
-       if err = writeDep(fdDep, cwd, doFile); err != nil {
-               cleanup()
-               return TgtErr{tgtOrig, err}
-       }
 
        // Determine basename and DIRPREFIX
        ents := strings.Split(cwd, "/")
@@ -289,52 +285,32 @@ func runScript(tgtOrig string, errs chan error, traced bool) error {
                cwd = path.Join(cwd, "..")
        }
        cwd = path.Clean(cwd)
+       doFilePath := path.Join(cwd, doFile)
        basename := tgt
        runErr := RunErr{Tgt: tgtOrig}
        if strings.HasPrefix(doFile, "default.") {
                basename = tgt[:len(tgt)-(len(doFile)-len("default.")-len(".do"))-1]
                runErr.DoFile = doFile
        }
+
+       if err = writeDep(fdDep, cwd, doFile); err != nil {
+               cleanup()
+               return TgtErr{tgtOrig, err}
+       }
        trace(CWait, "%s", runErr.Name())
-       doFile = path.Base(doFile)
 
        // Prepare command line
        var cmdName string
        var args []string
-       if err = unix.Access(path.Join(cwd, doFile), unix.X_OK); err == nil {
-               // Ordinary executable file
-               cmdName = doFile
+       if err = unix.Access(doFilePath, unix.X_OK); err == nil {
+               cmdName = doFilePath
                args = make([]string, 0, 3)
        } else {
-               fd, err := os.Open(path.Join(cwd, doFile))
-               if err != nil {
-                       cleanup()
-                       return TgtErr{tgtOrig, err}
-               }
-               buf := make([]byte, 512)
-               n, err := fd.Read(buf)
-               if err != nil {
-                       cleanup()
-                       return TgtErr{tgtOrig, err}
-               }
-               if n > 3 && string(buf[:3]) == "#!/" {
-                       // Shebanged
-                       t := string(buf[2:n])
-                       nlIdx := strings.Index(t, "\n")
-                       if nlIdx == -1 {
-                               cleanup()
-                               return TgtErr{tgtOrig, errors.New("not fully read shebang")}
-                       }
-                       args = strings.Split(t[:nlIdx], " ")
-                       cmdName, args = args[0], args[1:]
+               cmdName = "/bin/sh"
+               if traced {
+                       args = append(args, "-ex")
                } else {
-                       // Shell
-                       cmdName = "/bin/sh"
-                       if traced {
-                               args = append(args, "-ex")
-                       } else {
-                               args = append(args, "-e")
-                       }
+                       args = append(args, "-e")
                }
                args = append(args, doFile)
        }