mirror of
https://github.com/safing/portbase
synced 2025-09-02 18:50:14 +00:00
Release to master
This commit is contained in:
commit
74e6085ea6
3 changed files with 30 additions and 11 deletions
|
@ -85,7 +85,13 @@ func FullVersion() string {
|
||||||
|
|
||||||
// CheckVersion checks if the metadata is ok.
|
// CheckVersion checks if the metadata is ok.
|
||||||
func CheckVersion() error {
|
func CheckVersion() error {
|
||||||
if !strings.HasSuffix(os.Args[0], ".test") {
|
switch {
|
||||||
|
case strings.HasSuffix(os.Args[0], ".test"):
|
||||||
|
return nil // testing on linux/darwin
|
||||||
|
case strings.HasSuffix(os.Args[0], ".test.exe"):
|
||||||
|
return nil // testing on windows
|
||||||
|
default:
|
||||||
|
// check version information
|
||||||
if name == "[NAME]" {
|
if name == "[NAME]" {
|
||||||
return errors.New("must call SetInfo() before calling CheckVersion()")
|
return errors.New("must call SetInfo() before calling CheckVersion()")
|
||||||
}
|
}
|
||||||
|
@ -100,5 +106,6 @@ func CheckVersion() error {
|
||||||
return errors.New("please build using the supplied build script.\n$ ./build {main.go|...}")
|
return errors.New("please build using the supplied build script.\n$ ./build {main.go|...}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,9 @@ var (
|
||||||
// lock modules when starting
|
// lock modules when starting
|
||||||
modulesLocked = abool.New()
|
modulesLocked = abool.New()
|
||||||
|
|
||||||
|
moduleStartTimeout = 2 * time.Minute
|
||||||
|
moduleStopTimeout = 1 * time.Minute
|
||||||
|
|
||||||
// ErrCleanExit is returned by Start() when the program is interrupted before starting. This can happen for example, when using the "--help" flag.
|
// ErrCleanExit is returned by Start() when the program is interrupted before starting. This can happen for example, when using the "--help" flag.
|
||||||
ErrCleanExit = errors.New("clean exit requested")
|
ErrCleanExit = errors.New("clean exit requested")
|
||||||
)
|
)
|
||||||
|
@ -117,7 +120,7 @@ func (m *Module) prep(reports chan *report) {
|
||||||
// execute function
|
// execute function
|
||||||
err = m.runCtrlFnWithTimeout(
|
err = m.runCtrlFnWithTimeout(
|
||||||
"prep module",
|
"prep module",
|
||||||
10*time.Second,
|
moduleStartTimeout,
|
||||||
m.prepFn,
|
m.prepFn,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -173,7 +176,7 @@ func (m *Module) start(reports chan *report) {
|
||||||
// execute function
|
// execute function
|
||||||
err = m.runCtrlFnWithTimeout(
|
err = m.runCtrlFnWithTimeout(
|
||||||
"start module",
|
"start module",
|
||||||
10*time.Second,
|
moduleStartTimeout,
|
||||||
m.startFn,
|
m.startFn,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -248,7 +251,7 @@ func (m *Module) stopAllTasks(reports chan *report) {
|
||||||
// wait for results
|
// wait for results
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
case <-time.After(30 * time.Second):
|
case <-time.After(moduleStopTimeout):
|
||||||
log.Warningf(
|
log.Warningf(
|
||||||
"%s: timed out while waiting for stopfn/workers/tasks to finish: stopFn=%v workers=%d tasks=%d microtasks=%d, continuing shutdown...",
|
"%s: timed out while waiting for stopfn/workers/tasks to finish: stopFn=%v workers=%d tasks=%d microtasks=%d, continuing shutdown...",
|
||||||
m.Name,
|
m.Name,
|
||||||
|
|
11
rng/rng.go
11
rng/rng.go
|
@ -1,6 +1,7 @@
|
||||||
package rng
|
package rng
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
|
@ -49,14 +50,22 @@ func start() error {
|
||||||
return errors.New("failed to initialize rng")
|
return errors.New("failed to initialize rng")
|
||||||
}
|
}
|
||||||
|
|
||||||
// explicitly add randomness
|
// add another (async) OS rng seed
|
||||||
|
module.StartWorker("initial rng feed", func(_ context.Context) error {
|
||||||
|
// get entropy from OS
|
||||||
osEntropy := make([]byte, minFeedEntropy/8)
|
osEntropy := make([]byte, minFeedEntropy/8)
|
||||||
_, err := rand.Read(osEntropy)
|
_, err := rand.Read(osEntropy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not read entropy from os: %s", err)
|
return fmt.Errorf("could not read entropy from os: %s", err)
|
||||||
}
|
}
|
||||||
|
// feed
|
||||||
|
rngLock.Lock()
|
||||||
rng.Reseed(osEntropy)
|
rng.Reseed(osEntropy)
|
||||||
|
rngLock.Unlock()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
// mark as ready
|
||||||
rngReady = true
|
rngReady = true
|
||||||
|
|
||||||
// random source: OS
|
// random source: OS
|
||||||
|
|
Loading…
Add table
Reference in a new issue