From 7014cd1dbddb24409329868cc2a022045abee3ba Mon Sep 17 00:00:00 2001 From: William Wilson Date: Fri, 28 Jan 2022 15:00:16 -0600 Subject: [PATCH 1/2] osutil/mkfs: Expose more fakeroot flags --- osutil/mkfs/mkfs.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/osutil/mkfs/mkfs.go b/osutil/mkfs/mkfs.go index efaffc74202..e62116d4717 100644 --- a/osutil/mkfs/mkfs.go +++ b/osutil/mkfs/mkfs.go @@ -25,6 +25,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" "github.com/snapcore/snapd/gadget/quantity" "github.com/snapcore/snapd/osutil" @@ -106,11 +107,12 @@ func mkfsExt4(img, label, contentsRootDir string, deviceSize, sectorSize quantit var cmd *exec.Cmd if os.Geteuid() != 0 { // run through fakeroot so that files are owned by root - fakerootLib := os.Getenv("FAKEROOT_LIB") - if fakerootLib != "" { + fakerootFlags := os.Getenv("FAKEROOT_FLAGS") + if fakerootFlags != "" { // When executing fakeroot from a classic confinement snap the location of // libfakeroot must be specified, or else it will be loaded from the host system - mkfsArgs = append([]string{"--lib", fakerootLib, "--"}, mkfsArgs...) + fakerootArgs := append(strings.Split(fakerootFlags, " "), "--") + mkfsArgs = append(fakerootArgs, mkfsArgs...) } cmd = exec.Command("fakeroot", mkfsArgs...) } else { From 9242b0bea18555d6d1db8012d62912aae0a23e81 Mon Sep 17 00:00:00 2001 From: William Wilson Date: Mon, 31 Jan 2022 09:09:13 -0600 Subject: [PATCH 2/2] Use strutil.shlex rather than strings --- osutil/mkfs/mkfs.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/osutil/mkfs/mkfs.go b/osutil/mkfs/mkfs.go index e62116d4717..d2f48bb1107 100644 --- a/osutil/mkfs/mkfs.go +++ b/osutil/mkfs/mkfs.go @@ -25,10 +25,10 @@ import ( "os" "os/exec" "path/filepath" - "strings" "github.com/snapcore/snapd/gadget/quantity" "github.com/snapcore/snapd/osutil" + "github.com/snapcore/snapd/strutil/shlex" ) // MakeFunc defines a function signature that is used by all of the mkfs. @@ -111,8 +111,14 @@ func mkfsExt4(img, label, contentsRootDir string, deviceSize, sectorSize quantit if fakerootFlags != "" { // When executing fakeroot from a classic confinement snap the location of // libfakeroot must be specified, or else it will be loaded from the host system - fakerootArgs := append(strings.Split(fakerootFlags, " "), "--") - mkfsArgs = append(fakerootArgs, mkfsArgs...) + flags, err := shlex.Split(fakerootFlags) + if err != nil { + return fmt.Errorf("cannot split fakeroot command: %v", err) + } + if len(fakerootFlags) > 0 { + fakerootArgs := append(flags, "--") + mkfsArgs = append(fakerootArgs, mkfsArgs...) + } } cmd = exec.Command("fakeroot", mkfsArgs...) } else {