git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git subcommand sigint gotcha
@ 2010-10-19  4:53 Joey Hess
  2010-10-19  9:55 ` Dmitry Potapov
  0 siblings, 1 reply; 10+ messages in thread
From: Joey Hess @ 2010-10-19  4:53 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 1321 bytes --]

I was trying to write a git subcommand, and I noticed that if I ctrl-c'd
it, git would return, but leave the subcommand running in the
background.

You can see the problem with this test case. 

#!/usr/bin/perl
print "first sleep...\n";
$ret=system("sleep", "1m");
print "second sleep...\n";
system("sleep", "1s");
print "done with second sleep\n";

If you put it in path named git-sleep, then run "git sleep" and press ctrl-c,
it keeps running:

joey@gnu:~>git sleep
first sleep...
^Csecond sleep...
joey@gnu:~>done with second sleep

So what's going on? Well, perl's system() blocks sigint while the child
process is running. So if you run this as git-sleep, and press ctrl-c,
it will continue on to the second sleep. If the code above checked the
return status of system() it could detect that it was killed by SIGINT
and itself exit.

What I don't understand is, why does git not wait() on the subcommand it
ran? Any subcommand that forgets to check exit codes is liable to exhibit
this weird behavior sometimes. 

Ie, imagine the subcommand was running something like 
"git config --get core.bare" instead of sleep. 
It'd be easy to forget to check the exit status of that for a SIGINT; if
the user ctrl-c'd at just the right instant, weird things would happen.

-- 
see shy jo

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 828 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2010-10-19 21:11 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-19  4:53 git subcommand sigint gotcha Joey Hess
2010-10-19  9:55 ` Dmitry Potapov
2010-10-19 11:59   ` RFC: [PATCH] ignore SIGINT&QUIT while waiting for external command Dmitry Potapov
2010-10-19 13:32     ` Jeff King
2010-10-19 13:40       ` Jeff King
2010-10-19 19:16         ` Jonathan Nieder
2010-10-19 19:50           ` Jeff King
2010-10-19 21:06           ` Jakub Narebski
2010-10-19 21:07             ` Jonathan Nieder
2010-10-19 16:31       ` Dmitry Potapov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).