The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/distrobuilder/pull/90
This e-mail was sent by the LXC bot, direct replies will not reach the author unless they happen to be subscribed to this list. === Description (from pull-request) === Just have a PersistentPreRun hook for cobra isn't enough, because right before the app.Execute() we call ioutil.TempDir, which tries to create a new distrory under /var/cache, so it fails as bellow: distrobuilder help Failed to create cache directory: mkdir /var/cache/distrobuilder.685166231: permission denied By moving the check for root user as the first thing distrobuilder does solves the problem. Signed-off-by: Marcos Paulo de Souza <marcos.souza....@gmail.com>
From be0540af614bb4fcc0c45112a346b93418effa7c Mon Sep 17 00:00:00 2001 From: Marcos Paulo de Souza <marcos.souza....@gmail.com> Date: Sat, 7 Apr 2018 13:19:22 -0300 Subject: [PATCH] main.go: Check for root user as the first thing in main Just have a PersistentPreRun hook for cobra isn't enough, because right before the app.Execute() we call ioutil.TempDir, which tries to create a new distrory under /var/cache, so it fails as bellow: distrobuilder help Failed to create cache directory: mkdir /var/cache/distrobuilder.685166231: permission denied By moving the check for root user as the first thing distrobuilder does solves the problem. Signed-off-by: Marcos Paulo de Souza <marcos.souza....@gmail.com> --- distrobuilder/main.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/distrobuilder/main.go b/distrobuilder/main.go index 2c0512d..05a7243 100644 --- a/distrobuilder/main.go +++ b/distrobuilder/main.go @@ -80,19 +80,18 @@ type cmdGlobal struct { } func main() { + // Sanity checks + if os.Geteuid() != 0 { + fmt.Fprintf(os.Stderr, "You must be root to run this tool\n") + os.Exit(1) + } + // Global flags globalCmd := cmdGlobal{} app := &cobra.Command{ - Use: "distrobuilder", - Short: "System container image builder for LXC and LXD", - PersistentPreRun: func(cmd *cobra.Command, args []string) { - // Sanity checks - if os.Geteuid() != 0 { - fmt.Fprintf(os.Stderr, "You must be root to run this tool\n") - os.Exit(1) - } - }, + Use: "distrobuilder", + Short: "System container image builder for LXC and LXD", PersistentPostRunE: globalCmd.postRun, }
_______________________________________________ lxc-devel mailing list lxc-devel@lists.linuxcontainers.org http://lists.linuxcontainers.org/listinfo/lxc-devel