]> git.ipfire.org Git - thirdparty/git.git/blobdiff - common-main.c
gc: use temporary file for editing crontab
[thirdparty/git.git] / common-main.c
index 29fb7452f8a0b78cf7784ee4a1af7b26ebb53379..c531372f3ff0f13839a2056568cbaa7fd37f98a8 100644 (file)
@@ -55,10 +55,30 @@ int main(int argc, const char **argv)
 
        result = cmd_main(argc, argv);
 
+       /* Not exit(3), but a wrapper calling our common_exit() */
+       exit(result);
+}
+
+static void check_bug_if_BUG(void)
+{
+       if (!bug_called_must_BUG)
+               return;
+       BUG("on exit(): had bug() call(s) in this process without explicit BUG_if_bug()");
+}
+
+/* We wrap exit() to call common_exit() in git-compat-util.h */
+int common_exit(const char *file, int line, int code)
+{
        /*
-        * We define exit() to call trace2_cmd_exit_fl() in
-        * git-compat-util.h. Whether we reach this or exit()
-        * elsewhere we'll always run our trace2 exit handler.
+        * For non-POSIX systems: Take the lowest 8 bits of the "code"
+        * to e.g. turn -1 into 255. On a POSIX system this is
+        * redundant, see exit(3) and wait(2), but as it doesn't harm
+        * anything there we don't need to guard this with an "ifdef".
         */
-       exit(result);
+       code &= 0xff;
+
+       check_bug_if_BUG();
+       trace2_cmd_exit_fl(file, line, code);
+
+       return code;
 }