Skip to content

Commit ec68f07

Browse files
committed
Fix Lint on Windows and enable the job
[NO NEW TESTS NEEDED] Purely refactoring Signed-off-by: Matt Heon <mheon@redhat.com>
1 parent d5a17ad commit ec68f07

25 files changed

Lines changed: 203 additions & 142 deletions

cmd/podman-wslkerninst/main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ import (
1616
)
1717

1818
const (
19+
//nolint:stylecheck
1920
MB_ICONWARNING = 0x00000030
20-
MB_OK = 0x00000000
21-
MB_DEFBUTTON1 = 0x00000000
21+
//nolint:stylecheck
22+
MB_OK = 0x00000000
23+
//nolint:stylecheck
24+
MB_DEFBUTTON1 = 0x00000000
2225
)
2326

2427
const KernelWarning = "WSL Kernel installation did not complete successfully. " +
@@ -85,7 +88,7 @@ func warn(title string, caption string) int {
8588

8689
func main() {
8790
args := os.Args
88-
setupLogging(path.Base(args[0]))
91+
_, _ = setupLogging(path.Base(args[0]))
8992
if wutil.IsWSLInstalled() {
9093
// nothing to do
9194
logrus.Info("WSL Kernel already installed")

cmd/winpath/main.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ import (
1818
type operation int
1919

2020
const (
21-
HWND_BROADCAST = 0xFFFF
22-
WM_SETTINGCHANGE = 0x001A
23-
SMTO_ABORTIFHUNG = 0x0002
24-
ERR_BAD_ARGS = 0x000A
25-
OPERATION_FAILED = 0x06AC
26-
Environment = "Environment"
27-
Add operation = iota
21+
//nolint:stylecheck
22+
HWND_BROADCAST = 0xFFFF
23+
//nolint:stylecheck
24+
WM_SETTINGCHANGE = 0x001A
25+
//nolint:stylecheck
26+
SMTO_ABORTIFHUNG = 0x0002
27+
//nolint:stylecheck
28+
ERR_BAD_ARGS = 0x000A
29+
//nolint:stylecheck
30+
OPERATION_FAILED = 0x06AC
31+
32+
Environment = "Environment"
33+
Add operation = iota
2834
Remove
2935
Open
3036
NotSpecified
@@ -143,6 +149,8 @@ func removePathFromRegistry(path string) error {
143149
return err
144150
}
145151

152+
// No point preallocating we can't know how big the array needs to be.
153+
//nolint:prealloc
146154
var elements []string
147155
for _, element := range strings.Split(existing, ";") {
148156
if strings.EqualFold(element, path) {
@@ -174,6 +182,7 @@ func broadcastEnvironmentChange() {
174182
user32 := syscall.NewLazyDLL("user32")
175183
proc := user32.NewProc("SendMessageTimeoutW")
176184
millis := 3000
185+
//nolint:dogsled
177186
_, _, _ = proc.Call(HWND_BROADCAST, WM_SETTINGCHANGE, 0, uintptr(unsafe.Pointer(env)), SMTO_ABORTIFHUNG, uintptr(millis), 0)
178187
}
179188

contrib/cirrus/runner.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ function _run_altbuild() {
281281
rm -rf $context_dir
282282
;;
283283
*Windows*)
284-
showrun make lint GOOS=windows || true # TODO: Enable when code passes check
284+
showrun make .install.pre-commit
285+
showrun make lint GOOS=windows CGO_ENABLED=0
285286
showrun make podman-remote-release-windows_amd64.zip
286287
;;
287288
*RPM*)

hack/golangci-lint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ set -e
1515
BUILD_TAGS_DEFAULT="apparmor,seccomp,selinux"
1616
BUILD_TAGS_ABI="$BUILD_TAGS_DEFAULT,systemd"
1717
BUILD_TAGS_TUNNEL="$BUILD_TAGS_DEFAULT,remote"
18-
BUILD_TAGS_REMOTE="remote"
18+
BUILD_TAGS_REMOTE="remote,containers_image_openpgp"
1919

2020
SKIP_DIRS_ABI=""
2121
SKIP_DIRS_TUNNEL="pkg/api,pkg/domain/infra/abi"
@@ -40,6 +40,6 @@ for to_lint in "${to_lint[@]}"; do
4040
# Make it really easy for a developer to copy-paste the command-line
4141
# to focus or debug a single, specific linting category.
4242
set -x
43-
./bin/golangci-lint run --build-tags="${!tags_var}" --skip-dirs="${!skip_var}" "$@"
43+
./bin/golangci-lint run --timeout=10m --build-tags="${!tags_var}" --skip-dirs="${!skip_var}" "$@"
4444
)
4545
done

pkg/bindings/containers/term_windows.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ func notifyWinChange(ctx context.Context, winChange chan os.Signal, stdin *os.Fi
6161
}
6262
}
6363
}()
64-
6564
}
6665

6766
func getTermSize(stdin *os.File, stdout *os.File) (width, height int, err error) {

pkg/machine/e2e/config_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ func isWSL() bool {
236236
return isVmtype(define.WSLVirt)
237237
}
238238

239-
//nolint:unused
239+
// Only used on Windows
240+
//
241+
//nolint:unparam,unused
240242
func runSystemCommand(binary string, cmdArgs []string, timeout time.Duration, wait bool) (*machineSession, error) {
241243
GinkgoWriter.Println(binary + " " + strings.Join(cmdArgs, " "))
242244
c := exec.Command(binary, cmdArgs...)

pkg/machine/e2e/init_windows_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ var _ = Describe("podman machine init - windows only", func() {
3838
Expect(session).To(Exit(0))
3939

4040
defer func() {
41-
_, err := runSystemCommand(wutil.FindWSL(), []string{"--terminate", "podman-net-usermode"}, defaultTimeout, true)
41+
_, err := runSystemCommand(wutil.FindWSL(), []string{"--terminate", "podman-net-usermode"}, defaultTimeout, true)
4242
if err != nil {
4343
fmt.Println("unable to terminate podman-net-usermode")
4444
}
4545

46-
_, err = runSystemCommand(wutil.FindWSL(), []string{"--unregister", "podman-net-usermode"}, defaultTimeout, true)
46+
_, err = runSystemCommand(wutil.FindWSL(), []string{"--unregister", "podman-net-usermode"}, defaultTimeout, true)
4747
if err != nil {
4848
fmt.Println("unable to unregister podman-net-usermode")
4949
}
@@ -87,6 +87,7 @@ var _ = Describe("podman machine init - windows only", func() {
8787
}()
8888
i := new(initMachine)
8989
session, err := mb.setName(name).setCmd(i.withImagePath(mb.imagePath)).run()
90+
Expect(err).ToNot(HaveOccurred())
9091
Expect(session).To(Exit(125))
9192
Expect(session.errorToString()).To(ContainSubstring("already exists on hypervisor"))
9293
})

pkg/machine/fedora_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func DetermineMachineArch() string {
1414
current, _ := syscall.GetCurrentProcess()
1515

1616
if err := windows.IsWow64Process2(windows.Handle(current), &machine, &native); err != nil {
17-
logrus.Warnf("Failure detecting native system architecture, %s: %w", fallbackMsg, err)
17+
logrus.Warnf("Failure detecting native system architecture, %s: %v", fallbackMsg, err)
1818
// Fall-back to binary arch
1919
return runtime.GOARCH
2020
}
@@ -26,7 +26,7 @@ func DetermineMachineArch() string {
2626
case 0x8664:
2727
return "amd64"
2828
default:
29-
logrus.Warnf("Unknown or unsupported native system architecture [%d], %s", fallbackMsg)
29+
logrus.Warnf("Unknown or unsupported native system architecture [%d], %s", native, fallbackMsg)
3030
return runtime.GOARCH
3131
}
3232
}

pkg/machine/gvproxy.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,10 @@ package machine
33
import (
44
"fmt"
55
"strconv"
6-
"time"
76

87
"github.com/containers/podman/v5/pkg/machine/define"
9-
psutil "github.com/shirou/gopsutil/v3/process"
108
)
119

12-
const (
13-
loops = 8
14-
sleepTime = time.Millisecond * 1
15-
)
16-
17-
// backoffForProcess checks if the process still exists, for something like
18-
// sigterm. If the process still exists after loops and sleep time are exhausted,
19-
// an error is returned
20-
func backoffForProcess(p *psutil.Process) error {
21-
sleepInterval := sleepTime
22-
for i := 0; i < loops; i++ {
23-
running, err := p.IsRunning()
24-
if err != nil {
25-
return fmt.Errorf("checking if process running: %w", err)
26-
}
27-
if !running {
28-
return nil
29-
}
30-
31-
time.Sleep(sleepInterval)
32-
// double the time
33-
sleepInterval += sleepInterval
34-
}
35-
return fmt.Errorf("process %d has not ended", p.Pid)
36-
}
37-
3810
// CleanupGVProxy reads the --pid-file for gvproxy attempts to stop it
3911
func CleanupGVProxy(f define.VMFile) error {
4012
gvPid, err := f.Read()

pkg/machine/gvproxy_unix.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,38 @@ import (
66
"errors"
77
"fmt"
88
"syscall"
9+
"time"
910

1011
psutil "github.com/shirou/gopsutil/v3/process"
1112
"github.com/sirupsen/logrus"
1213
)
1314

15+
const (
16+
loops = 8
17+
sleepTime = time.Millisecond * 1
18+
)
19+
20+
// backoffForProcess checks if the process still exists, for something like
21+
// sigterm. If the process still exists after loops and sleep time are exhausted,
22+
// an error is returned
23+
func backoffForProcess(p *psutil.Process) error {
24+
sleepInterval := sleepTime
25+
for i := 0; i < loops; i++ {
26+
running, err := p.IsRunning()
27+
if err != nil {
28+
return fmt.Errorf("checking if process running: %w", err)
29+
}
30+
if !running {
31+
return nil
32+
}
33+
34+
time.Sleep(sleepInterval)
35+
// double the time
36+
sleepInterval += sleepInterval
37+
}
38+
return fmt.Errorf("process %d has not ended", p.Pid)
39+
}
40+
1441
// / waitOnProcess takes a pid and sends a sigterm to it. it then waits for the
1542
// process to not exist. if the sigterm does not end the process after an interval,
1643
// then sigkill is sent. it also waits for the process to exit after the sigkill too.

0 commit comments

Comments
 (0)