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