From e0d571fe334808d8549bb399d75f5120f89bbeb2 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 25 Feb 2021 09:56:23 -0800 Subject: Fix gitlab-shell panic when log file not writable Previously when the gitlab-shell log was not writable, gitlab-shell would attempt to fall back to the syslog to log an error. However, if the syslog logger creation succeeded, gitlab-shell would panic since `err` was `nil`. Relates to https://gitlab.com/gitlab-org/gitlab-shell/-/issues/510 --- internal/logger/logger.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'internal/logger/logger.go') diff --git a/internal/logger/logger.go b/internal/logger/logger.go index f836555..3608574 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -22,8 +22,10 @@ func Configure(cfg *config.Config) { logFile, err := os.OpenFile(cfg.LogFile, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644) if err != nil { progName, _ := os.Executable() - syslogLogger, err := syslog.NewLogger(syslog.LOG_ERR|syslog.LOG_USER, 0) - syslogLogger.Print(progName + ": Unable to configure logging: " + err.Error()) + syslogLogger, sysLogErr := syslog.NewLogger(syslog.LOG_ERR|syslog.LOG_USER, 0) + if sysLogErr != nil { + syslogLogger.Print(progName + ": Unable to configure logging: " + err.Error()) + } // Discard logs since a log file was specified but couldn't be opened log.SetOutput(ioutil.Discard) -- cgit v1.2.1