From 38ee19c04b1a7a9f8858d791c68c8a9b711a4e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 23 Sep 2020 12:20:14 +0200 Subject: [PATCH] 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.) --- src/nspawn/nspawn.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index ea5be3f72d..36a2604664 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)