From 6ace082bc2f480eb5138c3fee7526e5136d2c9fe Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 20 Dec 2022 20:53:52 +0530 Subject: [PATCH] Add openbsd and dragonfly support to shm --- tools/utils/shm/shm_fs.go | 3 +- tools/utils/shm/shm_openbsd.go | 40 --------------------------- tools/utils/shm/specific_dragonfly.go | 16 +++++++++++ tools/utils/shm/specific_linux.go | 5 +++- tools/utils/shm/specific_netbsd.go | 5 +++- tools/utils/shm/specific_openbsd.go | 21 ++++++++++++++ 6 files changed, 47 insertions(+), 43 deletions(-) delete mode 100644 tools/utils/shm/shm_openbsd.go create mode 100644 tools/utils/shm/specific_dragonfly.go create mode 100644 tools/utils/shm/specific_openbsd.go diff --git a/tools/utils/shm/shm_fs.go b/tools/utils/shm/shm_fs.go index dbadff30c..50836b847 100644 --- a/tools/utils/shm/shm_fs.go +++ b/tools/utils/shm/shm_fs.go @@ -1,5 +1,5 @@ // License: GPLv3 Copyright: 2022, Kovid Goyal, -//go:build linux || netbsd +//go:build linux || netbsd || openbsd || dragonfly package shm @@ -12,6 +12,7 @@ import ( var _ = fmt.Print func create_temp(pattern string, size uint64) (MMap, error) { + pattern = modify_pattern(pattern) ans, err := os.CreateTemp(SHM_DIR, pattern) if err != nil { return nil, err diff --git a/tools/utils/shm/shm_openbsd.go b/tools/utils/shm/shm_openbsd.go deleted file mode 100644 index d96f5e3b4..000000000 --- a/tools/utils/shm/shm_openbsd.go +++ /dev/null @@ -1,40 +0,0 @@ -// License: GPLv3 Copyright: 2022, Kovid Goyal, - -package shm - -import ( - "fmt" - "os" - "path/filepath" -) - -var _ = fmt.Print - -const SHM_DIR = "/tmp" - -func create_temp(pattern string) (*os.File, error) { - ans, err := os.CreateTemp(SHM_DIR, pattern) - if err != nil { - return nil, err - } - return ans, nil -} - -func Open(name string) (*os.File, error) { - if !filepath.IsAbs(name) { - name = filepath.Join(SHM_DIR, name) - } - ans, err := os.OpenFile(name, os.O_RDONLY, 0) - if err != nil { - return nil, err - } - return ans, nil -} - -func Unlink(name string) error { - if !filepath.IsAbs(name) { - name = filepath.Join(SHM_DIR, name) - } - return os.Remove(name) - -} diff --git a/tools/utils/shm/specific_dragonfly.go b/tools/utils/shm/specific_dragonfly.go new file mode 100644 index 000000000..2b8fdb22c --- /dev/null +++ b/tools/utils/shm/specific_dragonfly.go @@ -0,0 +1,16 @@ +// License: GPLv3 Copyright: 2022, Kovid Goyal, + +package shm + +import ( + "fmt" +) + +var _ = fmt.Print + +// https://www.dragonflybsd.org/cgi/web-man?command=shm_open§ion=3 +const SHM_DIR = "/var/run/shm" + +func modify_pattern(pattern string) string { + return pattern +} diff --git a/tools/utils/shm/specific_linux.go b/tools/utils/shm/specific_linux.go index 486ef3eca..bc9e94dcf 100644 --- a/tools/utils/shm/specific_linux.go +++ b/tools/utils/shm/specific_linux.go @@ -9,4 +9,7 @@ import ( var _ = fmt.Print const SHM_DIR = "/dev/shm" -const SHM_NAME_MAX = 1023 + +func modify_pattern(pattern string) string { + return pattern +} diff --git a/tools/utils/shm/specific_netbsd.go b/tools/utils/shm/specific_netbsd.go index 875b22e54..e8bd8d2c4 100644 --- a/tools/utils/shm/specific_netbsd.go +++ b/tools/utils/shm/specific_netbsd.go @@ -9,4 +9,7 @@ import ( var _ = fmt.Print const SHM_DIR = "/var/shm" -const SHM_NAME_MAX = 1023 + +func modify_pattern(pattern string) string { + return pattern +} diff --git a/tools/utils/shm/specific_openbsd.go b/tools/utils/shm/specific_openbsd.go new file mode 100644 index 000000000..b571b593f --- /dev/null +++ b/tools/utils/shm/specific_openbsd.go @@ -0,0 +1,21 @@ +// License: GPLv3 Copyright: 2022, Kovid Goyal, + +package shm + +import ( + "fmt" +) + +var _ = fmt.Print + +const SHM_DIR = "/tmp" + +func modify_pattern(pattern string) string { + // https://github.com/openbsd/src/blob/master/lib/libc/gen/shm_open.c + if strings.Contains(pattern, "*") { + pattern += ".shm" + } else { + pattern += "*.shm" + } + return pattern +}