-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squashed commit of the following: commit 6c90850 Author: Ainar Garipov <[email protected]> Date: Fri Apr 12 19:01:08 2024 +0300 osutil, service: windows support
- Loading branch information
Showing
7 changed files
with
83 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//go:build unix | ||
|
||
package osutil | ||
|
||
import ( | ||
"os" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
// isShutdownSignal returns true if sig is a Unix shutdown signal. | ||
func isShutdownSignal(sig os.Signal) (ok bool) { | ||
switch sig { | ||
case | ||
unix.SIGINT, | ||
unix.SIGQUIT, | ||
unix.SIGTERM: | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
// notifyShutdownSignal notifies c on receiving Unix shutdown signals using n. | ||
func notifyShutdownSignal(n SignalNotifier, c chan<- os.Signal) { | ||
n.Notify(c, unix.SIGINT, unix.SIGQUIT, unix.SIGTERM) | ||
} |
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,26 @@ | ||
//go:build windows | ||
|
||
package osutil | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
) | ||
|
||
// isShutdownSignal returns true if sig is a Windows shutdown signal. | ||
func isShutdownSignal(sig os.Signal) (ok bool) { | ||
switch sig { | ||
case os.Interrupt, syscall.SIGTERM: | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
|
||
// notifyShutdownSignal notifies c on receiving Windows shutdown signals using | ||
// n. | ||
func notifyShutdownSignal(n SignalNotifier, c chan<- os.Signal) { | ||
// syscall.SIGTERM is processed automatically. See go doc os/signal, | ||
// section Windows. | ||
n.Notify(c, os.Interrupt) | ||
} |
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
//go:build unix | ||
|
||
package service_test | ||
|
||
import "time" | ||
|
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
//go:build unix | ||
|
||
package service_test | ||
|
||
import ( | ||
|
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,18 @@ | ||
package testutil | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
) | ||
|
||
// ContextWithTimeout is a helper that creates a new context with timeout and | ||
// registers ctx's cleanup with tb.Cleanup. | ||
func ContextWithTimeout(tb testing.TB, timeout time.Duration) (ctx context.Context) { | ||
tb.Helper() | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), timeout) | ||
tb.Cleanup(cancel) | ||
|
||
return ctx | ||
} |