ronantakizawa/codereview-bench huggingface dataset:
Repository: moby/moby
File: daemon/info_windows.go (Go)

Code before:
package daemon // import "github.com/docker/docker/daemon"

import (
	"context"

	"github.com/docker/docker/api/types"
	"github.com/docker/docker/api/types/system"
	"github.com/docker/docker/daemon/config"
	"github.com/docker/docker/pkg/sysinfo"
)

// fillPlatformInfo fills the platform related info.
func (daemon *Daemon) fillPlatformInfo(ctx context.Context, v *system.Info, sysInfo *sysinfo.SysInfo, cfg *configStore) error {
	return nil
}

func (daemon *Daemon) fillPlatformVersion(ctx context.Context, v *types.Version, cfg *configStore) error {
	return nil
}

func fillDriverWarnings(v *system.Info) {
}

func cgroupNamespacesEnabled(sysInfo *sysinfo.SysInfo, cfg *config.Config) bool {
	return false
}

// Rootless returns true if daemon is running in rootless mode
func Rootless(*config.Config) bool {
	return false
}

func noNewPrivileges(*config.Config) bool {
	return false
}


Review comment (refactor):
Thanks! Yes, I was thinking we'd need it only if someone has `false` set, but I guess this is good as well to tell them "remove this from your config"

We can remove this in v29.0 or so (maybe earlier, it's just a warning)

Code after:
package daemon // import "github.com/docker/docker/daemon"

import (
	"context"

	"github.com/docker/docker/api/types"
	"github.com/docker/docker/api/types/system"
	"github.com/docker/docker/daemon/config"
	"github.com/docker/docker/pkg/sysinfo"
)

// fillPlatformInfo fills the platform related info.
func (daemon *Daemon) fillPlatformInfo(ctx context.Context, v *system.Info, sysInfo *sysinfo.SysInfo, cfg *configStore) error {
	if _, ok := cfg.Features["windows-dns-proxy"]; ok {
		v.Warnings = append(v.Warnings, `
WARNING: Feature flag "windows-dns-proxy" has been removed, forwarding to external DNS resolvers is enabled.`)
	}
	return nil
}

func (daemon *Daemon) fillPlatformVersion(ctx context.Context, v *types.Version, cfg *configStore) error {
	return nil
}

func fillDriverWarnings(v *system.Info) {
}

func cgroupNamespacesEnabled(sysInfo *sysinfo.SysInfo, cfg *config.Config) bool {
	return false
}

// Rootless returns true if daemon is running in rootless mode
func Rootless(*config.Config) bool {
	return false
}

func noNewPrivileges(*config.Config) bool {
	return false
}
Repository: moby/moby
File: daemon/logger/ring.go (Go)

Code before:
package logger // import "github.com/docker/docker/daemon/logger"

import (
	"context"
	"errors"
	"sync"
	"sync/atomic"
)

const (
	defaultRingMaxSize = 1e6 // 1MB
)

// RingLogger is a ring buffer that implements the Logger interface.
// This is used when lossy logging is OK.
type RingLogger struct {
	buffer    *messageRing
	l         Logger
	logInfo   Info
	closeFlag atomic.Bool
	wg        sync.WaitGroup
}

var (
	_ SizedLogger = (*RingLogger)(nil)
	_ LogReader   = (*ringWithReader)(nil)
)

type ringWithReader struct {
	*RingLogger
}

func (r *ringWithReader) ReadLogs(ctx context.Context, cfg ReadConfig) *LogWatcher {
	reader, ok := r.l.(LogReader)
	if !ok {
		// something is wrong if we get here
		panic("expected log reader")
	}
	return reader.ReadLogs(ctx, cfg)
}

func newRingLogger(driver Logger, logInfo Info, maxSize int64) *RingLogger {
	l := &RingLogger{
		buffer:  newRing(maxSize),
		l:       driver,
		logInfo: logInfo,
	}
	l.wg.Add(1)
	go l.run()
	return l
}

Review comment (suggestion):
Actually wondering if (but for a  follow-up) `NewRingLogger` should explicitly return a `SizedLogger`, because that's what's implemented by both; https://github.com/moby/moby/blob/264801efb1f8676a6a4b1b6e023fbdbb56cf28e6/daemon/logger/ring.go#L53-L55

And perhaps assert that here as well for `ringWithReader`;

```go
	_ SizedLogger = (*ringWithReader)(nil)
```

Code after:
package logger // import "github.com/docker/docker/daemon/logger"

import (
	"context"
	"errors"
	"sync"
	"sync/atomic"
)

const (
	defaultRingMaxSize = 1e6 // 1MB
)

// ringLogger is a ring buffer that implements the Logger interface.
// This is used when lossy logging is OK.
type ringLogger struct {
	buffer    *messageRing
	l         Logger
	logInfo   Info
	closeFlag atomic.Bool
	wg        sync.WaitGroup
}

var (
	_ SizedLogger = (*ringLogger)(nil)
	_ LogReader   = (*ringWithReader)(nil)
)

type ringWithReader struct {
	*ringLogger
}

func (r *ringWithReader) ReadLogs(ctx context.Context, cfg ReadConfig) *LogWatcher {
	reader, ok := r.l.(LogReader)
	if !ok {
		// something is wrong if we get here
		panic("expected log reader")
	}
	return reader.ReadLogs(ctx, cfg)
}

func newRingLogger(driver Logger, logInfo Info, maxSize int64) *ringLogger {
	l := &ringLogger{
		buffer:  newRing(maxSize),
		l:       driver,
		logInfo: logInfo,
	}
	l.wg.Add(1)
	go l.run()
	return l
}
Repository: moby/moby
File: daemon/containerd/image_tag.go (Go)

Code before:
		// If there already exists an image with this tag, delete it
		if err := i.softImageDelete(ctx, *replacedImg, all); err != nil {
			return errors.Wrapf(err, "failed to delete previous image %s", replacedImg.Name)
		}

		if _, err := i.images.Create(context.WithoutCancel(ctx), newImg); err != nil {
			return errdefs.System(errors.Wrapf(err, "failed to create an image %s with target %s after deleting the existing one",
				newImg.Name, newImg.Target.Digest))
		}
	}

	logger := log.G(ctx).WithFields(log.Fields{
		"imageID": newImg.Target.Digest,
		"tag":     newImg.Name,
	})
	logger.Info("image created")

	if !creatingDangling {
		if err := i.images.Delete(ctx, danglingName); err != nil {
			if !cerrdefs.IsNotFound(err) {
				logger.WithError(err).Warn("unexpected error when deleting dangling image")
			}
		}
	}

	i.LogImageEvent(ctx, string(newImg.Target.Digest), imageFamiliarName(newImg), events.ActionTag)
	return nil
}


