From 2538b49e07de6c094f8e2c8f4d970bc0c1c9d84e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= Date: Tue, 20 Feb 2018 02:14:23 -0500 Subject: [PATCH] Move check for root to Go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber --- distrobuilder/main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/distrobuilder/main.go b/distrobuilder/main.go index ac04290..3ee81aa 100644 --- a/distrobuilder/main.go +++ b/distrobuilder/main.go @@ -16,8 +16,7 @@ __attribute__((constructor)) void init(void) { int ret; if (geteuid() != 0) { - fprintf(stderr, "Need to run as root\n"); - _exit(1); + return; } // Unshare a new mntns so our mounts don't leak @@ -130,6 +129,11 @@ func run(c *cli.Context) error { arch string ) + // Sanity checks + if os.Geteuid() != 0 { + return fmt.Errorf("You must be root to run this tool") + } + os.RemoveAll(c.GlobalString("cache-dir")) os.MkdirAll(c.GlobalString("cache-dir"), 0755)