Josh Steadmon <steadmon@xxxxxxxxxx> writes: > diff --git a/common-exit.c b/common-exit.c > new file mode 100644 > index 0000000000..1aaa538be3 > --- /dev/null > +++ b/common-exit.c > @@ -0,0 +1,26 @@ > +#include "git-compat-util.h" > +#include "trace2.h" > + > +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()"); > +} Nice that this can stay file-scope static. > +/* We wrap exit() to call common_exit() in git-compat-util.h */ > +int common_exit(const char *file, int line, int code) > +{ > + /* > + * 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". > + */ > + code &= 0xff; > + > + check_bug_if_BUG(); > + trace2_cmd_exit_fl(file, line, code); > + > + return code; > +} I wonder if at least the part that primes the trace2 system needs to also be split out of the file that defines our own main(), though. Are libgit.a users now responsible for calling things like trace2_initialize_clock(), trace2_initialize(), etc., themselves? I am wondering if these calls are encapsulated into a simple helper function, say common_startup(), then the story we need to tell the libgit.a users may become simpler, i.e. you call common_startup, do your things, and then you somehow cause common_exit() to be called.