help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Option execfail does not work in subshells


From: Chet Ramey
Subject: Re: [Help-bash] Option execfail does not work in subshells
Date: Wed, 16 Aug 2017 10:56:16 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

On 8/16/17 9:53 AM, David Niklas wrote:

>>>> If this is set, a non-interactive shell will not exit if it cannot 
>>>> execute the file specified as an argument to the exec builtin
>>>> command.   
>>> See the word "file", it's not equivalent to the word "function"[1].  
>>
>> True, but it doesn't matter in this case, since the example does not
>> have exec attempting to execute a shell function. `exec' always treats
>> its argument as an executable file.
> 
> I mean that exec is a builtin which is a C function (I would imagine), and
> is not a program, but a builtin. But that is probably another case
> of reading too much into what was written.

What does this mean? I still don't understand how the fact that exec is a
builtin implemented as a C function affects how it treats its argument.

> 
>>> Notice also that exec could fail for other reasons which are not
>>> listed above but also not covered.  
>>
>> But execfail doesn't cover those. The idea behind execfail is that if
>> execve fails, the shell doesn't exit.
>>
>>>> An interactive shell does not exit if exec fails.  
>>> OTOH, an interactive shell would not exit if, for *any* reason exec
>>> fails.  
>>
>> You're reading too much into it. The only other reasons the builtin
>> would fail is if given an invalid option or if the shell is restricted,
>> and execfail doesn't act on those cases. The shell doesn't exit if
>> those happen.
> 
> What about having incorrect permissions for the file, like read but no
> exec, or exec but no read?
> Or, how about an OOM condition?

That is what I wrote. Those are all reasons for execve(2) to fail:

     [EACCES]           Search permission is denied for a component of the
                        path prefix.

     [EACCES]           The new process file is not an ordinary file.

     [EACCES]           The new process file mode denies execute permission.

     [EACCES]           The new process file is on a filesystem mounted with
                        execution disabled (MNT_NOEXEC in <sys/mount.h>).

                [...]

     [ENOMEM]           The new process requires more virtual memory than is
                        allowed by the imposed maximum (getrlimit(2)).

and so on. These are the cases where execfail has an effect. If you supply
an invalid option to the builtin, the builtin will fail (return a non-zero
status), but the shell will not exit. These are the "other reasons."

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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