tools: add check to verify that running with root privileges

Add a check to acrnd and acrnctl to make sure we are running with root
privileges. If not, print out a message instructing the user to run with root
privileges and exit returning an error (-1).

Add notes to the documentation as well to make it more obvious.

Tracked-On: #3330
Signed-off-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com>
Reviewed-by: Binbin Wu <binbin.wu@intel.com>
This commit is contained in:
Geoffroy Van Cutsem 2019-06-24 13:43:59 +02:00 committed by wenlingz
parent 4c3f298ed6
commit c64877f519
3 changed files with 17 additions and 0 deletions

View File

@ -35,6 +35,9 @@ You can see the available ``acrnctl`` commands by running:
blkrescan blkrescan
Use acrnctl [cmd] help for details Use acrnctl [cmd] help for details
.. note::
You must run ``acrnctl`` with root privileges.
Here are some usage examples: Here are some usage examples:
Add a VM Add a VM
@ -163,6 +166,9 @@ A ``systemd`` service file (``acrnd.service``) is installed by default that will
start the ``acrnd`` daemon when the Service OS comes up. start the ``acrnd`` daemon when the Service OS comes up.
You can restart/stop acrnd service using ``systemctl`` You can restart/stop acrnd service using ``systemctl``
.. note::
You must run ``acrnd`` with root privileges.
Build and Install Build and Install
***************** *****************

View File

@ -807,6 +807,11 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
if (getuid() != 0) {
printf("Please run acrnctl with root privileges. Exiting.\n");
return -1;
}
acrnctl_bin_path = argv[0]; acrnctl_bin_path = argv[0];
/* first check acrnctl reserved operations */ /* first check acrnctl reserved operations */

View File

@ -734,6 +734,12 @@ int main(int argc, char *argv[])
{ {
int ret; int ret;
if (getuid() != 0) {
printf("Please run acrnd with root privileges. Exiting.\n");
return -1;
}
if (parse_opt(argc, argv)) if (parse_opt(argc, argv))
return -1; return -1;