From 9647711921a03785bfea417a6eb48088d0d30197 Mon Sep 17 00:00:00 2001 From: delthas Date: Sun, 20 Mar 2022 14:31:16 +0100 Subject: [PATCH] Fix build on systems without syscall.Rlimit On some systems (namely Windows), syscall.Rlimit is not defined, and makes the build fail. This fixes the build by making the rlimit calls only run on archs where it is defined, defaulting to a stub on other systems. See: https://github.com/golang/go/commit/8427429c592588af8c49522c76b3e0e0e335d270 --- cmd/soju/main.go | 12 ------------ cmd/soju/rlimit.go | 21 +++++++++++++++++++++ cmd/soju/rlimit_stub.go | 8 ++++++++ 3 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 cmd/soju/rlimit.go create mode 100644 cmd/soju/rlimit_stub.go diff --git a/cmd/soju/main.go b/cmd/soju/main.go index 3771be0..5e784c9 100644 --- a/cmd/soju/main.go +++ b/cmd/soju/main.go @@ -40,18 +40,6 @@ func (v *stringSliceFlag) Set(s string) error { return nil } -func bumpOpenedFileLimit() error { - var rlimit syscall.Rlimit - if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil { - return fmt.Errorf("failed to get RLIMIT_NOFILE: %v", err) - } - rlimit.Cur = rlimit.Max - if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil { - return fmt.Errorf("failed to set RLIMIT_NOFILE: %v", err) - } - return nil -} - var ( configPath string debug bool diff --git a/cmd/soju/rlimit.go b/cmd/soju/rlimit.go new file mode 100644 index 0000000..a0c51c9 --- /dev/null +++ b/cmd/soju/rlimit.go @@ -0,0 +1,21 @@ +//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris +// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris + +package main + +import ( + "fmt" + "syscall" +) + +func bumpOpenedFileLimit() error { + var rlimit syscall.Rlimit + if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil { + return fmt.Errorf("failed to get RLIMIT_NOFILE: %v", err) + } + rlimit.Cur = rlimit.Max + if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlimit); err != nil { + return fmt.Errorf("failed to set RLIMIT_NOFILE: %v", err) + } + return nil +} diff --git a/cmd/soju/rlimit_stub.go b/cmd/soju/rlimit_stub.go new file mode 100644 index 0000000..c409b1a --- /dev/null +++ b/cmd/soju/rlimit_stub.go @@ -0,0 +1,8 @@ +//go:build !aix && !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !solaris +// +build !aix,!darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!solaris + +package main + +func bumpOpenedFileLimit() error { + return nil +}