Skip to content

Commit

Permalink
Merge pull request #126 from kolyshkin/ws-nits
Browse files Browse the repository at this point in the history
lint: fix warnings from whitespace and gocritic, enable those
  • Loading branch information
rhatdan authored Oct 30, 2020
2 parents 7daab85 + 824b400 commit bca2471
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
run:
concurrency: 6
deadline: 5m
linters:
enable:
- whitespace
- gocritic
5 changes: 2 additions & 3 deletions go-selinux/label/label_selinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ var ErrIncompatibleLabel = errors.New("Bad SELinux option z and Z can not be use
// the container. A list of options can be passed into this function to alter
// the labels. The labels returned will include a random MCS String, that is
// guaranteed to be unique.
func InitLabels(options []string) (plabel string, mlabel string, Err error) {
func InitLabels(options []string) (plabel string, mlabel string, retErr error) {
if !selinux.GetEnabled() {
return "", "", nil
}
processLabel, mountLabel := selinux.ContainerLabels()
if processLabel != "" {
defer func() {
if Err != nil {
if retErr != nil {
selinux.ReleaseLabel(mountLabel)
}
}()
Expand All @@ -57,7 +57,6 @@ func InitLabels(options []string) (plabel string, mlabel string, Err error) {
con := strings.SplitN(opt, ":", 2)
if !validOptions[con[0]] {
return "", "", errors.Errorf("Bad label option %q, valid options 'disable, user, role, level, type, filetype'", con[0])

}
if con[0] == "filetype" {
mcon["type"] = con[1]
Expand Down
1 change: 0 additions & 1 deletion go-selinux/label/label_selinux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ func TestIsShared(t *testing.T) {
if shared := IsShared("Zz"); !shared {
t.Fatalf("Expected label `Zz` to be shared, got %v", shared)
}

}

func TestSELinuxNoLevel(t *testing.T) {
Expand Down
10 changes: 4 additions & 6 deletions go-selinux/selinux_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,11 +828,11 @@ func intToMcs(id int, catRange uint32) string {
}

for ORD > TIER {
ORD = ORD - TIER
ORD -= TIER
TIER--
}
TIER = SETSIZE - TIER
ORD = ORD + TIER
ORD += TIER
return fmt.Sprintf("s0:c%d,c%d", TIER, ORD)
}

Expand All @@ -850,10 +850,8 @@ func uniqMcs(catRange uint32) string {
c2 = n % catRange
if c1 == c2 {
continue
} else {
if c1 > c2 {
c1, c2 = c2, c1
}
} else if c1 > c2 {
c1, c2 = c2, c1
}
mcs = fmt.Sprintf("s0:c%d,c%d", c1, c2)
if err := mcsAdd(mcs); err != nil {
Expand Down
4 changes: 1 addition & 3 deletions go-selinux/selinux_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func TestKVMLabels(t *testing.T) {
plabel, flabel := KVMContainerLabels()
if plabel == "" {
t.Log("Failed to read kvm label")

}
t.Log(plabel)
t.Log(flabel)
Expand Down Expand Up @@ -267,8 +266,8 @@ func TestClassIndex(t *testing.T) {
if err == nil {
t.Errorf("ClassIndex(\"foobar\") succeeded, expected to fail:")
}

}

func TestComputeCreateContext(t *testing.T) {
if !GetEnabled() {
t.Skip("SELinux not enabled, skipping.")
Expand All @@ -295,7 +294,6 @@ func TestComputeCreateContext(t *testing.T) {
if err == nil {
t.Errorf("ComputeCreateContext(%s, %s, %s) succeeded, expected failure", badcon, tmp, process)
}

}

func TestGlbLub(t *testing.T) {
Expand Down

0 comments on commit bca2471

Please sign in to comment.