ronantakizawa/codereview-bench huggingface dataset:
Repository: opencontainers/runc
File: libcontainer/cgroups/fs/hugetlb.go (Go)

Code before:
func (s *HugetlbGroup) Name() string {
	return "hugetlb"
}

func (s *HugetlbGroup) Apply(path string, _ *configs.Resources, pid int) error {
	return apply(path, pid)
}

func (s *HugetlbGroup) Set(path string, r *configs.Resources) error {
	for _, hugetlb := range r.HugetlbLimit {
		if err := cgroups.WriteFile(path, "hugetlb."+hugetlb.Pagesize+".limit_in_bytes", strconv.FormatUint(hugetlb.Limit, 10)); err != nil {
			return err
		}
	}

	return nil
}

func (s *HugetlbGroup) GetStats(path string, stats *cgroups.Stats) error {
	if !cgroups.PathExists(path) {
		return nil
	}
	hugetlbStats := cgroups.HugetlbStats{}
	for _, pageSize := range cgroups.HugePageSizes() {
		usage := "hugetlb." + pageSize + ".usage_in_bytes"
		value, err := fscommon.GetCgroupParamUint(path, usage)
		if err != nil {
			return err
		}
		hugetlbStats.Usage = value

		maxUsage := "hugetlb." + pageSize + ".max_usage_in_bytes"
		value, err = fscommon.GetCgroupParamUint(path, maxUsage)
		if err != nil {
			return err
		}
		hugetlbStats.MaxUsage = value

		failcnt := "hugetlb." + pageSize + ".failcnt"
		value, err = fscommon.GetCgroupParamUint(path, failcnt)
		if err != nil {
			return err
		}
		hugetlbStats.Failcnt = value

		stats.HugetlbStats[pageSize] = hugetlbStats
	}

	return nil
}


Review comment (suggestion):
the idea here, those `.rsvd.` files either exist or not, so if the first such file doesn't exist, we set the `skipRsvd=true` and do not try to use `.rsvd.` files any more.

Code after:
type HugetlbGroup struct{}

func (s *HugetlbGroup) Name() string {
	return "hugetlb"
}

func (s *HugetlbGroup) Apply(path string, _ *configs.Resources, pid int) error {
	return apply(path, pid)
}

func (s *HugetlbGroup) Set(path string, r *configs.Resources) error {
	const suffix = ".limit_in_bytes"
	skipRsvd := false

	for _, hugetlb := range r.HugetlbLimit {
		prefix := "hugetlb." + hugetlb.Pagesize
		val := strconv.FormatUint(hugetlb.Limit, 10)
		if err := cgroups.WriteFile(path, prefix+suffix, val); err != nil {
			return err
		}
		if skipRsvd {
			continue
		}
		if err := cgroups.WriteFile(path, prefix+".rsvd"+suffix, val); err != nil {
			if errors.Is(err, os.ErrNotExist) {
				skipRsvd = true
				continue
			}
			return err
		}
	}

	return nil
}

