If the NSS implementation of the host and the container is
incompatible, getpwuid() will fail and the shell of the user in the
container cannot be determined. In that case, don't simply fail, but
rather default to /bin/sh. Since this code path is only executed when
attaching to a container without a command argument, this makes the
default behavior of lxc-attach a lot more robust.

Signed-off-by: Christian Seiler <christ...@iwakd.de>
---
 src/lxc/lxc_attach.c |   22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/lxc/lxc_attach.c b/src/lxc/lxc_attach.c
index 1f60266..292b5b5 100644
--- a/src/lxc/lxc_attach.c
+++ b/src/lxc/lxc_attach.c
@@ -438,15 +438,26 @@ int main(int argc, char *argv[])
                uid = getuid();
 
                passwd = getpwuid(uid);
-               if (!passwd) {
-                       SYSERROR("failed to get passwd "                \
-                                "entry for uid '%d'", uid);
-                       return -1;
+
+               if (passwd) {
+                       char *const args[] = {
+                               passwd->pw_shell,
+                               NULL,
+                       };
+
+                       execvp(args[0], args);
                }
 
+               /* executed if either no passwd entry or execvp fails,
+                * we will fall back on /bin/sh as a default shell
+                *
+                * this will make lxc-attach work better out of the box,
+                * esp. when attaching to a container that has an
+                * incompatible nss implementation
+                */
                {
                        char *const args[] = {
-                               passwd->pw_shell,
+                               "/bin/sh",
                                NULL,
                        };
 
@@ -454,7 +465,6 @@ int main(int argc, char *argv[])
                        SYSERROR("failed to exec '%s'", args[0]);
                        return -1;
                }
-
        }
 
        return 0;
-- 
1.7.10.4


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel

Reply via email to