Skip to content

Commit

Permalink
Convert lib/shell to use slog (#50306)
Browse files Browse the repository at this point in the history
  • Loading branch information
rosstimothy authored Dec 17, 2024
1 parent 57f4618 commit 8191a51
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
package shell

import (
"context"
"log/slog"

"github.com/gravitational/trace"
"github.com/sirupsen/logrus"
)

const (
Expand All @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions lib/shell/shell_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
}

Expand Down

0 comments on commit 8191a51

Please sign in to comment.