char buf[INTTYPE_TO_STRLEN(int)] = {0};
again:
- n = read(fd, buf, sizeof(buf) - 1);
+ n = read(fd, buf, STRARRAYLEN(buf));
if (n < 0 && errno == EINTR) {
goto again;
} else if (n >= 0) {
len = strlen(entry);
prefixed = must_alloc(len + 6);
- memcpy(prefixed, "name=", sizeof("name=") - 1);
- memcpy(prefixed + sizeof("name=") - 1, entry, len);
+
+ memcpy(prefixed, "name=", STRLITERALLEN("name="));
+ memcpy(prefixed + STRLITERALLEN("name="), entry, len);
prefixed[len + 5] = '\0';
return prefixed;
}
free(full_path);
- len = strlen(base_path) + sizeof("/lxc-1000") - 1 +
- sizeof("/cgroup-procs") - 1;
+ len = strlen(base_path) + STRLITERALLEN("/lxc-1000") +
+ STRLITERALLEN("/cgroup-procs");
full_path = must_alloc(len + 1);
do {
if (idx)
for (i = 0; argv && argv[i]; i++)
size += strlen(argv[i]) + 1;
- size += sizeof("exec");
+ size += STRLITERALLEN("exec");
+ size++;
size += strlen(script);
size++;
size += strlen(p) + 1;
va_end(ap);
- size += strlen("exec");
+ size += STRLITERALLEN("exec");
size += strlen(script);
size += strlen(name);
size += strlen(section);
mntopt_sets[0] = devpts_mntopts;
/* !gid=5 && max= */
- mntopt_sets[1] = devpts_mntopts + sizeof("gid=5");
+ mntopt_sets[1] = devpts_mntopts + STRLITERALLEN("gid=5") + 1;
/* gid=5 && !max= */
mntopt_sets[2] = default_devpts_mntopts;
/* !gid=5 && !max= */
- mntopt_sets[3] = default_devpts_mntopts + sizeof("gid=5");
+ mntopt_sets[3] = default_devpts_mntopts + STRLITERALLEN("gid=5") + 1;
/* end */
mntopt_sets[4] = NULL;
*/
static const char nesting_helpers[] =
"proc dev/.lxc/proc proc create=dir,optional\n"
-"sys dev/.lxc/sys sysfs create=dir,optional\n"
-;
+"sys dev/.lxc/sys sysfs create=dir,optional\n";
FILE *make_anonymous_mount_file(struct lxc_list *mount,
bool include_nesting_helpers)
if (include_nesting_helpers) {
ret = lxc_write_nointr(fd, nesting_helpers,
- sizeof(nesting_helpers) - 1);
- if (ret != sizeof(nesting_helpers) - 1)
+ STRARRAYLEN(nesting_helpers));
+ if (ret != STRARRAYLEN(nesting_helpers))
goto on_error;
}
}
if (fd >= 0) {
- buflen = sizeof("deny\n") - 1;
+ buflen = STRLITERALLEN("deny\n");
errno = 0;
ret = lxc_write_nointr(fd, "deny\n", buflen);
close(fd);
if (version == CGROUP2_SUPER_MAGIC) {
global_token = "lxc.cgroup2";
namespaced_token = "lxc.cgroup2.";
- namespaced_token_len = sizeof("lxc.cgroup2.") - 1;
+ namespaced_token_len = STRLITERALLEN("lxc.cgroup2.");
list = &c->cgroup2;
} else if (version == CGROUP_SUPER_MAGIC) {
global_token = "lxc.cgroup";
namespaced_token = "lxc.cgroup.";
- namespaced_token_len = sizeof("lxc.cgroup.") - 1;
+ namespaced_token_len = STRLITERALLEN("lxc.cgroup.");
list = &c->cgroup;
} else {
return -EINVAL;
if (strcmp(key, global_token) == 0)
all = true;
- else if (strncmp(key, namespaced_token, sizeof(namespaced_token) - 1) == 0)
+ else if (strncmp(key, namespaced_token, namespaced_token_len) == 0)
k += namespaced_token_len;
else
return -EINVAL;
if (strcmp(key, "lxc.limit") == 0 || strcmp(key, "lxc.prlimit") == 0)
all = true;
- else if (strncmp(key, "lxc.limit.", sizeof("lxc.limit.") - 1) == 0)
- k = key + sizeof("lxc.limit.") - 1;
- else if (strncmp(key, "lxc.prlimit.", sizeof("lxc.prlimit.") - 1) == 0)
- k = key + sizeof("lxc.prlimit.") - 1;
+ else if (strncmp(key, "lxc.limit.", STRLITERALLEN("lxc.limit.")) == 0)
+ k = key + STRLITERALLEN("lxc.limit.");
+ else if (strncmp(key, "lxc.prlimit.", STRLITERALLEN("lxc.prlimit.")) == 0)
+ k = key + STRLITERALLEN("lxc.prlimit.");
else
return -1;
if (strcmp(key, "lxc.sysctl") == 0)
all = true;
- else if (strncmp(key, "lxc.sysctl.", sizeof("lxc.sysctl.") - 1) == 0)
- k = key + sizeof("lxc.sysctl.") - 1;
+ else if (strncmp(key, "lxc.sysctl.", STRLITERALLEN("lxc.sysctl.")) == 0)
+ k = key + STRLITERALLEN("lxc.sysctl.");
else
return -1;
if (strcmp(key, "lxc.proc") == 0)
all = true;
- else if (strncmp(key, "lxc.proc.", sizeof("lxc.proc.") - 1) == 0)
- k = key + sizeof("lxc.proc.") - 1;
+ else if (strncmp(key, "lxc.proc.", STRLITERALLEN("lxc.proc.")) == 0)
+ k = key + STRLITERALLEN("lxc.proc.");
else
return -1;
if (strcmp(key, "lxc.hook") == 0)
all = true;
- else if (strncmp(key, "lxc.hook.", sizeof("lxc.hook.") - 1) == 0)
- k = key + sizeof("lxc.hook.") - 1;
+ else if (strncmp(key, "lxc.hook.", STRLITERALLEN("lxc.hook.")) == 0)
+ k = key + STRLITERALLEN("lxc.hook.");
else
return -1;
if (lxc_config_value_empty(value))
return lxc_clear_limits(lxc_conf, key);
- if (strncmp(key, "lxc.prlimit.", sizeof("lxc.prlimit.") - 1) != 0)
+ if (strncmp(key, "lxc.prlimit.", STRLITERALLEN("lxc.prlimit.")) != 0)
return -1;
- key += sizeof("lxc.prlimit.") - 1;
+ key += STRLITERALLEN("lxc.prlimit.");
/* soft limit comes first in the value */
if (!parse_limit_value(&value, &limit_value))
if (lxc_config_value_empty(value))
return clr_config_sysctl(key, lxc_conf, NULL);
- if (strncmp(key, "lxc.sysctl.", sizeof("lxc.sysctl.") - 1) != 0)
+ if (strncmp(key, "lxc.sysctl.", STRLITERALLEN("lxc.sysctl.")) != 0)
return -1;
- key += sizeof("lxc.sysctl.") - 1;
+ key += STRLITERALLEN("lxc.sysctl.");
/* find existing list element */
lxc_list_for_each(iter, &lxc_conf->sysctls) {
if (lxc_config_value_empty(value))
return clr_config_proc(key, lxc_conf, NULL);
- if (strncmp(key, "lxc.proc.", sizeof("lxc.proc.") -1) != 0)
+ if (strncmp(key, "lxc.proc.", STRLITERALLEN("lxc.proc.")) != 0)
return -1;
- subkey = key + sizeof("lxc.proc.") - 1;
+ subkey = key + STRLITERALLEN("lxc.proc.");
if (*subkey == '\0')
return -EINVAL;
break;
if (strcmp("shmounts:", allowed_auto_mounts[i].token) == 0 &&
- strncmp("shmounts:", token, sizeof("shmounts:") - 1) == 0) {
+ strncmp("shmounts:", token, STRLITERALLEN("shmounts:")) == 0) {
is_shmounts = true;
break;
}
lxc_conf->auto_mounts &= ~allowed_auto_mounts[i].mask;
lxc_conf->auto_mounts |= allowed_auto_mounts[i].flag;
if (is_shmounts) {
- lxc_conf->shmount.path_host = strdup(token + (sizeof("shmounts:") - 1));
+ lxc_conf->shmount.path_host = strdup(token + STRLITERALLEN("shmounts:"));
if (!lxc_conf->shmount.path_host) {
SYSERROR("Failed to copy shmounts host path");
goto on_error;
if (lxc_config_value_empty(value))
return clr_config_namespace_share(key, lxc_conf, data);
- namespace = key + sizeof("lxc.namespace.share.") - 1;
+ namespace = key + STRLITERALLEN("lxc.namespace.share.");
ns_idx = lxc_namespace_2_ns_idx(namespace);
if (ns_idx < 0)
return ns_idx;
if (version == CGROUP2_SUPER_MAGIC) {
global_token = "lxc.cgroup2";
namespaced_token = "lxc.cgroup2.";
- namespaced_token_len = sizeof("lxc.cgroup2.") - 1;;
+ namespaced_token_len = STRLITERALLEN("lxc.cgroup2.");
} else if (version == CGROUP_SUPER_MAGIC) {
global_token = "lxc.cgroup";
namespaced_token = "lxc.cgroup.";
- namespaced_token_len = sizeof("lxc.cgroup.") - 1;;
+ namespaced_token_len = STRLITERALLEN("lxc.cgroup.");
} else {
return -1;
}
struct lxc_limit *lim = it->elem;
if (lim->limit.rlim_cur == RLIM_INFINITY) {
- memcpy(buf, "unlimited", sizeof("unlimited"));
- partlen = sizeof("unlimited") - 1;
+ memcpy(buf, "unlimited", STRLITERALLEN("unlimited") + 1);
+ partlen = STRLITERALLEN("unlimited");
} else {
partlen = sprintf(buf, "%" PRIu64,
(uint64_t)lim->limit.rlim_cur);
if (lim->limit.rlim_cur != lim->limit.rlim_max) {
if (lim->limit.rlim_max == RLIM_INFINITY)
memcpy(buf + partlen, ":unlimited",
- sizeof(":unlimited"));
+ STRLITERALLEN(":unlimited") + 1);
else
sprintf(buf + partlen, ":%" PRIu64,
(uint64_t)lim->limit.rlim_max);
if (strcmp(key, "lxc.sysctl") == 0)
get_all = true;
- else if (strncmp(key, "lxc.sysctl.", sizeof("lxc.sysctl.") - 1) == 0)
- key += sizeof("lxc.sysctl.") - 1;
+ else if (strncmp(key, "lxc.sysctl.", STRLITERALLEN("lxc.sysctl.")) == 0)
+ key += STRLITERALLEN("lxc.sysctl.");
else
return -1;
if (strcmp(key, "lxc.proc") == 0)
get_all = true;
- else if (strncmp(key, "lxc.proc.", sizeof("lxc.proc.") - 1) == 0)
- key += sizeof("lxc.proc.") - 1;
+ else if (strncmp(key, "lxc.proc.", STRLITERALLEN("lxc.proc.")) == 0)
+ key += STRLITERALLEN("lxc.proc.");
else
return -1;
else
memset(retv, 0, inlen);
- namespace = key + sizeof("lxc.namespace.share.") - 1;
+ namespace = key + STRLITERALLEN("lxc.namespace.share.");
ns_idx = lxc_namespace_2_ns_idx(namespace);
if (ns_idx < 0)
return ns_idx;
int ns_idx;
const char *namespace;
- namespace = key + sizeof("lxc.namespace.share.") - 1;
+ namespace = key + STRLITERALLEN("lxc.namespace.share.");
ns_idx = lxc_namespace_2_ns_idx(namespace);
if (ns_idx < 0)
return ns_idx;
{
char *endptr = NULL;
- if (strncmp(*value, "unlimited", sizeof("unlimited") - 1) == 0) {
+ if (strncmp(*value, "unlimited", STRLITERALLEN("unlimited")) == 0) {
*res = RLIM_INFINITY;
- *value += sizeof("unlimited") - 1;
+ *value += STRLITERALLEN("unlimited");
return true;
}
if (n < 0)
return n;
- if ((size_t)n < (sizeof(buffer) - 1)) {
+ if ((size_t)n < STRARRAYLEN(buffer)) {
ret = vsnprintf(buffer + n, sizeof(buffer) - n, event->fmt, *event->vap);
if (ret < 0)
return 0;
}
if ((size_t)n >= sizeof(buffer))
- n = sizeof(buffer) - 1;
+ n = STRARRAYLEN(buffer);
buffer[n] = '\n';
inline void lxc_log_set_prefix(const char *prefix)
{
- /* We don't care if thte prefix is truncated. */
+ /* We don't care if the prefix is truncated. */
(void)strlcpy(log_prefix, prefix, sizeof(log_prefix));
}
size = strlen(profile);
must_append_sized(&profile, &size, AA_PROFILE_BASE,
- sizeof(AA_PROFILE_BASE) - 1);
+ STRARRAYLEN(AA_PROFILE_BASE));
if (aa_supports_unix)
must_append_sized(&profile, &size, AA_PROFILE_UNIX_SOCKETS,
- sizeof(AA_PROFILE_UNIX_SOCKETS) - 1);
+ STRARRAYLEN(AA_PROFILE_UNIX_SOCKETS));
if (file_exists("/proc/self/ns/cgroup"))
must_append_sized(&profile, &size, AA_PROFILE_CGROUP_NAMESPACES,
- sizeof(AA_PROFILE_CGROUP_NAMESPACES) - 1);
+ STRARRAYLEN(AA_PROFILE_CGROUP_NAMESPACES));
if (aa_can_stack && !aa_is_stacked) {
char *namespace, *temp;
must_append_sized(&profile, &size, AA_PROFILE_STACKING_BASE,
- sizeof(AA_PROFILE_STACKING_BASE) - 1);
+ STRARRAYLEN(AA_PROFILE_STACKING_BASE));
namespace = apparmor_namespace(conf->name, lxcpath);
temp = must_concat(" change_profile -> \":", namespace, ":*\",\n"
free(temp);
} else {
must_append_sized(&profile, &size, AA_PROFILE_NO_STACKING,
- sizeof(AA_PROFILE_NO_STACKING) - 1);
+ STRARRAYLEN(AA_PROFILE_NO_STACKING));
}
if (conf->lsm_aa_allow_nesting) {
must_append_sized(&profile, &size, AA_PROFILE_NESTING_BASE,
- sizeof(AA_PROFILE_NESTING_BASE) - 1);
+ STRARRAYLEN(AA_PROFILE_NESTING_BASE));
if (!aa_can_stack || aa_is_stacked) {
char *temp;
if (!is_privileged(conf) || am_host_unpriv())
must_append_sized(&profile, &size, AA_PROFILE_UNPRIVILEGED,
- sizeof(AA_PROFILE_UNPRIVILEGED) - 1);
+ STRARRAYLEN(AA_PROFILE_UNPRIVILEGED));
lxc_list_for_each(it, &conf->lsm_aa_raw) {
const char *line = it->elem;
if (aa_can_stack && !aa_is_stacked) {
char *namespace = apparmor_namespace(conf->name, lxcpath);
size_t llen = strlen(genlabel);
- must_append_sized(&genlabel, &llen, "//&:", sizeof("//&:") - 1);
+ must_append_sized(&genlabel, &llen, "//&:", STRARRAYLEN("//&:"));
must_append_sized(&genlabel, &llen, namespace, strlen(namespace));
- must_append_sized(&genlabel, &llen, ":", sizeof(":")); /* with the nul byte */
+ must_append_sized(&genlabel, &llen, ":", STRARRAYLEN(":") + 1); /* with the nul byte */
free(namespace);
}
*/
/* length of "/lxc/lock/" + $lxcpath + "/" + "." + $lxcname + '\0' */
- len = (sizeof("/lxc/lock/") - 1) + strlen(n) + strlen(p) + 3;
+ len = STRLITERALLEN("/lxc/lock/") + strlen(n) + strlen(p) + 3;
rundir = get_rundir();
if (!rundir)
#include "confile.h"
#include "log.h"
#include "lxccontainer.h"
+#include "macro.h"
#include "overlay.h"
#include "rsync.h"
#include "storage.h"
return -22;
}
- if (strlen(lastslash) < (sizeof("/rootfs") - 1)) {
+ if (strlen(lastslash) < STRLITERALLEN("/rootfs")) {
ERROR("Failed to detect \"/rootfs\" in string \"%s\"",
new->dest);
return -22;
}
memcpy(delta, new->dest, lastslashidx + 1);
- memcpy(delta + lastslashidx, "delta0", sizeof("delta0") - 1);
- delta[lastslashidx + sizeof("delta0") - 1] = '\0';
+ memcpy(delta + lastslashidx, "delta0", STRLITERALLEN("delta0"));
+ delta[lastslashidx + STRLITERALLEN("delta0")] = '\0';
ret = mkdir(delta, 0755);
if (ret < 0 && errno != EEXIST) {
}
memcpy(work, new->dest, lastslashidx + 1);
- memcpy(work + lastslashidx, "olwork", sizeof("olwork") - 1);
- work[lastslashidx + sizeof("olwork") - 1] = '\0';
+ memcpy(work + lastslashidx, "olwork", STRLITERALLEN("olwork"));
+ work[lastslashidx + STRLITERALLEN("olwork")] = '\0';
ret = mkdir(work, 0755);
if (ret < 0) {
}
memcpy(work, ndelta, lastslashidx + 1);
- memcpy(work + lastslashidx, "olwork", sizeof("olwork") - 1);
- work[lastslashidx + sizeof("olwork") - 1] = '\0';
+ memcpy(work + lastslashidx, "olwork", STRLITERALLEN("olwork"));
+ work[lastslashidx + STRLITERALLEN("olwork")] = '\0';
ret = mkdir(work, 0755);
if (ret < 0 && errno != EEXIST) {
return -1;
}
- if (!strncmp(s1, "/snaps", sizeof("/snaps") - 1)) {
+ if (!strncmp(s1, "/snaps", STRLITERALLEN("/snaps"))) {
s1 = clean_new_path;
s2 = clean_old_path;
s3 = (char *)cname;
- } else if (!strncmp(s2, "/snaps", sizeof("/snaps") - 1)) {
+ } else if (!strncmp(s2, "/snaps", STRLITERALLEN("/snaps"))) {
s1 = clean_old_path;
s2 = clean_new_path;
s3 = (char *)oldname;
ERROR("Failed to allocate memory");
return -1;
}
- memcpy(delta + len - 6, "delta0", sizeof("delta0") - 1);
+ memcpy(delta + len - 6, "delta0", STRLITERALLEN("delta0"));
ret = mkdir_p(delta, 0755);
if (ret < 0) {
}
memcpy(work, upper, lastslashidx + 1);
- memcpy(work + lastslashidx, "olwork", sizeof("olwork") - 1);
- work[lastslashidx + sizeof("olwork") - 1] = '\0';
+ memcpy(work + lastslashidx, "olwork", STRLITERALLEN("olwork"));
+ work[lastslashidx + STRLITERALLEN("olwork")] = '\0';
ret = parse_mntopts(bdev->mntopts, &mntflags, &mntdata);
if (ret < 0) {