2016-10-22 07:21:28 +00:00
|
|
|
// Accounting and limiting reader
|
|
|
|
// Unix specific functions.
|
|
|
|
|
2016-10-30 19:20:16 +00:00
|
|
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
2016-10-22 07:21:28 +00:00
|
|
|
|
|
|
|
package fs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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 19:20:16 +00:00
|
|
|
tokenBucketMu.Lock()
|
|
|
|
tokenBucket, prevTokenBucket = prevTokenBucket, tokenBucket
|
|
|
|
s := "disabled"
|
|
|
|
if tokenBucket != nil {
|
|
|
|
s = "enabled"
|
2016-10-22 07:21:28 +00:00
|
|
|
}
|
2016-10-30 19:20:16 +00:00
|
|
|
tokenBucketMu.Unlock()
|
2017-02-09 11:01:20 +00:00
|
|
|
Logf(nil, "Bandwidth limit %s by user", s)
|
2016-10-22 07:21:28 +00:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|