bug-bash
[Top][All Lists]
Advanced

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

Re: bash exiting session, command substitution, command_not_found_handle


From: Chet Ramey
Subject: Re: bash exiting session, command substitution, command_not_found_handle
Date: Sat, 28 Dec 2013 17:22:00 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

On 12/28/13, 12:48 PM, Pierre Gaston wrote:

>> Running a command that is not found in the background with a handler
>> using  command substitution kills the shell, or the whole session.
>>
>> Here is a test case:
>>
>> $ ( bash -ci 'command_not_found_handle () { printf "$(true)"; };
>> nonexistingcommand &')
>> [1] 4696
>> $ bash: child setpgid (4697 to 4687): Operation not permitted
>>
>> it will sometimes also exit the outer shell, closing the terminal.
>>
>> The following reproducer always exit the outer shell (the handle in this
>> shell, and the options set don't matter):
>>
>> $ (bash -ci 'command_not_founhandle () (:); nonexistingcommand &' )
>>
>> I can reproduce this with 4.3rc1
>>
>>
> Sorry, this last example was bogus, I meant:
> ( bash -ci 'command_not_found_handle { $(:);  }; nonexistingcommand &')

It's a race condition.  The -i creates an interactive shell, which has
job control enabled.  An interactive shell with job control enabled
wants the terminal in its own process group.  When the shell runs the
command_not_found handle, it gives the terminal to its own process group,
effectively stealing it away from the shell that ran the command.  When
that shell tries to read from the terminal, the read returns an error
because the terminal belongs to another process group, and the calling
shell exits.

Chet

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



reply via email to

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