diff --git a/branding/templates/qtinstaller/osx-data/post-install.go b/branding/templates/qtinstaller/osx-data/post-install.go index 5f1afe72346cc070b318359b2045de1c5c92cf7d..8840eb58b8c0b0d0cb0e107901d528478c14fb31 100644 --- a/branding/templates/qtinstaller/osx-data/post-install.go +++ b/branding/templates/qtinstaller/osx-data/post-install.go @@ -45,8 +45,14 @@ const ( <integer>5</integer> <key>Label</key> <string>{{ .Label }}</string> - <key>Program</key> - <string>{{ .Path }}/bitmask-helper</string> + <key>ProgramArguments</key> + <array> + <string>{{ .Path }}/bitmask-helper</string> + <string>-socket-uid</string> + <string>{{.Uid}}</string> + <string>-socket-gid</string> + <string>{{.Gid}}</string> + </array> </dict> </plist>` @@ -59,6 +65,10 @@ const ( // -stage flag values stagePre = "preinstall" stageUninstall = "uninstall" + + // listening socket flag values + socketUid = "socket-uid" + socketGid = "socket-gid" ) var ( @@ -78,6 +88,9 @@ var ( plistPath string launchdDaemonLabel string + + uid int + gid int ) func init() { @@ -94,6 +107,9 @@ func init() { flag.StringVar(&installerStage, stage, stageUninstall, usageStage) flag.StringVar(&appName, appname, "", usageAppName) + flag.IntVar(&uid, socketUid, 0, "Helper unix socket UID") + flag.IntVar(&gid, socketGid, 0, "Helper unix socket GID") + flag.Parse() } @@ -260,9 +276,13 @@ func generatePlist() (string, error) { appPath := struct { Path string Label string + Uid int + Gid int }{ Path: appBundlePath(), Label: launchdDaemonLabel, + Uid: uid, + Gid: gid, } t, err := template.New("plist").Parse(plistTemplate) diff --git a/branding/templates/qtinstaller/packages/bitmaskvpn/meta/install.js b/branding/templates/qtinstaller/packages/bitmaskvpn/meta/install.js index 83106431c1f43aee031cc8e702013f1f4d46bebe..b8904c8f1698ceb365ed06f7a33e75a86627c01e 100644 --- a/branding/templates/qtinstaller/packages/bitmaskvpn/meta/install.js +++ b/branding/templates/qtinstaller/packages/bitmaskvpn/meta/install.js @@ -35,11 +35,19 @@ function cancelInstaller(message) function Component() { // Check whether OS is supported. // start installer with -v to see debug output + var uid = installer.execute("/usr/bin/id", ["-u"])[0] + var gid = installer.execute("/usr/bin/id", ["-g"])[0] + + installer.setValue("HelperSocketUid", uid.trim()) + installer.setValue("HelperSocketGid", gid.trim()) installer.gainAdminRights(); console.log("OS: " + systemInfo.productType); console.log("Kernel: " + systemInfo.kernelType + "/" + systemInfo.kernelVersion); + + console.log("UID: " + uid) + console.log("GID: " + gid) installer.setDefaultPageVisible(QInstaller.TargetDirectory, false); if (installer.isInstaller()) { @@ -200,10 +208,12 @@ function uninstallOSX() { } function postInstallOSX() { + var uid = installer.value("HelperSocketUid") + var gid = installer.value("HelperSocketGid") console.log("Post-installation for OSX"); component.addElevatedOperation( "Execute", "{0}", - "@TargetDir@/post-install", "-action=post-install", "-appname=@ProductName@", + "@TargetDir@/post-install", "-action=post-install", "-appname=@ProductName@", "-socket-uid=" + uid, "-socket-gid=" + gid, "errormessage=There was an error during the post-installation script, things might be broken. Please report this error and attach the post-install.log file.", "UNDOEXECUTE", "@TargetDir@/post-install", "-action=uninstall", "-appname=@ProductName@" diff --git a/cmd/bitmask-helper/main.go b/cmd/bitmask-helper/main.go index 41803c578e9bf4cfe1e064cbd0d3801f39b361ab..eaf508c4a14d69fe6a161cc5b6b6573c0d95aa2a 100644 --- a/cmd/bitmask-helper/main.go +++ b/cmd/bitmask-helper/main.go @@ -16,6 +16,7 @@ package main import ( + "flag" "path" "0xacab.org/leap/bitmask-vpn/pkg/config" @@ -30,9 +31,18 @@ const ( var ( Version string AppName string + + socketUid int + socketGid int ) +func init() { + flag.IntVar(&socketUid, "socket-uid", 0, "The UID for the unix socket to listen on") + flag.IntVar(&socketGid, "socket-gid", 0, "The GID for the unix socket to listen on") +} + func main() { + flag.Parse() config.LogPath = path.Join(config.Path, logFile) config.ConfigureLogger() defer config.CloseLogger() @@ -40,5 +50,5 @@ func main() { helper.AppName = AppName // StartHelper is the main entry point - it also handles cli args in windows, and starts the http server. - helper.StartHelper(preferredPort) + helper.StartHelper(preferredPort, socketUid, socketGid) } diff --git a/go.mod b/go.mod index 032aca040f8229ce1adb9f492ac5ed1c9204ca58..40666d63018d7b021e2808bcf05fd5162300199c 100644 --- a/go.mod +++ b/go.mod @@ -9,10 +9,8 @@ require ( github.com/ProtonMail/go-autostart v0.0.0-20210130080809-00ed301c8e9a github.com/cretz/bine v0.2.0 github.com/dchest/siphash v1.2.3 // indirect - github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 // indirect github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19 github.com/pion/webrtc/v3 v3.2.44 - github.com/sevlyar/go-daemon v0.1.6 github.com/smartystreets/goconvey v1.6.4 github.com/xtaci/kcp-go/v5 v5.6.11 github.com/xtaci/smux v1.5.24 diff --git a/go.sum b/go.sum index 106951ab94534e37ee0f60735934860543acca05..f02a51c3d272a087f369eabed0a5bdf6a0f84a54 100644 --- a/go.sum +++ b/go.sum @@ -217,8 +217,6 @@ github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7 github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 h1:iQTw/8FWTuc7uiaSepXwyf3o52HaUYcV+Tu66S3F5GA= -github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0/go.mod h1:1NbS8ALrpOvjt0rHPNLyCIeMtbizbir8U//inJ+zuB8= github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19 h1:WjT3fLi9n8YWh/Ih8Q1LHAPsTqGddPcHqscN+PJ3i68= github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19/go.mod h1:hY+WOq6m2FpbvyrI93sMaypsttvaIL5nhVR92dTMUcQ= github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= @@ -432,8 +430,6 @@ github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= -github.com/sevlyar/go-daemon v0.1.6 h1:EUh1MDjEM4BI109Jign0EaknA2izkOyi0LV3ro3QQGs= -github.com/sevlyar/go-daemon v0.1.6/go.mod h1:6dJpPatBT9eUwM5VCw9Bt6CdX9Tk6UWvhW3MebLDRKE= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= diff --git a/pkg/helper/darwin.go b/pkg/helper/darwin.go index f5cd9bb6bd564df2d1ad49c8000124452916ff20..435520092fc194d4f953985ff048f6111563a09c 100644 --- a/pkg/helper/darwin.go +++ b/pkg/helper/darwin.go @@ -35,13 +35,10 @@ import ( "os/exec" "path" "path/filepath" - "strconv" "strings" "time" "github.com/rs/zerolog/log" - - "github.com/sevlyar/go-daemon" ) const ( @@ -80,34 +77,6 @@ func parseCliArgs() { func initializeService(port int) {} func daemonize() { - cntxt := &daemon.Context{ - PidFileName: "pid", - PidFilePerm: 0644, - LogFileName: "bitmask-helper.log", - LogFilePerm: 0640, - WorkDir: filepath.Join(getHelperDir(), "helper"), - Umask: 027, - Args: []string{"[bitmask-helper]"}, - } - - d, err := cntxt.Reborn() - if err != nil { - log.Fatal(). - Err(err). - Msg("Unable to run bitmask helper") - } - if d != nil { - return - } - defer cntxt.Release() - log.Info().Msg("Successfully started bitmask-helper daemon") -} - -func runServer(preferredPort int) { - port := getFirstAvailablePortFrom(preferredPort) - writePortToFile(port) - bindAddr := "localhost:" + strconv.Itoa(port) - serveHTTP(bindAddr) } func getOpenvpnPath() string { diff --git a/pkg/helper/helper.go b/pkg/helper/helper.go index 0e3e943f1a5283d7a41da4350f4d39aaeb61ad51..481b9b0d264ed4ed84aaf66401b61f2c9ce9c797 100644 --- a/pkg/helper/helper.go +++ b/pkg/helper/helper.go @@ -15,9 +15,9 @@ // This helper is intended to be long-lived, and run with administrator privileges. // It will launch a http server and expose a REST API to control OpenVPN and the firewall. -// At the moment, it is only used in Darwin and Windows - although it could also be used in GNU/Linux systems (but we use the one-shot bitmask-root wrapper in GNU/Linux instead). -// In Windows, this helper will run on the first available port after the standard one (7171). -// In other systems, the 7171 port is hardcoded. +// At the moment, it is only used in Darwin - although it could also be used in GNU/Linux systems (but we use the one-shot bitmask-root wrapper in GNU/Linux instead). +// In Darwin, this helper will use a unix domain socket for the http server +// The /tmp/bitmask-helper.sock path for the socket is hardcoded. package helper @@ -31,6 +31,8 @@ import ( "github.com/rs/zerolog/log" ) +const helperSocket = "bitmask-helper.sock" + var ( AppName = "DemoLibVPN" BinaryName = "bitmask" @@ -43,31 +45,35 @@ type openvpnT struct { // startHelper is the main entrypoint. It can react to cli args (used to install or manage the service in windows), and // eventually will start the http server. -func StartHelper(port int) { +func StartHelper(port, socketUid, socketGid int) { initializeService(port) parseCliArgs() daemonize() - runServer(port) + runServer(socketUid, socketGid) } // serveHTTP will start the HTTP server that exposes the firewall and openvpn api. // this can be called at different times by the different implementations of the helper. -func serveHTTP(bindAddr string) { - log.Info(). - Str("bindAddr", bindAddr). - Msg("Starting HTTP server") +func serveHTTP(unixListener net.Listener) { openvpn := openvpnT{nil} - http.HandleFunc("/openvpn/start", openvpn.start) - http.HandleFunc("/openvpn/stop", openvpn.stop) - http.HandleFunc("/firewall/start", firewallStartHandler) - http.HandleFunc("/firewall/stop", firewallStopHandler) - http.HandleFunc("/firewall/isup", firewallIsUpHandler) - http.HandleFunc("/version", versionHandler) - err := http.ListenAndServe(bindAddr, nil) - log.Fatal(). - Err(err). - Msg("Could not start HTTP Server") + mux := http.NewServeMux() + mux.HandleFunc("/openvpn/start", openvpn.start) + mux.HandleFunc("/openvpn/stop", openvpn.stop) + mux.HandleFunc("/firewall/start", firewallStartHandler) + mux.HandleFunc("/firewall/stop", firewallStopHandler) + mux.HandleFunc("/firewall/isup", firewallIsUpHandler) + mux.HandleFunc("/version", versionHandler) + + server := http.Server{ + Handler: mux, + } + + if err := server.Serve(unixListener); err != nil { + log.Fatal(). + Err(err). + Msg("Could not start http server") + } } func (openvpn *openvpnT) start(w http.ResponseWriter, r *http.Request) { diff --git a/pkg/helper/linux.go b/pkg/helper/linux.go index 5f424b96a734130ad75d94ad3e64252099208c95..2596c537d564c816fafac8dd496c4836e09756ab 100644 --- a/pkg/helper/linux.go +++ b/pkg/helper/linux.go @@ -21,7 +21,6 @@ package helper import ( "os" "os/exec" - "strconv" "github.com/rs/zerolog/log" @@ -55,11 +54,6 @@ func initializeService(port int) {} func daemonize() {} -func runServer(port int) { - // defined in helper.go - serveHTTP("localhost:" + strconv.Itoa(port)) -} - func getOpenvpnPath() string { if os.Getenv("SNAP") != "" { return snapOpenvpnPath diff --git a/pkg/helper/listener_unix.go b/pkg/helper/listener_unix.go new file mode 100644 index 0000000000000000000000000000000000000000..0f164cdf734593ee9abfcf77c9f226d8d2764e47 --- /dev/null +++ b/pkg/helper/listener_unix.go @@ -0,0 +1,40 @@ +//go:build darwin || linux +// +build darwin linux + +package helper + +import ( + "github.com/rs/zerolog/log" + "net" + "os" + "path/filepath" +) + +func runServer(socketUid, socketGid int) { + socketPath := filepath.Join("/tmp", helperSocket) + if err := os.Remove(socketPath); err != nil { + log.Warn(). + Err(err). + Msg("unable to remove socket file or it doesn't exist") + } + unixListener, err := net.Listen("unix", socketPath) + if err != nil { + log.Warn(). + Err(err). + Msg("unable to create unix listener") + } + log.Info(). + Str("socketPath", socketPath). + Msg("created listener") + log.Info(). + Int("socket uid", socketUid). + Int("socket gid", socketGid). + Msg("changing socket ownership") + + if err = os.Chown(socketPath, socketUid, socketGid); err != nil { + log.Fatal(). + Err(err). + Msg("unable to change owner of socket file") + } + serveHTTP(unixListener) +} diff --git a/pkg/helper/windows.go b/pkg/helper/windows.go index f32e7ea4581ebd73f58b048804fb6dff6898aabe..a1b28de768197815828e61a3326f740b04e2bf33 100644 --- a/pkg/helper/windows.go +++ b/pkg/helper/windows.go @@ -150,7 +150,7 @@ func initializeService(preferredPort int) { func daemonize() {} // runServer does nothing, serveHTTP is called from within Execute in windows -func runServer(port int) {} +func runServer(uid, gid int) {} func getOpenvpnPath() string { openvpn := path.Join(getExecDir(), "openvpn.exe") diff --git a/pkg/launcher/launcher_darwin.go b/pkg/launcher/launcher_darwin.go index fae57c9ce109909a6626178d4b650a4da28188c5..9bd7f03ca9f607cff7c2837aaa10251cc7502d76 100644 --- a/pkg/launcher/launcher_darwin.go +++ b/pkg/launcher/launcher_darwin.go @@ -17,13 +17,15 @@ package launcher import ( "bytes" + "context" "encoding/json" "errors" "fmt" "io" - "io/ioutil" + "net" "net/http" "os" + "path/filepath" "strconv" "strings" "time" @@ -36,31 +38,35 @@ import ( type Launcher struct { helperAddr string + client *http.Client Failed bool MngPass string } -const initialHelperPort = 7171 +const helperSocket = "bitmask-helper.sock" -func probeHelperPort(port int) (int, error) { - // this should be enough for a local reply - timeout := time.Duration(500 * time.Millisecond) - c := http.Client{Timeout: timeout} - for { - if smellsLikeOurHelperSpirit(port, &c) { - return port, nil - } - port++ - /* we could go until 65k, but there's really no need */ - if port > 10000 { - break - } +func getHelperSocketPath() string { + return filepath.Join("/tmp", helperSocket) +} + +func probeHelper() (*http.Client, error) { + client := http.Client{ + Transport: &http.Transport{ + DialContext: func(_ context.Context, _, _ string) (net.Conn, error) { + return net.Dial("unix", getHelperSocketPath()) + }, + }, + Timeout: 500 * time.Millisecond, // this should be enough for a local reply + } + + if smellsLikeOurHelperSpirit(&client) { + return &client, nil } - return -1, errors.New("Could not find port of helper backend") + return nil, errors.New("Could not find port of helper backend") } -func smellsLikeOurHelperSpirit(port int, c *http.Client) bool { - uri := "http://localhost:" + strconv.Itoa(port) + "/version" +func smellsLikeOurHelperSpirit(c *http.Client) bool { + uri := "http://bitmask/version" resp, err := c.Get(uri) if err != nil { log.Warn(). @@ -70,7 +76,7 @@ func smellsLikeOurHelperSpirit(port int, c *http.Client) bool { return false } if resp.StatusCode == 200 { - ver, err := ioutil.ReadAll(resp.Body) + ver, err := io.ReadAll(resp.Body) defer resp.Body.Close() if err != nil { log.Warn(). @@ -94,12 +100,15 @@ func smellsLikeOurHelperSpirit(port int, c *http.Client) bool { } func NewLauncher() (*Launcher, error) { - helperPort, err := probeHelperPort(initialHelperPort) + client, err := probeHelper() if err != nil { return nil, err } - helperAddr := "http://localhost:" + strconv.Itoa(helperPort) - return &Launcher{helperAddr: helperAddr, Failed: false}, nil + return &Launcher{ + helperAddr: "http://bitmask", + client: client, + Failed: false, + }, nil } func (l *Launcher) Close() error { @@ -144,7 +153,7 @@ func (l *Launcher) FirewallStop() error { func (l *Launcher) FirewallIsUp() bool { var isup bool = false - res, err := http.Post(l.helperAddr+"/firewall/isup", "", nil) + res, err := l.client.Post(l.helperAddr+"/firewall/isup", "", nil) if err != nil { return false } @@ -156,7 +165,7 @@ func (l *Launcher) FirewallIsUp() bool { Msg("Got an error status code for firewall/isup") isup = false } else { - upStr, err := ioutil.ReadAll(res.Body) + upStr, err := io.ReadAll(res.Body) if err != nil { log.Warn(). Err(err). @@ -179,15 +188,17 @@ func (l *Launcher) send(path string, body []byte) error { if body != nil { reader = bytes.NewReader(body) } - res, err := http.Post(l.helperAddr+path, "", reader) + res, err := l.client.Post(l.helperAddr+path, "", reader) if err != nil { return err } defer res.Body.Close() - resErr, err := ioutil.ReadAll(res.Body) + // read the error sent back by helper + // in case of no error helper doesn't + // write anything as reponse + resErr, err := io.ReadAll(res.Body) if len(resErr) > 0 { - /* FIXME why do we trigger a fatal with this error? */ return fmt.Errorf("FATAL: Helper returned an error: %q", resErr) } return err diff --git a/vendor/github.com/kardianos/osext/LICENSE b/vendor/github.com/kardianos/osext/LICENSE deleted file mode 100644 index 74487567632c8f137ef3971b0f5912ca50bebcda..0000000000000000000000000000000000000000 --- a/vendor/github.com/kardianos/osext/LICENSE +++ /dev/null @@ -1,27 +0,0 @@ -Copyright (c) 2012 The Go Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/vendor/github.com/kardianos/osext/README.md b/vendor/github.com/kardianos/osext/README.md deleted file mode 100644 index 15cbc3d953eda87ea0e972700ba23cc81d1d032f..0000000000000000000000000000000000000000 --- a/vendor/github.com/kardianos/osext/README.md +++ /dev/null @@ -1,21 +0,0 @@ -### Extensions to the "os" package. - -[](https://godoc.org/github.com/kardianos/osext) - -## Find the current Executable and ExecutableFolder. - -As of go1.8 the Executable function may be found in `os`. The Executable function -in the std lib `os` package is used if available. - -There is sometimes utility in finding the current executable file -that is running. This can be used for upgrading the current executable -or finding resources located relative to the executable file. Both -working directory and the os.Args[0] value are arbitrary and cannot -be relied on; os.Args[0] can be "faked". - -Multi-platform and supports: - * Linux - * OS X - * Windows - * Plan 9 - * BSDs. diff --git a/vendor/github.com/kardianos/osext/osext.go b/vendor/github.com/kardianos/osext/osext.go deleted file mode 100644 index 17f380f0e8dfeb2fcba348e52a9ceeea177b676a..0000000000000000000000000000000000000000 --- a/vendor/github.com/kardianos/osext/osext.go +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2012 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. - -// Extensions to the standard "os" package. -package osext // import "github.com/kardianos/osext" - -import "path/filepath" - -var cx, ce = executableClean() - -func executableClean() (string, error) { - p, err := executable() - return filepath.Clean(p), err -} - -// Executable returns an absolute path that can be used to -// re-invoke the current program. -// It may not be valid after the current program exits. -func Executable() (string, error) { - return cx, ce -} - -// Returns same path as Executable, returns just the folder -// path. Excludes the executable name and any trailing slash. -func ExecutableFolder() (string, error) { - p, err := Executable() - if err != nil { - return "", err - } - - return filepath.Dir(p), nil -} diff --git a/vendor/github.com/kardianos/osext/osext_go18.go b/vendor/github.com/kardianos/osext/osext_go18.go deleted file mode 100644 index 009d8a9262bd7afa1408bf312f7f67aa596d4ad8..0000000000000000000000000000000000000000 --- a/vendor/github.com/kardianos/osext/osext_go18.go +++ /dev/null @@ -1,9 +0,0 @@ -//+build go1.8,!openbsd - -package osext - -import "os" - -func executable() (string, error) { - return os.Executable() -} diff --git a/vendor/github.com/kardianos/osext/osext_plan9.go b/vendor/github.com/kardianos/osext/osext_plan9.go deleted file mode 100644 index 95e237137ac46863ae958a484db58da7794457a0..0000000000000000000000000000000000000000 --- a/vendor/github.com/kardianos/osext/osext_plan9.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2012 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. - -//+build !go1.8 - -package osext - -import ( - "os" - "strconv" - "syscall" -) - -func executable() (string, error) { - f, err := os.Open("/proc/" + strconv.Itoa(os.Getpid()) + "/text") - if err != nil { - return "", err - } - defer f.Close() - return syscall.Fd2path(int(f.Fd())) -} diff --git a/vendor/github.com/kardianos/osext/osext_procfs.go b/vendor/github.com/kardianos/osext/osext_procfs.go deleted file mode 100644 index e1f16f88511f9c4a7f048f96e61244acb5672962..0000000000000000000000000000000000000000 --- a/vendor/github.com/kardianos/osext/osext_procfs.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2012 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. - -// +build !go1.8,android !go1.8,linux !go1.8,netbsd !go1.8,solaris !go1.8,dragonfly - -package osext - -import ( - "errors" - "fmt" - "os" - "runtime" - "strings" -) - -func executable() (string, error) { - switch runtime.GOOS { - case "linux", "android": - const deletedTag = " (deleted)" - execpath, err := os.Readlink("/proc/self/exe") - if err != nil { - return execpath, err - } - execpath = strings.TrimSuffix(execpath, deletedTag) - execpath = strings.TrimPrefix(execpath, deletedTag) - return execpath, nil - case "netbsd": - return os.Readlink("/proc/curproc/exe") - case "dragonfly": - return os.Readlink("/proc/curproc/file") - case "solaris": - return os.Readlink(fmt.Sprintf("/proc/%d/path/a.out", os.Getpid())) - } - return "", errors.New("ExecPath not implemented for " + runtime.GOOS) -} diff --git a/vendor/github.com/kardianos/osext/osext_sysctl.go b/vendor/github.com/kardianos/osext/osext_sysctl.go deleted file mode 100644 index 33cee2522beef8106612a0ede3ae2f6dfed6a35b..0000000000000000000000000000000000000000 --- a/vendor/github.com/kardianos/osext/osext_sysctl.go +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright 2012 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. - -// +build !go1.8,darwin !go1.8,freebsd openbsd - -package osext - -import ( - "os" - "os/exec" - "path/filepath" - "runtime" - "syscall" - "unsafe" -) - -var initCwd, initCwdErr = os.Getwd() - -func executable() (string, error) { - var mib [4]int32 - switch runtime.GOOS { - case "freebsd": - mib = [4]int32{1 /* CTL_KERN */, 14 /* KERN_PROC */, 12 /* KERN_PROC_PATHNAME */, -1} - case "darwin": - mib = [4]int32{1 /* CTL_KERN */, 38 /* KERN_PROCARGS */, int32(os.Getpid()), -1} - case "openbsd": - mib = [4]int32{1 /* CTL_KERN */, 55 /* KERN_PROC_ARGS */, int32(os.Getpid()), 1 /* KERN_PROC_ARGV */} - } - - n := uintptr(0) - // Get length. - _, _, errNum := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), 4, 0, uintptr(unsafe.Pointer(&n)), 0, 0) - if errNum != 0 { - return "", errNum - } - if n == 0 { // This shouldn't happen. - return "", nil - } - buf := make([]byte, n) - _, _, errNum = syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(unsafe.Pointer(&mib[0])), 4, uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&n)), 0, 0) - if errNum != 0 { - return "", errNum - } - if n == 0 { // This shouldn't happen. - return "", nil - } - - var execPath string - switch runtime.GOOS { - case "openbsd": - // buf now contains **argv, with pointers to each of the C-style - // NULL terminated arguments. - var args []string - argv := uintptr(unsafe.Pointer(&buf[0])) - Loop: - for { - argp := *(**[1 << 20]byte)(unsafe.Pointer(argv)) - if argp == nil { - break - } - for i := 0; uintptr(i) < n; i++ { - // we don't want the full arguments list - if string(argp[i]) == " " { - break Loop - } - if argp[i] != 0 { - continue - } - args = append(args, string(argp[:i])) - n -= uintptr(i) - break - } - if n < unsafe.Sizeof(argv) { - break - } - argv += unsafe.Sizeof(argv) - n -= unsafe.Sizeof(argv) - } - execPath = args[0] - // There is no canonical way to get an executable path on - // OpenBSD, so check PATH in case we are called directly - if execPath[0] != '/' && execPath[0] != '.' { - execIsInPath, err := exec.LookPath(execPath) - if err == nil { - execPath = execIsInPath - } - } - default: - for i, v := range buf { - if v == 0 { - buf = buf[:i] - break - } - } - execPath = string(buf) - } - - var err error - // execPath will not be empty due to above checks. - // Try to get the absolute path if the execPath is not rooted. - if execPath[0] != '/' { - execPath, err = getAbs(execPath) - if err != nil { - return execPath, err - } - } - // For darwin KERN_PROCARGS may return the path to a symlink rather than the - // actual executable. - if runtime.GOOS == "darwin" { - if execPath, err = filepath.EvalSymlinks(execPath); err != nil { - return execPath, err - } - } - return execPath, nil -} - -func getAbs(execPath string) (string, error) { - if initCwdErr != nil { - return execPath, initCwdErr - } - // The execPath may begin with a "../" or a "./" so clean it first. - // Join the two paths, trailing and starting slashes undetermined, so use - // the generic Join function. - return filepath.Join(initCwd, filepath.Clean(execPath)), nil -} diff --git a/vendor/github.com/kardianos/osext/osext_windows.go b/vendor/github.com/kardianos/osext/osext_windows.go deleted file mode 100644 index 074b3b385ca8a8f501d871717ce1a7df0db84057..0000000000000000000000000000000000000000 --- a/vendor/github.com/kardianos/osext/osext_windows.go +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2012 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. - -//+build !go1.8 - -package osext - -import ( - "syscall" - "unicode/utf16" - "unsafe" -) - -var ( - kernel = syscall.MustLoadDLL("kernel32.dll") - getModuleFileNameProc = kernel.MustFindProc("GetModuleFileNameW") -) - -// GetModuleFileName() with hModule = NULL -func executable() (exePath string, err error) { - return getModuleFileName() -} - -func getModuleFileName() (string, error) { - var n uint32 - b := make([]uint16, syscall.MAX_PATH) - size := uint32(len(b)) - - r0, _, e1 := getModuleFileNameProc.Call(0, uintptr(unsafe.Pointer(&b[0])), uintptr(size)) - n = uint32(r0) - if n == 0 { - return "", e1 - } - return string(utf16.Decode(b[0:n])), nil -} diff --git a/vendor/github.com/sevlyar/go-daemon/.travis.yml b/vendor/github.com/sevlyar/go-daemon/.travis.yml deleted file mode 100644 index 03d430511d7fd27968d2504e18ded503874c2cc0..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/.travis.yml +++ /dev/null @@ -1,15 +0,0 @@ -language: go - -go: - - 1.3 - - 1.5 - - tip - -before_install: - - go get -t -v ./... - -script: - - go test -v -coverprofile=coverage.txt -covermode=atomic - -after_success: - - bash <(curl -s https://codecov.io/bash) diff --git a/vendor/github.com/sevlyar/go-daemon/LICENSE b/vendor/github.com/sevlyar/go-daemon/LICENSE deleted file mode 100644 index 6923f2f222678c34f148a3f63b8879e7b77cc560..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/LICENSE +++ /dev/null @@ -1,7 +0,0 @@ -Copyright (C) 2013 Sergey Yarmonov - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/github.com/sevlyar/go-daemon/README.md b/vendor/github.com/sevlyar/go-daemon/README.md deleted file mode 100644 index af5b768438d5e18a82d184312cdf1b337719eae7..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/README.md +++ /dev/null @@ -1,70 +0,0 @@ -# go-daemon [](https://travis-ci.org/sevlyar/go-daemon) [](https://godoc.org/github.com/sevlyar/go-daemon) - -Library for writing system daemons in Go. - -Now supported only UNIX-based OS (Windows is not supported). But the library was tested only on Linux -and OSX, so that if you have an ability to test the library on other platforms, give me feedback, please (#26). - -*Please, feel free to send me bug reports and fixes. Many thanks to all contributors.* - -## Features - -* Goroutine-safe daemonization; -* Out of box work with pid-files; -* Easy handling of system signals; -* The control of a daemon. - -## Installation - - go get github.com/sevlyar/go-daemon - -You can use [gopkg.in](http://labix.org/gopkg.in): - - go get gopkg.in/sevlyar/go-daemon.v0 - -If you want to use the library in production project, please use vendoring, -because i can not ensure backward compatibility before release v1.0. - -## Examples - -* [Simple](examples/cmd/gd-simple/) -* [Log rotation](examples/cmd/gd-log-rotation/) -* [Signal handling](examples/cmd/gd-signal-handling/) - -## Documentation - -[godoc.org/github.com/sevlyar/go-daemon](https://godoc.org/github.com/sevlyar/go-daemon) - -## How it works - -We can not use `fork` syscall in Golang's runtime, because child process doesn't inherit -threads and goroutines in that case. The library uses a simple trick: it runs its own copy with -a mark - a predefined environment variable. Availability of the variable for the process means -an execution in the child's copy. So that if the mark is not setted - the library executes -parent's operations and runs its own copy with mark, and if the mark is setted - the library -executes child's operations: - -```go -import "log" - -func main() { - Pre() - - context := new(Context) - child, _ := context.Reborn() - - if child != nil { - PostParent() - } else { - defer func() { - if err := context.Release(); err != nil { - log.Printf("Unable to release pid-file: %s", err.Error()) - } - }() - - PostChild() - } -} -``` - - diff --git a/vendor/github.com/sevlyar/go-daemon/command.go b/vendor/github.com/sevlyar/go-daemon/command.go deleted file mode 100644 index 07d23c8299306f6eaba6c2347083177588822eae..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/command.go +++ /dev/null @@ -1,99 +0,0 @@ -package daemon - -import ( - "os" -) - -// AddCommand is wrapper on AddFlag and SetSigHandler functions. -func AddCommand(f Flag, sig os.Signal, handler SignalHandlerFunc) { - if f != nil { - AddFlag(f, sig) - } - if handler != nil { - SetSigHandler(handler, sig) - } -} - -// Flag is the interface implemented by an object that has two state: -// 'set' and 'unset'. -type Flag interface { - IsSet() bool -} - -// BoolFlag returns new object that implements interface Flag and -// has state 'set' when var with the given address is true. -func BoolFlag(f *bool) Flag { - return &boolFlag{f} -} - -// StringFlag returns new object that implements interface Flag and -// has state 'set' when var with the given address equals given value of v. -func StringFlag(f *string, v string) Flag { - return &stringFlag{f, v} -} - -type boolFlag struct { - b *bool -} - -func (f *boolFlag) IsSet() bool { - if f == nil { - return false - } - return *f.b -} - -type stringFlag struct { - s *string - v string -} - -func (f *stringFlag) IsSet() bool { - if f == nil { - return false - } - return *f.s == f.v -} - -var flags = make(map[Flag]os.Signal) - -// Flags returns flags that was added by the function AddFlag. -func Flags() map[Flag]os.Signal { - return flags -} - -// AddFlag adds the flag and signal to the internal map. -func AddFlag(f Flag, sig os.Signal) { - flags[f] = sig -} - -// SendCommands sends active signals to the given process. -func SendCommands(p *os.Process) (err error) { - for _, sig := range signals() { - if err = p.Signal(sig); err != nil { - return - } - } - return -} - -// ActiveFlags returns flags that has the state 'set'. -func ActiveFlags() (ret []Flag) { - ret = make([]Flag, 0, 1) - for f := range flags { - if f.IsSet() { - ret = append(ret, f) - } - } - return -} - -func signals() (ret []os.Signal) { - ret = make([]os.Signal, 0, 1) - for f, sig := range flags { - if f.IsSet() { - ret = append(ret, sig) - } - } - return -} diff --git a/vendor/github.com/sevlyar/go-daemon/daemon.go b/vendor/github.com/sevlyar/go-daemon/daemon.go deleted file mode 100644 index 81c7507e6d465fab8248d9e575351eaa64e29b89..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/daemon.go +++ /dev/null @@ -1,44 +0,0 @@ -package daemon - -import ( - "errors" - "os" -) - -var errNotSupported = errors.New("daemon: Non-POSIX OS is not supported") - -// Mark of daemon process - system environment variable _GO_DAEMON=1 -const ( - MARK_NAME = "_GO_DAEMON" - MARK_VALUE = "1" -) - -// Default file permissions for log and pid files. -const FILE_PERM = os.FileMode(0640) - -// WasReborn returns true in child process (daemon) and false in parent process. -func WasReborn() bool { - return os.Getenv(MARK_NAME) == MARK_VALUE -} - -// Reborn runs second copy of current process in the given context. -// function executes separate parts of code in child process and parent process -// and provides demonization of child process. It look similar as the -// fork-daemonization, but goroutine-safe. -// In success returns *os.Process in parent process and nil in child process. -// Otherwise returns error. -func (d *Context) Reborn() (child *os.Process, err error) { - return d.reborn() -} - -// Search searches daemons process by given in context pid file name. -// If success returns pointer on daemons os.Process structure, -// else returns error. Returns nil if filename is empty. -func (d *Context) Search() (daemon *os.Process, err error) { - return d.search() -} - -// Release provides correct pid-file release in daemon. -func (d *Context) Release() error { - return d.release() -} diff --git a/vendor/github.com/sevlyar/go-daemon/daemon_stub.go b/vendor/github.com/sevlyar/go-daemon/daemon_stub.go deleted file mode 100644 index 9b2fbc281a2d634cd22999e5e18d14dc3e8fba74..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/daemon_stub.go +++ /dev/null @@ -1,53 +0,0 @@ -//go:build !darwin && !dragonfly && !freebsd && !linux &&!netbsd && !openbsd && !plan9 && !solaris -// +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!plan9,!solaris - -package daemon - -import ( - "os" -) - -// A Context describes daemon context. -type Context struct { - // If PidFileName is non-empty, parent process will try to create and lock - // pid file with given name. Child process writes process id to file. - PidFileName string - // Permissions for new pid file. - PidFilePerm os.FileMode - - // If LogFileName is non-empty, parent process will create file with given name - // and will link to fd 2 (stderr) for child process. - LogFileName string - // Permissions for new log file. - LogFilePerm os.FileMode - - // If WorkDir is non-empty, the child changes into the directory before - // creating the process. - WorkDir string - // If Chroot is non-empty, the child changes root directory - Chroot string - - // If Env is non-nil, it gives the environment variables for the - // daemon-process in the form returned by os.Environ. - // If it is nil, the result of os.Environ will be used. - Env []string - // If Args is non-nil, it gives the command-line args for the - // daemon-process. If it is nil, the result of os.Args will be used - // (without program name). - Args []string - - // If Umask is non-zero, the daemon-process call Umask() func with given value. - Umask int -} - -func (d *Context) reborn() (child *os.Process, err error) { - return nil, errNotSupported -} - -func (d *Context) search() (daemon *os.Process, err error) { - return nil, errNotSupported -} - -func (d *Context) release() (err error) { - return errNotSupported -} diff --git a/vendor/github.com/sevlyar/go-daemon/daemon_unix.go b/vendor/github.com/sevlyar/go-daemon/daemon_unix.go deleted file mode 100644 index 57c37b1d54e7c98c3fc8c6936df3510fd48ac0d3..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/daemon_unix.go +++ /dev/null @@ -1,270 +0,0 @@ -//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || plan9 || solaris -// +build darwin dragonfly freebsd linux netbsd openbsd plan9 solaris - -package daemon - -import ( - "encoding/json" - "fmt" - "os" - "path/filepath" - "syscall" -) - -// A Context describes daemon context. -type Context struct { - // If PidFileName is non-empty, parent process will try to create and lock - // pid file with given name. Child process writes process id to file. - PidFileName string - // Permissions for new pid file. - PidFilePerm os.FileMode - - // If LogFileName is non-empty, parent process will create file with given name - // and will link to fd 2 (stderr) for child process. - LogFileName string - // Permissions for new log file. - LogFilePerm os.FileMode - - // If WorkDir is non-empty, the child changes into the directory before - // creating the process. - WorkDir string - // If Chroot is non-empty, the child changes root directory - Chroot string - - // If Env is non-nil, it gives the environment variables for the - // daemon-process in the form returned by os.Environ. - // If it is nil, the result of os.Environ will be used. - Env []string - // If Args is non-nil, it gives the command-line args for the - // daemon-process. If it is nil, the result of os.Args will be used. - Args []string - - // Credential holds user and group identities to be assumed by a daemon-process. - Credential *syscall.Credential - // If Umask is non-zero, the daemon-process call Umask() func with given value. - Umask int - - // Struct contains only serializable public fields (!!!) - abspath string - pidFile *LockFile - logFile *os.File - nullFile *os.File - - rpipe, wpipe *os.File -} - -func (d *Context) reborn() (child *os.Process, err error) { - if !WasReborn() { - child, err = d.parent() - } else { - err = d.child() - } - return -} - -func (d *Context) search() (daemon *os.Process, err error) { - if len(d.PidFileName) > 0 { - var pid int - if pid, err = ReadPidFile(d.PidFileName); err != nil { - return - } - daemon, err = os.FindProcess(pid) - if err == nil && daemon != nil { - // Send a test signal to test if this daemon is actually alive or dead - // An error means it is dead - if daemon.Signal(syscall.Signal(0)) != nil { - daemon = nil - } - } - } - return -} - -func (d *Context) parent() (child *os.Process, err error) { - if err = d.prepareEnv(); err != nil { - return - } - - defer d.closeFiles() - if err = d.openFiles(); err != nil { - return - } - - attr := &os.ProcAttr{ - Dir: d.WorkDir, - Env: d.Env, - Files: d.files(), - Sys: &syscall.SysProcAttr{ - //Chroot: d.Chroot, - Credential: d.Credential, - Setsid: true, - }, - } - - if child, err = os.StartProcess(d.abspath, d.Args, attr); err != nil { - if d.pidFile != nil { - d.pidFile.Remove() - } - return - } - - d.rpipe.Close() - encoder := json.NewEncoder(d.wpipe) - if err = encoder.Encode(d); err != nil { - return - } - _, err = fmt.Fprint(d.wpipe, "\n\n") - return -} - -func (d *Context) openFiles() (err error) { - if d.PidFilePerm == 0 { - d.PidFilePerm = FILE_PERM - } - if d.LogFilePerm == 0 { - d.LogFilePerm = FILE_PERM - } - - if d.nullFile, err = os.Open(os.DevNull); err != nil { - return - } - - if len(d.PidFileName) > 0 { - if d.PidFileName, err = filepath.Abs(d.PidFileName); err != nil { - return err - } - if d.pidFile, err = OpenLockFile(d.PidFileName, d.PidFilePerm); err != nil { - return - } - if err = d.pidFile.Lock(); err != nil { - return - } - if len(d.Chroot) > 0 { - // Calculate PID-file absolute path in child's environment - if d.PidFileName, err = filepath.Rel(d.Chroot, d.PidFileName); err != nil { - return err - } - d.PidFileName = "/" + d.PidFileName - } - } - - if len(d.LogFileName) > 0 { - if d.LogFileName == "/dev/stdout" { - d.logFile = os.Stdout - } else if d.LogFileName == "/dev/stderr" { - d.logFile = os.Stderr - } else if d.logFile, err = os.OpenFile(d.LogFileName, - os.O_WRONLY|os.O_CREATE|os.O_APPEND, d.LogFilePerm); err != nil { - return - } - } - - d.rpipe, d.wpipe, err = os.Pipe() - return -} - -func (d *Context) closeFiles() (err error) { - cl := func(file **os.File) { - if *file != nil { - (*file).Close() - *file = nil - } - } - cl(&d.rpipe) - cl(&d.wpipe) - cl(&d.logFile) - cl(&d.nullFile) - if d.pidFile != nil { - d.pidFile.Close() - d.pidFile = nil - } - return -} - -func (d *Context) prepareEnv() (err error) { - if d.abspath, err = osExecutable(); err != nil { - return - } - - if len(d.Args) == 0 { - d.Args = os.Args - } - - mark := fmt.Sprintf("%s=%s", MARK_NAME, MARK_VALUE) - if len(d.Env) == 0 { - d.Env = os.Environ() - } - d.Env = append(d.Env, mark) - - return -} - -func (d *Context) files() (f []*os.File) { - log := d.nullFile - if d.logFile != nil { - log = d.logFile - } - - f = []*os.File{ - d.rpipe, // (0) stdin - log, // (1) stdout - log, // (2) stderr - d.nullFile, // (3) dup on fd 0 after initialization - } - - if d.pidFile != nil { - f = append(f, d.pidFile.File) // (4) pid file - } - return -} - -var initialized = false - -func (d *Context) child() (err error) { - if initialized { - return os.ErrInvalid - } - initialized = true - - decoder := json.NewDecoder(os.Stdin) - if err = decoder.Decode(d); err != nil { - return - } - - // create PID file after context decoding to know PID file full path. - if len(d.PidFileName) > 0 { - d.pidFile = NewLockFile(os.NewFile(4, d.PidFileName)) - if err = d.pidFile.WritePid(); err != nil { - return - } - defer func() { - if err != nil { - d.pidFile.Remove() - } - }() - } - - if err = syscallDup(3, 0); err != nil { - return - } - - if d.Umask != 0 { - syscall.Umask(int(d.Umask)) - } - if len(d.Chroot) > 0 { - err = syscall.Chroot(d.Chroot) - if err != nil { - return - } - } - - return -} - -func (d *Context) release() error { - if !initialized || d.pidFile == nil { - return nil - } - - return d.pidFile.Remove() -} diff --git a/vendor/github.com/sevlyar/go-daemon/lock_file.go b/vendor/github.com/sevlyar/go-daemon/lock_file.go deleted file mode 100644 index 1ec81db4c6ae29cf6d846b9bce7fdbe30e654566..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/lock_file.go +++ /dev/null @@ -1,109 +0,0 @@ -package daemon - -import ( - "errors" - "fmt" - "os" -) - -var ( - // ErrWouldBlock indicates on locking pid-file by another process. - ErrWouldBlock = errors.New("daemon: Resource temporarily unavailable") -) - -// LockFile wraps *os.File and provide functions for locking of files. -type LockFile struct { - *os.File -} - -// NewLockFile returns a new LockFile with the given File. -func NewLockFile(file *os.File) *LockFile { - return &LockFile{file} -} - -// CreatePidFile opens the named file, applies exclusive lock and writes -// current process id to file. -func CreatePidFile(name string, perm os.FileMode) (lock *LockFile, err error) { - if lock, err = OpenLockFile(name, perm); err != nil { - return - } - if err = lock.Lock(); err != nil { - lock.Remove() - return - } - if err = lock.WritePid(); err != nil { - lock.Remove() - } - return -} - -// OpenLockFile opens the named file with flags os.O_RDWR|os.O_CREATE and specified perm. -// If successful, function returns LockFile for opened file. -func OpenLockFile(name string, perm os.FileMode) (lock *LockFile, err error) { - var file *os.File - if file, err = os.OpenFile(name, os.O_RDWR|os.O_CREATE, perm); err == nil { - lock = &LockFile{file} - } - return -} - -// Lock apply exclusive lock on an open file. If file already locked, returns error. -func (file *LockFile) Lock() error { - return lockFile(file.Fd()) -} - -// Unlock remove exclusive lock on an open file. -func (file *LockFile) Unlock() error { - return unlockFile(file.Fd()) -} - -// ReadPidFile reads process id from file with give name and returns pid. -// If unable read from a file, returns error. -func ReadPidFile(name string) (pid int, err error) { - var file *os.File - if file, err = os.OpenFile(name, os.O_RDONLY, 0640); err != nil { - return - } - defer file.Close() - - lock := &LockFile{file} - pid, err = lock.ReadPid() - return -} - -// WritePid writes current process id to an open file. -func (file *LockFile) WritePid() (err error) { - if _, err = file.Seek(0, os.SEEK_SET); err != nil { - return - } - var fileLen int - if fileLen, err = fmt.Fprint(file, os.Getpid()); err != nil { - return - } - if err = file.Truncate(int64(fileLen)); err != nil { - return - } - err = file.Sync() - return -} - -// ReadPid reads process id from file and returns pid. -// If unable read from a file, returns error. -func (file *LockFile) ReadPid() (pid int, err error) { - if _, err = file.Seek(0, os.SEEK_SET); err != nil { - return - } - _, err = fmt.Fscan(file, &pid) - return -} - -// Remove removes lock, closes and removes an open file. -func (file *LockFile) Remove() error { - defer file.Close() - - if err := file.Unlock(); err != nil { - return err - } - - return os.Remove(file.Name()) -} diff --git a/vendor/github.com/sevlyar/go-daemon/lock_file_solaris.go b/vendor/github.com/sevlyar/go-daemon/lock_file_solaris.go deleted file mode 100644 index 6578fd0d25552cd81ebfcae442537545ad2fc892..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/lock_file_solaris.go +++ /dev/null @@ -1,41 +0,0 @@ -//go:build solaris -// +build solaris - -package daemon - -import ( - "io" - "syscall" -) - -func lockFile(fd uintptr) error { - lockInfo := syscall.Flock_t{ - Type: syscall.F_WRLCK, - Whence: io.SeekStart, - Start: 0, - Len: 0, - } - if err := syscall.FcntlFlock(fd, syscall.F_SETLK, &lockInfo); err != nil { - if err == syscall.EAGAIN { - err = ErrWouldBlock - } - return err - } - return nil -} - -func unlockFile(fd uintptr) error { - lockInfo := syscall.Flock_t{ - Type: syscall.F_UNLCK, - Whence: io.SeekStart, - Start: 0, - Len: 0, - } - if err := syscall.FcntlFlock(fd, syscall.F_GETLK, &lockInfo); err != nil { - if err == syscall.EAGAIN { - err = ErrWouldBlock - } - return err - } - return nil -} diff --git a/vendor/github.com/sevlyar/go-daemon/lock_file_stub.go b/vendor/github.com/sevlyar/go-daemon/lock_file_stub.go deleted file mode 100644 index baf43d80b87f816a65156cf1ac8993c98bc2ff2f..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/lock_file_stub.go +++ /dev/null @@ -1,12 +0,0 @@ -//go:build !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !plan9 && !solaris -// +build !darwin,!dragonfly,!freebsd,!linux,!netbsd,!openbsd,!plan9,!solaris - -package daemon - -func lockFile(fd uintptr) error { - return errNotSupported -} - -func unlockFile(fd uintptr) error { - return errNotSupported -} diff --git a/vendor/github.com/sevlyar/go-daemon/lock_file_unix.go b/vendor/github.com/sevlyar/go-daemon/lock_file_unix.go deleted file mode 100644 index 94673e966ee1eedf490b215f7b37c8873ca09fce..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/lock_file_unix.go +++ /dev/null @@ -1,24 +0,0 @@ -//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || plan9 -// +build darwin dragonfly freebsd linux netbsd openbsd plan9 - -package daemon - -import ( - "syscall" -) - -func lockFile(fd uintptr) error { - err := syscall.Flock(int(fd), syscall.LOCK_EX|syscall.LOCK_NB) - if err == syscall.EWOULDBLOCK { - err = ErrWouldBlock - } - return err -} - -func unlockFile(fd uintptr) error { - err := syscall.Flock(int(fd), syscall.LOCK_UN) - if err == syscall.EWOULDBLOCK { - err = ErrWouldBlock - } - return err -} diff --git a/vendor/github.com/sevlyar/go-daemon/os_executable.go b/vendor/github.com/sevlyar/go-daemon/os_executable.go deleted file mode 100644 index ddebe3df114aa72d6feaa9fdaf4cd48fc75f4122..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/os_executable.go +++ /dev/null @@ -1,12 +0,0 @@ -//go:build go1.8 -// +build go1.8 - -package daemon - -import ( - "os" -) - -func osExecutable() (string, error) { - return os.Executable() -} diff --git a/vendor/github.com/sevlyar/go-daemon/os_executable_pre18.go b/vendor/github.com/sevlyar/go-daemon/os_executable_pre18.go deleted file mode 100644 index 281a82c6984c1a829837c52d68e76dd9ae3371bd..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/os_executable_pre18.go +++ /dev/null @@ -1,12 +0,0 @@ -//go:build !go1.8 -// +build !go1.8 - -package daemon - -import ( - "github.com/kardianos/osext" -) - -func osExecutable() (string, error) { - return osext.Executable() -} diff --git a/vendor/github.com/sevlyar/go-daemon/signal.go b/vendor/github.com/sevlyar/go-daemon/signal.go deleted file mode 100644 index fe512da406a7052aecfcadfa923d756e6f6776cd..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/signal.go +++ /dev/null @@ -1,59 +0,0 @@ -package daemon - -import ( - "errors" - "os" - "os/signal" - "syscall" -) - -// ErrStop should be returned signal handler function -// for termination of handling signals. -var ErrStop = errors.New("stop serve signals") - -// SignalHandlerFunc is the interface for signal handler functions. -type SignalHandlerFunc func(sig os.Signal) (err error) - -// SetSigHandler sets handler for the given signals. -// SIGTERM has the default handler, he returns ErrStop. -func SetSigHandler(handler SignalHandlerFunc, signals ...os.Signal) { - for _, sig := range signals { - handlers[sig] = handler - } -} - -// ServeSignals calls handlers for system signals. -func ServeSignals() (err error) { - signals := make([]os.Signal, 0, len(handlers)) - for sig := range handlers { - signals = append(signals, sig) - } - - ch := make(chan os.Signal, 8) - signal.Notify(ch, signals...) - - for sig := range ch { - err = handlers[sig](sig) - if err != nil { - break - } - } - - signal.Stop(ch) - - if err == ErrStop { - err = nil - } - - return -} - -var handlers = make(map[os.Signal]SignalHandlerFunc) - -func init() { - handlers[syscall.SIGTERM] = sigtermDefaultHandler -} - -func sigtermDefaultHandler(sig os.Signal) error { - return ErrStop -} diff --git a/vendor/github.com/sevlyar/go-daemon/syscall_dup.go b/vendor/github.com/sevlyar/go-daemon/syscall_dup.go deleted file mode 100644 index 654d6b86e9d6fd3c5b821ad3fefb2acbec5e5dfb..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/syscall_dup.go +++ /dev/null @@ -1,13 +0,0 @@ -//go:build (!linux || !arm64) && (!linux || !riscv64) && !windows && go1.7 -// +build !linux !arm64 -// +build !linux !riscv64 -// +build !windows -// +build go1.7 - -package daemon - -import "golang.org/x/sys/unix" - -func syscallDup(oldfd int, newfd int) (err error) { - return unix.Dup2(oldfd, newfd) -} diff --git a/vendor/github.com/sevlyar/go-daemon/syscall_dup3.go b/vendor/github.com/sevlyar/go-daemon/syscall_dup3.go deleted file mode 100644 index 16bddc927d1d98e93f383a52bcc4c4f90c6433bb..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/syscall_dup3.go +++ /dev/null @@ -1,13 +0,0 @@ -//go:build linux && (riscv64 || arm64) -// +build linux -// +build riscv64 arm64 - -package daemon - -import "syscall" - -func syscallDup(oldfd int, newfd int) (err error) { - // linux_arm64 platform doesn't have syscall.Dup2 - // so use the nearly identical syscall.Dup3 instead. - return syscall.Dup3(oldfd, newfd, 0) -} diff --git a/vendor/github.com/sevlyar/go-daemon/syscall_dup_pre17.go b/vendor/github.com/sevlyar/go-daemon/syscall_dup_pre17.go deleted file mode 100644 index 381db7583c9273b92b2071cb031ab1f0cecbb2c3..0000000000000000000000000000000000000000 --- a/vendor/github.com/sevlyar/go-daemon/syscall_dup_pre17.go +++ /dev/null @@ -1,14 +0,0 @@ -//go:build (!linux || !arm64) && !windows && !go1.7 -// +build !linux !arm64 -// +build !windows -// +build !go1.7 - -package daemon - -import ( - "syscall" -) - -func syscallDup(oldfd int, newfd int) (err error) { - return syscall.Dup2(oldfd, newfd) -} diff --git a/vendor/modules.txt b/vendor/modules.txt index aa1496ec293cd7c9a5216bda6cd7010b306feeb3..823605be4edca90513ef1056218944526a3d5996 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -169,9 +169,6 @@ github.com/josharian/intern # github.com/jtolds/gls v4.20.0+incompatible ## explicit github.com/jtolds/gls -# github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0 -## explicit -github.com/kardianos/osext # github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19 ## explicit github.com/keybase/go-ps @@ -337,9 +334,6 @@ github.com/rs/zerolog github.com/rs/zerolog/internal/cbor github.com/rs/zerolog/internal/json github.com/rs/zerolog/log -# github.com/sevlyar/go-daemon v0.1.6 -## explicit -github.com/sevlyar/go-daemon # github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d ## explicit github.com/smartystreets/assertions