Can not make graceful exit (C-API) program

Discussions about RaZberry - Z-Wave board for Raspberry computer
Post Reply
whipped
Posts: 2
Joined: 14 Sep 2018 19:42

Can not make graceful exit (C-API) program

Post by whipped » 14 Sep 2018 20:24

Hello

I am using z-way libzway API quite successfully in my C application it
seems to be quite robust as is.
However the exit - I cannot make it cleanly.
The app (service) is terminated by a signal SIGINT, SIGHUP or SIGTERM
launcing ShutdownHandler
The ShutdownHandler calls for zway_stop(zway) & zway_terminate(&zway)
but either one is re-calling the ShutdownHandler again and this leads into
endless loop so the service never stops.
I do have several zdata_add_callback_ex() "threads"in the program but trying to cancel/free them
(before zway_stop() in ShutdownHandler) with zdata_remove_callback_ex() does
return something else than 'NoError'
I do have to go throug ShutdownHandler as the other parts of the software needs cleaning also.

User avatar
PoltoS
Posts: 4251
Joined: 26 Jan 2011 19:36

Re: Can not make graceful exit (C-API) program

Post by PoltoS » 15 Sep 2018 21:20

  • zway_stop is stopping the Z-Way thread (opposite to zway_start)
  • zway_terminate is freeing zway structure (opposite to zway_init) - it calls zway_stop internally before freeing
The termination_callback is called on Z-Way thread stop, so on both cases. But in this callback function you don't need to call zway_stop or zway_terminate - this callback is for you to trap Z-Way thread termination.

whipped
Posts: 2
Joined: 14 Sep 2018 19:42

Re: Can not make graceful exit (C-API) program

Post by whipped » 17 Sep 2018 16:18

Great,
Thanks for pointing the direction - got it now.

Post Reply