How can my C/C++ application determine if the root user is executing the command?

前端 未结 4 1160
借酒劲吻你
借酒劲吻你 2021-01-05 11:34

I am writing an application that requires root user privileges to execute. If executed by a non root user, it exits and terminates with a perror message such as:

<         


        
4条回答
  •  無奈伤痛
    2021-01-05 11:57

    What you really want to check for is if you have the right capability set (CAP_SYS_NICE I think is the capability you need) see man pages capabilities (7) and capget (2) this way it won't error out if you have the ability to do what you want, but you aren't root.

提交回复
热议问题