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