parent
1a34c8d5ff
commit
d3ff3a6bb1
|
@ -16,7 +16,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"github.com/facebookgo/pidfile"
|
|
||||||
"github.com/jedisct1/dlog"
|
"github.com/jedisct1/dlog"
|
||||||
stamps "github.com/jedisct1/go-dnsstamps"
|
stamps "github.com/jedisct1/go-dnsstamps"
|
||||||
netproxy "golang.org/x/net/proxy"
|
netproxy "golang.org/x/net/proxy"
|
||||||
|
@ -626,7 +625,6 @@ func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error {
|
||||||
dlog.Fatal(err)
|
dlog.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = pidfile.Write()
|
|
||||||
// if 'userName' is set and we are the parent process drop privilege and exit
|
// if 'userName' is set and we are the parent process drop privilege and exit
|
||||||
if len(proxy.userName) > 0 && !proxy.child {
|
if len(proxy.userName) > 0 && !proxy.child {
|
||||||
proxy.dropPrivilege(proxy.userName, FileDescriptors)
|
proxy.dropPrivilege(proxy.userName, FileDescriptors)
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/facebookgo/pidfile"
|
|
||||||
"github.com/jedisct1/dlog"
|
"github.com/jedisct1/dlog"
|
||||||
"github.com/kardianos/service"
|
"github.com/kardianos/service"
|
||||||
)
|
)
|
||||||
|
@ -127,12 +126,14 @@ func (app *App) AppMain() {
|
||||||
if err := ConfigLoad(app.proxy, app.flags); err != nil {
|
if err := ConfigLoad(app.proxy, app.flags); err != nil {
|
||||||
dlog.Fatal(err)
|
dlog.Fatal(err)
|
||||||
}
|
}
|
||||||
|
if err := PidFileCreate(); err != nil {
|
||||||
|
dlog.Criticalf("Unable to create the PID file: %v", err)
|
||||||
|
}
|
||||||
if err := app.proxy.InitPluginsGlobals(); err != nil {
|
if err := app.proxy.InitPluginsGlobals(); err != nil {
|
||||||
dlog.Fatal(err)
|
dlog.Fatal(err)
|
||||||
}
|
}
|
||||||
app.quit = make(chan struct{})
|
app.quit = make(chan struct{})
|
||||||
app.wg.Add(1)
|
app.wg.Add(1)
|
||||||
_ = pidfile.Write()
|
|
||||||
app.proxy.StartProxy()
|
app.proxy.StartProxy()
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
<-app.quit
|
<-app.quit
|
||||||
|
@ -141,9 +142,7 @@ func (app *App) AppMain() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *App) Stop(service service.Service) error {
|
func (app *App) Stop(service service.Service) error {
|
||||||
if pidFilePath := pidfile.GetPidfilePath(); len(pidFilePath) > 1 {
|
PidFileRemove()
|
||||||
os.Remove(pidFilePath)
|
|
||||||
}
|
|
||||||
dlog.Notice("Stopped.")
|
dlog.Notice("Stopped.")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/dchest/safefile"
|
||||||
|
)
|
||||||
|
|
||||||
|
var pidFile = flag.String("pidfile", "", "Store the PID into a file")
|
||||||
|
|
||||||
|
func PidFileCreate() error {
|
||||||
|
if pidFile == nil || len(*pidFile) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if err := os.MkdirAll(filepath.Dir(*pidFile), 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return safefile.WriteFile(*pidFile, []byte(strconv.Itoa(os.Getpid())), 0644)
|
||||||
|
}
|
||||||
|
|
||||||
|
func PidFileRemove() error {
|
||||||
|
if pidFile == nil || len(*pidFile) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return os.Remove(*pidFile)
|
||||||
|
}
|
4
go.mod
4
go.mod
|
@ -7,8 +7,6 @@ require (
|
||||||
github.com/VividCortex/ewma v1.1.1
|
github.com/VividCortex/ewma v1.1.1
|
||||||
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
|
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
|
||||||
github.com/dchest/safefile v0.0.0-20151022103144-855e8d98f185
|
github.com/dchest/safefile v0.0.0-20151022103144-855e8d98f185
|
||||||
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5 // indirect
|
|
||||||
github.com/facebookgo/pidfile v0.0.0-20150612191647-f242e2999868
|
|
||||||
github.com/hashicorp/go-immutable-radix v1.2.0
|
github.com/hashicorp/go-immutable-radix v1.2.0
|
||||||
github.com/hashicorp/golang-lru v0.5.4
|
github.com/hashicorp/golang-lru v0.5.4
|
||||||
github.com/hectane/go-acl v0.0.0-20190604041725-da78bae5fc95
|
github.com/hectane/go-acl v0.0.0-20190604041725-da78bae5fc95
|
||||||
|
@ -21,7 +19,7 @@ require (
|
||||||
github.com/kardianos/service v1.1.0
|
github.com/kardianos/service v1.1.0
|
||||||
github.com/miekg/dns v1.1.30
|
github.com/miekg/dns v1.1.30
|
||||||
github.com/powerman/check v1.2.1
|
github.com/powerman/check v1.2.1
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
|
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
|
||||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381
|
golang.org/x/net v0.0.0-20200707034311-ab3426394381
|
||||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae
|
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0
|
gopkg.in/natefinch/lumberjack.v2 v2.0.0
|
||||||
|
|
7
go.sum
7
go.sum
|
@ -12,10 +12,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dchest/safefile v0.0.0-20151022103144-855e8d98f185 h1:3T8ZyTDp5QxTx3NU48JVb2u+75xc040fofcBaN+6jPA=
|
github.com/dchest/safefile v0.0.0-20151022103144-855e8d98f185 h1:3T8ZyTDp5QxTx3NU48JVb2u+75xc040fofcBaN+6jPA=
|
||||||
github.com/dchest/safefile v0.0.0-20151022103144-855e8d98f185/go.mod h1:cFRxtTwTOJkz2x3rQUNCYKWC93yP1VKjR8NUhqFxZNU=
|
github.com/dchest/safefile v0.0.0-20151022103144-855e8d98f185/go.mod h1:cFRxtTwTOJkz2x3rQUNCYKWC93yP1VKjR8NUhqFxZNU=
|
||||||
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5 h1:BBso6MBKW8ncyZLv37o+KNyy0HrrHgfnOaGQC2qvN+A=
|
|
||||||
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5/go.mod h1:JpoxHjuQauoxiFMl1ie8Xc/7TfLuMZ5eOCONd1sUBHg=
|
|
||||||
github.com/facebookgo/pidfile v0.0.0-20150612191647-f242e2999868 h1:KZ75X3ZCl6yy4jg9R1ziYoCZFDBRqildm+fGComWU7U=
|
|
||||||
github.com/facebookgo/pidfile v0.0.0-20150612191647-f242e2999868/go.mod h1:3Hzo46xzfVpIdv4lJw7YBp9fUJ7HpUgbjH1fFDgy4qM=
|
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c h1:7lF+Vz0LqiRidnzC1Oq86fpX1q/iEv2KJdrCtttYjT4=
|
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c h1:7lF+Vz0LqiRidnzC1Oq86fpX1q/iEv2KJdrCtttYjT4=
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||||
|
@ -62,8 +58,9 @@ github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20190909091759-094676da4a83/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190909091759-094676da4a83/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
|
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899 h1:DZhuSZLsGlFL4CmhA8BcRA0mnthyA/nZ00AqCUo7vHg=
|
||||||
|
golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
language: go
|
|
||||||
|
|
||||||
go:
|
|
||||||
- 1.4
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- go get -v golang.org/x/tools/cmd/vet
|
|
||||||
- go get -v golang.org/x/tools/cmd/cover
|
|
||||||
- go get -v github.com/golang/lint/golint
|
|
||||||
|
|
||||||
install:
|
|
||||||
- go install -race -v std
|
|
||||||
- go get -race -t -v ./...
|
|
||||||
- go install -race -v ./...
|
|
||||||
|
|
||||||
script:
|
|
||||||
- go vet ./...
|
|
||||||
- $HOME/gopath/bin/golint .
|
|
||||||
- go test -cpu=2 -race -v ./...
|
|
||||||
- go test -cpu=2 -covermode=atomic ./...
|
|
|
@ -1,59 +0,0 @@
|
||||||
// Package atomicfile provides the ability to write a file with an eventual
|
|
||||||
// rename on Close (using os.Rename). This allows for a file to always be in a
|
|
||||||
// consistent state and never represent an in-progress write.
|
|
||||||
//
|
|
||||||
// NOTE: `os.Rename` may not be atomic on your operating system.
|
|
||||||
package atomicfile
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
)
|
|
||||||
|
|
||||||
// File behaves like os.File, but does an atomic rename operation at Close.
|
|
||||||
type File struct {
|
|
||||||
*os.File
|
|
||||||
path string
|
|
||||||
}
|
|
||||||
|
|
||||||
// New creates a new temporary file that will replace the file at the given
|
|
||||||
// path when Closed.
|
|
||||||
func New(path string, mode os.FileMode) (*File, error) {
|
|
||||||
f, err := ioutil.TempFile(filepath.Dir(path), filepath.Base(path))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if err := os.Chmod(f.Name(), mode); err != nil {
|
|
||||||
f.Close()
|
|
||||||
os.Remove(f.Name())
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &File{File: f, path: path}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close the file replacing the configured file.
|
|
||||||
func (f *File) Close() error {
|
|
||||||
if err := f.File.Close(); err != nil {
|
|
||||||
os.Remove(f.File.Name())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := os.Rename(f.Name(), f.path); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Abort closes the file and removes it instead of replacing the configured
|
|
||||||
// file. This is useful if after starting to write to the file you decide you
|
|
||||||
// don't want it anymore.
|
|
||||||
func (f *File) Abort() error {
|
|
||||||
if err := f.File.Close(); err != nil {
|
|
||||||
os.Remove(f.Name())
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := os.Remove(f.Name()); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
BSD License
|
|
||||||
|
|
||||||
For atomicfile software
|
|
||||||
|
|
||||||
Copyright (c) 2015, Facebook, Inc. 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 Facebook 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 HOLDER 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.
|
|
|
@ -1,33 +0,0 @@
|
||||||
Additional Grant of Patent Rights Version 2
|
|
||||||
|
|
||||||
"Software" means the atomicfile software distributed by Facebook, Inc.
|
|
||||||
|
|
||||||
Facebook, Inc. ("Facebook") hereby grants to each recipient of the Software
|
|
||||||
("you") a perpetual, worldwide, royalty-free, non-exclusive, irrevocable
|
|
||||||
(subject to the termination provision below) license under any Necessary
|
|
||||||
Claims, to make, have made, use, sell, offer to sell, import, and otherwise
|
|
||||||
transfer the Software. For avoidance of doubt, no license is granted under
|
|
||||||
Facebook’s rights in any patent claims that are infringed by (i) modifications
|
|
||||||
to the Software made by you or any third party or (ii) the Software in
|
|
||||||
combination with any software or other technology.
|
|
||||||
|
|
||||||
The license granted hereunder will terminate, automatically and without notice,
|
|
||||||
if you (or any of your subsidiaries, corporate affiliates or agents) initiate
|
|
||||||
directly or indirectly, or take a direct financial interest in, any Patent
|
|
||||||
Assertion: (i) against Facebook or any of its subsidiaries or corporate
|
|
||||||
affiliates, (ii) against any party if such Patent Assertion arises in whole or
|
|
||||||
in part from any software, technology, product or service of Facebook or any of
|
|
||||||
its subsidiaries or corporate affiliates, or (iii) against any party relating
|
|
||||||
to the Software. Notwithstanding the foregoing, if Facebook or any of its
|
|
||||||
subsidiaries or corporate affiliates files a lawsuit alleging patent
|
|
||||||
infringement against you in the first instance, and you respond by filing a
|
|
||||||
patent infringement counterclaim in that lawsuit against that party that is
|
|
||||||
unrelated to the Software, the license granted hereunder will not terminate
|
|
||||||
under section (i) of this paragraph due to such counterclaim.
|
|
||||||
|
|
||||||
A "Necessary Claim" is a claim of a patent owned by Facebook that is
|
|
||||||
necessarily infringed by the Software standing alone.
|
|
||||||
|
|
||||||
A "Patent Assertion" is any lawsuit or other action alleging direct, indirect,
|
|
||||||
or contributory infringement or inducement to infringe any patent, including a
|
|
||||||
cross-claim or counterclaim.
|
|
|
@ -1,9 +0,0 @@
|
||||||
atomicfile [![Build Status](https://secure.travis-ci.org/facebookgo/atomicfile.png)](https://travis-ci.org/facebookgo/atomicfile)
|
|
||||||
==========
|
|
||||||
|
|
||||||
Documentation: https://godoc.org/github.com/facebookgo/atomicfile
|
|
||||||
|
|
||||||
NOTE: This package uses `os.Rename`, which may or may not be atomic on your
|
|
||||||
operating system. It is known to not be atomic on Windows.
|
|
||||||
https://github.com/natefinch/atomic provides a similar library that is atomic
|
|
||||||
on Windows as well and may be worth investigating.
|
|
|
@ -1,24 +0,0 @@
|
||||||
language: go
|
|
||||||
|
|
||||||
go:
|
|
||||||
- 1.2
|
|
||||||
- 1.3
|
|
||||||
|
|
||||||
matrix:
|
|
||||||
fast_finish: true
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- go get -v code.google.com/p/go.tools/cmd/vet
|
|
||||||
- go get -v github.com/golang/lint/golint
|
|
||||||
- go get -v code.google.com/p/go.tools/cmd/cover
|
|
||||||
|
|
||||||
install:
|
|
||||||
- go install -race -v std
|
|
||||||
- go get -race -t -v ./...
|
|
||||||
- go install -race -v ./...
|
|
||||||
|
|
||||||
script:
|
|
||||||
- go vet ./...
|
|
||||||
- $HOME/gopath/bin/golint .
|
|
||||||
- go test -cpu=2 -race -v ./...
|
|
||||||
- go test -cpu=2 -covermode=atomic ./...
|
|
|
@ -1,30 +0,0 @@
|
||||||
BSD License
|
|
||||||
|
|
||||||
For pidfile software
|
|
||||||
|
|
||||||
Copyright (c) 2015, Facebook, Inc. 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 Facebook 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 HOLDER 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.
|
|
|
@ -1,33 +0,0 @@
|
||||||
Additional Grant of Patent Rights Version 2
|
|
||||||
|
|
||||||
"Software" means the pidfile software distributed by Facebook, Inc.
|
|
||||||
|
|
||||||
Facebook, Inc. ("Facebook") hereby grants to each recipient of the Software
|
|
||||||
("you") a perpetual, worldwide, royalty-free, non-exclusive, irrevocable
|
|
||||||
(subject to the termination provision below) license under any Necessary
|
|
||||||
Claims, to make, have made, use, sell, offer to sell, import, and otherwise
|
|
||||||
transfer the Software. For avoidance of doubt, no license is granted under
|
|
||||||
Facebook’s rights in any patent claims that are infringed by (i) modifications
|
|
||||||
to the Software made by you or any third party or (ii) the Software in
|
|
||||||
combination with any software or other technology.
|
|
||||||
|
|
||||||
The license granted hereunder will terminate, automatically and without notice,
|
|
||||||
if you (or any of your subsidiaries, corporate affiliates or agents) initiate
|
|
||||||
directly or indirectly, or take a direct financial interest in, any Patent
|
|
||||||
Assertion: (i) against Facebook or any of its subsidiaries or corporate
|
|
||||||
affiliates, (ii) against any party if such Patent Assertion arises in whole or
|
|
||||||
in part from any software, technology, product or service of Facebook or any of
|
|
||||||
its subsidiaries or corporate affiliates, or (iii) against any party relating
|
|
||||||
to the Software. Notwithstanding the foregoing, if Facebook or any of its
|
|
||||||
subsidiaries or corporate affiliates files a lawsuit alleging patent
|
|
||||||
infringement against you in the first instance, and you respond by filing a
|
|
||||||
patent infringement counterclaim in that lawsuit against that party that is
|
|
||||||
unrelated to the Software, the license granted hereunder will not terminate
|
|
||||||
under section (i) of this paragraph due to such counterclaim.
|
|
||||||
|
|
||||||
A "Necessary Claim" is a claim of a patent owned by Facebook that is
|
|
||||||
necessarily infringed by the Software standing alone.
|
|
||||||
|
|
||||||
A "Patent Assertion" is any lawsuit or other action alleging direct, indirect,
|
|
||||||
or contributory infringement or inducement to infringe any patent, including a
|
|
||||||
cross-claim or counterclaim.
|
|
|
@ -1,89 +0,0 @@
|
||||||
// Package pidfile manages pid files.
|
|
||||||
package pidfile
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"errors"
|
|
||||||
"flag"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/facebookgo/atomicfile"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
errNotConfigured = errors.New("pidfile not configured")
|
|
||||||
pidfile = flag.String("pidfile", "", "If specified, write pid to file.")
|
|
||||||
)
|
|
||||||
|
|
||||||
// IsNotConfigured returns true if the error indicates the pidfile location has
|
|
||||||
// not been configured.
|
|
||||||
func IsNotConfigured(err error) bool {
|
|
||||||
if err == errNotConfigured {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPidfilePath returns the configured pidfile path.
|
|
||||||
func GetPidfilePath() string {
|
|
||||||
return *pidfile
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetPidfilePath sets the pidfile path.
|
|
||||||
func SetPidfilePath(p string) {
|
|
||||||
*pidfile = p
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write the pidfile based on the flag. It is an error if the pidfile hasn't
|
|
||||||
// been configured.
|
|
||||||
func Write() error {
|
|
||||||
if *pidfile == "" {
|
|
||||||
return errNotConfigured
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.MkdirAll(filepath.Dir(*pidfile), os.FileMode(0755)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
file, err := atomicfile.New(*pidfile, os.FileMode(0644))
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error opening pidfile %s: %s", *pidfile, err)
|
|
||||||
}
|
|
||||||
defer file.Close() // in case we fail before the explicit close
|
|
||||||
|
|
||||||
_, err = fmt.Fprintf(file, "%d", os.Getpid())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = file.Close()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the pid from the configured file. It is an error if the pidfile hasn't
|
|
||||||
// been configured.
|
|
||||||
func Read() (int, error) {
|
|
||||||
if *pidfile == "" {
|
|
||||||
return 0, errNotConfigured
|
|
||||||
}
|
|
||||||
|
|
||||||
d, err := ioutil.ReadFile(*pidfile)
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
pid, err := strconv.Atoi(string(bytes.TrimSpace(d)))
|
|
||||||
if err != nil {
|
|
||||||
return 0, fmt.Errorf("error parsing pid from %s: %s", *pidfile, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return pid, nil
|
|
||||||
}
|
|
|
@ -1,5 +0,0 @@
|
||||||
pidfile [![Build Status](https://secure.travis-ci.org/facebookgo/pidfile.png)](http://travis-ci.org/facebookgo/pidfile)
|
|
||||||
=======
|
|
||||||
|
|
||||||
Package pidfile manages pid files:
|
|
||||||
http://godoc.org/github.com/facebookgo/pidfile
|
|
|
@ -17,12 +17,6 @@ github.com/davecgh/go-spew/spew
|
||||||
# github.com/dchest/safefile v0.0.0-20151022103144-855e8d98f185
|
# github.com/dchest/safefile v0.0.0-20151022103144-855e8d98f185
|
||||||
## explicit
|
## explicit
|
||||||
github.com/dchest/safefile
|
github.com/dchest/safefile
|
||||||
# github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5
|
|
||||||
## explicit
|
|
||||||
github.com/facebookgo/atomicfile
|
|
||||||
# github.com/facebookgo/pidfile v0.0.0-20150612191647-f242e2999868
|
|
||||||
## explicit
|
|
||||||
github.com/facebookgo/pidfile
|
|
||||||
# github.com/hashicorp/go-immutable-radix v1.2.0
|
# github.com/hashicorp/go-immutable-radix v1.2.0
|
||||||
## explicit
|
## explicit
|
||||||
github.com/hashicorp/go-immutable-radix
|
github.com/hashicorp/go-immutable-radix
|
||||||
|
@ -70,7 +64,7 @@ github.com/powerman/check
|
||||||
# github.com/smartystreets/goconvey v1.6.4
|
# github.com/smartystreets/goconvey v1.6.4
|
||||||
github.com/smartystreets/goconvey/convey/gotest
|
github.com/smartystreets/goconvey/convey/gotest
|
||||||
github.com/smartystreets/goconvey/convey/reporting
|
github.com/smartystreets/goconvey/convey/reporting
|
||||||
# golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
|
# golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899
|
||||||
## explicit
|
## explicit
|
||||||
golang.org/x/crypto/blake2b
|
golang.org/x/crypto/blake2b
|
||||||
golang.org/x/crypto/curve25519
|
golang.org/x/crypto/curve25519
|
||||||
|
|
Loading…
Reference in New Issue