]> git.proxmox.com Git - mirror_lxc.git/commitdiff
lxc-ls: Show a simple error message when non-root
authorStéphane Graber <stgraber@ubuntu.com>
Tue, 4 Dec 2012 21:17:08 +0000 (16:17 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Tue, 4 Dec 2012 22:32:04 +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-ls

index 8a1d1ed883964b47417c23931510d9805c47aed1..2ad1f7f0c3f57c99888091a7c08b6d9be1dc110c 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 re
 import sys
 
@@ -115,6 +116,12 @@ parser.add_argument("filter", metavar='FILTER', type=str, nargs="?",
 
 args = parser.parse_args()
 
+# Basic checks
+## 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])))
+
 # --active is the same as --running --frozen
 if args.active:
     if not args.state: