How to abort an time consumming capi callback?

Hi,

As the subject, we have an capi, which might run for a long time.
We want to abort the action when confd_cli user type “ctrl-c”.
How we can achieve that?

Are you referring to /clispec/$MODE/show/callback/capi clispec callback?

As far as I know, only exec callback has interrupt option. See /clispec/$MODE/show/callback/exec/options/interrupt.

As a workaround you can write wrapper application as exec callback (executable binary), which would call functionality you need (e.g. communicating with your application over socket). This could be then interrupted with ctrl-c. Of course, you should also handle this interrupt event (freeing resources, etc.).

Thanks mnovak,
But if we use exec, then we cannot use confd_cli pipe command.
That is why we choose capi.

For a “capi callback”, the thing corresponding to the interrupt option is to implement and register the abort() action callback - see the confd_lib_dp(3) manual page. I’m not 100% sure that this actually works for all the types of “capi callbacks” that can be defined in a clispec, but it should work for those that can be expected to be “long-running”.