Merge pull request #10030 from angdraug/no-panicwrap-in-plugins

no panicwrap in plugins
This commit is contained in:
Megan Marsh 2020-10-06 12:21:15 -07:00 committed by GitHub
commit d05eb3401b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

16
main.go
View File

@ -43,7 +43,11 @@ func realMain() int {
wrapConfig.CookieKey = "PACKER_WRAP_COOKIE"
wrapConfig.CookieValue = "49C22B1A-3A93-4C98-97FA-E07D18C787B5"
if !panicwrap.Wrapped(&wrapConfig) {
if inPlugin() || panicwrap.Wrapped(&wrapConfig) {
// Call the real main
return wrappedMain()
}
// Generate a UUID for this packer run and pass it to the environment.
// GenerateUUID always returns a nil error (based on rand.Read) so we'll
// just ignore it.
@ -118,10 +122,8 @@ func realMain() int {
// We're the child, so just close the tempfile we made in order to
// save file handles since the tempfile is only used by the parent.
logTempFile.Close()
}
// Call the real main
return wrappedMain()
return 0
}
// wrappedMain is called only when we're wrapped by panicwrap and
@ -135,7 +137,7 @@ func wrappedMain() int {
packer.LogSecretFilter.SetOutput(os.Stderr)
log.SetOutput(&packer.LogSecretFilter)
inPlugin := os.Getenv(plugin.MagicCookieKey) == plugin.MagicCookieValue
inPlugin := inPlugin()
if inPlugin {
// This prevents double-logging timestamps
log.SetFlags(0)
@ -387,6 +389,10 @@ func copyOutput(r io.Reader, doneCh chan<- struct{}) {
wg.Wait()
}
func inPlugin() bool {
return os.Getenv(plugin.MagicCookieKey) == plugin.MagicCookieValue
}
func init() {
// Seed the random number generator
rand.Seed(time.Now().UTC().UnixNano())