summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/env/env.go20
-rw-r--r--pkg/machine/qemu/claim_unsupported.go4
-rw-r--r--pkg/machine/qemu/config.go3
-rw-r--r--pkg/machine/qemu/machine.go14
-rw-r--r--pkg/specgen/generate/container.go6
-rw-r--r--pkg/specgenutil/specgen.go5
6 files changed, 32 insertions, 20 deletions
diff --git a/pkg/env/env.go b/pkg/env/env.go
index 8af9fd77c..fb7949ad8 100644
--- a/pkg/env/env.go
+++ b/pkg/env/env.go
@@ -37,6 +37,22 @@ func Slice(m map[string]string) []string {
return env
}
+// Map transforms the specified slice of environment variables into a
+// map.
+func Map(slice []string) map[string]string {
+ envmap := make(map[string]string, len(slice))
+ for _, val := range slice {
+ data := strings.SplitN(val, "=", 2)
+
+ if len(data) > 1 {
+ envmap[data[0]] = data[1]
+ } else {
+ envmap[data[0]] = ""
+ }
+ }
+ return envmap
+}
+
// Join joins the two environment maps with override overriding base.
func Join(base map[string]string, override map[string]string) map[string]string {
if len(base) == 0 {
@@ -87,10 +103,6 @@ func parseEnv(env map[string]string, line string) error {
}
// trim the front of a variable, but nothing else
name := strings.TrimLeft(data[0], whiteSpaces)
- if strings.ContainsAny(name, whiteSpaces) {
- return fmt.Errorf("name %q has white spaces, poorly formatted name", name)
- }
-
if len(data) > 1 {
env[name] = data[1]
} else {
diff --git a/pkg/machine/qemu/claim_unsupported.go b/pkg/machine/qemu/claim_unsupported.go
index e0b3dd3d3..187ef9d69 100644
--- a/pkg/machine/qemu/claim_unsupported.go
+++ b/pkg/machine/qemu/claim_unsupported.go
@@ -1,5 +1,5 @@
-//go:build !darwin && !windows
-// +build !darwin,!windows
+//go:build !darwin
+// +build !darwin
package qemu
diff --git a/pkg/machine/qemu/config.go b/pkg/machine/qemu/config.go
index bada1af9b..8081727f6 100644
--- a/pkg/machine/qemu/config.go
+++ b/pkg/machine/qemu/config.go
@@ -1,6 +1,3 @@
-//go:build (amd64 && !windows) || (arm64 && !windows)
-// +build amd64,!windows arm64,!windows
-
package qemu
import (
diff --git a/pkg/machine/qemu/machine.go b/pkg/machine/qemu/machine.go
index 71752a101..e97b68e31 100644
--- a/pkg/machine/qemu/machine.go
+++ b/pkg/machine/qemu/machine.go
@@ -870,7 +870,7 @@ func NewQMPMonitor(network, name string, timeout time.Duration) (Monitor, error)
if err != nil {
return Monitor{}, err
}
- if !rootless.IsRootless() {
+ if isRootful() {
rtDir = "/run"
}
rtDir = filepath.Join(rtDir, "podman")
@@ -1371,7 +1371,7 @@ func (v *MachineVM) setPIDSocket() error {
if err != nil {
return err
}
- if !rootless.IsRootless() {
+ if isRootful() {
rtPath = "/run"
}
socketDir := filepath.Join(rtPath, "podman")
@@ -1397,7 +1397,7 @@ func (v *MachineVM) getSocketandPid() (string, string, error) {
if err != nil {
return "", "", err
}
- if !rootless.IsRootless() {
+ if isRootful() {
rtPath = "/run"
}
socketDir := filepath.Join(rtPath, "podman")
@@ -1735,3 +1735,11 @@ func isProcessAlive(pid int) bool {
func (p *Provider) VMType() string {
return vmtype
}
+
+func isRootful() bool {
+ // Rootless is not relevant on Windows. In the future rootless.IsRootless
+ // could be switched to return true on Windows, and other codepaths migrated
+ // for now will check additionally for valid os.Getuid
+
+ return !rootless.IsRootless() && os.Getuid() != -1
+}
diff --git a/pkg/specgen/generate/container.go b/pkg/specgen/generate/container.go
index e293ce010..d57efa0d1 100644
--- a/pkg/specgen/generate/container.go
+++ b/pkg/specgen/generate/container.go
@@ -152,10 +152,8 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
}
// First transform the os env into a map. We need it for the labels later in
// any case.
- osEnv, err := envLib.ParseSlice(os.Environ())
- if err != nil {
- return nil, fmt.Errorf("error parsing host environment variables: %w", err)
- }
+ osEnv := envLib.Map(os.Environ())
+
// Caller Specified defaults
if s.EnvHost {
defaultEnvs = envLib.Join(defaultEnvs, osEnv)
diff --git a/pkg/specgenutil/specgen.go b/pkg/specgenutil/specgen.go
index aab2eebd5..8c2c59fed 100644
--- a/pkg/specgenutil/specgen.go
+++ b/pkg/specgenutil/specgen.go
@@ -362,10 +362,7 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *entities.ContainerCreateOptions
// First transform the os env into a map. We need it for the labels later in
// any case.
- osEnv, err := envLib.ParseSlice(os.Environ())
- if err != nil {
- return fmt.Errorf("error parsing host environment variables: %w", err)
- }
+ osEnv := envLib.Map(os.Environ())
if !s.EnvHost {
s.EnvHost = c.EnvHost