[lxc-devel] [PATCH 3/3] lxc-device: Show an error message when non-root
Stéphane Graber
stgraber at ubuntu.com
Tue Dec 4 21:17:09 UTC 2012
Instead of returning a python stacktrace, check what the current euid is
and show an argparse error message similar to that used in lxc-start-ephemeral.
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
src/lxc/lxc-device | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/lxc/lxc-device b/src/lxc/lxc-device
index 6c91e67..467df17 100644
--- a/src/lxc/lxc-device
+++ b/src/lxc/lxc-device
@@ -32,6 +32,7 @@ warnings.filterwarnings("ignore", "The python-lxc API isn't yet stable")
import argparse
import gettext
import lxc
+import os
import sys
_ = gettext.gettext
@@ -49,6 +50,11 @@ parser.add_argument("--add", action="append", default=[], metavar="DEVICE",
args = parser.parse_args()
+# The user needs to be uid 0
+if not os.geteuid() == 0:
+ parser.error(_("You must be root to run this script. Try running: sudo %s"
+ % (sys.argv[0])))
+
container = lxc.Container(args.container)
if not container.running:
print("The container must be running.")
--
1.8.0
More information about the lxc-devel
mailing list