Commit 9097f9fb authored by Sebastian Stark's avatar Sebastian Stark

return proper errors in pidlocker

parent f3b09ecf
......@@ -5,6 +5,7 @@
package main
import (
"fmt"
"io/ioutil"
"log"
"os"
......@@ -23,22 +24,23 @@ func newPidLocker(lockfile string) *pidLocker {
}
}
func (pl *pidLocker) Lock() {
func (pl *pidLocker) Lock() error {
_, err := os.Stat(pl.f)
if err == nil {
log.Fatalf("pid file %s already exists. Is snaprd running already?", pl.f)
return fmt.Errorf("pid file %s already exists. Is snaprd running already?", pl.f)
}
debugf("write pid %d to pidfile %s", pl.pid, pl.f)
err = ioutil.WriteFile(pl.f, []byte(strconv.Itoa(pl.pid)), 0666)
if err != nil {
log.Fatalf("could not write pid file %s", pl.f)
return fmt.Errorf("could not write pid file %s: %s", pl.f, err)
}
return nil
}
func (pl *pidLocker) Unlock() {
debugf("delete pidfile %s", pl.f)
err := os.Remove(pl.f)
if err != nil {
log.Fatalf("could not remove pid file %s", pl.f)
log.Printf("could not remove pid file %s: %s", pl.f, err)
}
}
......@@ -67,7 +67,11 @@ func lastGoodTicker(in, out chan *snapshot, cl clock) {
// helper goroutines.
func subcmdRun() (ferr error) {
pl := newPidLocker(filepath.Join(config.repository, ".pid"))
pl.Lock()
err := pl.Lock()
if err != nil {
ferr = err
return
}
defer pl.Unlock()
if !config.NoWait {
sigc := make(chan os.Signal, 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment