realMain is executed from main and returns the exit status to exit with.
()
| 39 | |
| 40 | // realMain is executed from main and returns the exit status to exit with. |
| 41 | func realMain() int { |
| 42 | var wrapConfig panicwrap.WrapConfig |
| 43 | // When following env variable is set, packer |
| 44 | // won't panic wrap itself as it's already wrapped. |
| 45 | // i.e.: when terraform runs it. |
| 46 | wrapConfig.CookieKey = "PACKER_WRAP_COOKIE" |
| 47 | wrapConfig.CookieValue = "49C22B1A-3A93-4C98-97FA-E07D18C787B5" |
| 48 | |
| 49 | if inPlugin() || panicwrap.Wrapped(&wrapConfig) { |
| 50 | // Call the real main |
| 51 | return wrappedMain() |
| 52 | } |
| 53 | |
| 54 | // Generate a UUID for this packer run and pass it to the environment. |
| 55 | // GenerateUUID always returns a nil error (based on rand.Read) so we'll |
| 56 | // just ignore it. |
| 57 | UUID, _ := uuid.GenerateUUID() |
| 58 | os.Setenv("PACKER_RUN_UUID", UUID) |
| 59 | |
| 60 | // Determine where logs should go in general (requested by the user) |
| 61 | logWriter, err := logOutput() |
| 62 | if err != nil { |
| 63 | fmt.Fprintf(os.Stderr, "Couldn't setup log output: %s", err) |
| 64 | return 1 |
| 65 | } |
| 66 | if logWriter == nil { |
| 67 | logWriter = io.Discard |
| 68 | } |
| 69 | |
| 70 | packersdk.LogSecretFilter.SetOutput(logWriter) |
| 71 | |
| 72 | // Disable logging here |
| 73 | log.SetOutput(io.Discard) |
| 74 | |
| 75 | // We always send logs to a temporary file that we use in case |
| 76 | // there is a panic. Otherwise, we delete it. |
| 77 | logTempFile, err := tmp.File("packer-log") |
| 78 | if err != nil { |
| 79 | fmt.Fprintf(os.Stderr, "Couldn't setup logging tempfile: %s", err) |
| 80 | return 1 |
| 81 | } |
| 82 | defer os.Remove(logTempFile.Name()) |
| 83 | defer logTempFile.Close() |
| 84 | |
| 85 | // Setup the prefixed readers that send data properly to |
| 86 | // stdout/stderr. |
| 87 | doneCh := make(chan struct{}) |
| 88 | outR, outW := io.Pipe() |
| 89 | go copyOutput(outR, doneCh) |
| 90 | |
| 91 | // Enable checkpoint for panic reporting |
| 92 | if config, _ := loadConfig(); config != nil && !config.DisableCheckpoint { |
| 93 | packer.CheckpointReporter = packer.NewCheckpointReporter( |
| 94 | config.DisableCheckpointSignature, |
| 95 | ) |
| 96 | } |
| 97 | |
| 98 | // Create the configuration for panicwrap and wrap our executable |
no test coverage detected
searching dependent graphs…