From: Zbigniew Jędrzejewski-Szmek Date: Wed, 23 Sep 2020 10:20:14 +0000 (+0200) Subject: nspawn: give better message when invoked as non-root without arguments X-Git-Tag: v247-rc1~138^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=38ee19c04b1a7a9f8858d791c68c8a9b711a4e3d;p=thirdparty%2Fsystemd.git nspawn: give better message when invoked as non-root without arguments When invoked as non-root, we would suggest re-running as root without any further hint. But this immediately spawns a machine from the local directory, which can be rather surprising. So let's give a better hint. (In general, I don't think commandline programs should do "significant" things when invoked without any arguments. In this regard it would be better if systemd-nspawn would not spawn a machine from the current directory if called with no arguments and at least "-D ." would be required.) --- diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index ea5be3f72da..36a26046641 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -5134,9 +5134,12 @@ static int run(int argc, char *argv[]) { if (r <= 0) goto finish; - r = must_be_root(); - if (r < 0) + if (geteuid() != 0) { + r = log_warning_errno(SYNTHETIC_ERRNO(EPERM), + argc >= 2 ? "Need to be root." : + "Need to be root (and some arguments are usually required).\nHint: try --help"); goto finish; + } r = cant_be_in_netns(); if (r < 0)