4c5362
From 6b47ff61936d2b602d29b229b079bda00dadad7e Mon Sep 17 00:00:00 2001
4c5362
From: Debarshi Ray <rishi@fedoraproject.org>
4c5362
Date: Thu, 2 Sep 2021 14:57:37 +0200
4c5362
Subject: [PATCH] cmd/root: Suggest a way forward if coreos/toolbox was used
4c5362
4c5362
github.com/coreos/toolbox bind mounts the entire /run from the host
4c5362
operating system into the toolbox container. Due to this, when run
4c5362
rootful, the /run/.containerenv created by Podman inside the container
4c5362
is also seen on the host. This confuses Toolbox into thinking that it's
4c5362
running inside a container, even when it's running on the host.
4c5362
4c5362
This is an attempt to differentiate between a toolbox container and
4c5362
the host by looking at the 'container' environment variable, so that
4c5362
the user can be presented with a more helpful error message.
4c5362
4c5362
https://bugzilla.redhat.com/show_bug.cgi?id=1998191
4c5362
---
4c5362
 src/cmd/root.go | 10 ++++++++++
4c5362
 1 file changed, 10 insertions(+)
4c5362
4c5362
diff --git a/src/cmd/root.go b/src/cmd/root.go
4c5362
index 5e6f5874a469..139609592218 100644
4c5362
--- a/src/cmd/root.go
4c5362
+++ b/src/cmd/root.go
4c5362
@@ -130,6 +130,16 @@ func preRun(cmd *cobra.Command, args []string) error {
4c5362
 
4c5362
 	if toolboxPath == "" {
4c5362
 		if utils.IsInsideContainer() {
4c5362
+			if containerType := os.Getenv("container"); containerType == "" {
4c5362
+				var builder strings.Builder
4c5362
+				fmt.Fprintf(&builder, "/run/.containerenv found on what looks like the host\n")
4c5362
+				fmt.Fprintf(&builder, "If this is the host, then remove /run/.containerenv and try again.\n")
4c5362
+				fmt.Fprintf(&builder, "Otherwise, contact your system administrator or file a bug.")
4c5362
+
4c5362
+				errMsg := builder.String()
4c5362
+				return errors.New(errMsg)
4c5362
+			}
4c5362
+
4c5362
 			return errors.New("TOOLBOX_PATH not set")
4c5362
 		}
4c5362
 
4c5362
-- 
4c5362
2.31.1
4c5362