Merge pull request #2822 from markpeek/markpeek-alt-rand
Initialize the random seeding in main and the RPC server (for plugins)
This commit is contained in:
commit
f401e765df
|
@ -4,9 +4,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mitchellh/multistep"
|
||||
vboxcommon "github.com/mitchellh/packer/builder/virtualbox/common"
|
||||
|
@ -211,9 +209,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
|||
}
|
||||
|
||||
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
||||
// Seed the random number generator
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
|
||||
// Create the driver that we'll use to communicate with VirtualBox
|
||||
driver, err := vboxcommon.NewDriver()
|
||||
if err != nil {
|
||||
|
|
|
@ -4,8 +4,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/mitchellh/multistep"
|
||||
vboxcommon "github.com/mitchellh/packer/builder/virtualbox/common"
|
||||
|
@ -35,9 +33,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
|||
// Run executes a Packer build and returns a packer.Artifact representing
|
||||
// a VirtualBox appliance.
|
||||
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
||||
// Seed the random number generator
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
|
||||
// Create the driver that we'll use to communicate with VirtualBox
|
||||
driver, err := vboxcommon.NewDriver()
|
||||
if err != nil {
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -246,9 +245,6 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
state.Put("hook", hook)
|
||||
state.Put("ui", ui)
|
||||
|
||||
// Seed the random number generator
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
|
||||
steps := []multistep.Step{
|
||||
&vmwcommon.StepPrepareTools{
|
||||
RemoteType: b.config.RemoteType,
|
||||
|
|
7
main.go
7
main.go
|
@ -6,10 +6,12 @@ import (
|
|||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/mitchellh/cli"
|
||||
"github.com/mitchellh/packer/command"
|
||||
|
@ -292,3 +294,8 @@ func copyOutput(r io.Reader, doneCh chan<- struct{}) {
|
|||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Seed the random number generator
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
@ -33,3 +34,9 @@ func TestExtractMachineReadable(t *testing.T) {
|
|||
t.Fatal("should be mr")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRandom(t *testing.T) {
|
||||
if rand.Intn(9999999) == 8498210 {
|
||||
t.Fatal("math.rand is not seeded properly")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,12 +13,14 @@ import (
|
|||
packrpc "github.com/mitchellh/packer/packer/rpc"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
// This is a count of the number of interrupts the process has received.
|
||||
|
@ -138,3 +140,8 @@ func serverListener_unix() (net.Listener, error) {
|
|||
|
||||
return net.Listen("unix", path)
|
||||
}
|
||||
|
||||
func init() {
|
||||
// Seed the random number generator
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package plugin
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPluginServerRandom(t *testing.T) {
|
||||
if rand.Intn(9999999) == 8498210 {
|
||||
t.Fatal("math.rand is not seeded properly")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue