Function on_shutdown | Tarantool
Reference C API reference Function on_shutdown

Function on_shutdown

int box_on_shutdown(void *arg, int (*new_handler)(void*), int (*old_handler)(void*))

Register and/or deregister an on_shutdown function.

Parameters:
  • arg (void*) – Pointer to an area that the new handler can use
  • new_handler (function*) – Pointer to a function which will be registered, or NULL
  • old_handler (function*) – Pointer to a function which will be deregistered, or NULL
Returns:

status of operation. 0 - success, -1 - failure

Return type:

int

A function which is registered will be called when the Tarantool instance shuts down. This is functionally similar to what box.ctl.on_shutdown does.

If there are several on_shutdown functions, the Tarantool instance will call them in reverse order of registration, that is, it will call the last-registered function first.

Typically a module developer will register an on_shutdown function that does whatever cleanup work the module requires, and then returns control to the Tarantool instance. Such an on_shutdown function should be fast, or should use an asynchronous waiting mechanism (for example coio_wait).

Possible errors: old_handler does not exist (errno = EINVAL), new_handler and old_handler are both NULL (errno = EINVAL), memory allocation fails (errno = ENOMEM).

Example: if the C API .c program contains a function int on_shutdown_function(void *arg) {printf("Bye!\n");return 0; } and later, in the function which the instance calls, contains a line box_on_shutdown(NULL, on_shutdown_function, NULL); then, if all goes well, when the instance shuts down, it will display “Bye!”.

Added in version 2.8.1.

Found what you were looking for?
Feedback