From e3a6af31fa5e76d30413c38561a5f432693d32c7 Mon Sep 17 00:00:00 2001 From: rosstimothy <39066650+rosstimothy@users.noreply.github.com> Date: Tue, 17 Dec 2024 08:30:16 -0500 Subject: [PATCH] Convert lib/shell to use slog (#50306) --- lib/shell/shell.go | 6 ++++-- lib/shell/shell_unix.go | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/shell/shell.go b/lib/shell/shell.go index f9ac0350226f6..f42cc80899b85 100644 --- a/lib/shell/shell.go +++ b/lib/shell/shell.go @@ -19,8 +19,10 @@ package shell import ( + "context" + "log/slog" + "github.com/gravitational/trace" - "github.com/sirupsen/logrus" ) const ( @@ -35,7 +37,7 @@ func GetLoginShell(username string) (string, error) { shellcmd, err = getLoginShell(username) if err != nil { if trace.IsNotFound(err) { - logrus.Warnf("No shell specified for %v, using default %v.", username, DefaultShell) + slog.WarnContext(context.Background(), "No shell specified for user, using default", "username", username, "default_shell", DefaultShell) return DefaultShell, nil } return "", trace.Wrap(err) diff --git a/lib/shell/shell_unix.go b/lib/shell/shell_unix.go index f93df70061d02..e8d97ff4d90c1 100644 --- a/lib/shell/shell_unix.go +++ b/lib/shell/shell_unix.go @@ -36,13 +36,14 @@ static int mygetpwnam_r(const char *name, struct passwd *pwd, import "C" import ( + "context" + "log/slog" "os/user" "strings" "syscall" "unsafe" "github.com/gravitational/trace" - log "github.com/sirupsen/logrus" ) // getLoginShell determines the login shell for a given username @@ -63,7 +64,7 @@ func getLoginShell(username string) (string, error) { bufSize = 1024 } if bufSize <= 0 || bufSize > 1<<20 { - return "", trace.BadParameter("lookupPosixShell: unreasonable _SC_GETPW_R_SIZE_MAX of %d", bufSize) + return "", trace.BadParameter("unreasonable _SC_GETPW_R_SIZE_MAX of %d", bufSize) } buf := C.malloc(C.size_t(bufSize)) defer C.free(buf) @@ -76,7 +77,7 @@ func getLoginShell(username string) (string, error) { C.size_t(bufSize), &result) if rv != 0 || result == nil { - log.Errorf("lookupPosixShell: lookup username %s: %s", username, syscall.Errno(rv)) + slog.ErrorContext(context.Background(), "failed looking up username", "username", username, "error", syscall.Errno(rv).Error()) return "", trace.BadParameter("cannot determine shell for %s", username) }