public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Karel Zak <kzak@redhat.com>
To: "Zbigniew Jędrzejewski-Szmek" <zbyszek@in.waw.pl>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH 1/2] unshare,nsenter: spawn shell by default
Date: Wed, 13 Feb 2013 14:52:12 +0100	[thread overview]
Message-ID: <20130213135212.GF7799@x2.net.home> (raw)
In-Reply-To: <1360282142-1943-1-git-send-email-zbyszek@in.waw.pl>

On Thu, Feb 07, 2013 at 07:09:01PM -0500, Zbigniew Jędrzejewski-Szmek wrote:
> +#define DEFAULT_SHELL "/bin/sh"
> +
> +void __attribute__((__noreturn__)) exec_shell(void) {
> +	const char *shell = getenv("SHELL");
> +	if (!shell)
> +		shell = DEFAULT_SHELL;
> +	execl(shell, basename(shell), "-i", NULL);
> +	err(EXIT_FAILURE, _("exec %s failed"), shell);
> +}

 Do we really need "-i", for example su(1) uses

     arg0[0] = '-';
     strcpy (arg0 + 1, shell_basename);

     execv (shell, (char **) args);

 see login-utils/su-common.c

 man bash:

   A login shell is one whose first character of argument zero is a -,
   or one started with the --login option.

 Not sure, but I guess that "-basename" as argv[0] is more portable
 solution (it's originally from coreutils, it has to be portable :-).

> +	if (optind < argc)
> +		execvp(argv[optind], argv + optind);
> +	else
> +		exec_shell();
>  
>  	err(EXIT_FAILURE, _("failed to execute %s"), argv[optind]);

 It would be more readable:

   if (optind < argc) {
        execvp(argv[optind], argv + optind);
        err(EXIT_FAILURE, _("failed to execute %s"), argv[optind]);
   }
   exec_shell();

   
   Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

  parent reply	other threads:[~2013-02-13 13:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-08  0:09 [PATCH 1/2] unshare,nsenter: spawn shell by default Zbigniew Jędrzejewski-Szmek
2013-02-08  0:09 ` [PATCH 2/2] nsenter: fix errors in manpage Zbigniew Jędrzejewski-Szmek
2013-02-13 13:52 ` Karel Zak [this message]
2013-02-14  2:05   ` [PATCHv2 1/2] unshare,nsenter: spawn shell by default Zbigniew Jędrzejewski-Szmek
2013-02-14  2:05     ` [PATCHv2 2/2] nsenter: fix errors in manpage Zbigniew Jędrzejewski-Szmek
2013-02-14 13:50       ` Karel Zak
2013-02-14 13:48     ` [PATCHv2 1/2] unshare,nsenter: spawn shell by default Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130213135212.GF7799@x2.net.home \
    --to=kzak@redhat.com \
    --cc=util-linux@vger.kernel.org \
    --cc=zbyszek@in.waw.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox