Git.pm: allow command_close_bidi_pipe to be called as method
[gitweb.git] / editor.c
index 842f7829fc3a80850fd60b274bfb024b2ada130e..27bdecdaf3d99d3179737e07be971d2458408660 100644 (file)
--- a/editor.c
+++ b/editor.c
@@ -1,6 +1,7 @@
 #include "cache.h"
 #include "strbuf.h"
 #include "run-command.h"
+#include "sigchain.h"
 
 #ifndef DEFAULT_EDITOR
 #define DEFAULT_EDITOR "vi"
@@ -38,6 +39,7 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
        if (strcmp(editor, ":")) {
                const char *args[] = { editor, path, NULL };
                struct child_process p;
+               int ret, sig;
 
                memset(&p, 0, sizeof(p));
                p.argv = args;
@@ -46,7 +48,15 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
                if (start_command(&p) < 0)
                        return error("unable to start editor '%s'", editor);
 
-               if (finish_command(&p))
+               sigchain_push(SIGINT, SIG_IGN);
+               sigchain_push(SIGQUIT, SIG_IGN);
+               ret = finish_command(&p);
+               sig = ret - 128;
+               sigchain_pop(SIGINT);
+               sigchain_pop(SIGQUIT);
+               if (sig == SIGINT || sig == SIGQUIT)
+                       raise(sig);
+               if (ret)
                        return error("There was a problem with the editor '%s'.",
                                        editor);
        }