Skip to content

Commit

Permalink
Fix crash on windows service. (Velocidex#841)
Browse files Browse the repository at this point in the history
When a config file is missing, the service attempts to log but logging
is not yet available.
  • Loading branch information
scudette authored Dec 26, 2020
1 parent 3949b63 commit 1d3bb9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions bin/installer_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,10 @@ func loadClientConfig() (*config_proto.Config, error) {
WithWriteback().
LoadAndValidate()
if err != nil {
logger := logging.GetLogger(config_obj, &logging.ClientComponent)
logger.Info("Failed to load %v will try again soon.\n", *config_path)
// Config obj is not valid here, we can not actually
// log anything since we dont know where to send it so
// prelog instead.
logging.Prelog("Failed to load %v will try again soon.\n", *config_path)

return nil, err
}
Expand Down
5 changes: 5 additions & 0 deletions logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ func Prelog(format string, v ...interface{}) {
mu.Lock()
defer mu.Unlock()

// Truncate too many logs
if len(prelogs) > 10000 {
prelogs = nil
}

prelogs = append(prelogs, fmt.Sprintf(format, v...))
}

Expand Down

0 comments on commit 1d3bb9e

Please sign in to comment.