This question has been asked before: How to restart Linux from inside a C++ program?
However, none of the answers seem to work for me.
Here's my problem:
I have a program on a piece of hardware. I can log in as root and run it without any issues. However, if I login as a different user with root priveleges, the program executes fine but does not reboot as it should. It only shuts down the current Telnet session.
To reboot, I've used system(reboot)
.
So far I have tried:
sync();
reboot(RB_POWER_OFF);
And
execl("/sbin/reboot","reboot",NULL,NULL);
to no avail.
(I'm not sure, if I've used execl
correctly. It is the first time I use it. Please correct me if I messed up).
Any help would be appreciated.
Edit:
/data/local/sbin # cat /etc/passwd
root:x:0:0:root:/root:/bin/sh
service:54zljpSAe:0:0:root:/root:/data/local/sbin/script
if I login as service, "script" will be run. The user has a list options to choose from. One of the options is to run the above mentioned program.
Edit:
Also worth mentioning: One of the options in the script is to reboot the system. If called from inside the script, it works. But I would like to call reboot from the program.
first of all, login to your system as "a different user with root priveleges", and execute 'init 6', if system had been restarted ?
yes: use system("init 6"); in your program.
no: you have security issue, first you have to fix that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With