Repository: moby/moby
File: testutil/daemon/daemon.go (Go)

Code before:
		d.args = append(d.args, "--userns-remap", root)
	}

	// If we don't explicitly set the log-level or debug flag(-D) then
	// turn on debug mode
	foundLog := false
	foundSd := false
	for _, a := range providedArgs {
		if strings.Contains(a, "--log-level") || strings.Contains(a, "-D") || strings.Contains(a, "--debug") {
			foundLog = true
		}
		if strings.Contains(a, "--storage-driver") {
			foundSd = true
		}
	}
	if !foundLog {
		d.args = append(d.args, "--debug")
	}
	if d.storageDriver != "" && !foundSd {
		d.args = append(d.args, "--storage-driver", d.storageDriver)
	}

	// If no --firewall-backend is configured and env var DOCKER_FIREWALL_BACKEND has a value, use it.
	if !slices.ContainsFunc(providedArgs, func(s string) bool {
		return strings.HasPrefix(s, "--firewall-backend")
	}) {
		if fw := os.Getenv("DOCKER_FIREWALL_BACKEND"); fw != "" {
			d.args = append(d.args, "--firewall-backend="+fw)
		}
	}

	d.args = append(d.args, providedArgs...)
	cmd := exec.Command(dockerdBinary, d.args...)
	cmd.Env = append(os.Environ(), "DOCKER_SERVICE_PREFER_OFFLINE_IMAGE=1")
	cmd.Env = append(cmd.Env, d.extraEnv...)
	cmd.Env = append(cmd.Env, "OTEL_SERVICE_NAME=dockerd-"+d.id)
	cmd.Stdout = out
	cmd.Stderr = out
	d.logFile = out
	if d.rootlessUser != nil {
		// sudo requires this for propagating signals
		setsid(cmd)
	}

	if err := cmd.Start(); err != nil {
		return errors.Wrapf(err, "[%s] could not start daemon container", d.id)
	}

	wait := make(chan error, 1)
	d.cmd = cmd
	d.Wait = wait

Review comment (suggestion):
nit: Instead of a comment, this could be clearer with an intermediate variable.

```suggestion
	hasFwBackendArg := slices.ContainsFunc(providedArgs, func(s string) bool {
		return strings.HasPrefix(s, "--firewall-backend")
	})
	if !hasFwBackendArg {
```

(just a subjective nit though, @thaJeztah would probably disagree 😅)

Code after:
		d.args = append(d.args, "--userns-remap", root)
	}

	// If we don't explicitly set the log-level or debug flag(-D) then
	// turn on debug mode
	foundLog := false
	foundSd := false
	for _, a := range providedArgs {
		if strings.Contains(a, "--log-level") || strings.Contains(a, "-D") || strings.Contains(a, "--debug") {
			foundLog = true
		}
		if strings.Contains(a, "--storage-driver") {
			foundSd = true
		}
	}
	if !foundLog {
		d.args = append(d.args, "--debug")
	}
	if d.storageDriver != "" && !foundSd {
		d.args = append(d.args, "--storage-driver", d.storageDriver)
	}

	hasFwBackendArg := !slices.ContainsFunc(providedArgs, func(s string) bool {
		return strings.HasPrefix(s, "--firewall-backend")
	})
	if hasFwBackendArg {
		if fw := os.Getenv("DOCKER_FIREWALL_BACKEND"); fw != "" {
			d.args = append(d.args, "--firewall-backend="+fw)
		}
	}

	d.args = append(d.args, providedArgs...)
	cmd := exec.Command(dockerdBinary, d.args...)
	cmd.Env = append(os.Environ(), "DOCKER_SERVICE_PREFER_OFFLINE_IMAGE=1")
	cmd.Env = append(cmd.Env, d.extraEnv...)
	cmd.Env = append(cmd.Env, "OTEL_SERVICE_NAME=dockerd-"+d.id)
	cmd.Stdout = out
	cmd.Stderr = out
	d.logFile = out
	if d.rootlessUser != nil {
		// sudo requires this for propagating signals
		setsid(cmd)
	}

	if err := cmd.Start(); err != nil {
		return errors.Wrapf(err, "[%s] could not start daemon container", d.id)
	}

	wait := make(chan error, 1)
	d.cmd = cmd
	d.Wait = wait