summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2022-12-08 16:30:52 +0100
committerLudovic Courtès <ludo@gnu.org>2022-12-09 09:59:53 +0100
commit0406df0b9b1bf39caa39eba50f918c897ea204e6 (patch)
tree511da610d81a22dd127ed11723a7ef427079fbf3
parent416a691cff8b75d0fcba50412c6e347212ab5973 (diff)
environment: '-C' doesn't throw when the NSS is dysfunctional.
Previously, if the name service switch was dysfunctional, as can happen on foreign distros lacking nscd, "guix shell -C" would crash with a backtrace on the uncaught 'getpwuid' exception. To address that, catch the exception and deal with it gracefully. Reported by remsd1 on #guix. * guix/scripts/environment.scm (launch-environment/container): Wrap 'getpwuid' call in 'false-if-exception'.
-rw-r--r--guix/scripts/environment.scm15
1 files changed, 11 insertions, 4 deletions
diff --git a/guix/scripts/environment.scm b/guix/scripts/environment.scm
index 64597f6e9f8..ab11b35335d 100644
--- a/guix/scripts/environment.scm
+++ b/guix/scripts/environment.scm
@@ -728,14 +728,21 @@ WHILE-LIST."
728 (home (getenv "HOME")) 728 (home (getenv "HOME"))
729 (uid (if user 1000 (getuid))) 729 (uid (if user 1000 (getuid)))
730 (gid (if user 1000 (getgid))) 730 (gid (if user 1000 (getgid)))
731 (passwd (let ((pwd (getpwuid (getuid)))) 731
732 ;; On a foreign distro, the name service switch might be
733 ;; dysfunctional and 'getpwuid' throws. Don't let that hamper
734 ;; operations.
735 (passwd (let ((pwd (false-if-exception (getpwuid (getuid)))))
732 (password-entry 736 (password-entry
733 (name (or user (passwd:name pwd))) 737 (name (or user
734 (real-name (if user 738 (and=> pwd passwd:name)
739 (getenv "USER")
740 "charlie"))
741 (real-name (if (or user (not pwd))
735 "" 742 ""
736 (passwd:gecos pwd))) 743 (passwd:gecos pwd)))
737 (uid uid) (gid gid) (shell bash) 744 (uid uid) (gid gid) (shell bash)
738 (directory (if user 745 (directory (if (or user (not pwd))
739 (string-append "/home/" user) 746 (string-append "/home/" user)
740 (passwd:dir pwd)))))) 747 (passwd:dir pwd))))))
741 (groups (list (group-entry (name "users") (gid gid)) 748 (groups (list (group-entry (name "users") (gid gid))