How can I use ctrl + c to stop a long lead CLISpec command?


How can I use ctrl + c to stop a long lead CLISpec command which has a “cmdpoint”?

Harry Huang

You need to properly implement and register the action abort() callback, see the confd_lib_dp(3) man page.

Hi Per,

Our experience is that abort() will not be triggered by ctrl + c.

Is there any switch on that?

Harry Huang

No, there is no switch for that - in fact the CLI (indirectly) uses the presence of the abort() registration to enable interrupt via ctrl-c, otherwise it is just ignored. And it will result in invocation of abort(), unless there is a bug (unlikely) or you’re doing something wrong. Note what the documentation says, abort() is invoked on the control socket (since the worker socket is “tied up” with the invocation of the command() callback) - thus your application must of course poll the control socket and be prepared to invoke confd_fd_ready() even while the actual command is running.

This is not possible if your application has the simple structure that most of the ConfD examples do, a single thread and callbacks that always run to completion. The intro/7-c_actions has a “toy” demonstration of abort() for /config/system/abort-test, where the action() callback just never completes, due to returning CONFD_DELAYED_RESPONSE but never giving the actual reply. This approach (but of course giving the reply when done:-) can be used if the actual work of the command is done in a separate process, and the “main” process gets informed when it completes. The alternative is to use threads, as shown in the intro/9-c_threads example for /dm/sleep.

Neither of the examples show invocation via clispec (i.e. /clispec/$MODE/cmd/callback/capi/cmdpoint), though, but it should work the same except that command() is invoked instead of action().