bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Should this be this way?


From: Linda Walsh
Subject: Re: Should this be this way?
Date: Tue, 26 Feb 2013 12:39:08 -0800
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.24) Gecko/20100228 Lightning/0.9 Thunderbird/2.0.0.24 Mnenhy/0.7.6.666


Chet Ramey wrote:
> On 2/26/13 12:41 AM, Linda Walsh wrote:
> 
>>      It isn't using the current value of SHELL as my shell nor the value
>> of my login shell.
> 
> It uses $0 (or, rather, the basename of $0), which is initialized from
> the parent shell's argv[0].  What is $0 set to?

"-bash"

> 
>>      It is forcing interpretation into /bin/sh, which I don't use.
> 
> Not quite.  It is enabling posix mode.  There are a couple of ways to
> do that: $POSIXLY_CORRECT, $0 == "sh", or set -o posix.
---
Not doing either of those here...

I do have "MAN_POSIXLY_CORRECT" so man only gives me 1 man page followed
by the section numbers of other man pages, as opposed to acting like
'less' with multiple files (i.e. next to go to next page)...

But I don't see anything that would suggest to to bash to flip into shell.

The code that the original poster pointed me at doesn't appear to
have a check for what shell it was invoked as (or what is in $0).
It seems to go off the fact that line 0 didn't have an interpreter
line specified...

I.e., what I see is:

#next line is #5033
  /* Is this supposed to be an executable script?
     If so, the format of the line is "#! interpreter [argument]".
     A single argument is allowed.  The BSD kernel restricts
     the length of the entire line to 32 characters (32 bytes
     being the size of the BSD exec header), but we allow 80
     characters. */
  if (sample_len > 0)
    {
#if !defined (HAVE_HASH_BANG_EXEC)
      if (sample_len > 2 && sample[0] == '#' && sample[1] == '!')
        return (execute_shell_script (sample, sample_len, command, args, env));
      else
#endif
      if (check_binary_file (sample, sample_len))
        {
          internal_error (_("%s: cannot execute binary file"), command);
          return (EX_BINARY_FILE);
        }
    }

  /* We have committed to attempting to execute the contents of this file
     as shell commands. */

#if 1                                         <---------------Note problem??
(SuSE ism?)
  larray = strvec_len(args) + 1;
  args = strvec_resize(args, larray + 1);

  for (i = larray - 1; i; i--)
    args[i] = args[i - 1];

  args[0] = savestring(_PATH_BSHELL);
  args[1] = command;
  args[larray] = (char *)0;

  SETOSTYPE (0);                /* Some systems use for USG/POSIX semantics */
  execve ("/bin/sh", args, env);
  SETOSTYPE (1);

  internal_error (_("%s: cannot execute: %s"), command, strerror (errno));
#else
  initialize_subshell ();

  set_sigint_handler ();

  /* Insert the name of this shell into the argument list. */
  larray = strvec_len (args) + 1;
  args = strvec_resize (args, larray + 1);

  for (i = larray - 1; i; i--)
    args[i] = args[i - 1];

  args[0] = shell_name;
  args[1] = command;
  args[larray] = (char *)NULL;

  if (args[0][0] == '-')
    args[0]++;

#if defined (RESTRICTED_SHELL)
  if (restricted)
    change_flag ('r', FLAG_OFF);
#endif

  if (subshell_argv)
    {
      /* Can't free subshell_argv[0]; that is shell_name. */
      for (i = 1; i < subshell_argc; i++)
        free (subshell_argv[i]);
      free (subshell_argv);
    }

  dispose_command (currently_executing_command);        /* XXX */
  currently_executing_command = (COMMAND *)NULL;

  subshell_argc = larray;
  subshell_argv = args;
  subshell_envp = env;

  unbind_args ();       /* remove the positional parameters */

  longjmp (subshell_top_level, 1);
  /*NOTREACHED*/
#endif
  return (EX_NOEXEC);
}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]