Move check for root to Go

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
This commit is contained in:
Stéphane Graber 2018-02-20 02:14:23 -05:00
parent ce823c03c1
commit 2538b49e07
No known key found for this signature in database
GPG Key ID: C638974D64792D67

View File

@ -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)