Daniel Shahaf <d...@daniel.shahaf.name> writes: > This fixes the race I mentioned, but I think we have another problem > here: signum_cancelled is accessed by the signal handler so it must be > of type 'static volatile sig_atomic_t' (C89 ยง4.7.1.1)... but I don't > think anything guarantees that signal numbers are representable as > a sig_atomic_t. On Linux/amd64 and FreeBSD they are, but that need not > be the case everywhere. > > If we can't assume sig_atomic_t is at least as large as an int, I think > we have to use the following roundabout method:
I did something similar in r1729422. This code keeps growing and I'm thinking of moving both the signal handler and cancellation handler to libsvn_subr. We need some storage for the volatiles and using pool memory implies a limited lifetime that interacts badly with the signal handlers so I'm thinking of using static storage in the library. Something like: /* Setup signal handlers and return a cancellation handler. */ svn_cancel_func_t svn_cmdline__setup_cancellation_handler(); /* Return a signal that triggered cancellation or zero if no such signal. */ int svn_cmdline__get_cancelled_signum(); and the application would do: int main() { apr_pool_t *pool; ... SVN_ERR(svn_client_create_context2(&ctx, ..., pool)); ... ctx->cancel_func = svn_cmdline__setup_cancellation_handler(); ... svn_pool_destroy(pool); ... #ifndef WIN32 { int signum = svn_cmdline__get_cancelled_signum(); if (signum) kill(getpid(), signum); } #endif return exit_code; } -- Philip Martin WANdisco