Re: [PATCH] Fail like the shell when execvp fails

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

 



On 04/16/2016 11:53 PM, Nir Soffer wrote:
> On Sun, Apr 17, 2016 at 12:42 AM, Nir Soffer <nsoffer@xxxxxxxxxx> wrote:
>> On Sun, Apr 17, 2016 at 12:20 AM, Bernhard Voelker
>> <mail@xxxxxxxxxxxxxxxxxxx> wrote:
>>> On 04/16/2016 07:31 PM, Nir Soffer wrote:
>>>> For example, running the fuser command via taskset when fuser command is
>>>> not installed is failing now like this:
>>>>
>>>>     $ taskset -c 1 fuser /path/to/file; echo $?
>>>>     taskset: failed to execute fuser: No such file or directory
>>>>     1
>>>>
>>>> This failure looks like a real failure of the fuser command:
>>>>
>>>>     $ taskset -c 1 fuser /path/to/file; echo $?
>>>>     Specified filename /path/to/file does not exist.
>>>>     1
>>>>
>>>> Based on the exit code, a management program may do the wrong thing,
>>>> leading to catastrophic results. Detecting such failure requires fragile
>>>> parsing of standard error.
>>>>
>>>> With this patch this failure is easy to detect:
>>>>
>>>>     $ taskset -c 1 fuser /path/to/file; echo $?
>>>>     taskset: failed to execute fuser: No such file or directory
>>>>     127
>>>
>>> TBH I don't like this idea; how would you see from the exit code
>>> that 'taskset' itself wasn't the culprit?  I mean execve()ing
>>> taskset worked, but that tool simply wasn't lucky to execve() the
>>> secondary tool, well.
>>
>> So taskset will exit with 127, which is not an error code you expect from the
>> underlying tool?
>>
>>> So EXIT_FAILURE is the right thing to do IMO,
>>> and it is like that in almost any other - also non-util-linux tools
>>> (chroot, nice, ...).
>>
>> Good examples:
>>
>> $ nice -n 5 bleep 1; echo $?
>> nice: bleep: No such file or directory
>> 127
>>
>> $ sudo chroot /tmp bleep 1; echo $?
>> chroot: failed to run command ‘bleep’: No such file or directory
>> 127
>>
>> This is the behavior I suggest to adapt.
> 
> Looking in coreutils, it is using these exit codes:
> 
> /* Exit statuses for programs like 'env' that exec other programs.  */
> enum
> {
>   EXIT_TIMEDOUT = 124, /* Time expired before child completed.  */
>   EXIT_CANCELED = 125, /* Internal error prior to exec attempt.  */
>   EXIT_CANNOT_INVOKE = 126, /* Program located, but not usable.  */
>   EXIT_ENOENT = 127 /* Could not find program to exec.  */
> };
> 
> So we may adapt this behavior?

Good examples, indeed.  I really should've looked that up myself
before replying, sorry.  Thanks for correcting me.  So your patch
actually makes util-linux more consistent with other tools ...
which is good.

Have a nice day,
Berny
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux