[lxc-devel] [PATCH 2/3] lxc-ls: Show a simple error message when non-root
Stéphane Graber
stgraber at ubuntu.com
Tue Dec 4 21:17:08 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-ls | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/lxc/lxc-ls b/src/lxc/lxc-ls
index 8a1d1ed..2ad1f7f 100644
--- a/src/lxc/lxc-ls
+++ b/src/lxc/lxc-ls
@@ -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:
--
1.8.0
More information about the lxc-devel
mailing list