rclone/fs/accounting_unix.go
Marco Paganini cc4f5ba7ba Add support to toggle bandwidth limits via SIGUSR2.
Sending rclone a SIGUSR2 signal will toggle the limiter between off and
the limit set with the --bwlimit command-line option.
2016-10-30 17:46:59 +00:00

35 lines
664 B
Go

// Accounting and limiting reader
// Unix specific functions.
// +build darwin dragonfly freebsd linux netbsd openbsd
package fs
import (
"os"
"os/signal"
"syscall"
)
// startSignalHandler() sets a signal handler to catch SIGUSR2 and toggle throttling.
func startSignalHandler() {
// Don't do anything if no bandwidth limits requested.
if bwLimit <= 0 {
return
}
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGUSR2)
go func() {
// This runs forever, but blocks until the signal is received.
for {
<-signals
if tokenBucket == nil {
tokenBucket = origTokenBucket
} else {
tokenBucket = nil
}
}
}()
}