[Piglit] [PATCH] Use _exit() instead of exit() in child processes

Ian Romanick idr at freedesktop.org
Wed Jun 6 17:34:32 UTC 2018


On 06/06/2018 02:43 AM, Michel Dänzer wrote:
> From: Michel Dänzer <michel.daenzer at amd.com>
> 
> A child process which doesn't call exec() shouldn't use exit(), as that
> will attempt to run any atexit handlers of the parent, which may break.

I did not know that.  The manual page for exit does say, "All functions
registered with atexit(3) and on_exit(3) are  called, in the reverse
order of their registration."  But you also have to read the atexit
page, which says, "When  a child process is created via fork(2), it
inherits copies of its parent's registrations.  Upon a successful call
to one of the exec(3) functions, all registrations are removed."

So... what happens if after fork the child process calls atexit?  That
handler will be registered in the child only, and calling _exit will
skip it.  It's almost like these interfaces aren't very good. :(  It
seems like what you would want is a function the child could call to
unregister all previously registered atexit functions.

Boo.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

> It actually results in crashing with the Mesa radeonsi driver.
> 
> Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
> ---
>  .../spec/glx_ext_import_context/import-context-multi-process.c  | 2 +-
>  tests/spec/glx_ext_import_context/make-current-multi-process.c  | 2 +-
>  tests/spec/glx_ext_import_context/make-current-single-process.c | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/tests/spec/glx_ext_import_context/import-context-multi-process.c b/tests/spec/glx_ext_import_context/import-context-multi-process.c
> index 5f758d6a8..3d4ab9c91 100644
> --- a/tests/spec/glx_ext_import_context/import-context-multi-process.c
> +++ b/tests/spec/glx_ext_import_context/import-context-multi-process.c
> @@ -50,7 +50,7 @@ int main(int argc, char **argv)
>  		pass = try_import_context(0xDEADBEEF, invalid)
>  			&& pass;
>  
> -		exit(pass ? 0 : 1);
> +		_exit(pass ? 0 : 1);
>  	}
>  
>  	/* The test passes if the child exited normally with a return value of
> diff --git a/tests/spec/glx_ext_import_context/make-current-multi-process.c b/tests/spec/glx_ext_import_context/make-current-multi-process.c
> index 0f88eaf97..23e50715f 100644
> --- a/tests/spec/glx_ext_import_context/make-current-multi-process.c
> +++ b/tests/spec/glx_ext_import_context/make-current-multi-process.c
> @@ -62,7 +62,7 @@ int main(int argc, char **argv)
>  		XSync(dpy, 0);
>  		pass = validate_glx_error_code(BadAccess, -1);
>  
> -		exit(pass ? 0 : 1);
> +		_exit(pass ? 0 : 1);
>  	}
>  
>  	/* The test passes if the child exited normally with a return value of
> diff --git a/tests/spec/glx_ext_import_context/make-current-single-process.c b/tests/spec/glx_ext_import_context/make-current-single-process.c
> index 0475f4446..d8734032f 100644
> --- a/tests/spec/glx_ext_import_context/make-current-single-process.c
> +++ b/tests/spec/glx_ext_import_context/make-current-single-process.c
> @@ -52,7 +52,7 @@ int main(int argc, char **argv)
>  		XSync(dpy, 0);
>  		pass = validate_glx_error_code(Success, -1);
>  
> -		exit(pass ? 0 : 1);
> +		_exit(pass ? 0 : 1);
>  	}
>  
>  	/* The test passes if the child exited normally with a return value of
> 



More information about the Piglit mailing list