Scenario:
My C++ application runs on embedded linux Fedora on an iMX processor. It is an application which runs in user mode with no root access.
I need to run a system command which can reboot the system/OS. The command that works from C++ is something like below.
system("shutdown -r now");
Problem:
But above command works only when executed from an app having root access.
Also at times I need to be able to shutdown the system in a similar way.
system("shutdown now");
Above command obviously does not work because my app does not have root access. Adding a sudo like this [system("shutdown -r now")
] works but have to enter password which is not what I wish to do.
Question:
How can I enable my app to run a system command to reboot even if it is an user mode app? Are there any ways to do it without making my app run from root?
Is there something in the linux source or scripts I can tweak to provide only my app with privileges to shutdown and reboot the system?