*cdir = '\0';
snprintf(ent, maxlen, "%s/cgroup.subtree_control", cgroup_path);
DEBUG(" * %s\n", ent);
- if ((fd = open(ent, O_WRONLY)) == -1) {
+ if ((fd = open(ent, O_WRONLY)) < 0) {
ERROR("can't open %s: %m\n", ent);
continue;
}
if (write(fd, subtree_control, strlen(subtree_control)) == -1) {
ERROR("can't write to %s: %m\n", ent);
+ close(fd);
continue;
}
DEBUG("applying cgroup2 %s=\"%s\"\n", (char *)valp->avl.key, valp->val);
snprintf(ent, maxlen, "%s/%s", cgroup_path, (char *)valp->avl.key);
fd = open(ent, O_WRONLY);
- if (fd == -1) {
+ if (fd < 0) {
ERROR("can't open %s: %m\n", ent);
continue;
}
goto upper_etc_printf;
fd = creat(upperresolvconf, 0644);
- if (fd == -1) {
+ if (fd < 0) {
if (errno != EEXIST)
ERROR("creat(%s) failed: %m\n", upperresolvconf);
} else {
/* Open UNIX/98 virtual console */
console_fd = posix_openpt(O_RDWR | O_NOCTTY);
- if (console_fd == -1)
+ if (console_fd < 0)
return -1;
console_fname = ptsname(console_fd);
DEBUG("sysctl: writing '%s' to %s\n", (*cur)->value, fname);
f = open(fname, O_WRONLY);
- if (f == -1) {
+ if (f < 0) {
ERROR("sysctl: can't open %s\n", fname);
+ free(fname);
return errno;
}
if (write(f, (*cur)->value, strlen((*cur)->value)) < 0) {
ERROR("sysctl: write to %s\n", fname);
+ free(fname);
+ close(f);
return errno;
}
child_pid, gidmap?"gid_map":"uid_map") < 0)
return -1;
- if ((map_file = open(map_path, O_WRONLY)) == -1)
+ if ((map_file = open(map_path, O_WRONLY)) < 0)
return -1;
if (dprintf(map_file, "%s", mapstr)) {
child_pid, gidmap?"gid_map":"uid_map") < 0)
return -1;
- if ((map_file = open(map_path, O_WRONLY)) == -1)
+ if ((map_file = open(map_path, O_WRONLY)) < 0)
return -1;
- if (dprintf(map_file, map_format, 0, id, 1) == -1) {
+ if (dprintf(map_file, map_format, 0, id, 1) < 0) {
close(map_file);
return -1;
}
return -1;
}
- if ((setgroups_file = open(setgroups_path, O_WRONLY)) == -1) {
+ if ((setgroups_file = open(setgroups_path, O_WRONLY)) < 0) {
return -1;
}
assert(fd != NULL);
- if (*fd == -1)
+ if (*fd < 0)
return 0;
if (setns(*fd, nstype) == -1) {
/* prepend bundle directory in case of relative paths */
if (root_path[0] != '/') {
- strncpy(extroot, jsonfile, PATH_MAX);
+ strncpy(extroot, jsonfile, PATH_MAX - 1);
+
cur = strrchr(extroot, '/');
if (!cur)
blobmsg_get_string(tb[OCI_LINUX_NAMESPACE_PATH]));
fd = open(blobmsg_get_string(tb[OCI_LINUX_NAMESPACE_PATH]), O_RDONLY);
- if (fd == -1)
+ if (fd < 0)
return errno?:ESTALE;
- if (ioctl(fd, NS_GET_NSTYPE) != nstype)
+ if (ioctl(fd, NS_GET_NSTYPE) != nstype) {
+ close(fd);
return EINVAL;
+ }
DEBUG("opened existing %s namespace got filehandler %u\n",
blobmsg_get_string(tb[OCI_LINUX_NAMESPACE_TYPE]),
return ENOMEM;
tmp->mode = resolve_devtype(blobmsg_get_string(tb[OCI_DEVICES_TYPE]));
- if (!tmp->mode)
+ if (!tmp->mode) {
+ free(tmp);
return EINVAL;
+ }
if (tmp->mode != S_IFIFO) {
- if (!tb[OCI_DEVICES_MAJOR] || !tb[OCI_DEVICES_MINOR])
+ if (!tb[OCI_DEVICES_MAJOR] || !tb[OCI_DEVICES_MINOR]) {
+ free(tmp);
return ENODATA;
+ }
tmp->dev = makedev(blobmsg_get_u32(tb[OCI_DEVICES_MAJOR]),
blobmsg_get_u32(tb[OCI_DEVICES_MINOR]));
}
if (tb[OCI_DEVICES_FILEMODE]) {
- if (~(S_IRWXU|S_IRWXG|S_IRWXO) & blobmsg_get_u32(tb[OCI_DEVICES_FILEMODE]))
+ if (~(S_IRWXU|S_IRWXG|S_IRWXO) & blobmsg_get_u32(tb[OCI_DEVICES_FILEMODE])) {
+ free(tmp);
return EINVAL;
+ }
tmp->mode |= blobmsg_get_u32(tb[OCI_DEVICES_FILEMODE]);
} else {
snprintf(fname, sizeof(fname), "/proc/%u/oom_score_adj", jail_process.pid);
f = open(fname, O_WRONLY | O_TRUNC);
- if (f == -1)
+ if (f < 0)
return errno;
dprintf(f, "%d", opts.oom_score_adj);
static int checkpath(const char *path)
{
int dirfd = open(path, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
- if (dirfd == -1) {
+ if (dirfd < 0) {
ERROR("path %s open failed %m\n", path);
return -1;
}
uid_t uid = getuid();
const char log[] = "/dev/log";
const char ubus[] = "/var/run/ubus/ubus.sock";
- int ch, ret;
+ int ret = EXIT_FAILURE;
+ int ch;
if (uid) {
ERROR("not root, aborting: %m\n");
if (!(opts.namespace & CLONE_NEWNET)) {
add_mount_bind("/etc/resolv.conf", 1, 0);
- } else if (opts.setns.net == -1) {
+ } else if (opts.setns.ns == -1) {
+ /* new mount namespace to provide /dev/resolv.conf.d */
char hostdir[PATH_MAX];
snprintf(hostdir, PATH_MAX, "/tmp/resolv.conf-%s.d", opts.name);