Commit 695943fc authored by Sebastian Stark's avatar Sebastian Stark

Let CreateSnapshot handle os level signals on its own

  - no need to pass around a kill channel
parent b6a3f998
......@@ -67,7 +67,6 @@ func subcmdRun() (ferr error) {
createExitDone := make(chan bool)
purgeExit := make(chan bool)
purgeExitDone := make(chan bool)
killRsync := make(chan bool, 1)
// The obsoleteQueue should not be larger than the absolute number of
// expected snapshots. However, there is no way (yet) to calculate that
// number.
......@@ -94,7 +93,7 @@ func subcmdRun() (ferr error) {
createExitDone <- true
return
}
sn, err := CreateSnapshot(lastGood, killRsync)
sn, err := CreateSnapshot(lastGood)
if err != nil || sn == nil {
Debugf("snapshot creation finally failed (%s), exit loop", err)
breakLoop = true
......@@ -149,7 +148,6 @@ func subcmdRun() (ferr error) {
switch sig {
case syscall.SIGINT, syscall.SIGTERM:
log.Println("-> Immediate exit")
killRsync <- true
ferr = nil
case syscall.SIGUSR1:
log.Println("-> Graceful exit")
......
......@@ -9,6 +9,7 @@ import (
"log"
"os"
"os/exec"
"os/signal"
"path/filepath"
"syscall"
)
......@@ -52,11 +53,10 @@ func runRsyncCommand(cmd *exec.Cmd) (error, chan error) {
}
// CreateSnapshot starts a potentially long running rsync command and returns a
// Snapshot pointer on success. If something is sent on the kill channel the
// rsync process will be sent a SIGTERM signal.
// Snapshot pointer on success.
// For non-zero return values of rsync potentially restart the process if the
// error was presumably volatile.
func CreateSnapshot(base *Snapshot, kill chan bool) (*Snapshot, error) {
func CreateSnapshot(base *Snapshot) (*Snapshot, error) {
cl := new(realClock)
newSn := newIncompleteSnapshot(cl)
cmd := createRsyncCommand(newSn, base)
......@@ -65,11 +65,13 @@ func CreateSnapshot(base *Snapshot, kill chan bool) (*Snapshot, error) {
log.Fatalln("could not start rsync command:", err)
}
Debugf("rsync started")
sigc := make(chan os.Signal, 1)
signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM)
for {
select {
case <-kill:
Debugf("trying to kill rsync")
err := cmd.Process.Signal(syscall.SIGTERM)
case sig := <-sigc:
Debugf("trying to kill rsync with signal %v", sig)
err := cmd.Process.Signal(sig)
if err != nil {
log.Fatal("failed to kill: ", err)
}
......
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