git/list[1] front-page[2] threads[3] people[4] search[5] about
 

RE: t5570 trap use in start/stop_git_daemon

From
Randall S. Becker <rsbecker@nexbridge.com>
Date
Feb 13, 2015, 12:27 UTC
Message-ID
<019d01d04788$5e923970$1bb6ac50$@nexbridge.com>
In-Reply-To
<loom.20150213T094712-477@post.gmane.org>
On 2015/02/13 3:58AM Joachim Schmitz wrote:
Show 37 quoted lines
>Jeff King <peff <at> peff.net> writes:
> > On Fri, Feb 13, 2015 at 02:44:03AM -0500, Jeff King wrote:
> > On Thu, Feb 12, 2015 at 03:31:12PM -0500, Randall S. Becker wrote:
> > 
><snip> 
>> Hmm, today I learned something new about ksh. Apparently when you use
>> the "function" keyword to define a function like:
>> 
>>   function foo {
>>     trap 'echo trapped' EXIT
>>   }
>>   echo before
>>   foo
>>   echo after
>> 
>> then the trap runs when the function exits! If you declare the same
>> function as:
>> 
>>   foo() {
>>     trap 'echo trapped' EXIT
>>   }
>> 
>> it behaves differently. POSIX shell does not have the function keyword,
>> of course, and we are not using it here. Bash _does_ have the function
>> keyword, but seems to behave POSIX-y even when it is present. I.e.,
>> running the first script:
>> 
>>   $ ksh foo.sh
>>   before
>>   trapped
>>   after
>> 
>>   $ bash foo.sh
> >  before
>>   after
> >  trapped
>> 
<snip>
Show 21 quoted lines
>Both versions produce your first output on our platform
>$ ksh foo1.sh
>before
>trapped
>after
>$ bash foo1.sh
>before
>after
>trapped
>$ ksh foo2.sh
>before
>trapped
>after
>$ bash foo2.sh
>before
>after
>trapped
>$
>This might have been one (or even _the_) reason why we picked bash as our 
>SHELL_PATH in config.mak.uname (I don't remember, it's more than 2 years 
>ago), not sure which shell Randall's test used?

I tested both for trying to get t5570 to work. No matter which, without resetting the trap, function return would kill the git-daemon and the test would fail.

Previous: Joachim Schmitz
Message 5 of 5 in “t5570 trap use in start/stop_git_daemon”
  1. Randall S. BeckerFeb 12, 2015
  2. Jeff KingFeb 13, 2015
  3. Jeff KingFeb 13, 2015
  4. Joachim SchmitzFeb 13, 2015
  5. Randall S. BeckerFeb 13, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.