[lxc-devel] [PATCH 3/3] lxc-device: Show an error message when non-root
Serge Hallyn
serge.hallyn at canonical.com
Tue Dec 4 21:36:34 UTC 2012
Quoting Stéphane Graber (stgraber at ubuntu.com):
> 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>
Acked-by: Serge E. Hallyn <serge.hallyn 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
>
>
> ------------------------------------------------------------------------------
> LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
> Remotely access PCs and mobile devices and provide instant support
> Improve your efficiency, and focus on delivering more value-add services
> Discover what IT Professionals Know. Rescue delivers
> http://p.sf.net/sfu/logmein_12329d2d
> _______________________________________________
> Lxc-devel mailing list
> Lxc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel
More information about the lxc-devel
mailing list