func (s *HugetlbGroup) GetStats(path string, stats *cgroups.Stats) error {
	if !cgroups.PathExists(path) {
		return nil
	}
	rsvd := ".rsvd"
	hugetlbStats := cgroups.HugetlbStats{}
	for _, pageSize := range cgroups.HugePageSizes() {
	again:
		prefix := "hugetlb." + pageSize + rsvd

		value, err := fscommon.GetCgroupParamUint(path, prefix+".usage_in_bytes")
		if err != nil {
			if rsvd != "" && errors.Is(err, os.ErrNotExist) {
				rsvd = ""
				goto again
			}
Repository: opencontainers/runc
File: delete.go (Go)

Code before:
		if err := checkArgs(context, 1, exactArgs); err != nil {
			return err
		}

		id := context.Args().First()
		force := context.Bool("force")
		container, err := getContainer(context)
		if err != nil {
			if errors.Is(err, libcontainer.ErrNotExist) {
				// if there was an aborted start or something of the sort then the container's directory could exist but
				// libcontainer does not see it because the state.json file inside that directory was never created.
				path := filepath.Join(context.GlobalString("root"), id)
				if e := os.RemoveAll(path); e != nil {
					fmt.Fprintf(os.Stderr, "remove %s: %v\n", path, e)
				}
				if force {
					return nil
				}
			}
			return err
		}
		// When --force is given, we kill all container processes and
		// then destroy the container. This is done even for a stopped
		// container, because (in case it does not have its own PID
		// namespace) there may be some leftover processes in the
		// container's cgroup.
		if force {
			return killContainer(container)
		}
		s, err := container.Status()
		if err != nil {
			return err
		}
		switch s {
		case libcontainer.Stopped:
			destroy(container)
		case libcontainer.Created:
			return killContainer(container)
		default:
			return fmt.Errorf("cannot delete container %s that is not stopped: %s", id, s)
		}

		return nil
	},
}


Review comment (suggestion):
I don't know whether `containerd` always uses `runc kill` and `runc delete -f` or not when the container is in `stopped` state.

Code after:
			return err
		}

		id := context.Args().First()
		force := context.Bool("force")
		container, err := getContainer(context)
		if err != nil {
			if errors.Is(err, libcontainer.ErrNotExist) {
				// if there was an aborted start or something of the sort then the container's directory could exist but
				// libcontainer does not see it because the state.json file inside that directory was never created.
				path := filepath.Join(context.GlobalString("root"), id)
				if e := os.RemoveAll(path); e != nil {
					fmt.Fprintf(os.Stderr, "remove %s: %v\n", path, e)
				}
				if force {
					return nil
				}
			}
			return err
		}
		// When --force is given, we kill all container processes and
		// then destroy the container. This is done even for a stopped
		// container, because (in case it does not have its own PID
		// namespace) there may be some leftover processes in the
		// container's cgroup.
		if force {
			return killContainer(container)
		}
		s, err := container.Status()
		if err != nil {
			return err
		}
		switch s {
		case libcontainer.Stopped:
			return container.Destroy()
		case libcontainer.Created:
			return killContainer(container)
		default:
			return fmt.Errorf("cannot delete container %s that is not stopped: %s", id, s)
		}
	},
}
Repository: opencontainers/runc
File: libcontainer/init_linux.go (Go)

Code before:
		return fmt.Errorf("error setting scheduler: %w", err)
	}
	return nil
}

func setupPersonality(config *configs.Config) error {
	return system.SetLinuxPersonality(config.Personality.Domain)
}

// signalAllProcesses freezes then iterates over all the processes inside the
// manager's cgroups sending the signal s to them.
func signalAllProcesses(m cgroups.Manager, s unix.Signal) error {
	if !m.Exists() {
		return ErrNotRunning
	}
	// Use cgroup.kill, if available.
	if s == unix.SIGKILL {
		if p := m.Path(""); p != "" { // Either cgroup v2 or hybrid.
			err := cgroups.WriteFile(p, "cgroup.kill", "1")
			if err == nil || !errors.Is(err, os.ErrNotExist) {
				return err
			}
			// Fallback to old implementation.
		}
	}

	if err := m.Freeze(configs.Frozen); err != nil {
		logrus.Warn(err)
	}
	pids, err := m.GetAllPids()
	if err != nil {
		if err := m.Freeze(configs.Thawed); err != nil {
			logrus.Warn(err)
		}
		return err
	}
	for _, pid := range pids {
		err := unix.Kill(pid, s)
		if err != nil && err != unix.ESRCH {
			logrus.Warnf("kill %d: %v", pid, err)
		}
	}
	if err := m.Freeze(configs.Thawed); err != nil {
		logrus.Warn(err)
	}

	return nil
}


Review comment (bug):
nit: It seems like we'd want a separate error here, since the issue is not that the container isn't running, it's that the container "no longer exists" (or rather, the cgroup no longer exists). But I guess it doesn't matter too much.

Code after:
	return nil
}

func setupScheduler(config *configs.Config) error {
	attr, err := configs.ToSchedAttr(config.Scheduler)
	if err != nil {
		return err
	}
	if err := unix.SchedSetAttr(0, attr, 0); err != nil {
		if errors.Is(err, unix.EPERM) && config.Cgroups.CpusetCpus != "" {
			return errors.New("process scheduler can't be used together with AllowedCPUs")
		}
		return fmt.Errorf("error setting scheduler: %w", err)
	}
	return nil
}

func setupPersonality(config *configs.Config) error {
	return system.SetLinuxPersonality(config.Personality.Domain)
}

// signalAllProcesses freezes then iterates over all the processes inside the
// manager's cgroups sending the signal s to them.
func signalAllProcesses(m cgroups.Manager, s unix.Signal) error {
	if !m.Exists() {
		return ErrNotRunning
	}
	// Use cgroup.kill, if available.
	if s == unix.SIGKILL {
		if p := m.Path(""); p != "" { // Either cgroup v2 or hybrid.
			err := cgroups.WriteFile(p, "cgroup.kill", "1")
			if err == nil || !errors.Is(err, os.ErrNotExist) {
				return err
			}
			// Fallback to old implementation.
		}
	}

	if err := m.Freeze(configs.Frozen); err != nil {
		logrus.Warn(err)
	}
	pids, err := m.GetAllPids()
	if err != nil {
		if err := m.Freeze(configs.Thawed); err != nil {
			logrus.Warn(err)
		}
		return err
	}
	for _, pid := range pids {
		err := unix.Kill(pid, s)
		if err != nil && err != unix.ESRCH {
Repository: opencontainers/runc
File: libcontainer/state_linux.go (Go)

Code before:

func (p *pausedState) transition(s containerState) error {
	switch s.(type) {
	case *runningState, *stoppedState:
		p.c.state = s
		return nil
	case *pausedState:
		return nil
	}
	return newStateTransitionError(p, s)
}

func (p *pausedState) destroy() error {
	if p.c.hasInit() {
		return ErrPaused
	}
	if err := p.c.cgroupManager.Freeze(configs.Thawed); err != nil {
		return err
	}
	return destroy(p.c)
}

// restoredState is the same as the running state but also has associated checkpoint
// information that maybe need destroyed when the container is stopped and destroy is called.
type restoredState struct {
	imageDir string
	c        *Container
}

func (r *restoredState) status() Status {
	return Running
}

func (r *restoredState) transition(s containerState) error {
	switch s.(type) {
	case *stoppedState, *runningState:
		return nil
	}
	return newStateTransitionError(r, s)
}

func (r *restoredState) destroy() error {
	if _, err := os.Stat(filepath.Join(r.c.stateDir, "checkpoint")); err != nil {
		if !os.IsNotExist(err) {
			return err
		}
	}
	return destroy(r.c)
}

// loadedState is used whenever a container is restored, loaded, or setting additional

Review comment (suggestion):
when `t == Created`, hasInit() returns false:

* Before this commit: It returns ErrPaused.
* After this commit: `p.c.cgroupManager.Freeze(configs.Thawed)` is executed.

Code after:
}

// pausedState represents a container that is currently pause.  It cannot be destroyed in a
// paused state and must transition back to running first.
type pausedState struct {
	c *Container
}

func (p *pausedState) status() Status {
	return Paused
}

func (p *pausedState) transition(s containerState) error {
	switch s.(type) {
	case *runningState, *stoppedState:
		p.c.state = s
		return nil
	case *pausedState:
		return nil
	}
	return newStateTransitionError(p, s)
}

func (p *pausedState) destroy() error {
	if p.c.hasInit() {
		return ErrPaused
	}
	if err := p.c.cgroupManager.Freeze(configs.Thawed); err != nil {
		return err
	}
	return destroy(p.c)
}

// restoredState is the same as the running state but also has associated checkpoint
// information that maybe need destroyed when the container is stopped and destroy is called.
type restoredState struct {
	imageDir string
	c        *Container
}

func (r *restoredState) status() Status {
	return Running
}

func (r *restoredState) transition(s containerState) error {
	switch s.(type) {
	case *stoppedState, *runningState:
		return nil
	}
	return newStateTransitionError(r, s)
}
Repository: opencontainers/runc
File: tests/integration/helpers.bash (Shell)

Code before:
			local p f
			init_cgroup_paths
			if [ -v CGROUP_V1 ]; then
				p="$CGROUP_CPU_BASE_PATH"
				f="cpu.cfs_burst_us"
			elif [ -v CGROUP_V2 ]; then
				p="$CGROUP_BASE_PATH"
				f="cpu.max.burst"
			fi
			if [ -z "$(find "$p" -name "$f" -print -quit)" ]; then
				skip_me=1
			fi
			;;
		cgroups_blk_iocost)
			local p f f2
			init_cgroup_paths
			if [ -v CGROUP_V1 ]; then
				p="$CGROUP_CPU_BASE_PATH"
				f="blkio.weight"
				f2="blkio.bfq.weight"
			elif [ -v CGROUP_V2 ]; then
				p="$CGROUP_BASE_PATH"
				f="io.weight"
				f="io.bfq.weight"
			fi
			if [ -z "$(find "$p" -name "$f" -print -quit)" ] && [ -z "$(find "$p" -name "$f2" -print -quit)" ]; then
				skip_me=1
			fi
			;;
		cgroupns)
			if [ ! -e "/proc/self/ns/cgroup" ]; then
				skip_me=1
			fi
			;;
		timens)
			if [ ! -e "/proc/self/ns/time" ]; then
				skip_me=1
			fi
			;;
		cgroups_v1)
			init_cgroup_paths
			if [ ! -v CGROUP_V1 ]; then
				skip_me=1
			fi
			;;
		cgroups_v2)
			init_cgroup_paths
			if [ ! -v CGROUP_V2 ]; then
				skip_me=1
			fi
			;;

Review comment (suggestion):
Can be simplified to
```shell
if [ -z "$(find "$p" -type f \( -name "$f1" -o -name "$f2" \) -print -quit)" ]; then
```

(I've also added `-type f` to make it more robust, and used `$f1` instead of `$f`).

Code after:
		cgroups_rt)
			init_cgroup_paths
			if [ ! -e "${CGROUP_CPU_BASE_PATH}/cpu.rt_period_us" ]; then
				skip_me=1
			fi
			;;
		cgroups_swap)
			init_cgroup_paths
			if [ -v CGROUP_V1 ] && [ ! -e "${CGROUP_MEMORY_BASE_PATH}/memory.memsw.limit_in_bytes" ]; then
				skip_me=1
			fi
			;;
		cgroups_cpu_idle)
			local p
			init_cgroup_paths
			[ -v CGROUP_V1 ] && p="$CGROUP_CPU_BASE_PATH"
			[ -v CGROUP_V2 ] && p="$CGROUP_BASE_PATH"
			if [ -z "$(find "$p" -name cpu.idle -print -quit)" ]; then
				skip_me=1
			fi
			;;
		cgroups_cpu_burst)
			local p f
			init_cgroup_paths
			if [ -v CGROUP_V1 ]; then
				p="$CGROUP_CPU_BASE_PATH"
				f="cpu.cfs_burst_us"
			elif [ -v CGROUP_V2 ]; then
				# https://github.com/torvalds/linux/commit/f4183717b370ad28dd0c0d74760142b20e6e7931
				requires_kernel 5.14
				p="$CGROUP_BASE_PATH"
				f="cpu.max.burst"
			fi
			if [ -z "$(find "$p" -name "$f" -print -quit)" ]; then
				skip_me=1
			fi
			;;
		cgroups_io_weight)
			local p f1 f2
			init_cgroup_paths
			if [ -v CGROUP_V1 ]; then
				p="$CGROUP_CPU_BASE_PATH"
				f1="blkio.weight"
				f2="blkio.bfq.weight"
			elif [ -v CGROUP_V2 ]; then
				p="$CGROUP_BASE_PATH"
				f1="io.weight"
				f2="io.bfq.weight"
			fi
			if [ -z "$(find "$p" -type f \( -name "$f1" -o -name "$f2" \) -print -quit)" ]; then
				skip_me=1
Repository: opencontainers/runc
File: tests/integration/helpers.bash (Shell)

Code before:
			fi
			;;
		cgroups_cpu_idle)
			local p
			init_cgroup_paths
			[ -v CGROUP_V1 ] && p="$CGROUP_CPU_BASE_PATH"
			[ -v CGROUP_V2 ] && p="$CGROUP_BASE_PATH"
			if [ -z "$(find "$p" -name cpu.idle -print -quit)" ]; then
				skip_me=1
			fi
			;;
		cgroups_cpu_burst)
			local p f
			init_cgroup_paths
			if [ -v CGROUP_V1 ]; then
				p="$CGROUP_CPU_BASE_PATH"
				f="cpu.cfs_burst_us"
			elif [ -v CGROUP_V2 ]; then
				p="$CGROUP_BASE_PATH"
				f="cpu.max.burst"
			fi
			if [ -z "$(find "$p" -name "$f" -print -quit)" ]; then
				skip_me=1
			fi
			;;
		cgroups_blk_iocost)
			local p f f2
			init_cgroup_paths
			if [ -v CGROUP_V1 ]; then
				p="$CGROUP_CPU_BASE_PATH"
				f="blkio.weight"
				f2="blkio.bfq.weight"
			elif [ -v CGROUP_V2 ]; then
				p="$CGROUP_BASE_PATH"
				f="io.weight"
				f="io.bfq.weight"
			fi
			if [ -z "$(find "$p" -name "$f" -print -quit)" ] && [ -z "$(find "$p" -name "$f2" -print -quit)" ]; then
				skip_me=1
			fi
			;;
		cgroupns)
			if [ ! -e "/proc/self/ns/cgroup" ]; then
				skip_me=1
			fi
			;;
		timens)
			if [ ! -e "/proc/self/ns/time" ]; then
				skip_me=1
			fi
			;;

Review comment (suggestion):
(Can't comment on commit subject, so commenting here instead).

The subject says "check  CONFIG_BLK_CGROUP_IOCOST" but that's not what the commit does.

Also, maybe rename `cgroups_blk_iocost` to `cgroups_io_weight`.

Code after:
			fi
			;;
		rootless_no_cgroup)
			if rootless_cgroup; then
				skip_me=1
			fi
			;;
		rootless_no_features)
			if [ -n "$ROOTLESS_FEATURES" ]; then
				skip_me=1
			fi
			;;
		cgroups_rt)
			init_cgroup_paths
			if [ ! -e "${CGROUP_CPU_BASE_PATH}/cpu.rt_period_us" ]; then
				skip_me=1
			fi
			;;
		cgroups_swap)
			init_cgroup_paths
			if [ -v CGROUP_V1 ] && [ ! -e "${CGROUP_MEMORY_BASE_PATH}/memory.memsw.limit_in_bytes" ]; then
				skip_me=1
			fi
			;;
		cgroups_cpu_idle)
			local p
			init_cgroup_paths
			[ -v CGROUP_V1 ] && p="$CGROUP_CPU_BASE_PATH"
			[ -v CGROUP_V2 ] && p="$CGROUP_BASE_PATH"
			if [ -z "$(find "$p" -name cpu.idle -print -quit)" ]; then
				skip_me=1
			fi
			;;
		cgroups_cpu_burst)
			local p f
			init_cgroup_paths
			if [ -v CGROUP_V1 ]; then
				p="$CGROUP_CPU_BASE_PATH"
				f="cpu.cfs_burst_us"
			elif [ -v CGROUP_V2 ]; then
				# https://github.com/torvalds/linux/commit/f4183717b370ad28dd0c0d74760142b20e6e7931
				requires_kernel 5.14
				p="$CGROUP_BASE_PATH"
				f="cpu.max.burst"
			fi
			if [ -z "$(find "$p" -name "$f" -print -quit)" ]; then
				skip_me=1
			fi
			;;
		cgroups_io_weight)
			local p f1 f2
Repository: opencontainers/runc
File: script/check-config.sh (Shell)

Code before:
#!/usr/bin/env bash
set -e -u

# bits of this were adapted from check_config.sh in docker
# see also https://github.com/docker/docker/blob/master/contrib/check-config.sh

: "${NO_COLOR:=}"
if [ -z "$NO_COLOR" ] && ! [ -t 1 ]; then
	NO_COLOR=1
fi

possibleConfigs=(
	'/proc/config.gz'
	"/boot/config-$(uname -r)"
	"/usr/src/linux-$(uname -r)/.config"
	'/usr/src/linux/.config'
)
possibleConfigFiles=(
	'config.gz'
	"config-$(uname -r)"
	'.config'
)

if ! command -v zgrep &>/dev/null; then
	zgrep() {
		zcat "$2" | grep "$1"
	}
fi

kernelVersion="$(uname -r)"
kernelMajor="${kernelVersion%%.*}"
kernelMinor="${kernelVersion#"$kernelMajor".}"
kernelMinor="${kernelMinor%%.*}"

kernel_lt() {
	[ "$kernelMajor" -lt "$1" ] && return

Review comment (refactor):
Maybe we can simplify this to
```bash
[ -t 1 ] || NO_COLOR=1
```

Code after:
#!/usr/bin/env bash
set -e -u

[ -t 1 ] || NO_COLOR=1

# bits of this were adapted from check_config.sh in docker
# see also https://github.com/docker/docker/blob/master/contrib/check-config.sh

possibleConfigs=(
	'/proc/config.gz'
	"/boot/config-$(uname -r)"
	"/usr/src/linux-$(uname -r)/.config"
	'/usr/src/linux/.config'
)
possibleConfigFiles=(
	'config.gz'
	"config-$(uname -r)"
	'.config'
)

if ! command -v zgrep &>/dev/null; then
	zgrep() {
		zcat "$2" | grep "$1"
	}
fi

kernelVersion="$(uname -r)"
kernelMajor="${kernelVersion%%.*}"
kernelMinor="${kernelVersion#"$kernelMajor".}"
kernelMinor="${kernelMinor%%.*}"

# Usage: to check if kernel version is < 4.8, use
# 	kernel_lt 4 8
# (here "lt" stands for "less than").
kernel_lt() {
	[ "$kernelMajor" -lt "$1" ] && return
Repository: opencontainers/runc
File: script/check-config.sh (Shell)

Code before:
fi

kernelVersion="$(uname -r)"
kernelMajor="${kernelVersion%%.*}"
kernelMinor="${kernelVersion#"$kernelMajor".}"
kernelMinor="${kernelMinor%%.*}"

kernel_lt() {
	[ "$kernelMajor" -lt "$1" ] && return
	[ "$kernelMajor" -eq "$1" ] && [ "$kernelMinor" -le "$2" ]
}

is_set() {
	zgrep "CONFIG_$1=[y|m]" "$CONFIG" >/dev/null
}
is_set_in_kernel() {
	zgrep "CONFIG_$1=y" "$CONFIG" >/dev/null
}
is_set_as_module() {
	zgrep "CONFIG_$1=m" "$CONFIG" >/dev/null
}

color() {
	if [ "$NO_COLOR" = "1" ]; then
		return
	fi
	local codes=()
	if [ "$1" = 'bold' ]; then
		codes=("${codes[@]-}" '1')
		shift
	fi
	if [ "$#" -gt 0 ]; then
		local code=''
		case "$1" in
		# see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
		black) code=30 ;;
		red) code=31 ;;
		green) code=32 ;;
		yellow) code=33 ;;
		blue) code=34 ;;
		magenta) code=35 ;;
		cyan) code=36 ;;
		white) code=37 ;;
		esac
		if [ "$code" ]; then
			codes=("${codes[@]-}" "$code")
		fi
	fi
	local IFS=';'
	echo -en '\033['"${codes[*]-}"'m'
}

Review comment (suggestion):
... and this to
```bash
       [ -v NO_COLOR ] && return
```

Code after:
kernelMajor="${kernelVersion%%.*}"
kernelMinor="${kernelVersion#"$kernelMajor".}"
kernelMinor="${kernelMinor%%.*}"

# Usage: to check if kernel version is < 4.8, use
# 	kernel_lt 4 8
# (here "lt" stands for "less than").
kernel_lt() {
	[ "$kernelMajor" -lt "$1" ] && return
	[ "$kernelMajor" -eq "$1" ] && [ "$kernelMinor" -lt "$2" ]
}

# Usage: to check if kernel version is >= 6.1, use
#	kernel_ge 6 1
# (here "ge" stands for "greater or equal").
kernel_ge() {
	! kernel_lt "$1" "$2"
}

is_set() {
	zgrep "CONFIG_$1=[y|m]" "$CONFIG" >/dev/null
}
is_set_in_kernel() {
	zgrep "CONFIG_$1=y" "$CONFIG" >/dev/null
}
is_set_as_module() {
	zgrep "CONFIG_$1=m" "$CONFIG" >/dev/null
}

color() {
	[ -n "${NO_COLOR:-}" ] && return

	local codes=()
	if [ "$1" = 'bold' ]; then
		codes=("${codes[@]-}" '1')
		shift
	fi
	if [ "$#" -gt 0 ]; then
		local code=''
		case "$1" in
		# see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
		black) code=30 ;;
		red) code=31 ;;
		green) code=32 ;;
		yellow) code=33 ;;
		blue) code=34 ;;
		magenta) code=35 ;;
		cyan) code=36 ;;
		white) code=37 ;;
		esac
		if [ "$code" ]; then
Repository: opencontainers/runc
File: script/check-config.sh (Shell)

Code before:
# 	kernel_lt 4 8
# (here "lt" stands for "less than").
kernel_lt() {
	[ "$kernelMajor" -lt "$1" ] && return
	[ "$kernelMajor" -eq "$1" ] && [ "$kernelMinor" -lt "$2" ]
}

# Usage: to check if kernel version is >= 6.1, use
#	kernel_ge 6 1
# (here "ge" stands for "greater or equal").
kernel_ge() {
	! kernel_lt "$1" "$2"
}

is_set() {
	zgrep "CONFIG_$1=[y|m]" "$CONFIG" >/dev/null
}
is_set_in_kernel() {
	zgrep "CONFIG_$1=y" "$CONFIG" >/dev/null
}
is_set_as_module() {
	zgrep "CONFIG_$1=m" "$CONFIG" >/dev/null
}

color() {
	[ -v NO_COLOR ] && return

	local codes=()
	if [ "$1" = 'bold' ]; then
		codes=("${codes[@]-}" '1')
		shift
	fi
	if [ "$#" -gt 0 ]; then
		local code=''
		case "$1" in
		# see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
		black) code=30 ;;
		red) code=31 ;;
		green) code=32 ;;
		yellow) code=33 ;;
		blue) code=34 ;;
		magenta) code=35 ;;
		cyan) code=36 ;;
		white) code=37 ;;
		esac
		if [ "$code" ]; then
			codes=("${codes[@]-}" "$code")
		fi
	fi
	local IFS=';'
	echo -en '\033['"${codes[*]-}"'m'

Review comment (suggestion):
nit: In theory, according to [the spec](https://no-color.org/) this should be

```suggestion
	[ -n "$NO_COLOR" ] && return
```

(Because `NO_COLOR=` should be treated as `NO_COLOR` **not** being set.)

But it doesn't really matter.

Code after:
# 	kernel_lt 4 8
# (here "lt" stands for "less than").
kernel_lt() {
	[ "$kernelMajor" -lt "$1" ] && return
	[ "$kernelMajor" -eq "$1" ] && [ "$kernelMinor" -lt "$2" ]
}

# Usage: to check if kernel version is >= 6.1, use
#	kernel_ge 6 1
# (here "ge" stands for "greater or equal").
kernel_ge() {
	! kernel_lt "$1" "$2"
}

is_set() {
	zgrep "CONFIG_$1=[y|m]" "$CONFIG" >/dev/null
}
is_set_in_kernel() {
	zgrep "CONFIG_$1=y" "$CONFIG" >/dev/null
}
is_set_as_module() {
	zgrep "CONFIG_$1=m" "$CONFIG" >/dev/null
}

color() {
	[ -n "${NO_COLOR:-}" ] && return

	local codes=()
	if [ "$1" = 'bold' ]; then
		codes=("${codes[@]-}" '1')
		shift
	fi
	if [ "$#" -gt 0 ]; then
		local code=''
		case "$1" in
		# see https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
		black) code=30 ;;
		red) code=31 ;;
		green) code=32 ;;
		yellow) code=33 ;;
		blue) code=34 ;;
		magenta) code=35 ;;
		cyan) code=36 ;;
		white) code=37 ;;
		esac
		if [ "$code" ]; then
			codes=("${codes[@]-}" "$code")
		fi
	fi
	local IFS=';'
	echo -en '\033['"${codes[*]-}"'m'