Skip to content

Commit c64877f

Browse files
Geoffroy Van Cutsemwenlingz
authored andcommitted
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>
1 parent 4c3f298 commit c64877f

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

tools/acrn-manager/README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ You can see the available ``acrnctl`` commands by running:
3535
blkrescan
3636
Use acrnctl [cmd] help for details
3737
38+
.. note::
39+
You must run ``acrnctl`` with root privileges.
40+
3841
Here are some usage examples:
3942

4043
Add a VM
@@ -163,6 +166,9 @@ A ``systemd`` service file (``acrnd.service``) is installed by default that will
163166
start the ``acrnd`` daemon when the Service OS comes up.
164167
You can restart/stop acrnd service using ``systemctl``
165168

169+
.. note::
170+
You must run ``acrnd`` with root privileges.
171+
166172
Build and Install
167173
*****************
168174

tools/acrn-manager/acrnctl.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,11 @@ int main(int argc, char *argv[])
807807
return 0;
808808
}
809809

810+
if (getuid() != 0) {
811+
printf("Please run acrnctl with root privileges. Exiting.\n");
812+
return -1;
813+
}
814+
810815
acrnctl_bin_path = argv[0];
811816

812817
/* first check acrnctl reserved operations */

tools/acrn-manager/acrnd.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,12 @@ int main(int argc, char *argv[])
734734
{
735735
int ret;
736736

737+
if (getuid() != 0) {
738+
printf("Please run acrnd with root privileges. Exiting.\n");
739+
return -1;
740+
}
741+
742+
737743
if (parse_opt(argc, argv))
738744
return -1;
739745

0 commit comments

Comments
 (0)