]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc-attach: Default to /bin/sh if shell cannot be determined or exec'd
authorChristian Seiler <christian@iwakd.de>
Wed, 6 Mar 2013 19:41:54 +0000 (20:41 +0100)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Wed, 6 Mar 2013 20:30:24 +0000 (14:30 -0600)
If getpwuid() fails and also the fallback of spawning of a 'getent'
process, and the user specified no command to execute, default to
/bin/sh and only fail if even that is not available. This should ensure
that unless the container is *really* weird, no matter what, the user
should always end up with a shell when calling lxc-attach with no
further arguments.

Signed-off-by: Christian Seiler <christian@iwakd.de>
src/lxc/lxc_attach.c

index fdf8a0664e06f9bbae9b4b55c3643f6d2a604d27..69ebfaccaa04df86e0916e36ee598babada17e04 100644 (file)
@@ -452,15 +452,21 @@ int main(int argc, char *argv[])
                 else
                         user_shell = passwd->pw_shell;
 
-               if (!user_shell) {
-                       SYSERROR("failed to get passwd "                \
-                                "entry for uid '%d'", uid);
-                       return -1;
+                if (user_shell) {
+                       char *const args[] = {
+                               user_shell,
+                               NULL,
+                       };
+
+                       (void) execvp(args[0], args);
                }
 
+               /* executed if either no passwd entry or execvp fails,
+                * we will fall back on /bin/sh as a default shell
+                */
                {
                        char *const args[] = {
-                               user_shell,
+                               "/bin/sh",
                                NULL,
                        };