Shut down the system
#include <sys/shutdown.h> void shutdown_system( int type, int flags ); void shutdown_system_with_reason( int type, int flags, char *reason );
The shutdown_system() function reboots or shuts down the system. In order to use this function, your process needs to have these abilities enabled:
For more information, see procmgr_ability().
Depending on the type argument, shutdown_system() does the following:
export BOARD_SHUTDOWN_DLL=/some/path/my_shutdown_dll.so
If you don't set the environment variable, shutdown_system() tries to open shutdown-hardware.so, where hardware is the value of the machine member of the utsname structure obtained from uname(). If you provide this DLL, it must be in one of the directories that dlopen() searches.
The synopsis of the preshutdown function is as follows:
void board_pre_shutdown( int type );
The argument is the type argument passed to shutdown_system().
The interval between the SIGTERM and SIGKILL signals allows processes that have elected to catch the SIGTERM signal to perform any cleanup they need to do before the system is rebooted. The SIGCONT allows a stopped process to be terminated by the queued SIGTERM or the subsequent SIGKILL.
void board_shutdown( int type );
The argument is the type argument passed to shutdown_system(). You can use this function to shut down or reboot the board, depending on the type argument.
(QNX Neutrino 7.0 or later) The shutdown_system_with_reason() function is similar to shutdown_system(), but it first saves the given reason by loading a user-provided, board-specific DLL called shutdown_nvram.so, and then calling a function in the DLL:
void save_reset_info_to_nv( int type, char *reason );
This function should store the information in stable storage for later retrieval.
You can customize shutdown_system() by providing your own callouts to override those in the library (which is what the shutdown utility does):
You can define your callouts in the same file as your call to shutdown_system() or put them in a library that you link against before libshutdown.a.
ProcessClass_t shutdown_classify( ProcessInfo_t const *pip );
This callout determines the class of an application, based on the information provided in the structure that pip points to. The shutdown_system() function recognizes some applications by their name or other information, and calls shutdown_classify() to determine the type of applications that it doesn't recognize.
The ProcessInfo_t structure includes various fields, but only the following are set when this callout is invoked:
The shutdown_classify() callout should return one of the defined class types:
The default stub unconditionally returns CLASS_UNKNOWN.
void shutdown_display( int type, DisplayData_t const *display);
This callout can display the name of a process or class of processes being shut down, depending on the type argument:
The default stub does nothing.
The DisplayData_t structure provides information about what's currently being shut down. It's defined as follows:
typedef union { int proc_class; /* use for DISPLAY_CLASS */ char const *proc_name; /* use for DISPLAY_PROC */ } DisplayData_t;
The proc_class member is one of the class types that shutdown_classify() returns.
void shutdown_done( int type );
This callout is called before shutting down the display processes, but after shutting down the rest. The type argument is the typed passed to shutdown_system().
The default stub does nothing.
void shutdown_error( char const *msg );
The library invokes this callout if an error has occurred; the library exits, indicating a failure, after issuing this callout. The default stub does nothing.
void shutdown_process(void);
This callout is called to process intermediate events during the shutdown. The default stub does nothing.
void shutdown_progress( int done, int total );
This callout is called to display the progress being made at shutting down. The done argument indicates the number of processes already shut down, out of the given total.
The default stub does nothing.
int shutdown_prompt(char const *name,pid_t pid);
This callout is called to deal with a process that isn't responding. It should return one of the following to indicate to the library how to deal with the errant process:
The default stub returns PROMPT_SKIP.
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | No |
Thread | No |