In Windows, the function InitiateSystemShutdown can shutdown or reboot the system. In linux, we can achive this with shutdown or reboot command running as root or sudo.
However, when we pass such commands in linux, all the processes stop working.
I am currently porting my source code from windows to linux. and InitiateSystemShutdown system call is written an API, which is called by some modules.
InitiateSystemShutdown system calls returns status to caller and caller can take the action on the same.
In linux, if shutdown or reboot commands fails, then my caller will get the status.
1) How I can pass time parameter in shutdown or linux command. The parameter required in seconds. e.g. 5 seconds.
2) Is there any check to know whether I have authority to shutdown / reboot the system. So that based on that authority I can return some status to caller
The parameter passed to InitiateSystemShutdown functions are
BOOL WINAPI InitiateSystemShutdown(
__in_opt LPTSTR lpMachineName,
__in_opt LPTSTR lpMessage,
__in DWORD dwTimeout,
__in BOOL bForceAppsClosed,
__in BOOL bRebootAfterShutdown
lpMachineName [in, optional]
The network name of the computer to be shut down. If lpMachineName is NULL or an empty string, the function shuts down the local computer.
lpMessage [in, optional]
The message to be displayed in the shutdown dialog box. This parameter can be NULL if no message is required.
The length of time that the shutdown dialog box should be displayed, in seconds. While this dialog box is displayed, the shutdown can be stopped by the AbortSystemShutdown function.
If dwTimeout is not zero, InitiateSystemShutdown displays a dialog box on the specified computer. The dialog box displays the name of the user who called the function, displays the message specified by the lpMessage parameter, and prompts the user to log off. The dialog box beeps when it is created and remains on top of other windows in the system. The dialog box can be moved but not closed. A timer counts down the remaining time before a forced shutdown.
If dwTimeout is zero, the computer shuts down without displaying the dialog box, and the shutdown cannot be stopped by AbortSystemShutdown.
If this parameter is TRUE, applications with unsaved changes are to be forcibly closed. Note that this can result in data loss.
If this parameter is FALSE, the system displays a dialog box instructing the user to close the applications.
If this parameter is TRUE, the computer is to restart immediately after shutting down. If this parameter is FALSE, the system flushes all caches to disk and safely powers down the system.
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.