From c13f46b3a8d9442bc2bfc39fe995ce9a19749fa0 Mon Sep 17 00:00:00 2001 From: Ciprian Dorin Craciun Date: Sat, 25 Dec 2021 10:55:33 +0200 Subject: [PATCH] [common] Extract OS specific functions into common module. --- sources/cmd/archiver/archiver.go | 6 +++--- sources/cmd/server/server.go | 2 +- .../archiver/os-bsd.go => lib/common/os-freebsd-darwin.go} | 4 ++-- sources/{cmd/server => lib/common}/os-freebsd.go | 4 ++-- .../server/os-linux.go => lib/common/os-linux-darwin.go} | 4 ++-- .../archiver/os-linux.go => lib/common/os-linux-openbsd.go} | 4 ++-- sources/{cmd/server => lib/common}/os-openbsd.go | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) rename sources/{cmd/archiver/os-bsd.go => lib/common/os-freebsd-darwin.go} (75%) rename sources/{cmd/server => lib/common}/os-freebsd.go (90%) rename sources/{cmd/server/os-linux.go => lib/common/os-linux-darwin.go} (90%) rename sources/{cmd/archiver/os-linux.go => lib/common/os-linux-openbsd.go} (74%) rename sources/{cmd/server => lib/common}/os-openbsd.go (83%) diff --git a/sources/cmd/archiver/archiver.go b/sources/cmd/archiver/archiver.go index 01acec8..de60a3c 100644 --- a/sources/cmd/archiver/archiver.go +++ b/sources/cmd/archiver/archiver.go @@ -76,7 +76,7 @@ func archiveFile (_context *context, _pathResolved string, _pathInArchive string var _fileSize uint64 var _fileTimestamp uint64 if _stat, _error := os.Stat (_pathResolved); _error == nil { - _fileDev, _fileInode, _fileSize, _fileTimestamp, _error = statExtract (_stat) + _fileDev, _fileInode, _fileSize, _fileTimestamp, _error = SysStatExtract (_stat) if _error != nil { return _error } @@ -115,7 +115,7 @@ func archiveFile (_context *context, _pathResolved string, _pathInArchive string } defer _file.Close () if _stat, _error := _file.Stat (); _error == nil { - _fileDev_0, _fileInode_0, _fileSize_0, _fileTimestamp_0, _error := statExtract (_stat) + _fileDev_0, _fileInode_0, _fileSize_0, _fileTimestamp_0, _error := SysStatExtract (_stat) if _error != nil { return nil, _error } @@ -136,7 +136,7 @@ func archiveFile (_context *context, _pathResolved string, _pathInArchive string return nil, _error } if _stat, _error := _file.Stat (); _error == nil { - _, _, _fileSize_0, _fileTimestamp_0, _error := statExtract (_stat) + _, _, _fileSize_0, _fileTimestamp_0, _error := SysStatExtract (_stat) if _error != nil { return nil, _error } diff --git a/sources/cmd/server/server.go b/sources/cmd/server/server.go index 1928fea..604cf62 100644 --- a/sources/cmd/server/server.go +++ b/sources/cmd/server/server.go @@ -918,7 +918,7 @@ func main_0 () (error) { if !_quiet && _isMaster { log.Printf ("[ii] [2c130d70] limiting memory to %d MiB;\n", _limitMemory) } - if _error := setrlimit (_limitMemory); _error != nil { + if _error := SysSetrlimit (_limitMemory); _error != nil { AbortError (_error, "[4da96378] failed to configure memory limit!") } } diff --git a/sources/cmd/archiver/os-bsd.go b/sources/lib/common/os-freebsd-darwin.go similarity index 75% rename from sources/cmd/archiver/os-bsd.go rename to sources/lib/common/os-freebsd-darwin.go index 7832d1e..4761d32 100644 --- a/sources/cmd/archiver/os-bsd.go +++ b/sources/lib/common/os-freebsd-darwin.go @@ -2,7 +2,7 @@ //go:build freebsd || darwin -package archiver +package common import "fmt" @@ -12,7 +12,7 @@ import "syscall" -func statExtract (_stat os.FileInfo) (_dev uint64, _inode uint64, _size uint64, _timestamp uint64, _error error) { +func SysStatExtract (_stat os.FileInfo) (_dev uint64, _inode uint64, _size uint64, _timestamp uint64, _error error) { if _stat, _ok := _stat.Sys () .(*syscall.Stat_t); _ok { _dev = uint64 (_stat.Dev) _inode = uint64 (_stat.Ino) diff --git a/sources/cmd/server/os-freebsd.go b/sources/lib/common/os-freebsd.go similarity index 90% rename from sources/cmd/server/os-freebsd.go rename to sources/lib/common/os-freebsd.go index 0e13227..ef2a2d7 100644 --- a/sources/cmd/server/os-freebsd.go +++ b/sources/lib/common/os-freebsd.go @@ -2,14 +2,14 @@ //go:build freebsd -package server +package common import "syscall" -func setrlimit (_limitMemory uint) (error) { +func SysSetrlimit (_limitMemory uint) (error) { { _limitMb := (2 * _limitMemory) + (1 * 1024) _limit := syscall.Rlimit { diff --git a/sources/cmd/server/os-linux.go b/sources/lib/common/os-linux-darwin.go similarity index 90% rename from sources/cmd/server/os-linux.go rename to sources/lib/common/os-linux-darwin.go index f69e219..6c5ddad 100644 --- a/sources/cmd/server/os-linux.go +++ b/sources/lib/common/os-linux-darwin.go @@ -2,7 +2,7 @@ //go:build linux || darwin -package server +package common import "syscall" @@ -10,7 +10,7 @@ import "syscall" -func setrlimit (_limitMemory uint) (error) { +func SysSetrlimit (_limitMemory uint) (error) { { _limitMb := (2 * _limitMemory) + (1 * 1024) _limit := syscall.Rlimit { diff --git a/sources/cmd/archiver/os-linux.go b/sources/lib/common/os-linux-openbsd.go similarity index 74% rename from sources/cmd/archiver/os-linux.go rename to sources/lib/common/os-linux-openbsd.go index 4665eba..22c05cf 100644 --- a/sources/cmd/archiver/os-linux.go +++ b/sources/lib/common/os-linux-openbsd.go @@ -2,7 +2,7 @@ //go:build linux || openbsd -package archiver +package common import "fmt" @@ -12,7 +12,7 @@ import "syscall" -func statExtract (_stat os.FileInfo) (_dev uint64, _inode uint64, _size uint64, _timestamp uint64, _error error) { +func SysStatExtract (_stat os.FileInfo) (_dev uint64, _inode uint64, _size uint64, _timestamp uint64, _error error) { if _stat, _ok := _stat.Sys () .(*syscall.Stat_t); _ok { _dev = uint64 (_stat.Dev) _inode = uint64 (_stat.Ino) diff --git a/sources/cmd/server/os-openbsd.go b/sources/lib/common/os-openbsd.go similarity index 83% rename from sources/cmd/server/os-openbsd.go rename to sources/lib/common/os-openbsd.go index 1810dd4..ed7a090 100644 --- a/sources/cmd/server/os-openbsd.go +++ b/sources/lib/common/os-openbsd.go @@ -2,7 +2,7 @@ //go:build openbsd -package server +package common import "syscall" @@ -10,7 +10,7 @@ import "syscall" -func setrlimit (_limitMemory uint) (error) { +func SysSetrlimit (_limitMemory uint) (error) { { _limitMb := _limitMemory _limit := syscall.Rlimit {