]> Cypherpunks.ru repositories - goredo.git/blobdiff - main.go
Linting
[goredo.git] / main.go
diff --git a/main.go b/main.go
index c3b1be78677b731291db45ca8af4cfab7b74a5d3..9f1158182194446d20e8a2c0a103d9b4fa3d86f5 100644 (file)
--- a/main.go
+++ b/main.go
@@ -21,6 +21,7 @@ import (
        "bufio"
        "bytes"
        "crypto/rand"
+       "errors"
        "flag"
        "fmt"
        "io"
@@ -62,8 +63,8 @@ var (
        IsTopRedo bool // is it the top redo instance
 )
 
-func mustSetenv(key, value string) {
-       if err := os.Setenv(key, value); err != nil {
+func mustSetenv(key string) {
+       if err := os.Setenv(key, "1"); err != nil {
                panic(err)
        }
 }
@@ -154,28 +155,28 @@ func main() {
        DepCwd = os.Getenv(EnvDepCwd)
 
        if flagStderrKeep != nil && *flagStderrKeep {
-               mustSetenv(EnvStderrKeep, "1")
+               mustSetenv(EnvStderrKeep)
        }
        if flagStderrSilent != nil && *flagStderrSilent {
-               mustSetenv(EnvStderrSilent, "1")
+               mustSetenv(EnvStderrSilent)
        }
        if flagNoProgress != nil && *flagNoProgress {
-               mustSetenv(EnvNoProgress, "1")
+               mustSetenv(EnvNoProgress)
        }
        if flagDebug != nil && *flagDebug {
-               mustSetenv(EnvDebug, "1")
+               mustSetenv(EnvDebug)
        }
        if flagLogWait != nil && *flagLogWait {
-               mustSetenv(EnvLogWait, "1")
+               mustSetenv(EnvLogWait)
        }
        if flagLogLock != nil && *flagLogLock {
-               mustSetenv(EnvLogLock, "1")
+               mustSetenv(EnvLogLock)
        }
        if flagLogPid != nil && *flagLogPid {
-               mustSetenv(EnvLogPid, "1")
+               mustSetenv(EnvLogPid)
        }
        if flagLogJS != nil && *flagLogJS {
-               mustSetenv(EnvLogJS, "1")
+               mustSetenv(EnvLogJS)
        }
        StderrKeep = os.Getenv(EnvStderrKeep) == "1"
        StderrSilent = os.Getenv(EnvStderrSilent) == "1"
@@ -189,7 +190,7 @@ func main() {
        }
        var traced bool
        if flagTraceAll != nil && *flagTraceAll {
-               mustSetenv(EnvTrace, "1")
+               mustSetenv(EnvTrace)
        }
        if os.Getenv(EnvTrace) == "1" {
                TracedAll = true
@@ -227,7 +228,9 @@ func main() {
                if err != nil {
                        log.Fatalln(err)
                }
-               unix.Flock(int(fdLock.Fd()), unix.LOCK_UN)
+               if err = unix.Flock(int(fdLock.Fd()), unix.LOCK_UN); err != nil {
+                       log.Fatalln(err)
+               }
                OODTgts = map[string]struct{}{}
                for _, tgtRaw := range bytes.Split(tgtsRaw, []byte{0}) {
                        t := string(tgtRaw)
@@ -235,7 +238,7 @@ func main() {
                                continue
                        }
                        OODTgts[t] = struct{}{}
-                       trace(CDebug, "ood: known to be: %s", t)
+                       tracef(CDebug, "ood: known to be: %s", t)
                }
        }
 
@@ -284,23 +287,23 @@ func main() {
                }
        }
 
-       killed := make(chan os.Signal, 0)
+       killed := make(chan os.Signal, 1)
        signal.Notify(killed, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM)
        go func() {
                <-killed
-               trace(CDebug, "[%s] killed", BuildUUID)
+               tracef(CDebug, "[%s] killed", BuildUUID)
                jsReleaseAll()
                RunningProcsM.Lock()
                for pid, proc := range RunningProcs {
-                       trace(CDebug, "[%s] killing child %d", BuildUUID, pid)
-                       proc.Signal(syscall.SIGTERM)
+                       tracef(CDebug, "[%s] killing child %d", BuildUUID, pid)
+                       _ = proc.Signal(syscall.SIGTERM)
                }
                os.Exit(1)
        }()
 
        ok := true
        err = nil
-       trace(
+       tracef(
                CDebug, "[%s] run: %s %s cwd:%s dirprefix:%s",
                BuildUUID, cmdName, tgts, Cwd, DirPrefix,
        )
@@ -386,7 +389,7 @@ CmdSwitch:
                for {
                        m, err := r.NextMap()
                        if err != nil {
-                               if err == io.EOF {
+                               if errors.Is(err, io.EOF) {
                                        break
                                }
                                break CmdSwitch
@@ -487,6 +490,6 @@ CmdSwitch:
        if !ok || err != nil {
                rc = 1
        }
-       trace(CDebug, "[%s] finished: %s %s", BuildUUID, cmdName, tgts)
+       tracef(CDebug, "[%s] finished: %s %s", BuildUUID, cmdName, tgts)
        os.Exit(rc)
 }