Lint on pkg/* packages
- pkg/useragent - pkg/units - pkg/ulimit - pkg/truncindex - pkg/timeoutconn - pkg/term - pkg/tarsum - pkg/tailfile - pkg/systemd - pkg/stringutils - pkg/stringid - pkg/streamformatter - pkg/sockets - pkg/signal - pkg/proxy - pkg/progressreader - pkg/pools - pkg/plugins - pkg/pidfile - pkg/parsers - pkg/parsers/filters - pkg/parsers/kernel - pkg/parsers/operatingsystem Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
a922d62168
commit
9bcb3cba83
56 changed files with 455 additions and 195 deletions
|
@ -1,3 +1,6 @@
|
|||
// Package pidfile provides structure and helper functions to create and remove
|
||||
// PID file. A PID file is usually a file used to store the process ID of a
|
||||
// running process.
|
||||
package pidfile
|
||||
|
||||
import (
|
||||
|
@ -8,11 +11,12 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
type PidFile struct {
|
||||
// PIDFile is a file used to store the process ID of a running process.
|
||||
type PIDFile struct {
|
||||
path string
|
||||
}
|
||||
|
||||
func checkPidFileAlreadyExists(path string) error {
|
||||
func checkPIDFileAlreadyExists(path string) error {
|
||||
if pidString, err := ioutil.ReadFile(path); err == nil {
|
||||
if pid, err := strconv.Atoi(string(pidString)); err == nil {
|
||||
if _, err := os.Stat(filepath.Join("/proc", string(pid))); err == nil {
|
||||
|
@ -23,18 +27,20 @@ func checkPidFileAlreadyExists(path string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func New(path string) (*PidFile, error) {
|
||||
if err := checkPidFileAlreadyExists(path); err != nil {
|
||||
// New creates a PIDfile using the specified path.
|
||||
func New(path string) (*PIDFile, error) {
|
||||
if err := checkPIDFileAlreadyExists(path); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := ioutil.WriteFile(path, []byte(fmt.Sprintf("%d", os.Getpid())), 0644); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &PidFile{path: path}, nil
|
||||
return &PIDFile{path: path}, nil
|
||||
}
|
||||
|
||||
func (file PidFile) Remove() error {
|
||||
// Remove removes the PIDFile.
|
||||
func (file PIDFile) Remove() error {
|
||||
if err := os.Remove(file.path); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue