[lxc-devel] [distrobuilder/master] shared/util: Fix locale when importing GPG keys

monstermunchkin on Github lxc-bot at linuxcontainers.org
Wed Jun 17 08:04:57 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 383 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200617/74bcc890/attachment.bin>
-------------- next part --------------
From 434ba3e20fafc17697562222d3dbcf3326546ccf Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Wed, 17 Jun 2020 08:53:19 +0200
Subject: [PATCH] shared/util: Fix locale when importing GPG keys

Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
 shared/util.go | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/shared/util.go b/shared/util.go
index 0814dd3..e768db0 100644
--- a/shared/util.go
+++ b/shared/util.go
@@ -142,9 +142,16 @@ func recvGPGKeys(gpgDir string, keyserver string, keys []string) (bool, error) {
 	for _, f := range publicKeys {
 		args := append(args, "--import")
 
-		err := lxd.RunCommandWithFds(strings.NewReader(f), nil, "gpg", args...)
+		cmd := exec.Command("gpg", args...)
+		cmd.Stdin = strings.NewReader(f)
+		cmd.Env = append(os.Environ(), "LANG=C.UTF-8")
+
+		var buffer bytes.Buffer
+		cmd.Stderr = &buffer
+
+		err := cmd.Run()
 		if err != nil {
-			return false, err
+			return false, fmt.Errorf("Failed to run: %s: %s", strings.Join(cmd.Args, " "), strings.TrimSpace(buffer.String()))
 		}
 	}
 
@@ -154,7 +161,7 @@ func recvGPGKeys(gpgDir string, keyserver string, keys []string) (bool, error) {
 
 	args = append(args, append([]string{"--recv-keys"}, fingerprints...)...)
 
-	_, out, err := lxd.RunCommandSplit(nil, nil, "gpg", args...)
+	_, out, err := lxd.RunCommandSplit(append(os.Environ(), "LANG=C.UTF-8"), nil, "gpg", args...)
 	if err != nil {
 		return false, err
 	}


More information about the lxc-devel mailing list