-
Notifications
You must be signed in to change notification settings - Fork 512
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not support SIGUSR1 and SIGUSR2 syscall handling in windows
Signed-off-by: Ying Li <ying.li@docker.com>
- Loading branch information
Showing
13 changed files
with
191 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// +build !windows | ||
|
||
package notary | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
) | ||
|
||
// NotarySupportedSignals contains the signals we would like to capture: | ||
// - SIGUSR1, indicates a increment of the log level. | ||
// - SIGUSR2, indicates a decrement of the log level. | ||
var NotarySupportedSignals = []os.Signal{ | ||
syscall.SIGUSR1, | ||
syscall.SIGUSR2, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// +build windows | ||
|
||
package notary | ||
|
||
import "os" | ||
|
||
// NotarySupportedSignals does not contain any signals, because SIGUSR1/2 are not supported on windows | ||
var NotarySupportedSignals = []os.Signal{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// +build !windows | ||
|
||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"syscall" | ||
|
||
"github.com/Sirupsen/logrus" | ||
) | ||
|
||
// LogLevelSignalHandle will increase/decrease the logging level via the signal we get. | ||
func LogLevelSignalHandle(sig os.Signal) { | ||
switch sig { | ||
case syscall.SIGUSR1: | ||
if err := AdjustLogLevel(true); err != nil { | ||
fmt.Printf("Attempt to increase log level failed, will remain at %s level, error: %s\n", logrus.GetLevel(), err) | ||
return | ||
} | ||
case syscall.SIGUSR2: | ||
if err := AdjustLogLevel(false); err != nil { | ||
fmt.Printf("Attempt to decrease log level failed, will remain at %s level, error: %s\n", logrus.GetLevel(), err) | ||
return | ||
} | ||
} | ||
|
||
fmt.Println("Successfully setting log level to ", logrus.GetLevel()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// +build !windows | ||
|
||
package utils | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"syscall" | ||
"testing" | ||
|
||
"github.com/Sirupsen/logrus" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestLogLevelSignalHandle(t *testing.T) { | ||
tempdir, err := ioutil.TempDir("", "test-signal-handle") | ||
require.NoError(t, err) | ||
defer os.RemoveAll(tempdir) | ||
|
||
logrus.SetLevel(logrus.InfoLevel) | ||
|
||
// Info + SIGUSR1 -> Debug | ||
LogLevelSignalHandle(syscall.SIGUSR1) | ||
require.Equal(t, logrus.GetLevel(), logrus.DebugLevel) | ||
|
||
// Debug + SIGUSR1 -> Debug | ||
LogLevelSignalHandle(syscall.SIGUSR1) | ||
require.Equal(t, logrus.GetLevel(), logrus.DebugLevel) | ||
|
||
// Debug + SIGUSR2-> Info | ||
LogLevelSignalHandle(syscall.SIGUSR2) | ||
require.Equal(t, logrus.GetLevel(), logrus.InfoLevel) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// +build windows | ||
|
||
package utils | ||
|
||
import "os" | ||
|
||
// LogLevelSignalHandle will do nothing, because we aren't currently supporting signal handling in windows | ||
func LogLevelSignalHandle(sig os.Signal) { | ||
} |