cc4f5ba7ba
Sending rclone a SIGUSR2 signal will toggle the limiter between off and the limit set with the --bwlimit command-line option.
35 lines
664 B
Go
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
|
|
}
|
|
}
|
|
}()
|
|
}
|