How to restart Linux from inside a C++ program?

后端 未结 7 1830
天涯浪人
天涯浪人 2021-02-07 08:59

I have a Qt 4 GUI where I need to have a option in a drop-down menu that allows the user to choose to restart the computer. I realize this might seem redunant with the ability t

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-07 09:39

    suid-ing shell scripts is just dangerous as already mentioned (which is why that didn't work).

    I suspect that suid-ing the binary doesn't work because system spawns its subprocess with the user's actual uid and not the suid one, again for security reasons (it would let you substitute any binary for the one being called and run it as root).

    You could put a copy of reboot in a location protected such that only users you want have permission to can execute it, and then suid-root THAT.

    Alternately give them sudoer privilege to execute JUST the command you care about and system out to something like "ksh -c 'sudo reboot'"

提交回复
热议问题