ronantakizawa/codereview-bench huggingface dataset:
Repository: opencontainers/runc
File: tests/integration/helpers.bash (Shell)

Code before:

: "${RUNC:="${INTEGRATION_ROOT}/../../runc"}"

# Path to binaries compiled from packages in tests/cmd by "make test-binaries").
TESTBINDIR=${INTEGRATION_ROOT}/../cmd/_bin

# Some variables may not always be set. Set those to empty value,
# if unset, to avoid "unbound variable" error.
: "${ROOTLESS_FEATURES:=}"

# Test data path.
# shellcheck disable=SC2034
TESTDATA="${INTEGRATION_ROOT}/testdata"

# Kernel version
KERNEL_VERSION="$(uname -r)"
KERNEL_MAJOR="${KERNEL_VERSION%%.*}"
KERNEL_MINOR="${KERNEL_VERSION#"$KERNEL_MAJOR".}"
KERNEL_MINOR="${KERNEL_MINOR%%.*}"

ARCH=$(uname -m)

# Seccomp agent socket.
SECCCOMP_AGENT_SOCKET="$BATS_TMPDIR/seccomp-agent.sock"

# Wrapper around "run2 that logs output to make tests easier to debug.
function sane_run() {
	local cmd="$1"
	shift

	run "$cmd" "$@"

	local cmdname="${CMDNAME:-}"
	[ -n "$cmdname" ] || cmdname="$(basename "$cmd")"

	# Some debug information to make life easier. bats will only print it if the
	# test failed, in which case the output is useful.
	# shellcheck disable=SC2154
	echo "$cmdname $* (status=$status)" >&2
	# shellcheck disable=SC2154
	echo "$output" >&2
}

# Wrapper for runc.
function runc() {
	CMDNAME="$(basename "$RUNC")" sane_run __runc "$@"
}

# Raw wrapper for runc.
function __runc() {
	"$RUNC" ${RUNC_USE_SYSTEMD+--systemd-cgroup} \

Review comment (refactor):
In fact, bats has `--verbose-run` now which kind of removes the need for such helper. I haven't tried that though, might not be that useful.

Code after:

: "${RUNC:="${INTEGRATION_ROOT}/../../runc"}"

# Path to binaries compiled from packages in tests/cmd by "make test-binaries").
TESTBINDIR=${INTEGRATION_ROOT}/../cmd/_bin

# Some variables may not always be set. Set those to empty value,
# if unset, to avoid "unbound variable" error.
: "${ROOTLESS_FEATURES:=}"

# Test data path.
# shellcheck disable=SC2034
TESTDATA="${INTEGRATION_ROOT}/testdata"

# Kernel version
KERNEL_VERSION="$(uname -r)"
KERNEL_MAJOR="${KERNEL_VERSION%%.*}"
KERNEL_MINOR="${KERNEL_VERSION#"$KERNEL_MAJOR".}"
KERNEL_MINOR="${KERNEL_MINOR%%.*}"

ARCH=$(uname -m)

# Seccomp agent socket.
SECCCOMP_AGENT_SOCKET="$BATS_TMPDIR/seccomp-agent.sock"

# Wrapper around "run" that logs output to make tests easier to debug.
function sane_run() {
	local cmd="$1"
	local cmdname="${CMDNAME:-$(basename "$cmd")}"
	shift

	run "$cmd" "$@"

	# Some debug information to make life easier. bats will only print it if the
	# test failed, in which case the output is useful.
	# shellcheck disable=SC2154
	echo "$cmdname $* (status=$status)" >&2
	# shellcheck disable=SC2154
	echo "$output" >&2
}

# Wrapper for runc.
function runc() {
	CMDNAME="$(basename "$RUNC")" sane_run __runc "$@"
}

function setup_runc_cmdline() {
	RUNC_CMDLINE=("$RUNC")
	[[ -v RUNC_USE_SYSTEMD ]] && RUNC_CMDLINE+=("--systemd-cgroup")
	[[ -n "${ROOT:-}" ]] && RUNC_CMDLINE+=("--root" "$ROOT/state")
	export RUNC_CMDLINE
Repository: opencontainers/runc
File: libcontainer/nsenter/log.h (C/C++)

Code before:
 * Log levels are the same as in logrus.
 */
#define PANIC   0
#define FATAL   1
#define ERROR   2
#define WARNING 3
#define INFO    4
#define DEBUG   5
#define TRACE   6

/*
 * Sets up logging by getting log fd and log level from the environment,
 * if available.
 */
void setup_logpipe(void);

bool log_enabled_for(int level);

void write_log(int level, const char *format, ...) __attribute__((format(printf, 2, 3)));

extern int logfd;
#define bail(fmt, ...)                                               \
	do {                                                         \
		if (logfd < 0)                                       \
			fprintf(stderr, "FATAL: " fmt ": %m\n",      \
				##__VA_ARGS__);                      \
		else                                                 \
			write_log(FATAL, fmt ": %m", ##__VA_ARGS__); \
		exit(1);                                             \
	} while(0)

/* bailx is the same as bail, except it does not add ": %m" (errno). */
#define bailx(fmt, ...)                                                     \
	do {                                                                \
		if (logfd < 0)                                              \
			fprintf(stderr, "FATAL: " fmt "\n", ##__VA_ARGS__); \
		else                                                        \
			write_log(FATAL, fmt, ##__VA_ARGS__);               \
		exit(1);                                                    \
	} while(0)


#endif /* NSENTER_LOG_H */


Review comment (bug):
Very nice!

I think the first three commits are bug fixes — could you please move them to a separate PR?

Code after:
 * Log levels are the same as in logrus.
 */
#define PANIC   0
#define FATAL   1
#define ERROR   2
#define WARNING 3
#define INFO    4
#define DEBUG   5
#define TRACE   6

/*
 * Sets up logging by getting log fd and log level from the environment,
 * if available.
 */
void setup_logpipe(void);

bool log_enabled_for(int level);

void write_log(int level, const char *format, ...) __attribute__((format(printf, 2, 3)));

extern int logfd;

/* bailx logs a message to logfd (or stderr, if logfd is not available)
 * and terminates the program.
 */
#define bailx(fmt, ...)                                                     \
	do {                                                                \
		if (logfd < 0)                                              \
			fprintf(stderr, "FATAL: " fmt "\n", ##__VA_ARGS__); \
		else                                                        \
			write_log(FATAL, fmt, ##__VA_ARGS__);               \
		exit(1);                                                    \
	} while(0)

/* bail is the same as bailx, except it also adds ": %m" (errno). */
#define bail(fmt, ...) bailx(fmt ": %m", ##__VA_ARGS__)

#endif /* NSENTER_LOG_H */
Repository: opencontainers/runc
File: libcontainer/nsenter/nsexec.c (C)

Code before:

int setns(int fd, int nstype)
{
	return syscall(SYS_setns, fd, nstype);
}
#endif

/*
 * CHECK_IO calls op (read or write) and checks its return value.
 * If a syscall returns -1 (error), it calls bail() to report errno.
 * Otherwise, check for a short read/write and call bailx() on error.
 */
#define CHECK_IO(op, fd, buf, count, ...) \
	do { \
		ssize_t __ret = op(fd, buf, count); \
		if (__ret < 0) \
			bail(__VA_ARGS__); \
		if (__ret != (ssize_t)(count)) \
			bailx(__VA_ARGS__ ": short " #op); \
	} while (0)

/*
 * CHECK_IO_KILL is a variant of CHECK_IO that kills PIDs before bailing.
 * Use this when you need to kill child process(es) on I/O failure.
 */
#define CHECK_IO_KILL(op, fd, buf, count, pid1, pid2, ...) \
	do { \
		ssize_t __ret = op(fd, buf, count); \
		if (__ret != (ssize_t)(count)) { \
			sane_kill(pid1, SIGKILL); \
			sane_kill(pid2, SIGKILL); \
			if (__ret < 0) \
				bail(__VA_ARGS__); \
			bailx(__VA_ARGS__ ": short " #op); \
		} \
	} while (0)

/* XXX: This is ugly. */
static int syncfd = -1;

static int write_file(char *data, size_t data_len, char *pathfmt, ...)
{
	int fd, len, ret = 0;
	char path[PATH_MAX];

	va_list ap;
	va_start(ap, pathfmt);
	len = vsnprintf(path, PATH_MAX, pathfmt, ap);
	va_end(ap);
	if (len < 0)
		return -1;

Review comment (suggestion):
From my personal opinion, I'd rather use a function to replace these two macros to improve readability. For example:
```c
void check_io(int ret, size_t size, char *err_msg, pid_t stage1_pid, pid_t stage2_pid) {
    if (ret != size) {
        sane_kill(stage1_pid, SIGKILL);
        sane_kill(stage2_pid, SIGKILL);
        if (ret < 0)
            bail(err_msg);
        bailx("%s: %d byte(s), expected: %d byte(s)", err_msg, ret, size);
    }
}
```

Code after:

int setns(int fd, int nstype)
{
	return syscall(SYS_setns, fd, nstype);
}
#endif

/* XXX: This is ugly. */
static int syncfd = -1;

static int write_file(char *data, size_t data_len, char *pathfmt, ...)
{
	int fd, len, ret = 0;
	char path[PATH_MAX];

	va_list ap;
	va_start(ap, pathfmt);
	len = vsnprintf(path, PATH_MAX, pathfmt, ap);
	va_end(ap);
	if (len < 0)
		return -1;

	fd = open(path, O_RDWR);
	if (fd < 0) {
		return -1;
	}

	len = write(fd, data, data_len);
	if (len != data_len) {
		ret = -1;
		goto out;
	}

out:
	close(fd);
	return ret;
}

enum policy_t {
	SETGROUPS_DEFAULT = 0,
	SETGROUPS_ALLOW,
	SETGROUPS_DENY,
};

/* This *must* be called before we touch gid_map. */
static void update_setgroups(int pid, enum policy_t setgroup)
{
	char *policy;

	switch (setgroup) {
	case SETGROUPS_ALLOW:
Repository: opencontainers/runc
File: libcontainer/process_linux.go (Go)

Code before:
	if !ok {
		return ""
	}

	return fs2.UnifiedMountpoint + cgroup
}

func (p *setnsProcess) addIntoCgroupV2() error {
	sub := p.process.SubCgroupPaths[""]
	err := p.manager.AddPid(sub, p.pid())
	if err == nil {
		return nil
	}

	// Failed to join the configured cgroup. Fall back to container init's cgroup
	// unless sub-cgroup is explicitly requested.
	if sub != "" {
		goto fail
	}
	if path := p.initProcessCgroupPath(); path != "" {
		logrus.Debugf("adding pid %d to configured cgroup failed (%v), will join container init cgroup %q",
			p.pid(), err, path)
		// NOTE: path is not guaranteed to exist because we didn't pause the container.
		err = cgroups.WriteCgroupProc(path, p.pid())
		if err == nil {
			return nil
		}
	}

fail:
	if p.rootlessCgroups {
		// Ignore cgroup join errors when rootless.
		return nil
	}

	return fmt.Errorf("error adding pid %d to cgroups: %w", p.pid(), err)
}

func (p *setnsProcess) addIntoCgroup() error {
	if p.cmd.SysProcAttr.UseCgroupFD {
		// We've used cgroupfd successfully, so the process is
		// already in the proper cgroup, nothing to do here.
		return nil
	}
	if cgroups.IsCgroup2UnifiedMode() {
		return p.addIntoCgroupV2()
	}
	return p.addIntoCgroupV1()
}

// prepareCgroupFD sets up p.cmd to use clone3 with CLONE_INTO_CGROUP

Review comment (bug):
```suggestion
		if err := cgroups.WriteCgroupProc(path, p.pid()); err != nil {
			goto fail
	        }
	        return nil
```

Code after:
	if !ok {
		return ""
	}

	return fs2.UnifiedMountpoint + cgroup
}

func (p *setnsProcess) addIntoCgroupV2() error {
	sub := p.process.SubCgroupPaths[""]
	err := p.manager.AddPid(sub, p.pid())
	if err == nil {
		return nil
	}

	// Failed to join the configured cgroup. Fall back to container init's cgroup
	// unless sub-cgroup is explicitly requested.
	var path string
	if sub != "" {
		goto fail
	}
	path = p.initProcessCgroupPath()
	if path == "" {
		goto fail
	}
	logrus.Debugf("adding pid %d to configured cgroup failed (%v), will join container init cgroup %q", p.pid(), err, path)
	// NOTE: path is not guaranteed to exist because we didn't pause the container.
	err = cgroups.WriteCgroupProc(path, p.pid())
	if err != nil {
		goto fail
	}
	return nil

fail:
	if p.rootlessCgroups {
		// Ignore cgroup join errors when rootless.
		return nil
	}

	return fmt.Errorf("error adding pid %d to cgroups: %w", p.pid(), err)
}

func (p *setnsProcess) addIntoCgroup() error {
	if p.cmd.SysProcAttr.UseCgroupFD {
		// We've used cgroupfd successfully, so the process is
		// already in the proper cgroup, nothing to do here.
		return nil
	}
	if cgroups.IsCgroup2UnifiedMode() {
		return p.addIntoCgroupV2()
	}
	return p.addIntoCgroupV1()
Repository: opencontainers/runc
File: libcontainer/process_linux.go (Go)

Code before:
		return nil, nil
	}

	base := p.manager.Path("")
	if base == "" { // No cgroup to join.
		return nil, nil
	}
	sub := ""
	if p.process.SubCgroupPaths != nil {
		sub = p.process.SubCgroupPaths[""]
	}
	cgroup := path.Join(base, sub)
	if !strings.HasPrefix(cgroup, base) {
		return nil, fmt.Errorf("bad sub cgroup path: %s", sub)
	}

	fd, err := cgroups.OpenFile(base, sub, openFlags)
	if err == nil {
		goto success
	}
	// Failed to open the configured cgroup. Fall back to container init's cgroup
	// unless sub-cgroup is explicitly requested.
	if sub != "" {
		goto fail
	}
	if initCg := p.initProcessCgroupPath(); initCg != "" {
		logrus.Debugf("failed to open configured cgroup %q: %v, try using container init's cgroup %q",
			cgroup, err, initCg)
		// We do not freeze the container so cgroup is not guaranteed to exist.
		fd, err = cgroups.OpenFile(initCg, "", openFlags)
		if err != nil {
			goto fail
		}
		cgroup = initCg
	}

success:
	logrus.Debugf("using CLONE_INTO_CGROUP %q", cgroup)
	if p.cmd.SysProcAttr == nil {
		p.cmd.SysProcAttr = &syscall.SysProcAttr{}
	}
	p.cmd.SysProcAttr.UseCgroupFD = true
	p.cmd.SysProcAttr.CgroupFD = int(fd.Fd())

	return fd, nil

fail:
	// Ignore cgroup join error for rootless.
	if p.rootlessCgroups {
		return nil, nil
	}

Review comment (suggestion):
So if initCg is "" we  go to success. If that is inteded, I think I'd just handle that case explicitelly (`if initCg == "" { goto success } `. But is that on purpose? It seems that we couldn't open the cgroup and we didn't find a process cgroup, so we should return an error?

But it's morning here, I might be missing something obvious :D

Code after:
	const openFlags = unix.O_PATH | unix.O_DIRECTORY | unix.O_CLOEXEC

	if !cgroups.IsCgroup2UnifiedMode() {
		return nil, nil
	}

	base := p.manager.Path("")
	if base == "" { // No cgroup to join.
		return nil, nil
	}
	sub := ""
	if p.process.SubCgroupPaths != nil {
		sub = p.process.SubCgroupPaths[""]
	}
	cgroup := path.Join(base, sub)
	if !strings.HasPrefix(cgroup, base) {
		return nil, fmt.Errorf("bad sub cgroup path: %s", sub)
	}

	fd, err := cgroups.OpenFile(base, sub, openFlags)
	if err == nil {
		goto success
	}
	// Failed to open the configured cgroup. Fall back to container init's cgroup
	// unless sub-cgroup is explicitly requested. The fallback logic should be
	// the same as in addIntoCgroupV2.
	if sub != "" {
		goto fail
	}
	cgroup = p.initProcessCgroupPath()
	if cgroup == "" {
		goto fail
	}
	logrus.Debugf("failed to open configured cgroup (%v), will open container init cgroup %q", err, cgroup)
	// NOTE: path is not guaranteed to exist because we didn't pause the container.
	fd, err = cgroups.OpenFile(cgroup, "", openFlags)
	if err != nil {
		goto fail
	}

success:
	logrus.Debugf("using CLONE_INTO_CGROUP %q", cgroup)
	if p.cmd.SysProcAttr == nil {
		p.cmd.SysProcAttr = &syscall.SysProcAttr{}
	}
	p.cmd.SysProcAttr.UseCgroupFD = true
	p.cmd.SysProcAttr.CgroupFD = int(fd.Fd())

	return fd, nil

fail:
Repository: opencontainers/runc
File: libcontainer/process_linux.go (Go)

Code before:
	if p.initProcessPid == 0 || !cgroups.IsCgroup2UnifiedMode() {
		return ""
	}

	cg, err := cgroups.ParseCgroupFile("/proc/" + strconv.Itoa(p.initProcessPid) + "/cgroup")
	if err != nil {
		return ""
	}
	cgroup, ok := cg[""]
	if !ok {
		return ""
	}

	return fs2.UnifiedMountpoint + cgroup
}

func (p *setnsProcess) addIntoCgroupV2() error {
	sub := p.process.SubCgroupPaths[""]
	err := p.manager.AddPid(sub, p.pid())
	if err == nil {
		return nil
	}

	// Failed to join the configured cgroup. Fall back to container init's cgroup
	// unless sub-cgroup is explicitly requested.
	var path string
	if sub != "" {
		goto fail
	}
	if path = p.initProcessCgroupPath(); path == "" {
		goto fail
	}
	logrus.Debugf("adding pid %d to configured cgroup failed (%v), will join container init cgroup %q", p.pid(), err, path)
	// NOTE: path is not guaranteed to exist because we didn't pause the container.
	err = cgroups.WriteCgroupProc(path, p.pid())
	if err != nil {
		goto fail
	}
	return nil

fail:
	if p.rootlessCgroups {
		// Ignore cgroup join errors when rootless.
		return nil
	}

	return fmt.Errorf("error adding pid %d to cgroups: %w", p.pid(), err)
}

func (p *setnsProcess) addIntoCgroup() error {
	if p.cmd.SysProcAttr.UseCgroupFD {

Review comment (suggestion):
Super nit and feel free to ignore. But I don't really like the C89 style of declaring variables at the beginning (and since C99 already is not needed, almost 30 years ago :D). I think doing this before the if is more clear:
```
path := p.initProcessCgroupPath()
if path == "" { ....
```

And I also think it is clearer to not assign inside the if, when the variable is not scoped to the if. IMHO the code is more readable like that.

But again, this is a complete nit and personal preference, feel free to ignore :)

Code after:
	if p.initProcessPid == 0 || !cgroups.IsCgroup2UnifiedMode() {
		return ""
	}

	cg, err := cgroups.ParseCgroupFile("/proc/" + strconv.Itoa(p.initProcessPid) + "/cgroup")
	if err != nil {
		return ""
	}
	cgroup, ok := cg[""]
	if !ok {
		return ""
	}

	return fs2.UnifiedMountpoint + cgroup
}

func (p *setnsProcess) addIntoCgroupV2() error {
	sub := p.process.SubCgroupPaths[""]
	err := p.manager.AddPid(sub, p.pid())
	if err == nil {
		return nil
	}

	// Failed to join the configured cgroup. Fall back to container init's cgroup
	// unless sub-cgroup is explicitly requested.
	var path string
	if sub != "" {
		goto fail
	}
	path = p.initProcessCgroupPath()
	if path == "" {
		goto fail
	}
	logrus.Debugf("adding pid %d to configured cgroup failed (%v), will join container init cgroup %q", p.pid(), err, path)
	// NOTE: path is not guaranteed to exist because we didn't pause the container.
	err = cgroups.WriteCgroupProc(path, p.pid())
	if err != nil {
		goto fail
	}
	return nil

fail:
	if p.rootlessCgroups {
		// Ignore cgroup join errors when rootless.
		return nil
	}

	return fmt.Errorf("error adding pid %d to cgroups: %w", p.pid(), err)
}

func (p *setnsProcess) addIntoCgroup() error {
Repository: opencontainers/runc
File: libcontainer/process_linux.go (Go)

Code before:
	}

	base := p.manager.Path("")
	if base == "" { // No cgroup to join.
		return nil, nil
	}
	sub := ""
	if p.process.SubCgroupPaths != nil {
		sub = p.process.SubCgroupPaths[""]
	}
	cgroup := path.Join(base, sub)
	if !strings.HasPrefix(cgroup, base) {
		return nil, fmt.Errorf("bad sub cgroup path: %s", sub)
	}

	fd, err := cgroups.OpenFile(base, sub, openFlags)
	if err == nil {
		goto success
	}
	// Failed to open the configured cgroup. Fall back to container init's cgroup
	// unless sub-cgroup is explicitly requested. The fallback logic should be
	// the same as in addIntoCgroupV2.
	if sub != "" {
		goto fail
	}
	if cgroup = p.initProcessCgroupPath(); cgroup == "" {
		goto fail
	}
	logrus.Debugf("failed to open configured cgroup (%v), will open container init cgroup %q", err, cgroup)
	// NOTE: path is not guaranteed to exist because we didn't pause the container.
	fd, err = cgroups.OpenFile(cgroup, "", openFlags)
	if err != nil {
		goto fail
	}

success:
	logrus.Debugf("using CLONE_INTO_CGROUP %q", cgroup)
	if p.cmd.SysProcAttr == nil {
		p.cmd.SysProcAttr = &syscall.SysProcAttr{}
	}
	p.cmd.SysProcAttr.UseCgroupFD = true
	p.cmd.SysProcAttr.CgroupFD = int(fd.Fd())

	return fd, nil

fail:
	// Ignore cgroup join error for rootless.
	if p.rootlessCgroups {
		return nil, nil
	}
	return nil, fmt.Errorf("can't open cgroup: %w", err)

Review comment (bug):
And here too, if you like this pattern more (spaces probably broken, sorry :/):
```suggestion
    cgroup = p.initProcessCgroupPath(); 
	if cgroup == "" {
```

Or just ignore too :)

Code after:
		return nil, nil
	}

	base := p.manager.Path("")
	if base == "" { // No cgroup to join.
		return nil, nil
	}
	sub := ""
	if p.process.SubCgroupPaths != nil {
		sub = p.process.SubCgroupPaths[""]
	}
	cgroup := path.Join(base, sub)
	if !strings.HasPrefix(cgroup, base) {
		return nil, fmt.Errorf("bad sub cgroup path: %s", sub)
	}

	fd, err := cgroups.OpenFile(base, sub, openFlags)
	if err == nil {
		goto success
	}
	// Failed to open the configured cgroup. Fall back to container init's cgroup
	// unless sub-cgroup is explicitly requested. The fallback logic should be
	// the same as in addIntoCgroupV2.
	if sub != "" {
		goto fail
	}
	cgroup = p.initProcessCgroupPath()
	if cgroup == "" {
		goto fail
	}
	logrus.Debugf("failed to open configured cgroup (%v), will open container init cgroup %q", err, cgroup)
	// NOTE: path is not guaranteed to exist because we didn't pause the container.
	fd, err = cgroups.OpenFile(cgroup, "", openFlags)
	if err != nil {
		goto fail
	}

success:
	logrus.Debugf("using CLONE_INTO_CGROUP %q", cgroup)
	if p.cmd.SysProcAttr == nil {
		p.cmd.SysProcAttr = &syscall.SysProcAttr{}
	}
	p.cmd.SysProcAttr.UseCgroupFD = true
	p.cmd.SysProcAttr.CgroupFD = int(fd.Fd())

	return fd, nil

fail:
	// Ignore cgroup join error for rootless.
	if p.rootlessCgroups {
		return nil, nil
Repository: opencv/opencv
File: samples/opengl/opengl3_2.cpp (C++)

Code before:

void draw(void* userdata){
    DrawData* data = static_cast<DrawData*>(userdata);
    static float angle = 0.0f;
    angle += 1.f;

    cv::Mat trans = rot(CV_PI * angle / 360.f);

    glClearColor(0.0, 0.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glUseProgram(data->program);
    glUniformMatrix4fv(glGetUniformLocation(data->program, "transform"), 1, GL_FALSE, trans.ptr<float>());
    glBindTexture(GL_TEXTURE_2D, data->textureID);
    glBindVertexArray(data->vao);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    glBindVertexArray(0);
}

int main(int argc, char* argv[])
{
    string filename;
    if (argc < 2)
    {
        cout << "Usage: " << argv[0] << " image" << endl;
        filename = "lena.jpg";
    }
    else
        filename = argv[1];

    Mat img = imread(samples::findFile(filename));
    if (img.empty())
    {
        cerr << "Can't open image " << filename << endl;
        return -1;
    }
    flip(img, img, 0);

    namedWindow("OpenGL", WINDOW_OPENGL);
    resizeWindow("OpenGL", win_width, win_height);

    DrawData data;

    glEnable(GL_DEPTH_TEST);
    const char *vertex_shader_source =
            "#version 330 core\n"
            "layout (location = 0) in vec3 position;\n"
            "layout (location = 1) in vec2 texCoord;\n"
            "out vec2 TexCoord;\n"
            "uniform mat4 transform;\n"
            "void main() {\n"

Review comment (suggestion):
similar to #25635 - perhaps choose a different default file name from the https://github.com/opencv/opencv/tree/4.x/samples/data samples e.g.
```suggestion
        filename = "HappyFish.jpg";
```

Code after:

static void draw(void* userdata) {
    DrawData* data = static_cast<DrawData*>(userdata);
    static float angle = 0.0f;
    angle += 1.f;

    cv::Mat trans = rot(CV_PI * angle / 360.f);

    glClearColor(0.0, 0.0, 0.0, 1.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glUseProgram(data->program);
    glUniformMatrix4fv(glGetUniformLocation(data->program, "transform"), 1, GL_FALSE, trans.ptr<float>());
    glBindTexture(GL_TEXTURE_2D, data->textureID);
    glBindVertexArray(data->vao);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    glBindVertexArray(0);
}

int main(int argc, char* argv[])
{
    string filename;
    if (argc < 2)
    {
        cout << "Usage: " << argv[0] << " image" << endl;
        filename = "baboon.jpg";
    }
    else
        filename = argv[1];

    Mat img = imread(samples::findFile(filename));
    if (img.empty())
    {
        cerr << "Can't open image " << filename << endl;
        return -1;
    }
    flip(img, img, 0);

    namedWindow("OpenGL", WINDOW_OPENGL);
    resizeWindow("OpenGL", win_width, win_height);

    DrawData data;

    glEnable(GL_DEPTH_TEST);
    const char *vertex_shader_source =
            "#version 330 core\n"
            "layout (location = 0) in vec3 position;\n"
            "layout (location = 1) in vec2 texCoord;\n"
            "out vec2 TexCoord;\n"
            "uniform mat4 transform;\n"
            "void main() {\n"