Re: [PATCH v2 1/6] common-main.o: move non-trace2 exit() behavior out of trace2.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ævar Arnfjörð Bjarmason  <avarab@xxxxxxxxx> writes:

> diff --git a/common-main.c b/common-main.c
> index 29fb7452f8a..bb0100f6024 100644
> --- a/common-main.c
> +++ b/common-main.c
> @@ -56,9 +56,24 @@ int main(int argc, const char **argv)
>  	result = cmd_main(argc, argv);
>  
>  	/*
> -	 * We define exit() to call trace2_cmd_exit_fl() in
> -	 * git-compat-util.h. Whether we reach this or exit()
> +	 * We define exit() to call common_exit(), which will in turn
> +	 * call trace2_cmd_exit_fl(). Whether we reach this or exit()
>  	 * elsewhere we'll always run our trace2 exit handler.
>  	 */

I was expecting to see this comment to speak in a more generic terms
(i.e. "after the main processing is done, we clean up after
ourselves, either by exiting cmd_main and coming here or explicitly
calling exit()"), now we have introduced common_exit().

>  	exit(result);
>  }
> +
> +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;

And I expected that the trace2 specific comment, if it is still
needed, would migrate here before this call.

Not huge enough to cause a reroll, but if there are other reasons to
see an updated version, it would be good to fix it while at it.

> +	trace2_cmd_exit_fl(file, line, code);
> +
> +	return code;
> +}

> +/**
> + * The exit() function is defined as common_exit() in
> + * git-compat-util.h.
> + *
> + * Intercepting the exit() allows us to hook in at-exit behavior, such
> + * emitting trace2 logging before calling the real exit().
> + */
> +int common_exit(const char *file, int line, int code);

Nicely explained.

Thanks.




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux