You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Philip Martin <ph...@wandisco.com> on 2016/02/09 19:19:02 UTC

Moving cancellation support to libsvn_subr

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

Re: Moving cancellation support to libsvn_subr

Posted by Daniel Shahaf <d....@daniel.shahaf.name>.
Philip Martin wrote on Tue, Feb 09, 2016 at 18:19:02 +0000:
> 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();

For future reference, Philip implemented that in r1729463.