Review comment (suggestion):
Double check if this change is still correct now that the `if !creatingDangling {` condition was added

Code after:
		// If there already exists an image with this tag, delete it
		if err := i.softImageDelete(ctx, *replacedImg, all); err != nil {
			return errors.Wrapf(err, "failed to delete previous image %s", replacedImg.Name)
		}

		if _, err := i.images.Create(context.WithoutCancel(ctx), newImg); err != nil {
			return errdefs.System(errors.Wrapf(err, "failed to create an image %s with target %s after deleting the existing one",
				newImg.Name, newImg.Target.Digest))
		}
	}

	logger := log.G(ctx).WithFields(log.Fields{
		"imageID": newImg.Target.Digest,
		"tag":     newImg.Name,
	})
	logger.Info("image created")

	if !creatingDangling {
		defer i.LogImageEvent(ctx, string(newImg.Target.Digest), imageFamiliarName(newImg), events.ActionTag)

		if err := i.images.Delete(ctx, danglingName); err != nil {
			if !cerrdefs.IsNotFound(err) {
				logger.WithError(err).Warn("unexpected error when deleting dangling image")
			}
		}
	}

	return nil
}
Repository: moby/moby
File: daemon/containerd/progress.go (Go)

Code before:

			if sn.Kind == snapshots.KindCommitted {
				out.WriteProgress(progress.Progress{
					ID:         stringid.TruncateID(desc.Digest.Encoded()),
					Action:     "Pull complete",
					HideCounts: true,
					LastUpdate: true,
				})

				gone = append(gone, idx)
				return nil
			}
			return nil
		}, walkFilter)
		if err != nil {
			return err
		}
	}

	if len(gone) > 0 {
		sort.Ints(gone)
		for i := len(gone) - 1; i >= 0; i-- {
			p.layers = append(p.layers[:gone[i]], p.layers[gone[i]+1:]...)
		}
	}

	return nil
}

func (p *pullProgress) finished(ctx context.Context, out progress.Output, desc ocispec.Descriptor) {
	if images.IsLayerType(desc.MediaType) {
		p.layers = append(p.layers, desc)
	}
}

type pushProgress struct {
	Tracker                         docker.StatusTracker
	notStartedWaitingAreUnavailable atomic.Bool
}

// TurnNotStartedIntoUnavailable will mark all not started layers as "Unavailable" instead of "Waiting".
func (p *pushProgress) TurnNotStartedIntoUnavailable() {
	p.notStartedWaitingAreUnavailable.Store(true)
}

func (p *pushProgress) UpdateProgress(ctx context.Context, ongoing *jobs, out progress.Output, start time.Time) error {
	for _, j := range ongoing.Jobs() {
		key := remotes.MakeRefKey(ctx, j)
		id := stringid.TruncateID(j.Digest.Encoded())

		status, err := p.Tracker.GetStatus(key)

Review comment (suggestion):
```suggestion
	// remove finished/committed layers from p.layers
	if len(gone) > 0 {
		sort.Ints(gone)
		for i := len(gone) - 1; i >= 0; i-- {
			p.layers = append(p.layers[:gone[i]], p.layers[gone[i]+1:]...)
		}
	}
```

Code after:

			if sn.Kind == snapshots.KindCommitted {
				out.WriteProgress(progress.Progress{
					ID:         stringid.TruncateID(desc.Digest.Encoded()),
					Action:     "Pull complete",
					HideCounts: true,
					LastUpdate: true,
				})

				committedIdx = append(committedIdx, idx)
				return nil
			}
			return nil
		}, walkFilter)
		if err != nil {
			return err
		}
	}

	// Remove finished/committed layers from p.layers
	if len(committedIdx) > 0 {
		sort.Ints(committedIdx)
		for i := len(committedIdx) - 1; i >= 0; i-- {
			p.layers = append(p.layers[:committedIdx[i]], p.layers[committedIdx[i]+1:]...)
		}
	}

	return nil
}

func (p *pullProgress) finished(ctx context.Context, out progress.Output, desc ocispec.Descriptor) {
	if images.IsLayerType(desc.MediaType) {
		p.layers = append(p.layers, desc)
	}
}

type pushProgress struct {
	Tracker                         docker.StatusTracker
	notStartedWaitingAreUnavailable atomic.Bool
}

// TurnNotStartedIntoUnavailable will mark all not started layers as "Unavailable" instead of "Waiting".
func (p *pushProgress) TurnNotStartedIntoUnavailable() {
	p.notStartedWaitingAreUnavailable.Store(true)
}

func (p *pushProgress) UpdateProgress(ctx context.Context, ongoing *jobs, out progress.Output, start time.Time) error {
	for _, j := range ongoing.Jobs() {
		key := remotes.MakeRefKey(ctx, j)
		id := stringid.TruncateID(j.Digest.Encoded())
Repository: moby/moby
File: libnetwork/iptables/firewalld.go (Go)

Code before:
//go:build linux

package iptables

import (
	"context"
	"fmt"
	"strings"

	"github.com/containerd/log"
	dbus "github.com/godbus/dbus/v5"
	"github.com/pkg/errors"
)

const (
	dbusInterface   = "org.fedoraproject.FirewallD1"
	dbusPath        = "/org/fedoraproject/FirewallD1"
	dbusConfigPath  = "/org/fedoraproject/FirewallD1/config"
	dockerZone      = "docker"
	dockerFwdPolicy = "docker-forwarding"
)

// Conn is a connection to firewalld dbus endpoint.
type Conn struct {
	sysconn    *dbus.Conn
	sysObj     dbus.BusObject
	sysConfObj dbus.BusObject
	signal     chan *dbus.Signal
}

var (
	connection *Conn

	firewalldRunning bool      // is Firewalld service running
	onReloaded       []*func() // callbacks when Firewalld has been reloaded
)

// firewalldInit initializes firewalld management code.
func firewalldInit() error {
	var err error

	if connection, err = newConnection(); err != nil {
		return fmt.Errorf("Failed to connect to D-Bus system bus: %v", err)
	}
	firewalldRunning = checkRunning()
	if !firewalldRunning {
		connection.sysconn.Close()
		connection = nil
	}

Review comment (suggestion):
Had a quick peek if I could find consumers of this. I did find one public import in https://github.com/KatharaFramework/NetworkPlugin/blob/8474abd27dcd2c31e90fbffa7d0561aa09549977/bridge/go-src/src/bridge_utils.go

If we want to be on the safe side, we could add aliases and deprecate those;

```go
// IPV defines the table string
//
// Deprecated: use [IPVersion]
type IPV = IPVersion

const (
	// Iptables point ipv4 table
	//
	// Deprecated: use [IPv4].
	Iptables IPV = IPv4
	// IP6Tables point to ipv6 table
	//
	// Deprecated: use [IPv6].
	IP6Tables IPV = IPv6
)
```


Code after:
//go:build linux

package iptables

import (
	"context"
	"fmt"
	"strings"

	"github.com/containerd/log"
	dbus "github.com/godbus/dbus/v5"
	"github.com/pkg/errors"
)

// IPV defines the table string
//
// Deprecated: use [IPVersion]
type IPV = IPVersion

const (
	// Iptables point ipv4 table
	//
	// Deprecated: use [IPv4].
	Iptables IPV = IPv4
	// IP6Tables point to ipv6 table
	//
	// Deprecated: use [IPv6].
	IP6Tables IPV = IPv6
)

const (
	dbusInterface   = "org.fedoraproject.FirewallD1"
	dbusPath        = "/org/fedoraproject/FirewallD1"
	dbusConfigPath  = "/org/fedoraproject/FirewallD1/config"
	dockerZone      = "docker"
	dockerFwdPolicy = "docker-forwarding"
)

// Conn is a connection to firewalld dbus endpoint.
type Conn struct {
	sysconn    *dbus.Conn
	sysObj     dbus.BusObject
	sysConfObj dbus.BusObject
	signal     chan *dbus.Signal
}

var (
	connection *Conn
Repository: moby/moby
File: daemon/containerd/image_snapshot.go (Go)

Code before:

	var lease leases.Lease
	switch len(lss) {
	case 1:
		lease = lss[0]
	case 0:
		log.G(ctx).WithField("container", cid).Warn("rw layer lease not found for container")
	default:
		panic("this should never happen, more than one lease has the same id " + cid)
	}

	lrw := &rwLayer{
		id:              cid,
		snapshotterName: i.StorageDriver(),
		snapshotter:     sn,
		refCountMounter: i.refCountMounter,
		lease:           lease,
	}

	root, err := i.refCountMounter.Mounted(cid)
	if err != nil {
		log.G(ctx).WithField("container", cid).Warn("failed to determine if container is already mounted")
	}
	lrw.root = root

	return lrw, nil
}

func (l *rwLayer) Unmount() error {
	ctx := context.TODO()

	if l.root == "" {
		target, err := l.refCountMounter.Mounted(l.id)
		if err != nil {
			log.G(ctx).WithField("id", l.id).Warn("failed to determine if container is already mounted")
		}
		if target == "" {
			return errors.New("layer not mounted")
		}
		l.root = target
	}

	if err := l.refCountMounter.Unmount(l.root); err != nil {
		log.G(ctx).WithField("container", l.id).WithError(err).Error("error unmounting container")
		return fmt.Errorf("failed to unmount %s: %w", l.root, err)
	}

	return nil
}

func (l rwLayer) Metadata() (map[string]string, error) {

Review comment (bug):
Perhaps slightly cleaner / more atomic to construct the `rwLayer` at the end;


```go
	root, err := i.refCountMounter.Mounted(cid)
	if err != nil {
		log.G(ctx).WithField("container", cid).Warn("failed to determine if container is already mounted")
	}
	return &rwLayer{
		id:              cid,
		snapshotterName: i.StorageDriver(),
		snapshotter:     sn,
		refCountMounter: i.refCountMounter,
		root:            root,
		lease:           lease,
	}, nil
```

Code after:
	if err != nil {
		return nil, err
	}

	switch len(lss) {
	case 0:
		return nil, errdefs.NotFound(errors.New("rw layer lease not found for container " + cid))
	default:
		log.G(ctx).WithFields(log.Fields{"container": cid, "leases": lss}).Warn("multiple leases with the same id found, this should not happen")
	case 1:
	}

	root, err := i.refCountMounter.Mounted(cid)
	if err != nil {
		log.G(ctx).WithField("container", cid).Warn("failed to determine if container is already mounted")
	}

	return &rwLayer{
		id:              cid,
		snapshotterName: i.StorageDriver(),
		snapshotter:     sn,
		refCountMounter: i.refCountMounter,
		lease:           lss[0],
		root:            root,
	}, nil

}

func (l *rwLayer) Unmount() error {
	ctx := context.TODO()

	if l.root == "" {
		target, err := l.refCountMounter.Mounted(l.id)
		if err != nil {
			log.G(ctx).WithField("id", l.id).Warn("failed to determine if container is already mounted")
		}
		if target == "" {
			return errors.New("layer not mounted")
		}
		l.root = target
	}

	if err := l.refCountMounter.Unmount(l.root); err != nil {
		log.G(ctx).WithField("container", l.id).WithError(err).Error("error unmounting container")
		return fmt.Errorf("failed to unmount %s: %w", l.root, err)
	}

	return nil
}

func (l rwLayer) Metadata() (map[string]string, error) {
Repository: moby/moby
File: libnetwork/sandbox_linux.go (Go)

Code before:
	}
	sb.mu.Unlock()
	if osSbox == nil {
		return nil
	}
	osSbox.UnsetGateway()     //nolint:errcheck
	osSbox.UnsetGatewayIPv6() //nolint:errcheck
	if err := osSbox.UnsetDefaultRouteIPv4(); err != nil {
		log.G(context.TODO()).WithError(err).Warn("removing IPv4 default route")
	}
	if err := osSbox.UnsetDefaultRouteIPv6(); err != nil {
		log.G(context.TODO()).WithError(err).Warn("removing IPv6 default route")
	}

	if populated4 {
		ep4.mu.Lock()
		joinInfo := ep4.joinInfo
		ep4.mu.Unlock()

		if joinInfo.gw != nil {
			if err := osSbox.SetGateway(joinInfo.gw); err != nil {
				return fmt.Errorf("failed to set gateway while updating gateway: %v", err)
			}
		} else {
			if err := osSbox.SetDefaultRouteIPv4(ep4.iface.srcName); err != nil {
				return fmt.Errorf("failed to set IPv4 default route while updating gateway: %v", err)
			}
		}
	}

	if populated6 {
		ep6.mu.Lock()
		joinInfo := ep6.joinInfo
		ep6.mu.Unlock()

		if joinInfo.gw6 != nil {
			if err := osSbox.SetGatewayIPv6(joinInfo.gw6); err != nil {
				return fmt.Errorf("failed to set IPv6 gateway while updating gateway: %v", err)
			}
		} else {
			if err := osSbox.SetDefaultRouteIPv6(ep6.iface.srcName); err != nil {
				return fmt.Errorf("failed to set IPv6 default route while updating gateway: %v", err)
			}
		}
	}

	return nil
}

func (sb *Sandbox) ExecFunc(f func()) error {
	sb.mu.Lock()

Review comment (suggestion):
Wondering if (part of) decorating the error should be in `SetDefaultRoute` and `SetGateway`, in that case, the caller of this `Sandbox,updateGateway` could just use a general decoration, instead of having to repeat the "while updating gateway" everywhere 🤔;


```go
if err := sb.updateGateway(gwepAfter4, gwepAfter6); err != nil {
	return fmt.Errorf("updating gateway: %w", err)
}
```

Code after:
	}
	sb.mu.Unlock()
	if osSbox == nil {
		return nil
	}
	osSbox.UnsetGateway()     //nolint:errcheck
	osSbox.UnsetGatewayIPv6() //nolint:errcheck
	if err := osSbox.UnsetDefaultRouteIPv4(); err != nil {
		log.G(context.TODO()).WithError(err).Warn("removing IPv4 default route")
	}
	if err := osSbox.UnsetDefaultRouteIPv6(); err != nil {
		log.G(context.TODO()).WithError(err).Warn("removing IPv6 default route")
	}

	if populated4 {
		ep4.mu.Lock()
		joinInfo := ep4.joinInfo
		ep4.mu.Unlock()

		if joinInfo.gw != nil {
			if err := osSbox.SetGateway(joinInfo.gw); err != nil {
				return fmt.Errorf("failed to set gateway: %v", err)
			}
		} else {
			if err := osSbox.SetDefaultRouteIPv4(ep4.iface.srcName); err != nil {
				return fmt.Errorf("failed to set IPv4 default route: %v", err)
			}
		}
	}

	if populated6 {
		ep6.mu.Lock()
		joinInfo := ep6.joinInfo
		ep6.mu.Unlock()

		if joinInfo.gw6 != nil {
			if err := osSbox.SetGatewayIPv6(joinInfo.gw6); err != nil {
				return fmt.Errorf("failed to set IPv6 gateway: %v", err)
			}
		} else {
			if err := osSbox.SetDefaultRouteIPv6(ep6.iface.srcName); err != nil {
				return fmt.Errorf("failed to set IPv6 default route: %v", err)
			}
		}
	}

	return nil
}

func (sb *Sandbox) ExecFunc(f func()) error {
	sb.mu.Lock()
Repository: moby/moby
File: libnetwork/osl/route_linux.go (Go)

Code before:
package osl

import (
	"fmt"
	"net"
	"slices"

	"github.com/docker/docker/libnetwork/types"
	"github.com/vishvananda/netlink"
)

// Gateway returns the IPv4 gateway for the sandbox.
func (n *Namespace) Gateway() net.IP {
	n.mu.Lock()
	defer n.mu.Unlock()

	return n.gw
}

// GatewayIPv6 returns the IPv6 gateway for the sandbox.
func (n *Namespace) GatewayIPv6() net.IP {
	n.mu.Lock()
	defer n.mu.Unlock()

	return n.gwv6
}

// StaticRoutes returns additional static routes for the sandbox. Note that
// directly connected routes are stored on the particular interface they
// refer to.
func (n *Namespace) StaticRoutes() []*types.StaticRoute {
	n.mu.Lock()
	defer n.mu.Unlock()


Review comment (suggestion):
can you add a `//go:build` in this file? Similar to https://github.com/moby/moby/blob/ca0e6af56c0601eead2f03b16aa83cd1f59946df/daemon/daemon_unix.go#L1-L3



Code after:
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.22 && (linux || freebsd)

package osl

import (
	"fmt"
	"net"
	"slices"

	"github.com/docker/docker/libnetwork/types"
	"github.com/vishvananda/netlink"
)

// Gateway returns the IPv4 gateway for the sandbox.
func (n *Namespace) Gateway() net.IP {
	n.mu.Lock()
	defer n.mu.Unlock()

	return n.gw
}

// GatewayIPv6 returns the IPv6 gateway for the sandbox.
func (n *Namespace) GatewayIPv6() net.IP {
	n.mu.Lock()
	defer n.mu.Unlock()

	return n.gwv6
}

// StaticRoutes returns additional static routes for the sandbox. Note that
// directly connected routes are stored on the particular interface they
// refer to.
func (n *Namespace) StaticRoutes() []*types.StaticRoute {
Repository: moby/moby
File: testutil/daemon/ops.go (Go)

Code before:
		if err != nil {
			panic(err)
		}
		d.rootlessUser = u
	}
}

// WithOOMScoreAdjust sets OOM score for the daemon
func WithOOMScoreAdjust(score int) Option {
	return func(d *Daemon) {
		d.OOMScoreAdjust = score
	}
}

// WithEnvVars sets additional environment variables for the daemon
func WithEnvVars(vars ...string) Option {
	return func(d *Daemon) {
		d.extraEnv = append(d.extraEnv, vars...)
	}
}

// WithResolvConf allows a test to provide content for a resolv.conf file to be used
// as the basis for resolv.conf in the container, instead of the host's /etc/resolv.conf.
func WithResolvConf(content []byte) Option {
	return func(d *Daemon) {
		d.resolvConfContent = content
	}
}


Review comment (suggestion):
Not a blocker; wondering if `string` as arguments (and converting to `[]byte` internally) would make these utilities easier to use. Or at least, I often find myself creating a string, and then having to convert it to `[]byte`, because strings tend to be easier to produce 😅 

Code after:
		if err != nil {
			panic(err)
		}
		d.rootlessUser = u
	}
}

// WithOOMScoreAdjust sets OOM score for the daemon
func WithOOMScoreAdjust(score int) Option {
	return func(d *Daemon) {
		d.OOMScoreAdjust = score
	}
}

// WithEnvVars sets additional environment variables for the daemon
func WithEnvVars(vars ...string) Option {
	return func(d *Daemon) {
		d.extraEnv = append(d.extraEnv, vars...)
	}
}

// WithResolvConf allows a test to provide content for a resolv.conf file to be used
// as the basis for resolv.conf in the container, instead of the host's /etc/resolv.conf.
func WithResolvConf(content string) Option {
	return func(d *Daemon) {
		d.resolvConfContent = content
	}
}