I'm implementing a Reboot() call in my application. It's an embedded application, so no console, keyboard or power switch. The Reboot() must eventually restart the system no matter what. Ideally, I want it to fail gracefully.
I've had systems in the past cause problems where a call to reboot
or shutdown
did not result in a reboot of the machine. e.g. failure to sync drives, unmount a removed USB flash drive.
My system is embedded, with a read-only mounted root filing system, so a sudden power off isn't a big issue. But I do write logs to a Flash disc and I'd like to preserve this as much as possible.
My current Reboot() looks like this:
void Reboot()
{
system( "reboot" ); // try the reboot
sleep(2);
system( "reboot -f" ); // force
sleep(2);
system( "reboot -f -n" ); // force and don't try to sync
sleep(2);
system( "kill 1" ); // process 1 is the root process of all
sleep(2);
Reset();
}
The reset command is a hard system reset that will not fail. The system also has a Watchdog timer.
Would people care to comment on anything to add/replace/change in my Reboot() function?
e.g. should I use Magic SysRq?