char path[PATH_MAX];
ssize_t ret;
- ret = snprintf(path, sizeof(path), "%s/tty.info", directory);
- if (ret < 0 || (size_t)ret >= sizeof(path))
+ ret = strnprintf(path, sizeof(path), "%s/tty.info", directory);
+ if (ret < 0)
return ret_errno(EIO);
ret = lxc_read_from_file(path, output, len);
static_args += 2 * lxc_list_len(&opts->c->lxc_conf->mount_list);
- ret = snprintf(log, PATH_MAX, "%s/%s.log", opts->user->directory, opts->action);
- if (ret < 0 || ret >= PATH_MAX)
+ ret = strnprintf(log, sizeof(log), "%s/%s.log", opts->user->directory, opts->action);
+ if (ret < 0)
return ret_errno(EIO);
args = zalloc(sizeof(struct criu_exec_args) + (static_args * sizeof(char **)));
continue;
if (strcmp(opts->action, "dump") == 0)
- ret = snprintf(arg, sizeof(arg), "/%s:%s", mntent.mnt_dir, mntent.mnt_dir);
+ ret = strnprintf(arg, sizeof(arg), "/%s:%s", mntent.mnt_dir, mntent.mnt_dir);
else
- ret = snprintf(arg, sizeof(arg), "%s:%s", mntent.mnt_dir, mntent.mnt_fsname);
- if (ret < 0 || ret >= sizeof(arg))
+ ret = strnprintf(arg, sizeof(arg), "%s:%s", mntent.mnt_dir, mntent.mnt_fsname);
+ if (ret < 0)
return log_error_errno(-EIO, EIO, "Failed to create mount entry");
DECLARE_ARG("--ext-mount-map");
if (init_pid < 0)
return log_error_errno(-ESRCH, ESRCH, "Failed to retrieve init pid of container");
- ret = snprintf(init_pid_str, sizeof(init_pid_str), "%d", init_pid);
- if (ret < 0 || (size_t)ret >= sizeof(init_pid_str))
+ ret = strnprintf(init_pid_str, sizeof(init_pid_str), "%d", init_pid);
+ if (ret < 0)
return log_error_errno(-EIO, EIO, "Failed to create entry for init pid of container");
DECLARE_ARG("-t");
return log_error_errno(-ENOENT, ENOENT, "Failed getting freezer path");
if (pure_unified_layout(cgroup_ops))
- ret = snprintf(log, sizeof(log), "/sys/fs/cgroup/%s", freezer_relative);
+ ret = strnprintf(log, sizeof(log), "/sys/fs/cgroup/%s", freezer_relative);
else
- ret = snprintf(log, sizeof(log), "/sys/fs/cgroup/freezer/%s", freezer_relative);
- if (ret < 0 || ret >= sizeof(log))
+ ret = strnprintf(log, sizeof(log), "/sys/fs/cgroup/freezer/%s", freezer_relative);
+ if (ret < 0)
return log_error_errno(-EIO, EIO, "Failed to freezer cgroup entry");
if (!opts->user->disable_skip_in_flight &&
if (opts->console_fd < 0)
return log_error_errno(-EINVAL, EINVAL, "lxc.console.path configured on source host but not target");
- ret = snprintf(buf, sizeof(buf), "fd[%d]:%s", opts->console_fd, ttys);
- if (ret < 0 || ret >= sizeof(buf))
+ ret = strnprintf(buf, sizeof(buf), "fd[%d]:%s", opts->console_fd, ttys);
+ if (ret < 0)
return log_error_errno(-EIO, EIO, "Failed to create console entry");
DECLARE_ARG("--inherit-fd");
DECLARE_ARG(buf);
}
if (opts->console_name) {
- if (snprintf(buf, sizeof(buf), "console:%s", opts->console_name) < 0)
+ if (strnprintf(buf, sizeof(buf), "console:%s", opts->console_name) < 0)
return log_error_errno(-EIO, EIO, "Failed to create console entry");
DECLARE_ARG("--ext-mount-map");
if (lxc_conf->lsm_aa_profile || lxc_conf->lsm_se_context) {
if (lxc_conf->lsm_aa_profile)
- ret = snprintf(buf, sizeof(buf), "apparmor:%s", lxc_conf->lsm_aa_profile);
+ ret = strnprintf(buf, sizeof(buf), "apparmor:%s", lxc_conf->lsm_aa_profile);
else
- ret = snprintf(buf, sizeof(buf), "selinux:%s", lxc_conf->lsm_se_context);
- if (ret < 0 || ret >= sizeof(buf))
+ ret = strnprintf(buf, sizeof(buf), "selinux:%s", lxc_conf->lsm_se_context);
+ if (ret < 0)
return log_error_errno(-EIO, EIO, "Failed to create lsm entry");
DECLARE_ARG("--lsm-profile");
if (retlen >= sizeof(eth))
return log_error_errno(-E2BIG, E2BIG, "Failed to append veth device name");
} else {
- ret = snprintf(eth, sizeof(eth), "eth%d", netnr);
- if (ret < 0 || ret >= sizeof(eth))
+ ret = strnprintf(eth, sizeof(eth), "eth%d", netnr);
+ if (ret < 0)
return log_error_errno(-E2BIG, E2BIG, "Failed to append veth device name");
}
if (n->link[0] != '\0') {
if (external_not_veth)
- ret = snprintf(buf, sizeof(buf), "veth[%s]:%s@%s", eth, veth, n->link);
+ ret = strnprintf(buf, sizeof(buf), "veth[%s]:%s@%s", eth, veth, n->link);
else
- ret = snprintf(buf, sizeof(buf), "%s=%s@%s", eth, veth, n->link);
+ ret = strnprintf(buf, sizeof(buf), "%s=%s@%s", eth, veth, n->link);
} else {
if (external_not_veth)
- ret = snprintf(buf, sizeof(buf), "veth[%s]:%s", eth, veth);
+ ret = strnprintf(buf, sizeof(buf), "veth[%s]:%s", eth, veth);
else
- ret = snprintf(buf, sizeof(buf), "%s=%s", eth, veth);
+ ret = strnprintf(buf, sizeof(buf), "%s=%s", eth, veth);
}
- if (ret < 0 || ret >= sizeof(buf))
+ if (ret < 0)
return log_error_errno(-EIO, EIO, "Failed to append veth device name");
TRACE("Added veth device entry %s", buf);
if (n->link[0] == '\0')
return log_error_errno(-EINVAL, EINVAL, "Failed to find host interface for macvlan %s", n->name);
- ret = snprintf(buf, sizeof(buf), "macvlan[%s]:%s", eth, n->link);
- if (ret < 0 || ret >= sizeof(buf))
+ ret = strnprintf(buf, sizeof(buf), "macvlan[%s]:%s", eth, n->link);
+ if (ret < 0)
return log_error_errno(-EIO, EIO, "Failed to add macvlan entry");
TRACE("Added macvlan device entry %s", buf);
if (lxc_log_trace()) {
buf[0] = 0;
for (int i = 0, pos = 0; i < args->argc && args->argv[i]; i++) {
- ret = snprintf(buf + pos, sizeof(buf) - pos, "%s ", args->argv[i]);
- if (ret < 0 || ret >= sizeof(buf) - pos)
+ ret = strnprintf(buf + pos, sizeof(buf) - pos, "%s ", args->argv[i]);
+ if (ret < 0)
return log_error_errno(-EIO, EIO, "Failed to reorder entries");
else
pos += ret;
if (netdev->type != LXC_NET_VETH)
continue;
- ret = snprintf(template, sizeof(template), "vethXXXXXX");
- if (ret < 0 || ret >= sizeof(template))
+ ret = strnprintf(template, sizeof(template), "vethXXXXXX");
+ if (ret < 0)
goto out_unlock;
if (netdev->priv.veth_attr.pair[0] == '\0' &&
ERROR("criu process exited %d, output:\n%s", WEXITSTATUS(status), buf);
goto out_fini_handler;
} else {
- ret = snprintf(buf, sizeof(buf), "/proc/self/task/%lu/children", (unsigned long)syscall(__NR_gettid));
- if (ret < 0 || ret >= sizeof(buf)) {
- ERROR("snprintf'd too many characters: %d", ret);
+ ret = strnprintf(buf, sizeof(buf), "/proc/self/task/%lu/children", (unsigned long)syscall(__NR_gettid));
+ if (ret < 0) {
+ ERROR("strnprintf'd too many characters: %d", ret);
goto out_fini_handler;
}
* fail because it's just a beauty thing. We just
* assign the return here to silence potential.
*/
- ret = snprintf(title, sizeof(title), "[lxc monitor] %s %s", c->config_path, c->name);
- if (ret < 0 || (size_t)ret >= sizeof(title))
+ ret = strnprintf(title, sizeof(title), "[lxc monitor] %s %s", c->config_path, c->name);
+ if (ret < 0)
INFO("Setting truncated process name");
ret = setproctitle(title);
return 0;
}
- ret = snprintf(path, sizeof(path), "/proc/%d/root/dev/console", c->init_pid(c));
- if (ret < 0 || ret >= sizeof(path)) {
- ERROR("snprintf'd too many characters: %d", ret);
+ ret = strnprintf(path, sizeof(path), "/proc/%d/root/dev/console", c->init_pid(c));
+ if (ret < 0) {
+ ERROR("strnprintf'd too many characters: %d", ret);
return -1;
}
return -1;
}
- ret = snprintf(path, sizeof(path), "%s/tty.info", directory);
- if (ret < 0 || ret >= sizeof(path)) {
- ERROR("snprintf'd too many characters: %d", ret);
+ ret = strnprintf(path, sizeof(path), "%s/tty.info", directory);
+ if (ret < 0) {
+ ERROR("strnprintf'd too many characters: %d", ret);
return -1;
}
- ret = snprintf(tty_id, len, "tty[%llx:%llx]",
+ ret = strnprintf(tty_id, len, "tty[%llx:%llx]",
(long long unsigned) sb.st_rdev,
(long long unsigned) sb.st_dev);
- if (ret < 0 || ret >= sizeof(path)) {
- ERROR("snprintf'd too many characters: %d", ret);
+ if (ret < 0) {
+ ERROR("strnprintf'd too many characters: %d", ret);
return -1;
}
char path[PATH_MAX];
int ret;
- ret = snprintf(path, sizeof(path), "%s/inventory.img", opts->directory);
- if (ret < 0 || ret >= sizeof(path))
+ ret = strnprintf(path, sizeof(path), "%s/inventory.img", opts->directory);
+ if (ret < 0)
return false;
if (access(path, F_OK) == 0) {