-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5614 from oasisprotocol/kostko/feature/fix-window…
…s-build go: Make sure packages compile on Windows
- Loading branch information
Showing
14 changed files
with
149 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
go: Make sure packages compile on Windows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package common | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package common | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
// Mkdir creates a directory iff it does not exist. | ||
func Mkdir(d string) error { | ||
const permDir = os.FileMode(0o700) | ||
|
||
fi, err := os.Lstat(d) | ||
if err != nil { | ||
// Iff the directory does not exist, create it. | ||
if os.IsNotExist(err) { | ||
if err = os.MkdirAll(d, permDir); err == nil { | ||
return nil | ||
} | ||
} | ||
return err | ||
} | ||
|
||
// Ensure that the existing path is a directory. | ||
fm := fi.Mode() | ||
if !fm.IsDir() { | ||
return fmt.Errorf("common/Mkdir: path '%s' is not a directory", d) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Package syscall defines OS-specific syscall parameters. | ||
package syscall | ||
|
||
import "syscall" | ||
|
||
// CmdAttrs is the SysProcAttr used for spawning child processes. It is empty | ||
// for Windows as PR_SET_PDEATH_SIG is not implemented. As a consequence, child | ||
// processes may not be cleaned up. | ||
var CmdAttrs = &syscall.SysProcAttr{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package common | ||
|
||
import ( | ||
"fmt" | ||
"syscall" | ||
|
||
"github.com/oasisprotocol/oasis-core/go/config" | ||
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags" | ||
) | ||
|
||
func initRlimit() error { | ||
// Suppress this for tooling, as it likely does not matter. | ||
if !IsNodeCmd() { | ||
return nil | ||
} | ||
|
||
var rlim syscall.Rlimit | ||
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlim); err != nil { | ||
return fmt.Errorf("failed to query RLIMIT_NOFILE: %w", err) | ||
} | ||
|
||
desiredLimit := config.GlobalConfig.Common.Debug.Rlimit | ||
if flags.DebugDontBlameOasis() && desiredLimit > 0 && desiredLimit != rlim.Cur { | ||
rlim.Cur = desiredLimit | ||
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rlim); err != nil { | ||
return fmt.Errorf("failed setting RLIMIT_NOFILE: %w", err) | ||
} | ||
} | ||
|
||
if rlim.Cur < RequiredRlimit { | ||
return fmt.Errorf("too low RLIMIT_NOFILE, current: %d required: %d", rlim.Cur, RequiredRlimit) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func Umask(mask int) int { | ||
return syscall.Umask(mask) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package common | ||
|
||
func initRlimit() error { | ||
return nil | ||
} | ||
|
||
func Umask(int) int { | ||
return 0 | ||
} |
3 changes: 3 additions & 0 deletions
3
go/oasis-node/cmd/common/isatty.go → go/oasis-node/cmd/common/isatty_other.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package common | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package common | ||
|
||
// Isatty returns true iff the provided file descriptor is a terminal. | ||
func Isatty(fd uintptr) bool { | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package process | ||
|
||
import "syscall" | ||
|
||
// Implements Process. | ||
func (n *naked) Kill() { | ||
_ = n.cmd.Process.Kill() | ||
<-n.waitCh | ||
|
||
// Some environments (lolDocker) do not have something that | ||
// reaps zombie processes by default. Kill the process group | ||
// as well. | ||
_ = syscall.Kill(-n.cmd.Process.Pid, syscall.SIGKILL) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package process | ||
|
||
// Implements Process. | ||
func (n *naked) Kill() { | ||
_ = n.cmd.Process.Kill() | ||
<-n.waitCh | ||
} |