( c *cli.Context, info *cliutil.BuildInfo, namedTunnel *connection.TunnelProperties, log *zerolog.Logger, )
| 316 | } |
| 317 | |
| 318 | func StartServer( |
| 319 | c *cli.Context, |
| 320 | info *cliutil.BuildInfo, |
| 321 | namedTunnel *connection.TunnelProperties, |
| 322 | log *zerolog.Logger, |
| 323 | ) error { |
| 324 | err := sentry.Init(sentry.ClientOptions{ |
| 325 | Dsn: sentryDSN, |
| 326 | Release: c.App.Version, |
| 327 | }) |
| 328 | if err != nil { |
| 329 | return err |
| 330 | } |
| 331 | var wg sync.WaitGroup |
| 332 | listeners := gracenet.Net{} |
| 333 | errC := make(chan error) |
| 334 | |
| 335 | // Only log for locally configured tunnels (Token is blank). |
| 336 | if config.GetConfiguration().Source() == "" && c.String(TunnelTokenFlag) == "" { |
| 337 | log.Info().Msg(config.ErrNoConfigFile.Error()) |
| 338 | } |
| 339 | |
| 340 | if c.IsSet(cfdflags.TraceOutput) { |
| 341 | tmpTraceFile, err := os.CreateTemp("", "trace") |
| 342 | if err != nil { |
| 343 | log.Err(err).Msg("Failed to create new temporary file to save trace output") |
| 344 | } |
| 345 | |
| 346 | traceLog := log.With().Str(LogFieldTmpTraceFilename, tmpTraceFile.Name()).Logger() |
| 347 | |
| 348 | defer func() { |
| 349 | if err := tmpTraceFile.Close(); err != nil { |
| 350 | traceLog.Err(err).Msg("Failed to close temporary trace output file") |
| 351 | } |
| 352 | traceOutputFilepath := c.String(cfdflags.TraceOutput) |
| 353 | //nolint:gosec // File path is safe because it is explicitly provided by the user via the --trace-output flag |
| 354 | if err := os.Rename(tmpTraceFile.Name(), traceOutputFilepath); err != nil { |
| 355 | traceLog. |
| 356 | Err(err). |
| 357 | Str(LogFieldTraceOutputFilepath, traceOutputFilepath). |
| 358 | Msg("Failed to rename temporary trace output file") |
| 359 | } else { |
| 360 | //nolint:gosec // File path is safe, since it is created by os.CreateTemp |
| 361 | err := os.Remove(tmpTraceFile.Name()) |
| 362 | if err != nil { |
| 363 | traceLog.Err(err).Msg("Failed to remove the temporary trace file") |
| 364 | } |
| 365 | } |
| 366 | }() |
| 367 | |
| 368 | if err := trace.Start(tmpTraceFile); err != nil { |
| 369 | traceLog.Err(err).Msg("Failed to start trace") |
| 370 | return errors.Wrap(err, "Error starting tracing") |
| 371 | } |
| 372 | defer trace.Stop() |
| 373 | } |
| 374 | |
| 375 | info.Log(log) |
no test coverage detected