aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.golangci.yml3
-rw-r--r--pkg/ifuzz/decode.go2
-rw-r--r--pkg/ifuzz/encode.go2
-rw-r--r--pkg/osutil/osutil_unix.go32
4 files changed, 23 insertions, 16 deletions
diff --git a/.golangci.yml b/.golangci.yml
index 38e46f9fd..db5ea28cb 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -35,6 +35,7 @@ linters:
- stylecheck
- govet
- whitespace
+ - nestif
disable:
- typecheck
- ineffassign
@@ -56,6 +57,8 @@ linters-settings:
goconst:
min-len: 7
min-occurrences: 4
+ nestif:
+ min-complexity: 12
issues:
exclude-use-default: false
diff --git a/pkg/ifuzz/decode.go b/pkg/ifuzz/decode.go
index 4e4c5873e..b16c9f0bd 100644
--- a/pkg/ifuzz/decode.go
+++ b/pkg/ifuzz/decode.go
@@ -10,7 +10,7 @@ import (
// Decode decodes instruction length for the given mode.
// It can have falsely decode incorrect instructions,
// but should not fail to decode correct instructions.
-// nolint: gocyclo
+// nolint: gocyclo, nestif
func Decode(mode int, text []byte) (int, error) {
if len(text) == 0 {
return 0, fmt.Errorf("zero-length instruction")
diff --git a/pkg/ifuzz/encode.go b/pkg/ifuzz/encode.go
index 4780c4bd8..ecabcfcd9 100644
--- a/pkg/ifuzz/encode.go
+++ b/pkg/ifuzz/encode.go
@@ -11,7 +11,7 @@ import (
"math/rand"
)
-// nolint: gocyclo
+// nolint: gocyclo, nestif
func (insn *Insn) Encode(cfg *Config, r *rand.Rand) []byte {
if !insn.isCompatible(cfg) {
panic("instruction is not suitable for this mode")
diff --git a/pkg/osutil/osutil_unix.go b/pkg/osutil/osutil_unix.go
index 8f31a43e0..914398c79 100644
--- a/pkg/osutil/osutil_unix.go
+++ b/pkg/osutil/osutil_unix.go
@@ -36,21 +36,9 @@ func ProcessTempDir(where string) (string, error) {
err := os.Mkdir(path, DefaultDirPerm)
if os.IsExist(err) {
// Try to clean up.
- data, err := ioutil.ReadFile(pidfile)
- if err == nil && len(data) > 0 {
- pid, err := strconv.Atoi(string(data))
- if err == nil && pid > 1 {
- if err := syscall.Kill(pid, 0); err == syscall.ESRCH {
- if os.Remove(pidfile) == nil {
- if os.RemoveAll(path) == nil {
- i--
- continue
- }
- }
- }
- }
+ if cleanupTempDir(path, pidfile) {
+ i--
}
- // If err != nil, assume that the pid file is not created yet.
continue
}
if err != nil {
@@ -64,6 +52,22 @@ func ProcessTempDir(where string) (string, error) {
return "", fmt.Errorf("too many live instances")
}
+func cleanupTempDir(path, pidfile string) bool {
+ data, err := ioutil.ReadFile(pidfile)
+ if err == nil && len(data) > 0 {
+ pid, err := strconv.Atoi(string(data))
+ if err == nil && pid > 1 {
+ if err := syscall.Kill(pid, 0); err == syscall.ESRCH {
+ if os.Remove(pidfile) == nil {
+ return os.RemoveAll(path) == nil
+ }
+ }
+ }
+ }
+ // If err != nil, assume that the pid file is not created yet.
+ return false
+}
+
// HandleInterrupts closes shutdown chan on first SIGINT
// (expecting that the program will gracefully shutdown and exit)
// and terminates the process on third SIGINT.