]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc-device: Show an error message when non-root
authorStéphane Graber <stgraber@ubuntu.com>
Tue, 4 Dec 2012 21:17:09 +0000 (16:17 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Tue, 4 Dec 2012 22:32:08 +0000 (17:32 -0500)
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@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxc-device

index 6c91e67fb9321d7ab76c5ec1af8cfe1f110db0fe..467df17c09eac545ce985eeea7af1b02337958b2 100644 (file)
@@ -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.")