File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
bib/cmd/bootc-image-builder Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 7
7
"math"
8
8
"math/big"
9
9
"math/rand"
10
+ "os"
10
11
"slices"
11
12
"strconv"
12
13
"strings"
@@ -667,13 +668,23 @@ func getDistroAndRunner(osRelease osinfo.OSRelease) (manifest.Distro, runner.Run
667
668
return manifest .DISTRO_NULL , & runner.Linux {}, nil
668
669
}
669
670
671
+ // XXX: copied from images:internal/cmdutil/rand.go
672
+ const RNG_SEED_ENV_KEY = "OSBUILD_TESTING_RNG_SEED"
673
+
670
674
func createRand () * rand.Rand {
671
- seed , err := cryptorand .Int (cryptorand .Reader , big .NewInt (math .MaxInt64 ))
675
+ if envSeedStr := os .Getenv (RNG_SEED_ENV_KEY ); envSeedStr != "" {
676
+ envSeedInt , err := strconv .ParseInt (envSeedStr , 10 , 64 )
677
+ if err != nil {
678
+ panic (fmt .Errorf ("failed to parse %s: %s" , RNG_SEED_ENV_KEY , err ))
679
+ }
680
+ fmt .Fprintf (os .Stderr , "TEST MODE: using rng seed %d\n " , envSeedInt )
681
+ return rand .New (rand .NewSource (envSeedInt ))
682
+ }
683
+ randSeed , err := cryptorand .Int (cryptorand .Reader , big .NewInt (math .MaxInt64 ))
672
684
if err != nil {
673
- panic ("Cannot generate an RNG seed." )
685
+ panic (fmt . Errorf ( "failed to generate random seed: %s" , err ) )
674
686
}
675
-
676
687
// math/rand is good enough in this case
677
688
/* #nosec G404 */
678
- return rand .New (rand .NewSource (seed .Int64 ()))
689
+ return rand .New (rand .NewSource (randSeed .Int64 ()))
679
690
}
You can’t perform that action at this time.
0 commit comments