2016-10-22 09:21:28 +02:00
|
|
|
// Accounting and limiting reader
|
|
|
|
// Unix specific functions.
|
|
|
|
|
2016-10-30 20:20:16 +01:00
|
|
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
2016-10-22 09:21:28 +02:00
|
|
|
|
2018-01-12 17:30:54 +01:00
|
|
|
package accounting
|
2016-10-22 09:21:28 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2018-01-12 17:30:54 +01:00
|
|
|
|
2019-07-28 19:47:38 +02:00
|
|
|
"github.com/rclone/rclone/fs"
|
2016-10-22 09:21:28 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// startSignalHandler() sets a signal handler to catch SIGUSR2 and toggle throttling.
|
|
|
|
func startSignalHandler() {
|
|
|
|
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
|
2016-10-30 20:20:16 +01:00
|
|
|
tokenBucketMu.Lock()
|
2017-08-17 17:40:43 +02:00
|
|
|
bwLimitToggledOff = !bwLimitToggledOff
|
2016-10-30 20:20:16 +01:00
|
|
|
tokenBucket, prevTokenBucket = prevTokenBucket, tokenBucket
|
|
|
|
s := "disabled"
|
|
|
|
if tokenBucket != nil {
|
|
|
|
s = "enabled"
|
2016-10-22 09:21:28 +02:00
|
|
|
}
|
2016-10-30 20:20:16 +01:00
|
|
|
tokenBucketMu.Unlock()
|
2018-01-12 17:30:54 +01:00
|
|
|
fs.Logf(nil, "Bandwidth limit %s by user", s)
|
2016-10-22 09:21:28 +02:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|