Commit 21da9912 by Christian Seiler Committed by Serge Hallyn

lxc-attach: Default to /bin/sh if shell cannot be determined or exec'd

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: 's avatarChristian Seiler <christian@iwakd.de>
parent 905022f7
...@@ -452,15 +452,21 @@ int main(int argc, char *argv[]) ...@@ -452,15 +452,21 @@ int main(int argc, char *argv[])
else else
user_shell = passwd->pw_shell; user_shell = passwd->pw_shell;
if (!user_shell) { if (user_shell) {
SYSERROR("failed to get passwd " \ char *const args[] = {
"entry for uid '%d'", uid); user_shell,
return -1; 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[] = { char *const args[] = {
user_shell, "/bin/sh",
NULL, NULL,
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment