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