Commit daf04e4c by Stéphane Graber

lxc-ls: Show a simple error message when non-root

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: 's avatarStéphane Graber <stgraber@ubuntu.com> Acked-by: 's avatarSerge E. Hallyn <serge.hallyn@ubuntu.com>
parent c0b5f522
...@@ -32,6 +32,7 @@ warnings.filterwarnings("ignore", "The python-lxc API isn't yet stable") ...@@ -32,6 +32,7 @@ warnings.filterwarnings("ignore", "The python-lxc API isn't yet stable")
import argparse import argparse
import gettext import gettext
import lxc import lxc
import os
import re import re
import sys import sys
...@@ -115,6 +116,12 @@ parser.add_argument("filter", metavar='FILTER', type=str, nargs="?", ...@@ -115,6 +116,12 @@ parser.add_argument("filter", metavar='FILTER', type=str, nargs="?",
args = parser.parse_args() 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 # --active is the same as --running --frozen
if args.active: if args.active:
if not args.state: if not args.state:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment