1
0
mirror of https://github.com/opencontainers/runc.git synced 2026-02-05 18:45:28 +01:00
Files
runc/libcontainer/nsenter/getenv.c
Cory Snider 35fddfd28f chore(libct/nsenter): extract utility code
...from nsexec.c so they can be used in cloned_binary.c.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2023-07-04 17:56:25 +10:00

28 lines
543 B
C

#define _GNU_SOURCE
#include <errno.h>
#include <stdlib.h>
#include "getenv.h"
#include "log.h"
int getenv_int(const char *name)
{
char *val, *endptr;
int ret;
val = getenv(name);
/* Treat empty value as unset variable. */
if (val == NULL || *val == '\0')
return -ENOENT;
ret = strtol(val, &endptr, 10);
if (val == endptr || *endptr != '\0')
bail("unable to parse %s=%s", name, val);
/*
* Sanity check: this must be a non-negative number.
*/
if (ret < 0)
bail("bad value for %s=%s (%d)", name, val, ret);
return ret;
}