From 4a3e25712f25271876e83dfafe8ff2df4f643df7 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 7 Feb 2019 04:45:01 +0000 Subject: [PATCH] os, net, crypto/x509: add hurd support Patch by Svante Signell. Reviewed-on: https://go-review.googlesource.com/c/161519 From-SVN: r268604 --- gcc/go/gofrontend/MERGE | 2 +- libgo/go/crypto/x509/root_hurd.go | 11 +++++ .../{sendfile_linux.go => sendfile_glibc.go} | 2 + libgo/go/net/cgo_hurd.go | 17 ++++++++ .../{sendfile_linux.go => sendfile_glibc.go} | 2 + libgo/go/net/sockopt_hurd.go | 41 +++++++++++++++++++ libgo/go/os/executable_procfs.go | 2 +- libgo/go/os/{pipe_linux.go => pipe_glibc.go} | 2 + 8 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 libgo/go/crypto/x509/root_hurd.go rename libgo/go/internal/poll/{sendfile_linux.go => sendfile_glibc.go} (98%) create mode 100644 libgo/go/net/cgo_hurd.go rename libgo/go/net/{sendfile_linux.go => sendfile_glibc.go} (98%) create mode 100644 libgo/go/net/sockopt_hurd.go rename libgo/go/os/{pipe_linux.go => pipe_glibc.go} (97%) diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 53780e1bc21..b7efb211ca5 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -db618eeabdcf1ba56861d21d5639ca4514cd6934 +28b65174d9c9163f4ab2cfaf70dca646f1a7611f The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/libgo/go/crypto/x509/root_hurd.go b/libgo/go/crypto/x509/root_hurd.go new file mode 100644 index 00000000000..59e9ff0c81b --- /dev/null +++ b/libgo/go/crypto/x509/root_hurd.go @@ -0,0 +1,11 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// This file is derived from root_linux.go + +package x509 + +// Possible certificate files; stop after finding one. +var certFiles = []string{ + "/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu/Gentoo etc. +} diff --git a/libgo/go/internal/poll/sendfile_linux.go b/libgo/go/internal/poll/sendfile_glibc.go similarity index 98% rename from libgo/go/internal/poll/sendfile_linux.go rename to libgo/go/internal/poll/sendfile_glibc.go index 8e938065f17..6652e3fedc1 100644 --- a/libgo/go/internal/poll/sendfile_linux.go +++ b/libgo/go/internal/poll/sendfile_glibc.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build hurd linux + package poll import "syscall" diff --git a/libgo/go/net/cgo_hurd.go b/libgo/go/net/cgo_hurd.go new file mode 100644 index 00000000000..98e4cfa6352 --- /dev/null +++ b/libgo/go/net/cgo_hurd.go @@ -0,0 +1,17 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. +// This file is derived from cgo_bsd.go + +// +build cgo,!netgo +// +build hurd + +package net + +/* +#include +*/ + +import "syscall" + +const cgoAddrInfoFlags = syscall.AI_CANONNAME | syscall.AI_V4MAPPED | syscall.AI_ALL diff --git a/libgo/go/net/sendfile_linux.go b/libgo/go/net/sendfile_glibc.go similarity index 98% rename from libgo/go/net/sendfile_linux.go rename to libgo/go/net/sendfile_glibc.go index 297e625d24b..a71cfc961c2 100644 --- a/libgo/go/net/sendfile_linux.go +++ b/libgo/go/net/sendfile_glibc.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build hurd linux + package net import ( diff --git a/libgo/go/net/sockopt_hurd.go b/libgo/go/net/sockopt_hurd.go new file mode 100644 index 00000000000..c6de7a9a1f0 --- /dev/null +++ b/libgo/go/net/sockopt_hurd.go @@ -0,0 +1,41 @@ +// Copyright 2019 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package net + +import ( + "os" + "syscall" +) + +func setDefaultSockopts(s, family, sotype int, ipv6only bool) error { + if family == syscall.AF_INET6 && sotype != syscall.SOCK_RAW { + // Allow both IP versions even if the OS default + // is otherwise. Note that some operating systems + // never admit this option. + syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, boolint(ipv6only)) + } + // Allow broadcast. + if err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1); err != nil { + return os.NewSyscallError("setsockopt", err) + } + return nil +} + +func setDefaultListenerSockopts(s int) error { + // Allow reuse of recently-used addresses. + if err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil { + return os.NewSyscallError("setsockopt", err) + } + return nil +} + +func setDefaultMulticastSockopts(s int) error { + // Allow multicast UDP and raw IP datagram sockets to listen + // concurrently across multiple listeners. + if err := syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil { + return os.NewSyscallError("setsockopt", err) + } + return nil +} diff --git a/libgo/go/os/executable_procfs.go b/libgo/go/os/executable_procfs.go index d6ac270ace4..e690103b0ad 100644 --- a/libgo/go/os/executable_procfs.go +++ b/libgo/go/os/executable_procfs.go @@ -19,7 +19,7 @@ var executablePath, executablePathErr = func() (string, error) { switch runtime.GOOS { default: return "", errors.New("Executable not implemented for " + runtime.GOOS) - case "linux", "android": + case "hurd", "linux", "android": procfn = "/proc/self/exe" case "netbsd": procfn = "/proc/curproc/exe" diff --git a/libgo/go/os/pipe_linux.go b/libgo/go/os/pipe_glibc.go similarity index 97% rename from libgo/go/os/pipe_linux.go rename to libgo/go/os/pipe_glibc.go index acd7b88e1d4..31b144e92c7 100644 --- a/libgo/go/os/pipe_linux.go +++ b/libgo/go/os/pipe_glibc.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build hurd linux + package os import "syscall" -- 2.30.2