Merge pull request #2675 from brauner/2018-10-07/path_max

tree-wide: s/MAXPATHLEN/PATH_MAX/g
This commit is contained in:
Wolfgang Bumiller 2018-10-07 10:43:08 +02:00 committed by GitHub
commit 969e23f2e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 216 additions and 209 deletions

View File

@ -28,6 +28,7 @@
#include <errno.h> #include <errno.h>
#include <getopt.h> #include <getopt.h>
#include <libgen.h> #include <libgen.h>
#include <limits.h>
#include <pthread.h> #include <pthread.h>
#include <signal.h> #include <signal.h>
#include <stdio.h> #include <stdio.h>
@ -108,7 +109,7 @@ static void prevent_forking(void)
FILE *f; FILE *f;
size_t len = 0; size_t len = 0;
char *line = NULL; char *line = NULL;
char path[MAXPATHLEN]; char path[PATH_MAX];
f = fopen("/proc/self/cgroup", "r"); f = fopen("/proc/self/cgroup", "r");
if (!f) if (!f)
@ -202,10 +203,10 @@ static void remove_self(void)
{ {
int ret; int ret;
ssize_t n; ssize_t n;
char path[MAXPATHLEN] = {0}; char path[PATH_MAX] = {0};
n = readlink("/proc/self/exe", path, sizeof(path)); n = readlink("/proc/self/exe", path, sizeof(path));
if (n < 0 || n >= MAXPATHLEN) { if (n < 0 || n >= PATH_MAX) {
SYSDEBUG("Failed to readlink \"/proc/self/exe\""); SYSDEBUG("Failed to readlink \"/proc/self/exe\"");
return; return;
} }

View File

@ -542,7 +542,7 @@ int run_script(const char *name, const char *section, const char *script, ...)
int pin_rootfs(const char *rootfs) int pin_rootfs(const char *rootfs)
{ {
int fd, ret; int fd, ret;
char absrootfspin[MAXPATHLEN]; char absrootfspin[PATH_MAX];
char *absrootfs; char *absrootfs;
struct stat s; struct stat s;
struct statfs sfs; struct statfs sfs;
@ -565,9 +565,9 @@ int pin_rootfs(const char *rootfs)
return -2; return -2;
} }
ret = snprintf(absrootfspin, MAXPATHLEN, "%s/.lxc-keep", absrootfs); ret = snprintf(absrootfspin, PATH_MAX, "%s/.lxc-keep", absrootfs);
free(absrootfs); free(absrootfs);
if (ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return -1; return -1;
fd = open(absrootfspin, O_CREAT | O_RDWR, S_IWUSR | S_IRUSR); fd = open(absrootfspin, O_CREAT | O_RDWR, S_IWUSR | S_IRUSR);
@ -639,7 +639,7 @@ unsigned long add_required_remount_flags(const char *s, const char *d,
static int add_shmount_to_list(struct lxc_conf *conf) static int add_shmount_to_list(struct lxc_conf *conf)
{ {
char new_mount[MAXPATHLEN]; char new_mount[PATH_MAX];
/* Offset for the leading '/' since the path_cont /* Offset for the leading '/' since the path_cont
* is absolute inside the container. * is absolute inside the container.
*/ */
@ -833,7 +833,7 @@ static const struct dev_symlinks dev_symlinks[] = {
static int lxc_setup_dev_symlinks(const struct lxc_rootfs *rootfs) static int lxc_setup_dev_symlinks(const struct lxc_rootfs *rootfs)
{ {
int i, ret; int i, ret;
char path[MAXPATHLEN]; char path[PATH_MAX];
struct stat s; struct stat s;
for (i = 0; i < sizeof(dev_symlinks) / sizeof(dev_symlinks[0]); i++) { for (i = 0; i < sizeof(dev_symlinks) / sizeof(dev_symlinks[0]); i++) {
@ -841,7 +841,7 @@ static int lxc_setup_dev_symlinks(const struct lxc_rootfs *rootfs)
ret = snprintf(path, sizeof(path), "%s/dev/%s", ret = snprintf(path, sizeof(path), "%s/dev/%s",
rootfs->path ? rootfs->mount : "", d->name); rootfs->path ? rootfs->mount : "", d->name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return -1; return -1;
/* Stat the path first. If we don't get an error accept it as /* Stat the path first. If we don't get an error accept it as
@ -897,7 +897,7 @@ static int lxc_setup_ttys(struct lxc_conf *conf)
int i, ret; int i, ret;
const struct lxc_tty_info *ttys = &conf->ttys; const struct lxc_tty_info *ttys = &conf->ttys;
char *ttydir = ttys->dir; char *ttydir = ttys->dir;
char path[MAXPATHLEN], lxcpath[MAXPATHLEN]; char path[PATH_MAX], lxcpath[PATH_MAX];
if (!conf->rootfs.path) if (!conf->rootfs.path)
return 0; return 0;
@ -1218,13 +1218,13 @@ enum {
static int lxc_fill_autodev(const struct lxc_rootfs *rootfs) static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
{ {
int i, ret; int i, ret;
char path[MAXPATHLEN]; char path[PATH_MAX];
mode_t cmask; mode_t cmask;
int use_mknod = LXC_DEVNODE_MKNOD; int use_mknod = LXC_DEVNODE_MKNOD;
ret = snprintf(path, MAXPATHLEN, "%s/dev", ret = snprintf(path, PATH_MAX, "%s/dev",
rootfs->path ? rootfs->mount : ""); rootfs->path ? rootfs->mount : "");
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return -1; return -1;
/* ignore, just don't try to fill in */ /* ignore, just don't try to fill in */
@ -1235,12 +1235,12 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
cmask = umask(S_IXUSR | S_IXGRP | S_IXOTH); cmask = umask(S_IXUSR | S_IXGRP | S_IXOTH);
for (i = 0; i < sizeof(lxc_devices) / sizeof(lxc_devices[0]); i++) { for (i = 0; i < sizeof(lxc_devices) / sizeof(lxc_devices[0]); i++) {
char hostpath[MAXPATHLEN]; char hostpath[PATH_MAX];
const struct lxc_device_node *device = &lxc_devices[i]; const struct lxc_device_node *device = &lxc_devices[i];
ret = snprintf(path, MAXPATHLEN, "%s/dev/%s", ret = snprintf(path, PATH_MAX, "%s/dev/%s",
rootfs->path ? rootfs->mount : "", device->name); rootfs->path ? rootfs->mount : "", device->name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return -1; return -1;
if (use_mknod >= LXC_DEVNODE_MKNOD) { if (use_mknod >= LXC_DEVNODE_MKNOD) {
@ -1292,8 +1292,8 @@ static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
} }
/* Fallback to bind-mounting the device from the host. */ /* Fallback to bind-mounting the device from the host. */
ret = snprintf(hostpath, MAXPATHLEN, "/dev/%s", device->name); ret = snprintf(hostpath, PATH_MAX, "/dev/%s", device->name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return -1; return -1;
ret = safe_mount(hostpath, path, 0, MS_BIND, NULL, ret = safe_mount(hostpath, path, 0, MS_BIND, NULL,
@ -1747,7 +1747,7 @@ static int lxc_setup_dev_console(const struct lxc_rootfs *rootfs,
const struct lxc_terminal *console) const struct lxc_terminal *console)
{ {
int ret; int ret;
char path[MAXPATHLEN]; char path[PATH_MAX];
char *rootfs_path = rootfs->path ? rootfs->mount : ""; char *rootfs_path = rootfs->path ? rootfs->mount : "";
if (console->path && !strcmp(console->path, "none")) if (console->path && !strcmp(console->path, "none"))
@ -1801,7 +1801,7 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
char *ttydir) char *ttydir)
{ {
int ret; int ret;
char path[MAXPATHLEN], lxcpath[MAXPATHLEN]; char path[PATH_MAX], lxcpath[PATH_MAX];
char *rootfs_path = rootfs->path ? rootfs->mount : ""; char *rootfs_path = rootfs->path ? rootfs->mount : "";
if (console->path && !strcmp(console->path, "none")) if (console->path && !strcmp(console->path, "none"))
@ -2015,15 +2015,15 @@ static int mount_entry(const char *fsname, const char *target,
bool dev, bool relative, const char *rootfs) bool dev, bool relative, const char *rootfs)
{ {
int ret; int ret;
char srcbuf[MAXPATHLEN]; char srcbuf[PATH_MAX];
const char *srcpath = fsname; const char *srcpath = fsname;
#ifdef HAVE_STATVFS #ifdef HAVE_STATVFS
struct statvfs sb; struct statvfs sb;
#endif #endif
if (relative) { if (relative) {
ret = snprintf(srcbuf, MAXPATHLEN, "%s/%s", rootfs ? rootfs : "/", fsname ? fsname : ""); ret = snprintf(srcbuf, PATH_MAX, "%s/%s", rootfs ? rootfs : "/", fsname ? fsname : "");
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= PATH_MAX) {
ERROR("source path is too long"); ERROR("source path is too long");
return -1; return -1;
} }
@ -2257,7 +2257,7 @@ static inline int mount_entry_on_generic(struct mntent *mntent,
static inline int mount_entry_on_systemfs(struct mntent *mntent) static inline int mount_entry_on_systemfs(struct mntent *mntent)
{ {
int ret; int ret;
char path[MAXPATHLEN]; char path[PATH_MAX];
/* For containers created without a rootfs all mounts are treated as /* For containers created without a rootfs all mounts are treated as
* absolute paths starting at / on the host. * absolute paths starting at / on the host.
@ -2280,7 +2280,7 @@ static int mount_entry_on_absolute_rootfs(struct mntent *mntent,
int offset; int offset;
char *aux; char *aux;
const char *lxcpath; const char *lxcpath;
char path[MAXPATHLEN]; char path[PATH_MAX];
int ret = 0; int ret = 0;
lxcpath = lxc_global_config_value("lxc.lxcpath"); lxcpath = lxc_global_config_value("lxc.lxcpath");
@ -2290,8 +2290,8 @@ static int mount_entry_on_absolute_rootfs(struct mntent *mntent,
/* If rootfs->path is a blockdev path, allow container fstab to use /* If rootfs->path is a blockdev path, allow container fstab to use
* <lxcpath>/<name>/rootfs" as the target prefix. * <lxcpath>/<name>/rootfs" as the target prefix.
*/ */
ret = snprintf(path, MAXPATHLEN, "%s/%s/rootfs", lxcpath, lxc_name); ret = snprintf(path, PATH_MAX, "%s/%s/rootfs", lxcpath, lxc_name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
goto skipvarlib; goto skipvarlib;
aux = strstr(mntent->mnt_dir, path); aux = strstr(mntent->mnt_dir, path);
@ -2309,8 +2309,8 @@ skipvarlib:
offset = strlen(rootfs->path); offset = strlen(rootfs->path);
skipabs: skipabs:
ret = snprintf(path, MAXPATHLEN, "%s/%s", rootfs->mount, aux + offset); ret = snprintf(path, PATH_MAX, "%s/%s", rootfs->mount, aux + offset);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return -1; return -1;
return mount_entry_on_generic(mntent, path, rootfs, lxc_name, lxc_path); return mount_entry_on_generic(mntent, path, rootfs, lxc_name, lxc_path);
@ -2322,7 +2322,7 @@ static int mount_entry_on_relative_rootfs(struct mntent *mntent,
const char *lxc_path) const char *lxc_path)
{ {
int ret; int ret;
char path[MAXPATHLEN]; char path[PATH_MAX];
/* relative to root mount point */ /* relative to root mount point */
ret = snprintf(path, sizeof(path), "%s/%s", rootfs->mount, mntent->mnt_dir); ret = snprintf(path, sizeof(path), "%s/%s", rootfs->mount, mntent->mnt_dir);
@ -2662,7 +2662,7 @@ int setup_sysctl_parameters(struct lxc_list *sysctls)
struct lxc_sysctl *elem; struct lxc_sysctl *elem;
int ret = 0; int ret = 0;
char *tmp = NULL; char *tmp = NULL;
char filename[MAXPATHLEN] = {0}; char filename[PATH_MAX] = {0};
lxc_list_for_each (it, sysctls) { lxc_list_for_each (it, sysctls) {
elem = it->elem; elem = it->elem;
@ -2697,7 +2697,7 @@ int setup_proc_filesystem(struct lxc_list *procs, pid_t pid)
struct lxc_proc *elem; struct lxc_proc *elem;
int ret = 0; int ret = 0;
char *tmp = NULL; char *tmp = NULL;
char filename[MAXPATHLEN] = {0}; char filename[PATH_MAX] = {0};
lxc_list_for_each (it, procs) { lxc_list_for_each (it, procs) {
elem = it->elem; elem = it->elem;
@ -2806,13 +2806,13 @@ int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf,
size_t buf_size) size_t buf_size)
{ {
int fd, ret; int fd, ret;
char path[MAXPATHLEN]; char path[PATH_MAX];
if (geteuid() != 0 && idtype == ID_TYPE_GID) { if (geteuid() != 0 && idtype == ID_TYPE_GID) {
size_t buflen; size_t buflen;
ret = snprintf(path, MAXPATHLEN, "/proc/%d/setgroups", pid); ret = snprintf(path, PATH_MAX, "/proc/%d/setgroups", pid);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return -E2BIG; return -E2BIG;
fd = open(path, O_WRONLY); fd = open(path, O_WRONLY);
@ -2835,9 +2835,9 @@ int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf,
} }
} }
ret = snprintf(path, MAXPATHLEN, "/proc/%d/%cid_map", pid, ret = snprintf(path, PATH_MAX, "/proc/%d/%cid_map", pid,
idtype == ID_TYPE_UID ? 'u' : 'g'); idtype == ID_TYPE_UID ? 'u' : 'g');
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return -E2BIG; return -E2BIG;
fd = open(path, O_WRONLY); fd = open(path, O_WRONLY);
@ -2938,7 +2938,7 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid)
int fill, left; int fill, left;
char u_or_g; char u_or_g;
char *pos; char *pos;
char cmd_output[MAXPATHLEN]; char cmd_output[PATH_MAX];
struct id_map *map; struct id_map *map;
struct lxc_list *iterator; struct lxc_list *iterator;
enum idtype type; enum idtype type;
@ -3171,7 +3171,7 @@ int chown_mapped_root(const char *path, struct lxc_conf *conf)
"-m", map5, "-m", map5,
"--", "chown", ugid, path, "--", "chown", ugid, path,
NULL}; NULL};
char cmd_output[MAXPATHLEN]; char cmd_output[PATH_MAX];
hostuid = geteuid(); hostuid = geteuid();
hostgid = getegid(); hostgid = getegid();
@ -3507,7 +3507,7 @@ int lxc_setup_rootfs_prepare_root(struct lxc_conf *conf, const char *name,
static bool verify_start_hooks(struct lxc_conf *conf) static bool verify_start_hooks(struct lxc_conf *conf)
{ {
char path[MAXPATHLEN]; char path[PATH_MAX];
struct lxc_list *it; struct lxc_list *it;
lxc_list_for_each (it, &conf->hooks[LXCHOOK_START]) { lxc_list_for_each (it, &conf->hooks[LXCHOOK_START]) {
@ -3515,10 +3515,10 @@ static bool verify_start_hooks(struct lxc_conf *conf)
struct stat st; struct stat st;
char *hookname = it->elem; char *hookname = it->elem;
ret = snprintf(path, MAXPATHLEN, "%s%s", ret = snprintf(path, PATH_MAX, "%s%s",
conf->rootfs.path ? conf->rootfs.mount : "", conf->rootfs.path ? conf->rootfs.mount : "",
hookname); hookname);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return false; return false;
ret = stat(path, &st); ret = stat(path, &st);

View File

@ -2068,7 +2068,7 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf)
{ {
struct dirent *direntp; struct dirent *direntp;
DIR *dir; DIR *dir;
char path[MAXPATHLEN]; char path[PATH_MAX];
int len; int len;
int ret = -1; int ret = -1;
@ -2090,8 +2090,8 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf)
if (len < 6 || strncmp(fnam + len - 5, ".conf", 5) != 0) if (len < 6 || strncmp(fnam + len - 5, ".conf", 5) != 0)
continue; continue;
len = snprintf(path, MAXPATHLEN, "%s/%s", dirp, fnam); len = snprintf(path, PATH_MAX, "%s/%s", dirp, fnam);
if (len < 0 || len >= MAXPATHLEN) { if (len < 0 || len >= PATH_MAX) {
ret = -1; ret = -1;
goto out; goto out;
} }

View File

@ -339,7 +339,7 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
#ifdef STRERROR_R_CHAR_P #ifdef STRERROR_R_CHAR_P
#define lxc_log_strerror_r \ #define lxc_log_strerror_r \
char errno_buf[MAXPATHLEN / 2] = {"Failed to get errno string"}; \ char errno_buf[PATH_MAX / 2] = {"Failed to get errno string"}; \
char *ptr = NULL; \ char *ptr = NULL; \
{ \ { \
int saved_errno = errno; \ int saved_errno = errno; \
@ -350,7 +350,7 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
} }
#else #else
#define lxc_log_strerror_r \ #define lxc_log_strerror_r \
char errno_buf[MAXPATHLEN / 2] = {"Failed to get errno string"}; \ char errno_buf[PATH_MAX / 2] = {"Failed to get errno string"}; \
char *ptr = errno_buf; \ char *ptr = errno_buf; \
{ \ { \
int saved_errno = errno; \ int saved_errno = errno; \

View File

@ -809,7 +809,7 @@ static int run_apparmor_parser(char command,
struct lxc_conf *conf, struct lxc_conf *conf,
const char *lxcpath) const char *lxcpath)
{ {
char output[MAXPATHLEN]; char output[PATH_MAX];
int ret; int ret;
struct apparmor_parser_args args = { struct apparmor_parser_args args = {
.cmd = command, .cmd = command,

View File

@ -2673,8 +2673,8 @@ static bool mod_rdep(struct lxc_container *c0, struct lxc_container *c, bool inc
struct stat fbuf; struct stat fbuf;
void *buf = NULL; void *buf = NULL;
char *del = NULL; char *del = NULL;
char path[MAXPATHLEN]; char path[PATH_MAX];
char newpath[MAXPATHLEN]; char newpath[PATH_MAX];
int fd, ret, n = 0, v = 0; int fd, ret, n = 0, v = 0;
bool bret = false; bool bret = false;
size_t len = 0, bytes = 0; size_t len = 0, bytes = 0;
@ -2682,12 +2682,12 @@ static bool mod_rdep(struct lxc_container *c0, struct lxc_container *c, bool inc
if (container_disk_lock(c0)) if (container_disk_lock(c0))
return false; return false;
ret = snprintf(path, MAXPATHLEN, "%s/%s/lxc_snapshots", c0->config_path, c0->name); ret = snprintf(path, PATH_MAX, "%s/%s/lxc_snapshots", c0->config_path, c0->name);
if (ret < 0 || ret > MAXPATHLEN) if (ret < 0 || ret > PATH_MAX)
goto out; goto out;
ret = snprintf(newpath, MAXPATHLEN, "%s\n%s\n", c->config_path, c->name); ret = snprintf(newpath, PATH_MAX, "%s\n%s\n", c->config_path, c->name);
if (ret < 0 || ret > MAXPATHLEN) if (ret < 0 || ret > PATH_MAX)
goto out; goto out;
/* If we find an lxc-snapshot file using the old format only listing the /* If we find an lxc-snapshot file using the old format only listing the
@ -2798,14 +2798,14 @@ out:
void mod_all_rdeps(struct lxc_container *c, bool inc) void mod_all_rdeps(struct lxc_container *c, bool inc)
{ {
struct lxc_container *p; struct lxc_container *p;
char *lxcpath = NULL, *lxcname = NULL, path[MAXPATHLEN]; char *lxcpath = NULL, *lxcname = NULL, path[PATH_MAX];
size_t pathlen = 0, namelen = 0; size_t pathlen = 0, namelen = 0;
FILE *f; FILE *f;
int ret; int ret;
ret = snprintf(path, MAXPATHLEN, "%s/%s/lxc_rdepends", ret = snprintf(path, PATH_MAX, "%s/%s/lxc_rdepends",
c->config_path, c->name); c->config_path, c->name);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= PATH_MAX) {
ERROR("Path name too long"); ERROR("Path name too long");
return; return;
} }
@ -2845,14 +2845,14 @@ out:
static bool has_fs_snapshots(struct lxc_container *c) static bool has_fs_snapshots(struct lxc_container *c)
{ {
FILE *f; FILE *f;
char path[MAXPATHLEN]; char path[PATH_MAX];
int ret, v; int ret, v;
struct stat fbuf; struct stat fbuf;
bool bret = false; bool bret = false;
ret = snprintf(path, MAXPATHLEN, "%s/%s/lxc_snapshots", c->config_path, ret = snprintf(path, PATH_MAX, "%s/%s/lxc_snapshots", c->config_path,
c->name); c->name);
if (ret < 0 || ret > MAXPATHLEN) if (ret < 0 || ret > PATH_MAX)
goto out; goto out;
/* If the file doesn't exist there are no snapshots. */ /* If the file doesn't exist there are no snapshots. */
@ -2880,7 +2880,7 @@ out:
static bool has_snapshots(struct lxc_container *c) static bool has_snapshots(struct lxc_container *c)
{ {
char path[MAXPATHLEN]; char path[PATH_MAX];
struct dirent *direntp; struct dirent *direntp;
int count=0; int count=0;
DIR *dir; DIR *dir;
@ -3408,7 +3408,7 @@ static int copyhooks(struct lxc_container *oldc, struct lxc_container *c)
lxc_list_for_each(it, &c->lxc_conf->hooks[i]) { lxc_list_for_each(it, &c->lxc_conf->hooks[i]) {
char *hookname = it->elem; char *hookname = it->elem;
char *fname = strrchr(hookname, '/'); char *fname = strrchr(hookname, '/');
char tmppath[MAXPATHLEN]; char tmppath[PATH_MAX];
if (!fname) /* relative path - we don't support, but maybe we should */ if (!fname) /* relative path - we don't support, but maybe we should */
return 0; return 0;
@ -3418,9 +3418,9 @@ static int copyhooks(struct lxc_container *oldc, struct lxc_container *c)
} }
/* copy the script, and change the entry in confile */ /* copy the script, and change the entry in confile */
ret = snprintf(tmppath, MAXPATHLEN, "%s/%s/%s", ret = snprintf(tmppath, PATH_MAX, "%s/%s/%s",
c->config_path, c->name, fname+1); c->config_path, c->name, fname+1);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return -1; return -1;
ret = copy_file(it->elem, tmppath); ret = copy_file(it->elem, tmppath);
@ -3450,7 +3450,7 @@ static int copyhooks(struct lxc_container *oldc, struct lxc_container *c)
static int copy_fstab(struct lxc_container *oldc, struct lxc_container *c) static int copy_fstab(struct lxc_container *oldc, struct lxc_container *c)
{ {
char newpath[MAXPATHLEN]; char newpath[PATH_MAX];
char *oldpath = oldc->lxc_conf->fstab; char *oldpath = oldc->lxc_conf->fstab;
int ret; int ret;
@ -3463,9 +3463,9 @@ static int copy_fstab(struct lxc_container *oldc, struct lxc_container *c)
if (!p) if (!p)
return -1; return -1;
ret = snprintf(newpath, MAXPATHLEN, "%s/%s%s", ret = snprintf(newpath, PATH_MAX, "%s/%s%s",
c->config_path, c->name, p); c->config_path, c->name, p);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= PATH_MAX) {
ERROR("error printing new path for %s", oldpath); ERROR("error printing new path for %s", oldpath);
return -1; return -1;
} }
@ -3498,19 +3498,19 @@ static int copy_fstab(struct lxc_container *oldc, struct lxc_container *c)
static void copy_rdepends(struct lxc_container *c, struct lxc_container *c0) static void copy_rdepends(struct lxc_container *c, struct lxc_container *c0)
{ {
char path0[MAXPATHLEN], path1[MAXPATHLEN]; char path0[PATH_MAX], path1[PATH_MAX];
int ret; int ret;
ret = snprintf(path0, MAXPATHLEN, "%s/%s/lxc_rdepends", c0->config_path, ret = snprintf(path0, PATH_MAX, "%s/%s/lxc_rdepends", c0->config_path,
c0->name); c0->name);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= PATH_MAX) {
WARN("Error copying reverse dependencies"); WARN("Error copying reverse dependencies");
return; return;
} }
ret = snprintf(path1, MAXPATHLEN, "%s/%s/lxc_rdepends", c->config_path, ret = snprintf(path1, PATH_MAX, "%s/%s/lxc_rdepends", c->config_path,
c->name); c->name);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= PATH_MAX) {
WARN("Error copying reverse dependencies"); WARN("Error copying reverse dependencies");
return; return;
} }
@ -3524,13 +3524,13 @@ static void copy_rdepends(struct lxc_container *c, struct lxc_container *c0)
static bool add_rdepends(struct lxc_container *c, struct lxc_container *c0) static bool add_rdepends(struct lxc_container *c, struct lxc_container *c0)
{ {
int ret; int ret;
char path[MAXPATHLEN]; char path[PATH_MAX];
FILE *f; FILE *f;
bool bret; bool bret;
ret = snprintf(path, MAXPATHLEN, "%s/%s/lxc_rdepends", c->config_path, ret = snprintf(path, PATH_MAX, "%s/%s/lxc_rdepends", c->config_path,
c->name); c->name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return false; return false;
f = fopen(path, "a"); f = fopen(path, "a");
@ -3644,7 +3644,7 @@ static int clone_update_rootfs(struct clone_update_data *data)
int flags = data->flags; int flags = data->flags;
char **hookargs = data->hookargs; char **hookargs = data->hookargs;
int ret = -1; int ret = -1;
char path[MAXPATHLEN]; char path[PATH_MAX];
struct lxc_storage *bdev; struct lxc_storage *bdev;
FILE *fout; FILE *fout;
struct lxc_conf *conf = c->lxc_conf; struct lxc_conf *conf = c->lxc_conf;
@ -3720,10 +3720,10 @@ static int clone_update_rootfs(struct clone_update_data *data)
} }
if (!(flags & LXC_CLONE_KEEPNAME)) { if (!(flags & LXC_CLONE_KEEPNAME)) {
ret = snprintf(path, MAXPATHLEN, "%s/etc/hostname", bdev->dest); ret = snprintf(path, PATH_MAX, "%s/etc/hostname", bdev->dest);
storage_put(bdev); storage_put(bdev);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return -1; return -1;
if (!file_exists(path)) if (!file_exists(path))
@ -3785,7 +3785,7 @@ static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char
const char *bdevtype, const char *bdevdata, uint64_t newsize, const char *bdevtype, const char *bdevdata, uint64_t newsize,
char **hookargs) char **hookargs)
{ {
char newpath[MAXPATHLEN]; char newpath[PATH_MAX];
int fd, ret; int fd, ret;
struct clone_update_data data; struct clone_update_data data;
size_t saved_unexp_len; size_t saved_unexp_len;
@ -3812,8 +3812,8 @@ static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char
if (!lxcpath) if (!lxcpath)
lxcpath = do_lxcapi_get_config_path(c); lxcpath = do_lxcapi_get_config_path(c);
ret = snprintf(newpath, MAXPATHLEN, "%s/%s/config", lxcpath, newname); ret = snprintf(newpath, PATH_MAX, "%s/%s/config", lxcpath, newname);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= PATH_MAX) {
SYSERROR("clone: failed making config pathname"); SYSERROR("clone: failed making config pathname");
goto out; goto out;
} }
@ -3861,8 +3861,8 @@ static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char
saved_unexp_conf = NULL; saved_unexp_conf = NULL;
c->lxc_conf->unexpanded_len = saved_unexp_len; c->lxc_conf->unexpanded_len = saved_unexp_len;
ret = snprintf(newpath, MAXPATHLEN, "%s/%s/rootfs", lxcpath, newname); ret = snprintf(newpath, PATH_MAX, "%s/%s/rootfs", lxcpath, newname);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= PATH_MAX) {
SYSERROR("clone: failed making rootfs pathname"); SYSERROR("clone: failed making rootfs pathname");
goto out; goto out;
} }
@ -4111,13 +4111,13 @@ static bool get_snappath_dir(struct lxc_container *c, char *snappath)
* If the old style snapshot path exists, use it * If the old style snapshot path exists, use it
* /var/lib/lxc -> /var/lib/lxcsnaps * /var/lib/lxc -> /var/lib/lxcsnaps
*/ */
ret = snprintf(snappath, MAXPATHLEN, "%ssnaps", c->config_path); ret = snprintf(snappath, PATH_MAX, "%ssnaps", c->config_path);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return false; return false;
if (dir_exists(snappath)) { if (dir_exists(snappath)) {
ret = snprintf(snappath, MAXPATHLEN, "%ssnaps/%s", c->config_path, c->name); ret = snprintf(snappath, PATH_MAX, "%ssnaps/%s", c->config_path, c->name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return false; return false;
return true; return true;
@ -4127,8 +4127,8 @@ static bool get_snappath_dir(struct lxc_container *c, char *snappath)
* Use the new style path * Use the new style path
* /var/lib/lxc -> /var/lib/lxc + c->name + /snaps + \0 * /var/lib/lxc -> /var/lib/lxc + c->name + /snaps + \0
*/ */
ret = snprintf(snappath, MAXPATHLEN, "%s/%s/snaps", c->config_path, c->name); ret = snprintf(snappath, PATH_MAX, "%s/%s/snaps", c->config_path, c->name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return false; return false;
return true; return true;
@ -4140,7 +4140,7 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
time_t timer; time_t timer;
struct tm tm_info; struct tm tm_info;
struct lxc_container *c2; struct lxc_container *c2;
char snappath[MAXPATHLEN], newname[20]; char snappath[PATH_MAX], newname[20];
char buffer[25]; char buffer[25];
FILE *f; FILE *f;
@ -4260,12 +4260,12 @@ static char *get_snapcomment_path(char* snappath, char *name)
static char *get_timestamp(char* snappath, char *name) static char *get_timestamp(char* snappath, char *name)
{ {
char path[MAXPATHLEN], *s = NULL; char path[PATH_MAX], *s = NULL;
int ret, len; int ret, len;
FILE *fin; FILE *fin;
ret = snprintf(path, MAXPATHLEN, "%s/%s/ts", snappath, name); ret = snprintf(path, PATH_MAX, "%s/%s/ts", snappath, name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return NULL; return NULL;
fin = fopen(path, "r"); fin = fopen(path, "r");
@ -4293,7 +4293,7 @@ static char *get_timestamp(char* snappath, char *name)
static int do_lxcapi_snapshot_list(struct lxc_container *c, struct lxc_snapshot **ret_snaps) static int do_lxcapi_snapshot_list(struct lxc_container *c, struct lxc_snapshot **ret_snaps)
{ {
char snappath[MAXPATHLEN], path2[MAXPATHLEN]; char snappath[PATH_MAX], path2[PATH_MAX];
int count = 0, ret; int count = 0, ret;
struct dirent *direntp; struct dirent *direntp;
struct lxc_snapshot *snaps =NULL, *nsnaps; struct lxc_snapshot *snaps =NULL, *nsnaps;
@ -4320,8 +4320,8 @@ static int do_lxcapi_snapshot_list(struct lxc_container *c, struct lxc_snapshot
if (!strcmp(direntp->d_name, "..")) if (!strcmp(direntp->d_name, ".."))
continue; continue;
ret = snprintf(path2, MAXPATHLEN, "%s/%s/config", snappath, direntp->d_name); ret = snprintf(path2, PATH_MAX, "%s/%s/config", snappath, direntp->d_name);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= PATH_MAX) {
ERROR("pathname too long"); ERROR("pathname too long");
goto out_free; goto out_free;
} }
@ -4378,7 +4378,7 @@ WRAP_API_1(int, lxcapi_snapshot_list, struct lxc_snapshot **)
static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snapname, const char *newname) static bool do_lxcapi_snapshot_restore(struct lxc_container *c, const char *snapname, const char *newname)
{ {
char clonelxcpath[MAXPATHLEN]; char clonelxcpath[PATH_MAX];
int flags = 0; int flags = 0;
struct lxc_container *snap, *rest; struct lxc_container *snap, *rest;
struct lxc_storage *bdev; struct lxc_storage *bdev;
@ -4516,7 +4516,7 @@ static bool remove_all_snapshots(const char *path)
static bool do_lxcapi_snapshot_destroy(struct lxc_container *c, const char *snapname) static bool do_lxcapi_snapshot_destroy(struct lxc_container *c, const char *snapname)
{ {
char clonelxcpath[MAXPATHLEN]; char clonelxcpath[PATH_MAX];
if (!c || !c->name || !c->config_path || !snapname) if (!c || !c->name || !c->config_path || !snapname)
return false; return false;
@ -4531,7 +4531,7 @@ WRAP_API_1(bool, lxcapi_snapshot_destroy, const char *)
static bool do_lxcapi_snapshot_destroy_all(struct lxc_container *c) static bool do_lxcapi_snapshot_destroy_all(struct lxc_container *c)
{ {
char clonelxcpath[MAXPATHLEN]; char clonelxcpath[PATH_MAX];
if (!c || !c->name || !c->config_path) if (!c || !c->name || !c->config_path)
return false; return false;
@ -4560,7 +4560,7 @@ static bool do_add_remove_node(pid_t init_pid, const char *path, bool add,
int ret; int ret;
char *tmp; char *tmp;
pid_t pid; pid_t pid;
char chrootpath[MAXPATHLEN]; char chrootpath[PATH_MAX];
char *directory_path = NULL; char *directory_path = NULL;
pid = fork(); pid = fork();
@ -4580,8 +4580,8 @@ static bool do_add_remove_node(pid_t init_pid, const char *path, bool add,
} }
/* prepare the path */ /* prepare the path */
ret = snprintf(chrootpath, MAXPATHLEN, "/proc/%d/root", init_pid); ret = snprintf(chrootpath, PATH_MAX, "/proc/%d/root", init_pid);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return false; return false;
ret = chroot(chrootpath); ret = chroot(chrootpath);
@ -4974,7 +4974,7 @@ static int do_lxcapi_mount(struct lxc_container *c, const char *source,
struct lxc_mount *mnt) struct lxc_mount *mnt)
{ {
char *suff, *sret; char *suff, *sret;
char template[MAXPATHLEN], path[MAXPATHLEN]; char template[PATH_MAX], path[PATH_MAX];
pid_t pid, init_pid; pid_t pid, init_pid;
struct stat sb; struct stat sb;
int ret = -1, fd = -EBADF; int ret = -1, fd = -EBADF;

View File

@ -21,6 +21,7 @@
#define __LXC_MACRO_H #define __LXC_MACRO_H
#include <asm/types.h> #include <asm/types.h>
#include <limits.h>
#include <linux/if_link.h> #include <linux/if_link.h>
#include <linux/loop.h> #include <linux/loop.h>
#include <linux/netlink.h> #include <linux/netlink.h>
@ -33,6 +34,10 @@
#include <sys/un.h> #include <sys/un.h>
#include <unistd.h> #include <unistd.h>
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
/* Define __S_ISTYPE if missing from the C library. */ /* Define __S_ISTYPE if missing from the C library. */
#ifndef __S_ISTYPE #ifndef __S_ISTYPE
#define __S_ISTYPE(mode, mask) (((mode)&S_IFMT) == (mask)) #define __S_ISTYPE(mode, mask) (((mode)&S_IFMT) == (mask))
@ -179,7 +184,7 @@
*/ */
#define LXC_LSMATTRLEN (6 + INTTYPE_TO_STRLEN(pid_t) + 6 + 8 + 1) #define LXC_LSMATTRLEN (6 + INTTYPE_TO_STRLEN(pid_t) + 6 + 8 + 1)
#define LXC_CMD_DATA_MAX (MAXPATHLEN * 2) #define LXC_CMD_DATA_MAX (PATH_MAX * 2)
/* loop devices */ /* loop devices */
#ifndef LO_FLAGS_AUTOCLEAR #ifndef LO_FLAGS_AUTOCLEAR

View File

@ -1358,15 +1358,15 @@ static int proc_sys_net_write(const char *path, const char *value)
static int neigh_proxy_set(const char *ifname, int family, int flag) static int neigh_proxy_set(const char *ifname, int family, int flag)
{ {
int ret; int ret;
char path[MAXPATHLEN]; char path[PATH_MAX];
if (family != AF_INET && family != AF_INET6) if (family != AF_INET && family != AF_INET6)
return -EINVAL; return -EINVAL;
ret = snprintf(path, MAXPATHLEN, "/proc/sys/net/%s/conf/%s/%s", ret = snprintf(path, PATH_MAX, "/proc/sys/net/%s/conf/%s/%s",
family == AF_INET ? "ipv4" : "ipv6", ifname, family == AF_INET ? "ipv4" : "ipv6", ifname,
family == AF_INET ? "proxy_arp" : "proxy_ndp"); family == AF_INET ? "proxy_arp" : "proxy_ndp");
if (ret < 0 || (size_t)ret >= MAXPATHLEN) if (ret < 0 || (size_t)ret >= PATH_MAX)
return -E2BIG; return -E2BIG;
return proc_sys_net_write(path, flag ? "1" : "0"); return proc_sys_net_write(path, flag ? "1" : "0");
@ -1847,7 +1847,7 @@ static int lxc_ovs_delete_port_exec(void *data)
int lxc_ovs_delete_port(const char *bridge, const char *nic) int lxc_ovs_delete_port(const char *bridge, const char *nic)
{ {
int ret; int ret;
char cmd_output[MAXPATHLEN]; char cmd_output[PATH_MAX];
struct ovs_veth_args args; struct ovs_veth_args args;
args.bridge = bridge; args.bridge = bridge;
@ -1875,7 +1875,7 @@ static int lxc_ovs_attach_bridge_exec(void *data)
static int lxc_ovs_attach_bridge(const char *bridge, const char *nic) static int lxc_ovs_attach_bridge(const char *bridge, const char *nic)
{ {
int ret; int ret;
char cmd_output[MAXPATHLEN]; char cmd_output[PATH_MAX];
struct ovs_veth_args args; struct ovs_veth_args args;
args.bridge = bridge; args.bridge = bridge;
@ -2093,7 +2093,7 @@ static int lxc_create_network_unpriv_exec(const char *lxcpath, const char *lxcna
int bytes, pipefd[2]; int bytes, pipefd[2];
char *token, *saveptr = NULL; char *token, *saveptr = NULL;
char netdev_link[IFNAMSIZ]; char netdev_link[IFNAMSIZ];
char buffer[MAXPATHLEN] = {0}; char buffer[PATH_MAX] = {0};
size_t retlen; size_t retlen;
if (netdev->type != LXC_NET_VETH) { if (netdev->type != LXC_NET_VETH) {
@ -2163,7 +2163,7 @@ static int lxc_create_network_unpriv_exec(const char *lxcpath, const char *lxcna
/* close the write-end of the pipe */ /* close the write-end of the pipe */
close(pipefd[1]); close(pipefd[1]);
bytes = lxc_read_nointr(pipefd[0], &buffer, MAXPATHLEN); bytes = lxc_read_nointr(pipefd[0], &buffer, PATH_MAX);
if (bytes < 0) { if (bytes < 0) {
SYSERROR("Failed to read from pipe file descriptor"); SYSERROR("Failed to read from pipe file descriptor");
close(pipefd[0]); close(pipefd[0]);
@ -2257,7 +2257,7 @@ static int lxc_delete_network_unpriv_exec(const char *lxcpath, const char *lxcna
int bytes, ret; int bytes, ret;
pid_t child; pid_t child;
int pipefd[2]; int pipefd[2];
char buffer[MAXPATHLEN] = {0}; char buffer[PATH_MAX] = {0};
if (netdev->type != LXC_NET_VETH) { if (netdev->type != LXC_NET_VETH) {
ERROR("Network type %d not support for unprivileged use", netdev->type); ERROR("Network type %d not support for unprivileged use", netdev->type);
@ -2319,7 +2319,7 @@ static int lxc_delete_network_unpriv_exec(const char *lxcpath, const char *lxcna
close(pipefd[1]); close(pipefd[1]);
bytes = lxc_read_nointr(pipefd[0], &buffer, MAXPATHLEN); bytes = lxc_read_nointr(pipefd[0], &buffer, PATH_MAX);
if (bytes < 0) { if (bytes < 0) {
SYSERROR("Failed to read from pipe file descriptor."); SYSERROR("Failed to read from pipe file descriptor.");
close(pipefd[0]); close(pipefd[0]);

View File

@ -2408,13 +2408,13 @@ static int handle_login(const char *user, uid_t uid, gid_t gid)
{ {
int idx = 0, ret; int idx = 0, ret;
bool existed; bool existed;
char cg[MAXPATHLEN]; char cg[PATH_MAX];
cg_escape(); cg_escape();
while (idx >= 0) { while (idx >= 0) {
ret = snprintf(cg, MAXPATHLEN, "/user/%s/%d", user, idx); ret = snprintf(cg, PATH_MAX, "/user/%s/%d", user, idx);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= PATH_MAX) {
mysyslog(LOG_ERR, "Username too long\n", NULL); mysyslog(LOG_ERR, "Username too long\n", NULL);
return PAM_SESSION_ERR; return PAM_SESSION_ERR;
} }

View File

@ -2125,7 +2125,7 @@ int lxc_start(const char *name, char *const argv[], struct lxc_handler *handler,
static void lxc_destroy_container_on_signal(struct lxc_handler *handler, static void lxc_destroy_container_on_signal(struct lxc_handler *handler,
const char *name) const char *name)
{ {
char destroy[MAXPATHLEN]; char destroy[PATH_MAX];
struct lxc_container *c; struct lxc_container *c;
int ret = 0; int ret = 0;
bool bret = true; bool bret = true;
@ -2139,8 +2139,8 @@ static void lxc_destroy_container_on_signal(struct lxc_handler *handler,
} }
INFO("Destroyed rootfs for container \"%s\"", name); INFO("Destroyed rootfs for container \"%s\"", name);
ret = snprintf(destroy, MAXPATHLEN, "%s/%s", handler->lxcpath, name); ret = snprintf(destroy, PATH_MAX, "%s/%s", handler->lxcpath, name);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= PATH_MAX) {
ERROR("Error destroying directory for container \"%s\"", name); ERROR("Error destroying directory for container \"%s\"", name);
return; return;
} }

View File

@ -462,7 +462,7 @@ bool btrfs_create_clone(struct lxc_conf *conf, struct lxc_storage *orig,
{ {
int ret; int ret;
struct rsync_data data = {0, 0}; struct rsync_data data = {0, 0};
char cmd_output[MAXPATHLEN] = {0}; char cmd_output[PATH_MAX] = {0};
ret = rmdir(new->dest); ret = rmdir(new->dest);
if (ret < 0 && errno != ENOENT) if (ret < 0 && errno != ENOENT)

View File

@ -237,7 +237,7 @@ bool loop_detect(const char *path)
int loop_mount(struct lxc_storage *bdev) int loop_mount(struct lxc_storage *bdev)
{ {
int ret, loopfd; int ret, loopfd;
char loname[MAXPATHLEN]; char loname[PATH_MAX];
const char *src; const char *src;
if (strcmp(bdev->type, "loop")) if (strcmp(bdev->type, "loop"))
@ -301,7 +301,7 @@ static int do_loop_create(const char *path, uint64_t size, const char *fstype)
{ {
int fd, ret; int fd, ret;
off_t ret_size; off_t ret_size;
char cmd_output[MAXPATHLEN]; char cmd_output[PATH_MAX];
const char *cmd_args[2] = {fstype, path}; const char *cmd_args[2] = {fstype, path};
/* create the new loopback file */ /* create the new loopback file */

View File

@ -111,7 +111,7 @@ static int do_lvm_create(const char *path, uint64_t size, const char *thinpool)
{ {
int len, ret; int len, ret;
char *pathdup, *vg, *lv; char *pathdup, *vg, *lv;
char cmd_output[MAXPATHLEN]; char cmd_output[PATH_MAX];
char sz[24]; char sz[24];
char *tp = NULL; char *tp = NULL;
struct lvcreate_args cmd_args = {0}; struct lvcreate_args cmd_args = {0};
@ -201,7 +201,7 @@ bool lvm_detect(const char *path)
int fd; int fd;
ssize_t ret; ssize_t ret;
struct stat statbuf; struct stat statbuf;
char devp[MAXPATHLEN], buf[4]; char devp[PATH_MAX], buf[4];
if (!strncmp(path, "lvm:", 4)) if (!strncmp(path, "lvm:", 4))
return true; return true;
@ -213,9 +213,9 @@ bool lvm_detect(const char *path)
if (!S_ISBLK(statbuf.st_mode)) if (!S_ISBLK(statbuf.st_mode))
return false; return false;
ret = snprintf(devp, MAXPATHLEN, "/sys/dev/block/%d:%d/dm/uuid", ret = snprintf(devp, PATH_MAX, "/sys/dev/block/%d:%d/dm/uuid",
major(statbuf.st_rdev), minor(statbuf.st_rdev)); major(statbuf.st_rdev), minor(statbuf.st_rdev));
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= PATH_MAX) {
ERROR("Failed to create string"); ERROR("Failed to create string");
return false; return false;
} }
@ -335,7 +335,7 @@ static int lvm_snapshot(struct lxc_storage *orig, const char *path, uint64_t siz
char *lv, *pathdup; char *lv, *pathdup;
char sz[24]; char sz[24];
char fstype[100]; char fstype[100];
char cmd_output[MAXPATHLEN]; char cmd_output[PATH_MAX];
char repairchar; char repairchar;
const char *origsrc; const char *origsrc;
struct lvcreate_args cmd_args = {0}; struct lvcreate_args cmd_args = {0};
@ -506,7 +506,7 @@ bool lvm_create_clone(struct lxc_conf *conf, struct lxc_storage *orig,
const char *thinpool; const char *thinpool;
struct rsync_data data; struct rsync_data data;
const char *cmd_args[2]; const char *cmd_args[2];
char cmd_output[MAXPATHLEN] = {0}; char cmd_output[PATH_MAX] = {0};
char fstype[100] = "ext4"; char fstype[100] = "ext4";
uint64_t size = newsize; uint64_t size = newsize;
@ -593,7 +593,7 @@ bool lvm_create_snapshot(struct lxc_conf *conf, struct lxc_storage *orig,
int lvm_destroy(struct lxc_storage *orig) int lvm_destroy(struct lxc_storage *orig)
{ {
int ret; int ret;
char cmd_output[MAXPATHLEN]; char cmd_output[PATH_MAX];
struct lvcreate_args cmd_args = {0}; struct lvcreate_args cmd_args = {0};
cmd_args.lv = lxc_storage_get_path(orig->src, "lvm"); cmd_args.lv = lxc_storage_get_path(orig->src, "lvm");
@ -616,7 +616,7 @@ int lvm_create(struct lxc_storage *bdev, const char *dest, const char *n,
uint64_t sz; uint64_t sz;
int ret, len; int ret, len;
const char *cmd_args[2]; const char *cmd_args[2];
char cmd_output[MAXPATHLEN]; char cmd_output[PATH_MAX];
if (!specs) if (!specs)
return -1; return -1;

View File

@ -737,7 +737,7 @@ char *ovl_get_rootfs(const char *rootfs_path, size_t *rootfslen)
int ovl_mkdir(const struct mntent *mntent, const struct lxc_rootfs *rootfs, int ovl_mkdir(const struct mntent *mntent, const struct lxc_rootfs *rootfs,
const char *lxc_name, const char *lxc_path) const char *lxc_name, const char *lxc_path)
{ {
char lxcpath[MAXPATHLEN]; char lxcpath[PATH_MAX];
char **opts; char **opts;
int ret; int ret;
size_t arrlen, i, len, rootfslen; size_t arrlen, i, len, rootfslen;
@ -766,8 +766,8 @@ int ovl_mkdir(const struct mntent *mntent, const struct lxc_rootfs *rootfs,
} }
if (rootfs_path) { if (rootfs_path) {
ret = snprintf(lxcpath, MAXPATHLEN, "%s/%s", lxc_path, lxc_name); ret = snprintf(lxcpath, PATH_MAX, "%s/%s", lxc_path, lxc_name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
goto err; goto err;
rootfs_dir = ovl_get_rootfs(rootfs_path, &rootfslen); rootfs_dir = ovl_get_rootfs(rootfs_path, &rootfslen);
@ -825,8 +825,8 @@ int ovl_update_abs_paths(struct lxc_conf *lxc_conf, const char *lxc_path,
const char *lxc_name, const char *newpath, const char *lxc_name, const char *newpath,
const char *newname) const char *newname)
{ {
char new_upper[MAXPATHLEN], new_work[MAXPATHLEN], old_upper[MAXPATHLEN], char new_upper[PATH_MAX], new_work[PATH_MAX], old_upper[PATH_MAX],
old_work[MAXPATHLEN]; old_work[PATH_MAX];
size_t i; size_t i;
struct lxc_list *iterator; struct lxc_list *iterator;
char *cleanpath = NULL; char *cleanpath = NULL;
@ -852,13 +852,13 @@ int ovl_update_abs_paths(struct lxc_conf *lxc_conf, const char *lxc_path,
} }
ret = ret =
snprintf(old_work, MAXPATHLEN, "workdir=%s/%s", lxc_path, lxc_name); snprintf(old_work, PATH_MAX, "workdir=%s/%s", lxc_path, lxc_name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
goto err; goto err;
ret = ret =
snprintf(new_work, MAXPATHLEN, "workdir=%s/%s", cleanpath, newname); snprintf(new_work, PATH_MAX, "workdir=%s/%s", cleanpath, newname);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
goto err; goto err;
lxc_list_for_each(iterator, &lxc_conf->mount_list) { lxc_list_for_each(iterator, &lxc_conf->mount_list) {
@ -872,14 +872,14 @@ int ovl_update_abs_paths(struct lxc_conf *lxc_conf, const char *lxc_path,
if (!tmp) if (!tmp)
continue; continue;
ret = snprintf(old_upper, MAXPATHLEN, "%s=%s/%s", tmp, lxc_path, ret = snprintf(old_upper, PATH_MAX, "%s=%s/%s", tmp, lxc_path,
lxc_name); lxc_name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
goto err; goto err;
ret = snprintf(new_upper, MAXPATHLEN, "%s=%s/%s", tmp, ret = snprintf(new_upper, PATH_MAX, "%s=%s/%s", tmp,
cleanpath, newname); cleanpath, newname);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
goto err; goto err;
if (strstr(mnt_entry, old_upper)) { if (strstr(mnt_entry, old_upper)) {
@ -956,7 +956,7 @@ static int ovl_do_rsync(const char *src, const char *dest,
{ {
int ret = -1; int ret = -1;
struct rsync_data_char rdata = {0}; struct rsync_data_char rdata = {0};
char cmd_output[MAXPATHLEN] = {0}; char cmd_output[PATH_MAX] = {0};
rdata.src = (char *)src; rdata.src = (char *)src;
rdata.dest = (char *)dest; rdata.dest = (char *)dest;

View File

@ -104,7 +104,7 @@ int rbd_create(struct lxc_storage *bdev, const char *dest, const char *n,
int ret, len; int ret, len;
char sz[24]; char sz[24];
const char *cmd_args[2]; const char *cmd_args[2];
char cmd_output[MAXPATHLEN]; char cmd_output[PATH_MAX];
const char *rbdname = n; const char *rbdname = n;
struct rbd_args args = {0}; struct rbd_args args = {0};
@ -198,7 +198,7 @@ int rbd_destroy(struct lxc_storage *orig)
int ret; int ret;
const char *src; const char *src;
char *rbdfullname; char *rbdfullname;
char cmd_output[MAXPATHLEN]; char cmd_output[PATH_MAX];
struct rbd_args args = {0}; struct rbd_args args = {0};
size_t len; size_t len;

View File

@ -331,7 +331,7 @@ struct lxc_storage *storage_copy(struct lxc_container *c, const char *cname,
const char *src = c->lxc_conf->rootfs.path; const char *src = c->lxc_conf->rootfs.path;
const char *oldname = c->name; const char *oldname = c->name;
const char *oldpath = c->config_path; const char *oldpath = c->config_path;
char cmd_output[MAXPATHLEN] = {0}; char cmd_output[PATH_MAX] = {0};
struct rsync_data data = {0}; struct rsync_data data = {0};
if (!src) { if (!src) {

View File

@ -186,7 +186,7 @@ int detect_fs(struct lxc_storage *bdev, char *type, int len)
FILE *f; FILE *f;
char *sp1, *sp2, *sp3; char *sp1, *sp2, *sp3;
const char *l, *srcdev; const char *l, *srcdev;
char devpath[MAXPATHLEN]; char devpath[PATH_MAX];
char *line = NULL; char *line = NULL;
if (!bdev || !bdev->src || !bdev->dest) if (!bdev || !bdev->src || !bdev->dest)
@ -415,11 +415,11 @@ const char *linkderef(const char *path, char *dest)
if (!S_ISLNK(sbuf.st_mode)) if (!S_ISLNK(sbuf.st_mode))
return path; return path;
ret = readlink(path, dest, MAXPATHLEN); ret = readlink(path, dest, PATH_MAX);
if (ret < 0) { if (ret < 0) {
SYSERROR("error reading link %s", path); SYSERROR("error reading link %s", path);
return NULL; return NULL;
} else if (ret >= MAXPATHLEN) { } else if (ret >= PATH_MAX) {
ERROR("link in %s too long", path); ERROR("link in %s too long", path);
return NULL; return NULL;
} }

View File

@ -134,7 +134,7 @@ bool zfs_detect(const char *path)
int ret; int ret;
char *dataset; char *dataset;
struct zfs_args cmd_args = {0}; struct zfs_args cmd_args = {0};
char cmd_output[MAXPATHLEN] = {0}; char cmd_output[PATH_MAX] = {0};
if (!strncmp(path, "zfs:", 4)) if (!strncmp(path, "zfs:", 4))
return true; return true;
@ -185,7 +185,7 @@ int zfs_mount(struct lxc_storage *bdev)
char *mntdata, *tmp; char *mntdata, *tmp;
const char *src; const char *src;
unsigned long mntflags; unsigned long mntflags;
char cmd_output[MAXPATHLEN] = {0}; char cmd_output[PATH_MAX] = {0};
if (strcmp(bdev->type, "zfs")) if (strcmp(bdev->type, "zfs"))
return -22; return -22;
@ -287,7 +287,7 @@ bool zfs_copy(struct lxc_conf *conf, struct lxc_storage *orig,
struct lxc_storage *new, uint64_t newsize) struct lxc_storage *new, uint64_t newsize)
{ {
int ret; int ret;
char cmd_output[MAXPATHLEN], option[MAXPATHLEN]; char cmd_output[PATH_MAX], option[PATH_MAX];
struct rsync_data data = {0, 0}; struct rsync_data data = {0, 0};
struct zfs_args cmd_args = {0}; struct zfs_args cmd_args = {0};
const char *argv[] = {"zfs", /* 0 */ const char *argv[] = {"zfs", /* 0 */
@ -299,8 +299,8 @@ bool zfs_copy(struct lxc_conf *conf, struct lxc_storage *orig,
NULL}; NULL};
/* mountpoint */ /* mountpoint */
ret = snprintf(option, MAXPATHLEN, "mountpoint=%s", new->dest); ret = snprintf(option, PATH_MAX, "mountpoint=%s", new->dest);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= PATH_MAX) {
ERROR("Failed to create string"); ERROR("Failed to create string");
return false; return false;
} }
@ -348,7 +348,7 @@ bool zfs_snapshot(struct lxc_conf *conf, struct lxc_storage *orig,
char *tmp, *snap_name, *snapshot; char *tmp, *snap_name, *snapshot;
const char *orig_src; const char *orig_src;
struct zfs_args cmd_args = {0}; struct zfs_args cmd_args = {0};
char cmd_output[MAXPATHLEN] = {0}, option[MAXPATHLEN]; char cmd_output[PATH_MAX] = {0}, option[PATH_MAX];
orig_src = lxc_storage_get_path(orig->src, orig->type); orig_src = lxc_storage_get_path(orig->src, orig->type);
if (*orig_src == '/') { if (*orig_src == '/') {
@ -423,8 +423,8 @@ bool zfs_snapshot(struct lxc_conf *conf, struct lxc_storage *orig,
TRACE("Created zfs snapshot \"%s\"", snapshot); TRACE("Created zfs snapshot \"%s\"", snapshot);
} }
ret = snprintf(option, MAXPATHLEN, "mountpoint=%s", new->dest); ret = snprintf(option, PATH_MAX, "mountpoint=%s", new->dest);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= PATH_MAX) {
ERROR("Failed to create string"); ERROR("Failed to create string");
free(snapshot); free(snapshot);
return -1; return -1;
@ -455,7 +455,7 @@ int zfs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
char *dataset, *tmp; char *dataset, *tmp;
const char *orig_src; const char *orig_src;
size_t dataset_len, len; size_t dataset_len, len;
char cmd_output[MAXPATHLEN] = {0}; char cmd_output[PATH_MAX] = {0};
if (!orig->src || !orig->dest) if (!orig->src || !orig->dest)
return -1; return -1;
@ -586,7 +586,7 @@ int zfs_destroy(struct lxc_storage *orig)
bool found; bool found;
char *parent_snapshot = NULL; char *parent_snapshot = NULL;
struct zfs_args cmd_args = {0}; struct zfs_args cmd_args = {0};
char cmd_output[MAXPATHLEN] = {0}; char cmd_output[PATH_MAX] = {0};
src = lxc_storage_get_path(orig->src, orig->type); src = lxc_storage_get_path(orig->src, orig->type);
@ -714,7 +714,7 @@ int zfs_create(struct lxc_storage *bdev, const char *dest, const char *n,
int ret; int ret;
size_t len; size_t len;
struct zfs_args cmd_args = {0}; struct zfs_args cmd_args = {0};
char cmd_output[MAXPATHLEN], option[MAXPATHLEN]; char cmd_output[PATH_MAX], option[PATH_MAX];
const char *argv[] = {"zfs", /* 0 */ const char *argv[] = {"zfs", /* 0 */
"create", /* 1 */ "create", /* 1 */
"-o", "", /* 2, 3 */ "-o", "", /* 2, 3 */
@ -750,8 +750,8 @@ int zfs_create(struct lxc_storage *bdev, const char *dest, const char *n,
} }
argv[7] = lxc_storage_get_path(bdev->src, bdev->type); argv[7] = lxc_storage_get_path(bdev->src, bdev->type);
ret = snprintf(option, MAXPATHLEN, "mountpoint=%s", bdev->dest); ret = snprintf(option, PATH_MAX, "mountpoint=%s", bdev->dest);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= PATH_MAX) {
ERROR("Failed to create string"); ERROR("Failed to create string");
return -1; return -1;
} }

View File

@ -28,6 +28,7 @@
#include <stdio.h> #include <stdio.h>
#include "list.h" #include "list.h"
#include "macro.h"
#include "ringbuf.h" #include "ringbuf.h"
struct lxc_container; struct lxc_container;
@ -36,7 +37,7 @@ struct lxc_epoll_descr;
struct lxc_terminal_info { struct lxc_terminal_info {
/* the path name of the slave side */ /* the path name of the slave side */
char name[MAXPATHLEN]; char name[PATH_MAX];
/* the file descriptor of the master */ /* the file descriptor of the master */
int master; int master;
@ -89,7 +90,7 @@ struct lxc_terminal {
struct lxc_terminal_info proxy; struct lxc_terminal_info proxy;
struct lxc_epoll_descr *descr; struct lxc_epoll_descr *descr;
char *path; char *path;
char name[MAXPATHLEN]; char name[PATH_MAX];
struct termios *tios; struct termios *tios;
struct lxc_terminal_state *tty_state; struct lxc_terminal_state *tty_state;

View File

@ -137,10 +137,10 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else { } else {
char buffer[MAXPATHLEN]; char buffer[PATH_MAX];
int ret; int ret;
ret = c->get_cgroup_item(c, state_object, buffer, MAXPATHLEN); ret = c->get_cgroup_item(c, state_object, buffer, PATH_MAX);
if (ret < 0) { if (ret < 0) {
ERROR("Failed to retrieve value of '%s' for '%s:%s'", ERROR("Failed to retrieve value of '%s' for '%s:%s'",
state_object, my_args.lxcpath[0], my_args.name); state_object, my_args.lxcpath[0], my_args.name);

View File

@ -263,17 +263,17 @@ static struct mnts *add_mnt(struct mnts **mnts, unsigned int *num, enum mnttype
static int mk_rand_ovl_dirs(struct mnts *mnts, unsigned int num, struct lxc_arguments *arg) static int mk_rand_ovl_dirs(struct mnts *mnts, unsigned int num, struct lxc_arguments *arg)
{ {
char upperdir[MAXPATHLEN]; char upperdir[PATH_MAX];
char workdir[MAXPATHLEN]; char workdir[PATH_MAX];
unsigned int i; unsigned int i;
int ret; int ret;
struct mnts *m = NULL; struct mnts *m = NULL;
for (i = 0, m = mnts; i < num; i++, m++) { for (i = 0, m = mnts; i < num; i++, m++) {
if (m->mnt_type == LXC_MNT_OVL) { if (m->mnt_type == LXC_MNT_OVL) {
ret = snprintf(upperdir, MAXPATHLEN, "%s/%s/delta#XXXXXX", ret = snprintf(upperdir, PATH_MAX, "%s/%s/delta#XXXXXX",
arg->newpath, arg->newname); arg->newpath, arg->newname);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return -1; return -1;
if (!mkdtemp(upperdir)) if (!mkdtemp(upperdir))
@ -285,9 +285,9 @@ static int mk_rand_ovl_dirs(struct mnts *mnts, unsigned int num, struct lxc_argu
} }
if (m->mnt_type == LXC_MNT_OVL) { if (m->mnt_type == LXC_MNT_OVL) {
ret = snprintf(workdir, MAXPATHLEN, "%s/%s/work#XXXXXX", ret = snprintf(workdir, PATH_MAX, "%s/%s/work#XXXXXX",
arg->newpath, arg->newname); arg->newpath, arg->newname);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return -1; return -1;
if (!mkdtemp(workdir)) if (!mkdtemp(workdir))
@ -381,7 +381,7 @@ static int do_clone_ephemeral(struct lxc_container *c,
struct lxc_arguments *arg, char **args, int flags) struct lxc_arguments *arg, char **args, int flags)
{ {
char *premount; char *premount;
char randname[MAXPATHLEN]; char randname[PATH_MAX];
unsigned int i; unsigned int i;
int ret = 0; int ret = 0;
bool bret = true, started = false; bool bret = true, started = false;
@ -391,8 +391,8 @@ static int do_clone_ephemeral(struct lxc_container *c,
attach_options.env_policy = LXC_ATTACH_CLEAR_ENV; attach_options.env_policy = LXC_ATTACH_CLEAR_ENV;
if (!arg->newname) { if (!arg->newname) {
ret = snprintf(randname, MAXPATHLEN, "%s/%s_XXXXXX", arg->newpath, arg->name); ret = snprintf(randname, PATH_MAX, "%s/%s_XXXXXX", arg->newpath, arg->name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return -1; return -1;
if (!mkdtemp(randname)) if (!mkdtemp(randname))
@ -481,7 +481,7 @@ destroy_and_put:
if (started) if (started)
clone->shutdown(clone, -1); clone->shutdown(clone, -1);
ret = clone->get_config_item(clone, "lxc.ephemeral", tmp_buf, MAXPATHLEN); ret = clone->get_config_item(clone, "lxc.ephemeral", tmp_buf, PATH_MAX);
if (ret > 0 && strcmp(tmp_buf, "0")) if (ret > 0 && strcmp(tmp_buf, "0"))
clone->destroy(clone); clone->destroy(clone);

View File

@ -84,11 +84,11 @@ static bool do_destroy(struct lxc_container *c)
{ {
int ret; int ret;
bool bret = true; bool bret = true;
char path[MAXPATHLEN]; char path[PATH_MAX];
/* First check whether the container has dependent clones or snapshots. */ /* First check whether the container has dependent clones or snapshots. */
ret = snprintf(path, MAXPATHLEN, "%s/%s/lxc_snapshots", c->config_path, c->name); ret = snprintf(path, PATH_MAX, "%s/%s/lxc_snapshots", c->config_path, c->name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return false; return false;
if (file_exists(path)) { if (file_exists(path)) {
@ -96,8 +96,8 @@ static bool do_destroy(struct lxc_container *c)
return false; return false;
} }
ret = snprintf(path, MAXPATHLEN, "%s/%s/snaps", c->config_path, c->name); ret = snprintf(path, PATH_MAX, "%s/%s/snaps", c->config_path, c->name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return false; return false;
if (rmdir(path) < 0 && errno != ENOENT) { if (rmdir(path) < 0 && errno != ENOENT) {
@ -138,7 +138,7 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
struct lxc_container *c1; struct lxc_container *c1;
struct stat fbuf; struct stat fbuf;
bool bret = false; bool bret = false;
char path[MAXPATHLEN]; char path[PATH_MAX];
char *buf = NULL; char *buf = NULL;
char *lxcpath = NULL; char *lxcpath = NULL;
char *lxcname = NULL; char *lxcname = NULL;
@ -147,8 +147,8 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
ssize_t bytes; ssize_t bytes;
/* Destroy clones. */ /* Destroy clones. */
ret = snprintf(path, MAXPATHLEN, "%s/%s/lxc_snapshots", c->config_path, c->name); ret = snprintf(path, PATH_MAX, "%s/%s/lxc_snapshots", c->config_path, c->name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return false; return false;
fd = open(path, O_RDONLY | O_CLOEXEC); fd = open(path, O_RDONLY | O_CLOEXEC);
@ -195,8 +195,8 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
} }
/* Destroy snapshots located in the containers snap/ folder. */ /* Destroy snapshots located in the containers snap/ folder. */
ret = snprintf(path, MAXPATHLEN, "%s/%s/snaps", c->config_path, c->name); ret = snprintf(path, PATH_MAX, "%s/%s/snaps", c->config_path, c->name);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return false; return false;
if (rmdir(path) < 0 && errno != ENOENT) if (rmdir(path) < 0 && errno != ENOENT)

View File

@ -129,11 +129,11 @@ static int my_parser(struct lxc_arguments *args, int c, char *arg)
static bool set_argv(struct lxc_container *c, struct lxc_arguments *args) static bool set_argv(struct lxc_container *c, struct lxc_arguments *args)
{ {
int ret; int ret;
char buf[MAXPATHLEN]; char buf[PATH_MAX];
char **components, **p; char **components, **p;
buf[0] = '\0'; buf[0] = '\0';
ret = c->get_config_item(c, "lxc.execute.cmd", buf, MAXPATHLEN); ret = c->get_config_item(c, "lxc.execute.cmd", buf, PATH_MAX);
if (ret < 0) if (ret < 0)
return false; return false;

View File

@ -182,7 +182,7 @@ static int get_namespace_flags(char *namespaces)
static bool lookup_user(const char *optarg, uid_t *uid) static bool lookup_user(const char *optarg, uid_t *uid)
{ {
char name[MAXPATHLEN]; char name[PATH_MAX];
struct passwd pwent; struct passwd pwent;
struct passwd *pwentp = NULL; struct passwd *pwentp = NULL;
char *buf; char *buf;

View File

@ -84,7 +84,7 @@ static int _recursive_rmdir(const char *dirname, dev_t pdev,
struct dirent *direntp; struct dirent *direntp;
DIR *dir; DIR *dir;
int ret, failed=0; int ret, failed=0;
char pathname[MAXPATHLEN]; char pathname[PATH_MAX];
bool hadexclude = false; bool hadexclude = false;
dir = opendir(dirname); dir = opendir(dirname);
@ -101,8 +101,8 @@ static int _recursive_rmdir(const char *dirname, dev_t pdev,
!strcmp(direntp->d_name, "..")) !strcmp(direntp->d_name, ".."))
continue; continue;
rc = snprintf(pathname, MAXPATHLEN, "%s/%s", dirname, direntp->d_name); rc = snprintf(pathname, PATH_MAX, "%s/%s", dirname, direntp->d_name);
if (rc < 0 || rc >= MAXPATHLEN) { if (rc < 0 || rc >= PATH_MAX) {
ERROR("pathname too long"); ERROR("pathname too long");
failed=1; failed=1;
continue; continue;
@ -678,11 +678,11 @@ int detect_shared_rootfs(void)
bool switch_to_ns(pid_t pid, const char *ns) bool switch_to_ns(pid_t pid, const char *ns)
{ {
int fd, ret; int fd, ret;
char nspath[MAXPATHLEN]; char nspath[PATH_MAX];
/* Switch to new ns */ /* Switch to new ns */
ret = snprintf(nspath, MAXPATHLEN, "/proc/%d/ns/%s", pid, ns); ret = snprintf(nspath, PATH_MAX, "/proc/%d/ns/%s", pid, ns);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
return false; return false;
fd = open(nspath, O_RDONLY); fd = open(nspath, O_RDONLY);
@ -752,7 +752,7 @@ bool detect_ramfs_rootfs(void)
char *on_path(const char *cmd, const char *rootfs) char *on_path(const char *cmd, const char *rootfs)
{ {
char *entry = NULL, *path = NULL; char *entry = NULL, *path = NULL;
char cmdpath[MAXPATHLEN]; char cmdpath[PATH_MAX];
int ret; int ret;
path = getenv("PATH"); path = getenv("PATH");
@ -765,11 +765,11 @@ char *on_path(const char *cmd, const char *rootfs)
lxc_iterate_parts (entry, path, ":") { lxc_iterate_parts (entry, path, ":") {
if (rootfs) if (rootfs)
ret = snprintf(cmdpath, MAXPATHLEN, "%s/%s/%s", rootfs, ret = snprintf(cmdpath, PATH_MAX, "%s/%s/%s", rootfs,
entry, cmd); entry, cmd);
else else
ret = snprintf(cmdpath, MAXPATHLEN, "%s/%s", entry, cmd); ret = snprintf(cmdpath, PATH_MAX, "%s/%s", entry, cmd);
if (ret < 0 || ret >= MAXPATHLEN) if (ret < 0 || ret >= PATH_MAX)
continue; continue;
if (access(cmdpath, X_OK) == 0) { if (access(cmdpath, X_OK) == 0) {
@ -1191,20 +1191,20 @@ int safe_mount(const char *src, const char *dest, const char *fstype,
*/ */
int lxc_mount_proc_if_needed(const char *rootfs) int lxc_mount_proc_if_needed(const char *rootfs)
{ {
char path[MAXPATHLEN]; char path[PATH_MAX];
int link_to_pid, linklen, mypid, ret; int link_to_pid, linklen, mypid, ret;
char link[INTTYPE_TO_STRLEN(pid_t)] = {0}; char link[INTTYPE_TO_STRLEN(pid_t)] = {0};
ret = snprintf(path, MAXPATHLEN, "%s/proc/self", rootfs); ret = snprintf(path, PATH_MAX, "%s/proc/self", rootfs);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= PATH_MAX) {
SYSERROR("proc path name too long"); SYSERROR("proc path name too long");
return -1; return -1;
} }
linklen = readlink(path, link, sizeof(link)); linklen = readlink(path, link, sizeof(link));
ret = snprintf(path, MAXPATHLEN, "%s/proc", rootfs); ret = snprintf(path, PATH_MAX, "%s/proc", rootfs);
if (ret < 0 || ret >= MAXPATHLEN) { if (ret < 0 || ret >= PATH_MAX) {
SYSERROR("proc path name too long"); SYSERROR("proc path name too long");
return -1; return -1;
} }