[lxc-devel] [lxc/master] tree-wide: s/MAXPATHLEN/PATH_MAX/g
brauner on Github
lxc-bot at linuxcontainers.org
Sun Oct 7 08:11:03 UTC 2018
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20181007/3f8358db/attachment.bin>
-------------- next part --------------
From b35091695a195cfd4ffd0a2f67224ca7cbadc615 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 7 Oct 2018 09:53:30 +0200
Subject: [PATCH 01/15] macro: add PATH_MAX
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/macro.h | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/lxc/macro.h b/src/lxc/macro.h
index baee5ae8a..a91f9dc97 100644
--- a/src/lxc/macro.h
+++ b/src/lxc/macro.h
@@ -21,6 +21,7 @@
#define __LXC_MACRO_H
#include <asm/types.h>
+#include <limits.h>
#include <linux/if_link.h>
#include <linux/loop.h>
#include <linux/netlink.h>
@@ -33,6 +34,10 @@
#include <sys/un.h>
#include <unistd.h>
+#ifndef PATH_MAX
+#define PATH_MAX 4096
+#endif
+
/* Define __S_ISTYPE if missing from the C library. */
#ifndef __S_ISTYPE
#define __S_ISTYPE(mode, mask) (((mode)&S_IFMT) == (mask))
From eb22a12bbf0069a215d316a4784cf1973c359e29 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 7 Oct 2018 09:53:46 +0200
Subject: [PATCH 02/15] cmd: s/MAXPATHLEN/PATH_MAX/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/cmd/lxc_init.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/lxc/cmd/lxc_init.c b/src/lxc/cmd/lxc_init.c
index c643419ea..14cc5fd61 100644
--- a/src/lxc/cmd/lxc_init.c
+++ b/src/lxc/cmd/lxc_init.c
@@ -28,6 +28,7 @@
#include <errno.h>
#include <getopt.h>
#include <libgen.h>
+#include <limits.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
@@ -108,7 +109,7 @@ static void prevent_forking(void)
FILE *f;
size_t len = 0;
char *line = NULL;
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
f = fopen("/proc/self/cgroup", "r");
if (!f)
@@ -202,10 +203,10 @@ static void remove_self(void)
{
int ret;
ssize_t n;
- char path[MAXPATHLEN] = {0};
+ char path[PATH_MAX] = {0};
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\"");
return;
}
From 6b5a54cdfcd8e4b73d95a9cd4be721bd8aa1930b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 7 Oct 2018 09:58:56 +0200
Subject: [PATCH 03/15] conf: s/MAXPATHLEN/PATH_MAX/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/conf.c | 78 +++++++++++++++++++++++++-------------------------
1 file changed, 39 insertions(+), 39 deletions(-)
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index c450cfcbe..856fde1dd 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -542,7 +542,7 @@ int run_script(const char *name, const char *section, const char *script, ...)
int pin_rootfs(const char *rootfs)
{
int fd, ret;
- char absrootfspin[MAXPATHLEN];
+ char absrootfspin[PATH_MAX];
char *absrootfs;
struct stat s;
struct statfs sfs;
@@ -565,9 +565,9 @@ int pin_rootfs(const char *rootfs)
return -2;
}
- ret = snprintf(absrootfspin, MAXPATHLEN, "%s/.lxc-keep", absrootfs);
+ ret = snprintf(absrootfspin, PATH_MAX, "%s/.lxc-keep", absrootfs);
free(absrootfs);
- if (ret >= MAXPATHLEN)
+ if (ret < 0 || ret >= PATH_MAX)
return -1;
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)
{
- char new_mount[MAXPATHLEN];
+ char new_mount[PATH_MAX];
/* Offset for the leading '/' since the path_cont
* 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)
{
int i, ret;
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
struct stat s;
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",
rootfs->path ? rootfs->mount : "", d->name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ if (ret < 0 || ret >= PATH_MAX)
return -1;
/* 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;
const struct lxc_tty_info *ttys = &conf->ttys;
char *ttydir = ttys->dir;
- char path[MAXPATHLEN], lxcpath[MAXPATHLEN];
+ char path[PATH_MAX], lxcpath[PATH_MAX];
if (!conf->rootfs.path)
return 0;
@@ -1218,13 +1218,13 @@ enum {
static int lxc_fill_autodev(const struct lxc_rootfs *rootfs)
{
int i, ret;
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
mode_t cmask;
int use_mknod = LXC_DEVNODE_MKNOD;
- ret = snprintf(path, MAXPATHLEN, "%s/dev",
+ ret = snprintf(path, PATH_MAX, "%s/dev",
rootfs->path ? rootfs->mount : "");
- if (ret < 0 || ret >= MAXPATHLEN)
+ if (ret < 0 || ret >= PATH_MAX)
return -1;
/* 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);
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];
- ret = snprintf(path, MAXPATHLEN, "%s/dev/%s",
+ ret = snprintf(path, PATH_MAX, "%s/dev/%s",
rootfs->path ? rootfs->mount : "", device->name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ if (ret < 0 || ret >= PATH_MAX)
return -1;
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. */
- ret = snprintf(hostpath, MAXPATHLEN, "/dev/%s", device->name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(hostpath, PATH_MAX, "/dev/%s", device->name);
+ if (ret < 0 || ret >= PATH_MAX)
return -1;
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)
{
int ret;
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
char *rootfs_path = rootfs->path ? rootfs->mount : "";
if (console->path && !strcmp(console->path, "none"))
@@ -1801,7 +1801,7 @@ static int lxc_setup_ttydir_console(const struct lxc_rootfs *rootfs,
char *ttydir)
{
int ret;
- char path[MAXPATHLEN], lxcpath[MAXPATHLEN];
+ char path[PATH_MAX], lxcpath[PATH_MAX];
char *rootfs_path = rootfs->path ? rootfs->mount : "";
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)
{
int ret;
- char srcbuf[MAXPATHLEN];
+ char srcbuf[PATH_MAX];
const char *srcpath = fsname;
#ifdef HAVE_STATVFS
struct statvfs sb;
#endif
if (relative) {
- ret = snprintf(srcbuf, MAXPATHLEN, "%s/%s", rootfs ? rootfs : "/", fsname ? fsname : "");
- if (ret < 0 || ret >= MAXPATHLEN) {
+ ret = snprintf(srcbuf, PATH_MAX, "%s/%s", rootfs ? rootfs : "/", fsname ? fsname : "");
+ if (ret < 0 || ret >= PATH_MAX) {
ERROR("source path is too long");
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)
{
int ret;
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
/* For containers created without a rootfs all mounts are treated as
* absolute paths starting at / on the host.
@@ -2280,7 +2280,7 @@ static int mount_entry_on_absolute_rootfs(struct mntent *mntent,
int offset;
char *aux;
const char *lxcpath;
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
int ret = 0;
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
* <lxcpath>/<name>/rootfs" as the target prefix.
*/
- ret = snprintf(path, MAXPATHLEN, "%s/%s/rootfs", lxcpath, lxc_name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(path, PATH_MAX, "%s/%s/rootfs", lxcpath, lxc_name);
+ if (ret < 0 || ret >= PATH_MAX)
goto skipvarlib;
aux = strstr(mntent->mnt_dir, path);
@@ -2309,8 +2309,8 @@ static int mount_entry_on_absolute_rootfs(struct mntent *mntent,
offset = strlen(rootfs->path);
skipabs:
- ret = snprintf(path, MAXPATHLEN, "%s/%s", rootfs->mount, aux + offset);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(path, PATH_MAX, "%s/%s", rootfs->mount, aux + offset);
+ if (ret < 0 || ret >= PATH_MAX)
return -1;
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)
{
int ret;
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
/* relative to root mount point */
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;
int ret = 0;
char *tmp = NULL;
- char filename[MAXPATHLEN] = {0};
+ char filename[PATH_MAX] = {0};
lxc_list_for_each (it, sysctls) {
elem = it->elem;
@@ -2697,7 +2697,7 @@ int setup_proc_filesystem(struct lxc_list *procs, pid_t pid)
struct lxc_proc *elem;
int ret = 0;
char *tmp = NULL;
- char filename[MAXPATHLEN] = {0};
+ char filename[PATH_MAX] = {0};
lxc_list_for_each (it, procs) {
elem = it->elem;
@@ -2806,13 +2806,13 @@ int write_id_mapping(enum idtype idtype, pid_t pid, const char *buf,
size_t buf_size)
{
int fd, ret;
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
if (geteuid() != 0 && idtype == ID_TYPE_GID) {
size_t buflen;
- ret = snprintf(path, MAXPATHLEN, "/proc/%d/setgroups", pid);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(path, PATH_MAX, "/proc/%d/setgroups", pid);
+ if (ret < 0 || ret >= PATH_MAX)
return -E2BIG;
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');
- if (ret < 0 || ret >= MAXPATHLEN)
+ if (ret < 0 || ret >= PATH_MAX)
return -E2BIG;
fd = open(path, O_WRONLY);
@@ -2938,7 +2938,7 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid)
int fill, left;
char u_or_g;
char *pos;
- char cmd_output[MAXPATHLEN];
+ char cmd_output[PATH_MAX];
struct id_map *map;
struct lxc_list *iterator;
enum idtype type;
@@ -3171,7 +3171,7 @@ int chown_mapped_root(const char *path, struct lxc_conf *conf)
"-m", map5,
"--", "chown", ugid, path,
NULL};
- char cmd_output[MAXPATHLEN];
+ char cmd_output[PATH_MAX];
hostuid = geteuid();
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)
{
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
struct lxc_list *it;
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;
char *hookname = it->elem;
- ret = snprintf(path, MAXPATHLEN, "%s%s",
+ ret = snprintf(path, PATH_MAX, "%s%s",
conf->rootfs.path ? conf->rootfs.mount : "",
hookname);
- if (ret < 0 || ret >= MAXPATHLEN)
+ if (ret < 0 || ret >= PATH_MAX)
return false;
ret = stat(path, &st);
From 18740311c1ba851be39ebe05691b06f181e3770b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 7 Oct 2018 09:59:16 +0200
Subject: [PATCH 04/15] confile: s/MAXPATHLEN/PATH_MAX/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/confile.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index 8e13b123d..19693d6a0 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -2068,7 +2068,7 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf)
{
struct dirent *direntp;
DIR *dir;
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
int len;
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)
continue;
- len = snprintf(path, MAXPATHLEN, "%s/%s", dirp, fnam);
- if (len < 0 || len >= MAXPATHLEN) {
+ len = snprintf(path, PATH_MAX, "%s/%s", dirp, fnam);
+ if (len < 0 || len >= PATH_MAX) {
ret = -1;
goto out;
}
From 52539fcc7783e417f724f51836ab3470776ea246 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 7 Oct 2018 10:00:50 +0200
Subject: [PATCH 05/15] log: s/MAXPATHLEN/PATH_MAX/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/log.h | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/lxc/log.h b/src/lxc/log.h
index 7760f63b7..008df7a73 100644
--- a/src/lxc/log.h
+++ b/src/lxc/log.h
@@ -339,7 +339,7 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
#ifdef STRERROR_R_CHAR_P
#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; \
{ \
int saved_errno = errno; \
@@ -350,7 +350,7 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
}
#else
#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; \
{ \
int saved_errno = errno; \
@@ -361,10 +361,10 @@ ATTR_UNUSED static inline void LXC_##LEVEL(struct lxc_log_locinfo* locinfo, \
#elif ENFORCE_THREAD_SAFETY
#error ENFORCE_THREAD_SAFETY was set but cannot be guaranteed
#else
- #define lxc_log_strerror_r \
- char *ptr = NULL; \
- { \
- ptr = strerror(errno); \
+ #define lxc_log_strerror_r \
+ char *ptr = NULL; \
+ { \
+ ptr = strerror(errno); \
}
#endif
From 85d67fba9f9e450c3b97043d68aed010a8442fbb Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 7 Oct 2018 10:01:13 +0200
Subject: [PATCH 06/15] lsm: s/MAXPATHLEN/PATH_MAX/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/lsm/apparmor.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lxc/lsm/apparmor.c b/src/lxc/lsm/apparmor.c
index cc5391ab0..6371ab59b 100644
--- a/src/lxc/lsm/apparmor.c
+++ b/src/lxc/lsm/apparmor.c
@@ -809,7 +809,7 @@ static int run_apparmor_parser(char command,
struct lxc_conf *conf,
const char *lxcpath)
{
- char output[MAXPATHLEN];
+ char output[PATH_MAX];
int ret;
struct apparmor_parser_args args = {
.cmd = command,
From 8a22c168380fca1d5b880f470584a2c98d87faca Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 7 Oct 2018 10:01:30 +0200
Subject: [PATCH 07/15] lxccontainer: s/MAXPATHLEN/PATH_MAX/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/lxccontainer.c | 110 ++++++++++++++++++++---------------------
1 file changed, 55 insertions(+), 55 deletions(-)
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index bfd3c85a1..9941d646a 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -2673,8 +2673,8 @@ static bool mod_rdep(struct lxc_container *c0, struct lxc_container *c, bool inc
struct stat fbuf;
void *buf = NULL;
char *del = NULL;
- char path[MAXPATHLEN];
- char newpath[MAXPATHLEN];
+ char path[PATH_MAX];
+ char newpath[PATH_MAX];
int fd, ret, n = 0, v = 0;
bool bret = false;
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))
return false;
- ret = snprintf(path, MAXPATHLEN, "%s/%s/lxc_snapshots", c0->config_path, c0->name);
- if (ret < 0 || ret > MAXPATHLEN)
+ ret = snprintf(path, PATH_MAX, "%s/%s/lxc_snapshots", c0->config_path, c0->name);
+ if (ret < 0 || ret > PATH_MAX)
goto out;
- ret = snprintf(newpath, MAXPATHLEN, "%s\n%s\n", c->config_path, c->name);
- if (ret < 0 || ret > MAXPATHLEN)
+ ret = snprintf(newpath, PATH_MAX, "%s\n%s\n", c->config_path, c->name);
+ if (ret < 0 || ret > PATH_MAX)
goto out;
/* If we find an lxc-snapshot file using the old format only listing the
@@ -2798,14 +2798,14 @@ static bool mod_rdep(struct lxc_container *c0, struct lxc_container *c, bool inc
void mod_all_rdeps(struct lxc_container *c, bool inc)
{
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;
FILE *f;
int ret;
- ret = snprintf(path, MAXPATHLEN, "%s/%s/lxc_rdepends",
+ ret = snprintf(path, PATH_MAX, "%s/%s/lxc_rdepends",
c->config_path, c->name);
- if (ret < 0 || ret >= MAXPATHLEN) {
+ if (ret < 0 || ret >= PATH_MAX) {
ERROR("Path name too long");
return;
}
@@ -2845,14 +2845,14 @@ void mod_all_rdeps(struct lxc_container *c, bool inc)
static bool has_fs_snapshots(struct lxc_container *c)
{
FILE *f;
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
int ret, v;
struct stat fbuf;
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);
- if (ret < 0 || ret > MAXPATHLEN)
+ if (ret < 0 || ret > PATH_MAX)
goto out;
/* If the file doesn't exist there are no snapshots. */
@@ -2880,7 +2880,7 @@ static bool has_fs_snapshots(struct lxc_container *c)
static bool has_snapshots(struct lxc_container *c)
{
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
struct dirent *direntp;
int count=0;
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]) {
char *hookname = it->elem;
char *fname = strrchr(hookname, '/');
- char tmppath[MAXPATHLEN];
+ char tmppath[PATH_MAX];
if (!fname) /* relative path - we don't support, but maybe we should */
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 */
- ret = snprintf(tmppath, MAXPATHLEN, "%s/%s/%s",
+ ret = snprintf(tmppath, PATH_MAX, "%s/%s/%s",
c->config_path, c->name, fname+1);
- if (ret < 0 || ret >= MAXPATHLEN)
+ if (ret < 0 || ret >= PATH_MAX)
return -1;
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)
{
- char newpath[MAXPATHLEN];
+ char newpath[PATH_MAX];
char *oldpath = oldc->lxc_conf->fstab;
int ret;
@@ -3463,9 +3463,9 @@ static int copy_fstab(struct lxc_container *oldc, struct lxc_container *c)
if (!p)
return -1;
- ret = snprintf(newpath, MAXPATHLEN, "%s/%s%s",
+ ret = snprintf(newpath, PATH_MAX, "%s/%s%s",
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);
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)
{
- char path0[MAXPATHLEN], path1[MAXPATHLEN];
+ char path0[PATH_MAX], path1[PATH_MAX];
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);
- if (ret < 0 || ret >= MAXPATHLEN) {
+ if (ret < 0 || ret >= PATH_MAX) {
WARN("Error copying reverse dependencies");
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);
- if (ret < 0 || ret >= MAXPATHLEN) {
+ if (ret < 0 || ret >= PATH_MAX) {
WARN("Error copying reverse dependencies");
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)
{
int ret;
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
FILE *f;
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);
- if (ret < 0 || ret >= MAXPATHLEN)
+ if (ret < 0 || ret >= PATH_MAX)
return false;
f = fopen(path, "a");
@@ -3644,7 +3644,7 @@ static int clone_update_rootfs(struct clone_update_data *data)
int flags = data->flags;
char **hookargs = data->hookargs;
int ret = -1;
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
struct lxc_storage *bdev;
FILE *fout;
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)) {
- ret = snprintf(path, MAXPATHLEN, "%s/etc/hostname", bdev->dest);
+ ret = snprintf(path, PATH_MAX, "%s/etc/hostname", bdev->dest);
storage_put(bdev);
- if (ret < 0 || ret >= MAXPATHLEN)
+ if (ret < 0 || ret >= PATH_MAX)
return -1;
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,
char **hookargs)
{
- char newpath[MAXPATHLEN];
+ char newpath[PATH_MAX];
int fd, ret;
struct clone_update_data data;
size_t saved_unexp_len;
@@ -3812,8 +3812,8 @@ static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char
if (!lxcpath)
lxcpath = do_lxcapi_get_config_path(c);
- ret = snprintf(newpath, MAXPATHLEN, "%s/%s/config", lxcpath, newname);
- if (ret < 0 || ret >= MAXPATHLEN) {
+ ret = snprintf(newpath, PATH_MAX, "%s/%s/config", lxcpath, newname);
+ if (ret < 0 || ret >= PATH_MAX) {
SYSERROR("clone: failed making config pathname");
goto out;
}
@@ -3861,8 +3861,8 @@ static struct lxc_container *do_lxcapi_clone(struct lxc_container *c, const char
saved_unexp_conf = NULL;
c->lxc_conf->unexpanded_len = saved_unexp_len;
- ret = snprintf(newpath, MAXPATHLEN, "%s/%s/rootfs", lxcpath, newname);
- if (ret < 0 || ret >= MAXPATHLEN) {
+ ret = snprintf(newpath, PATH_MAX, "%s/%s/rootfs", lxcpath, newname);
+ if (ret < 0 || ret >= PATH_MAX) {
SYSERROR("clone: failed making rootfs pathname");
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
* /var/lib/lxc -> /var/lib/lxcsnaps
*/
- ret = snprintf(snappath, MAXPATHLEN, "%ssnaps", c->config_path);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(snappath, PATH_MAX, "%ssnaps", c->config_path);
+ if (ret < 0 || ret >= PATH_MAX)
return false;
if (dir_exists(snappath)) {
- ret = snprintf(snappath, MAXPATHLEN, "%ssnaps/%s", c->config_path, c->name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(snappath, PATH_MAX, "%ssnaps/%s", c->config_path, c->name);
+ if (ret < 0 || ret >= PATH_MAX)
return false;
return true;
@@ -4127,8 +4127,8 @@ static bool get_snappath_dir(struct lxc_container *c, char *snappath)
* Use the new style path
* /var/lib/lxc -> /var/lib/lxc + c->name + /snaps + \0
*/
- ret = snprintf(snappath, MAXPATHLEN, "%s/%s/snaps", c->config_path, c->name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(snappath, PATH_MAX, "%s/%s/snaps", c->config_path, c->name);
+ if (ret < 0 || ret >= PATH_MAX)
return false;
return true;
@@ -4140,7 +4140,7 @@ static int do_lxcapi_snapshot(struct lxc_container *c, const char *commentfile)
time_t timer;
struct tm tm_info;
struct lxc_container *c2;
- char snappath[MAXPATHLEN], newname[20];
+ char snappath[PATH_MAX], newname[20];
char buffer[25];
FILE *f;
@@ -4260,12 +4260,12 @@ static char *get_snapcomment_path(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;
FILE *fin;
- ret = snprintf(path, MAXPATHLEN, "%s/%s/ts", snappath, name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(path, PATH_MAX, "%s/%s/ts", snappath, name);
+ if (ret < 0 || ret >= PATH_MAX)
return NULL;
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)
{
- char snappath[MAXPATHLEN], path2[MAXPATHLEN];
+ char snappath[PATH_MAX], path2[PATH_MAX];
int count = 0, ret;
struct dirent *direntp;
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, ".."))
continue;
- ret = snprintf(path2, MAXPATHLEN, "%s/%s/config", snappath, direntp->d_name);
- if (ret < 0 || ret >= MAXPATHLEN) {
+ ret = snprintf(path2, PATH_MAX, "%s/%s/config", snappath, direntp->d_name);
+ if (ret < 0 || ret >= PATH_MAX) {
ERROR("pathname too long");
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)
{
- char clonelxcpath[MAXPATHLEN];
+ char clonelxcpath[PATH_MAX];
int flags = 0;
struct lxc_container *snap, *rest;
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)
{
- char clonelxcpath[MAXPATHLEN];
+ char clonelxcpath[PATH_MAX];
if (!c || !c->name || !c->config_path || !snapname)
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)
{
- char clonelxcpath[MAXPATHLEN];
+ char clonelxcpath[PATH_MAX];
if (!c || !c->name || !c->config_path)
return false;
@@ -4560,7 +4560,7 @@ static bool do_add_remove_node(pid_t init_pid, const char *path, bool add,
int ret;
char *tmp;
pid_t pid;
- char chrootpath[MAXPATHLEN];
+ char chrootpath[PATH_MAX];
char *directory_path = NULL;
pid = fork();
@@ -4580,8 +4580,8 @@ static bool do_add_remove_node(pid_t init_pid, const char *path, bool add,
}
/* prepare the path */
- ret = snprintf(chrootpath, MAXPATHLEN, "/proc/%d/root", init_pid);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(chrootpath, PATH_MAX, "/proc/%d/root", init_pid);
+ if (ret < 0 || ret >= PATH_MAX)
return false;
ret = chroot(chrootpath);
@@ -4974,7 +4974,7 @@ static int do_lxcapi_mount(struct lxc_container *c, const char *source,
struct lxc_mount *mnt)
{
char *suff, *sret;
- char template[MAXPATHLEN], path[MAXPATHLEN];
+ char template[PATH_MAX], path[PATH_MAX];
pid_t pid, init_pid;
struct stat sb;
int ret = -1, fd = -EBADF;
From 3c7361878931006d05997875390ec59449ac2b90 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 7 Oct 2018 10:01:59 +0200
Subject: [PATCH 08/15] macro: s/MAXPATHLEN/PATH_MAX/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/macro.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/lxc/macro.h b/src/lxc/macro.h
index a91f9dc97..6b6b5f794 100644
--- a/src/lxc/macro.h
+++ b/src/lxc/macro.h
@@ -184,7 +184,7 @@
*/
#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 */
#ifndef LO_FLAGS_AUTOCLEAR
From 419590daf4c759ff72320c219b1ccd6bff4f3101 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 7 Oct 2018 10:02:14 +0200
Subject: [PATCH 09/15] network: s/MAXPATHLEN/PATH_MAX/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/network.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/lxc/network.c b/src/lxc/network.c
index df1989272..d7cc0f6d0 100644
--- a/src/lxc/network.c
+++ b/src/lxc/network.c
@@ -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)
{
int ret;
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
if (family != AF_INET && family != AF_INET6)
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 ? "proxy_arp" : "proxy_ndp");
- if (ret < 0 || (size_t)ret >= MAXPATHLEN)
+ if (ret < 0 || (size_t)ret >= PATH_MAX)
return -E2BIG;
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 ret;
- char cmd_output[MAXPATHLEN];
+ char cmd_output[PATH_MAX];
struct ovs_veth_args args;
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)
{
int ret;
- char cmd_output[MAXPATHLEN];
+ char cmd_output[PATH_MAX];
struct ovs_veth_args args;
args.bridge = bridge;
@@ -2093,7 +2093,7 @@ static int lxc_create_network_unpriv_exec(const char *lxcpath, const char *lxcna
int bytes, pipefd[2];
char *token, *saveptr = NULL;
char netdev_link[IFNAMSIZ];
- char buffer[MAXPATHLEN] = {0};
+ char buffer[PATH_MAX] = {0};
size_t retlen;
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(pipefd[1]);
- bytes = lxc_read_nointr(pipefd[0], &buffer, MAXPATHLEN);
+ bytes = lxc_read_nointr(pipefd[0], &buffer, PATH_MAX);
if (bytes < 0) {
SYSERROR("Failed to read from pipe file descriptor");
close(pipefd[0]);
@@ -2257,7 +2257,7 @@ static int lxc_delete_network_unpriv_exec(const char *lxcpath, const char *lxcna
int bytes, ret;
pid_t child;
int pipefd[2];
- char buffer[MAXPATHLEN] = {0};
+ char buffer[PATH_MAX] = {0};
if (netdev->type != LXC_NET_VETH) {
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]);
- bytes = lxc_read_nointr(pipefd[0], &buffer, MAXPATHLEN);
+ bytes = lxc_read_nointr(pipefd[0], &buffer, PATH_MAX);
if (bytes < 0) {
SYSERROR("Failed to read from pipe file descriptor.");
close(pipefd[0]);
From bb3c1e56128294b48a245bc3272dae7f7a77e5aa Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 7 Oct 2018 10:02:39 +0200
Subject: [PATCH 10/15] pam: s/MAXPATHLEN/PATH_MAX/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/pam/pam_cgfs.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/lxc/pam/pam_cgfs.c b/src/lxc/pam/pam_cgfs.c
index bef9bee47..4b2aa567e 100644
--- a/src/lxc/pam/pam_cgfs.c
+++ b/src/lxc/pam/pam_cgfs.c
@@ -2408,13 +2408,13 @@ static int handle_login(const char *user, uid_t uid, gid_t gid)
{
int idx = 0, ret;
bool existed;
- char cg[MAXPATHLEN];
+ char cg[PATH_MAX];
cg_escape();
while (idx >= 0) {
- ret = snprintf(cg, MAXPATHLEN, "/user/%s/%d", user, idx);
- if (ret < 0 || ret >= MAXPATHLEN) {
+ ret = snprintf(cg, PATH_MAX, "/user/%s/%d", user, idx);
+ if (ret < 0 || ret >= PATH_MAX) {
mysyslog(LOG_ERR, "Username too long\n", NULL);
return PAM_SESSION_ERR;
}
From 245100a0cf39555348388a5d9b598a2f361f51dc Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 7 Oct 2018 10:02:53 +0200
Subject: [PATCH 11/15] start: s/MAXPATHLEN/PATH_MAX/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/start.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/lxc/start.c b/src/lxc/start.c
index 178067042..61a16e86a 100644
--- a/src/lxc/start.c
+++ b/src/lxc/start.c
@@ -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,
const char *name)
{
- char destroy[MAXPATHLEN];
+ char destroy[PATH_MAX];
struct lxc_container *c;
int ret = 0;
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);
- ret = snprintf(destroy, MAXPATHLEN, "%s/%s", handler->lxcpath, name);
- if (ret < 0 || ret >= MAXPATHLEN) {
+ ret = snprintf(destroy, PATH_MAX, "%s/%s", handler->lxcpath, name);
+ if (ret < 0 || ret >= PATH_MAX) {
ERROR("Error destroying directory for container \"%s\"", name);
return;
}
From 8c880e57d76fb1c9accbe9360489d2f36bb6578a Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 7 Oct 2018 10:03:55 +0200
Subject: [PATCH 12/15] terminal: s/MAXPATHLEN/PATH_MAX/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/terminal.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/lxc/terminal.h b/src/lxc/terminal.h
index d1d404a6f..ef09d50d2 100644
--- a/src/lxc/terminal.h
+++ b/src/lxc/terminal.h
@@ -28,6 +28,7 @@
#include <stdio.h>
#include "list.h"
+#include "macro.h"
#include "ringbuf.h"
struct lxc_container;
@@ -36,7 +37,7 @@ struct lxc_epoll_descr;
struct lxc_terminal_info {
/* the path name of the slave side */
- char name[MAXPATHLEN];
+ char name[PATH_MAX];
/* the file descriptor of the master */
int master;
@@ -89,7 +90,7 @@ struct lxc_terminal {
struct lxc_terminal_info proxy;
struct lxc_epoll_descr *descr;
char *path;
- char name[MAXPATHLEN];
+ char name[PATH_MAX];
struct termios *tios;
struct lxc_terminal_state *tty_state;
From d726953a2397406a87878ec9f1a7383a3521abca Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 7 Oct 2018 10:04:15 +0200
Subject: [PATCH 13/15] utils: s/MAXPATHLEN/PATH_MAX/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/utils.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index 1af6f512c..5714a78df 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -84,7 +84,7 @@ static int _recursive_rmdir(const char *dirname, dev_t pdev,
struct dirent *direntp;
DIR *dir;
int ret, failed=0;
- char pathname[MAXPATHLEN];
+ char pathname[PATH_MAX];
bool hadexclude = false;
dir = opendir(dirname);
@@ -101,8 +101,8 @@ static int _recursive_rmdir(const char *dirname, dev_t pdev,
!strcmp(direntp->d_name, ".."))
continue;
- rc = snprintf(pathname, MAXPATHLEN, "%s/%s", dirname, direntp->d_name);
- if (rc < 0 || rc >= MAXPATHLEN) {
+ rc = snprintf(pathname, PATH_MAX, "%s/%s", dirname, direntp->d_name);
+ if (rc < 0 || rc >= PATH_MAX) {
ERROR("pathname too long");
failed=1;
continue;
@@ -678,11 +678,11 @@ int detect_shared_rootfs(void)
bool switch_to_ns(pid_t pid, const char *ns)
{
int fd, ret;
- char nspath[MAXPATHLEN];
+ char nspath[PATH_MAX];
/* Switch to new ns */
- ret = snprintf(nspath, MAXPATHLEN, "/proc/%d/ns/%s", pid, ns);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(nspath, PATH_MAX, "/proc/%d/ns/%s", pid, ns);
+ if (ret < 0 || ret >= PATH_MAX)
return false;
fd = open(nspath, O_RDONLY);
@@ -752,7 +752,7 @@ bool detect_ramfs_rootfs(void)
char *on_path(const char *cmd, const char *rootfs)
{
char *entry = NULL, *path = NULL;
- char cmdpath[MAXPATHLEN];
+ char cmdpath[PATH_MAX];
int ret;
path = getenv("PATH");
@@ -765,11 +765,11 @@ char *on_path(const char *cmd, const char *rootfs)
lxc_iterate_parts (entry, path, ":") {
if (rootfs)
- ret = snprintf(cmdpath, MAXPATHLEN, "%s/%s/%s", rootfs,
+ ret = snprintf(cmdpath, PATH_MAX, "%s/%s/%s", rootfs,
entry, cmd);
else
- ret = snprintf(cmdpath, MAXPATHLEN, "%s/%s", entry, cmd);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(cmdpath, PATH_MAX, "%s/%s", entry, cmd);
+ if (ret < 0 || ret >= PATH_MAX)
continue;
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)
{
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
int link_to_pid, linklen, mypid, ret;
char link[INTTYPE_TO_STRLEN(pid_t)] = {0};
- ret = snprintf(path, MAXPATHLEN, "%s/proc/self", rootfs);
- if (ret < 0 || ret >= MAXPATHLEN) {
+ ret = snprintf(path, PATH_MAX, "%s/proc/self", rootfs);
+ if (ret < 0 || ret >= PATH_MAX) {
SYSERROR("proc path name too long");
return -1;
}
linklen = readlink(path, link, sizeof(link));
- ret = snprintf(path, MAXPATHLEN, "%s/proc", rootfs);
- if (ret < 0 || ret >= MAXPATHLEN) {
+ ret = snprintf(path, PATH_MAX, "%s/proc", rootfs);
+ if (ret < 0 || ret >= PATH_MAX) {
SYSERROR("proc path name too long");
return -1;
}
From 339de297af031e9d2cd48011a1072cb9ba4e5c37 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 7 Oct 2018 10:06:52 +0200
Subject: [PATCH 14/15] storage: s/MAXPATHLEN/PATH_MAX/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/storage/btrfs.c | 2 +-
src/lxc/storage/loop.c | 4 ++--
src/lxc/storage/lvm.c | 16 ++++++++--------
src/lxc/storage/overlay.c | 28 ++++++++++++++--------------
src/lxc/storage/rbd.c | 4 ++--
src/lxc/storage/storage.c | 2 +-
src/lxc/storage/storage_utils.c | 6 +++---
src/lxc/storage/zfs.c | 26 +++++++++++++-------------
8 files changed, 44 insertions(+), 44 deletions(-)
diff --git a/src/lxc/storage/btrfs.c b/src/lxc/storage/btrfs.c
index 049074a45..b850611dc 100644
--- a/src/lxc/storage/btrfs.c
+++ b/src/lxc/storage/btrfs.c
@@ -462,7 +462,7 @@ bool btrfs_create_clone(struct lxc_conf *conf, struct lxc_storage *orig,
{
int ret;
struct rsync_data data = {0, 0};
- char cmd_output[MAXPATHLEN] = {0};
+ char cmd_output[PATH_MAX] = {0};
ret = rmdir(new->dest);
if (ret < 0 && errno != ENOENT)
diff --git a/src/lxc/storage/loop.c b/src/lxc/storage/loop.c
index 8ea40e088..35cb13e06 100644
--- a/src/lxc/storage/loop.c
+++ b/src/lxc/storage/loop.c
@@ -237,7 +237,7 @@ bool loop_detect(const char *path)
int loop_mount(struct lxc_storage *bdev)
{
int ret, loopfd;
- char loname[MAXPATHLEN];
+ char loname[PATH_MAX];
const char *src;
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;
off_t ret_size;
- char cmd_output[MAXPATHLEN];
+ char cmd_output[PATH_MAX];
const char *cmd_args[2] = {fstype, path};
/* create the new loopback file */
diff --git a/src/lxc/storage/lvm.c b/src/lxc/storage/lvm.c
index 8bb16175d..6908e9066 100644
--- a/src/lxc/storage/lvm.c
+++ b/src/lxc/storage/lvm.c
@@ -111,7 +111,7 @@ static int do_lvm_create(const char *path, uint64_t size, const char *thinpool)
{
int len, ret;
char *pathdup, *vg, *lv;
- char cmd_output[MAXPATHLEN];
+ char cmd_output[PATH_MAX];
char sz[24];
char *tp = NULL;
struct lvcreate_args cmd_args = {0};
@@ -201,7 +201,7 @@ bool lvm_detect(const char *path)
int fd;
ssize_t ret;
struct stat statbuf;
- char devp[MAXPATHLEN], buf[4];
+ char devp[PATH_MAX], buf[4];
if (!strncmp(path, "lvm:", 4))
return true;
@@ -213,9 +213,9 @@ bool lvm_detect(const char *path)
if (!S_ISBLK(statbuf.st_mode))
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));
- if (ret < 0 || ret >= MAXPATHLEN) {
+ if (ret < 0 || ret >= PATH_MAX) {
ERROR("Failed to create string");
return false;
}
@@ -335,7 +335,7 @@ static int lvm_snapshot(struct lxc_storage *orig, const char *path, uint64_t siz
char *lv, *pathdup;
char sz[24];
char fstype[100];
- char cmd_output[MAXPATHLEN];
+ char cmd_output[PATH_MAX];
char repairchar;
const char *origsrc;
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;
struct rsync_data data;
const char *cmd_args[2];
- char cmd_output[MAXPATHLEN] = {0};
+ char cmd_output[PATH_MAX] = {0};
char fstype[100] = "ext4";
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 ret;
- char cmd_output[MAXPATHLEN];
+ char cmd_output[PATH_MAX];
struct lvcreate_args cmd_args = {0};
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;
int ret, len;
const char *cmd_args[2];
- char cmd_output[MAXPATHLEN];
+ char cmd_output[PATH_MAX];
if (!specs)
return -1;
diff --git a/src/lxc/storage/overlay.c b/src/lxc/storage/overlay.c
index a95c6b7e6..01546b1bf 100644
--- a/src/lxc/storage/overlay.c
+++ b/src/lxc/storage/overlay.c
@@ -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,
const char *lxc_name, const char *lxc_path)
{
- char lxcpath[MAXPATHLEN];
+ char lxcpath[PATH_MAX];
char **opts;
int ret;
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) {
- ret = snprintf(lxcpath, MAXPATHLEN, "%s/%s", lxc_path, lxc_name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(lxcpath, PATH_MAX, "%s/%s", lxc_path, lxc_name);
+ if (ret < 0 || ret >= PATH_MAX)
goto err;
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 *newname)
{
- char new_upper[MAXPATHLEN], new_work[MAXPATHLEN], old_upper[MAXPATHLEN],
- old_work[MAXPATHLEN];
+ char new_upper[PATH_MAX], new_work[PATH_MAX], old_upper[PATH_MAX],
+ old_work[PATH_MAX];
size_t i;
struct lxc_list *iterator;
char *cleanpath = NULL;
@@ -852,13 +852,13 @@ int ovl_update_abs_paths(struct lxc_conf *lxc_conf, const char *lxc_path,
}
ret =
- snprintf(old_work, MAXPATHLEN, "workdir=%s/%s", lxc_path, lxc_name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ snprintf(old_work, PATH_MAX, "workdir=%s/%s", lxc_path, lxc_name);
+ if (ret < 0 || ret >= PATH_MAX)
goto err;
ret =
- snprintf(new_work, MAXPATHLEN, "workdir=%s/%s", cleanpath, newname);
- if (ret < 0 || ret >= MAXPATHLEN)
+ snprintf(new_work, PATH_MAX, "workdir=%s/%s", cleanpath, newname);
+ if (ret < 0 || ret >= PATH_MAX)
goto err;
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)
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);
- if (ret < 0 || ret >= MAXPATHLEN)
+ if (ret < 0 || ret >= PATH_MAX)
goto err;
- ret = snprintf(new_upper, MAXPATHLEN, "%s=%s/%s", tmp,
+ ret = snprintf(new_upper, PATH_MAX, "%s=%s/%s", tmp,
cleanpath, newname);
- if (ret < 0 || ret >= MAXPATHLEN)
+ if (ret < 0 || ret >= PATH_MAX)
goto err;
if (strstr(mnt_entry, old_upper)) {
@@ -956,7 +956,7 @@ static int ovl_do_rsync(const char *src, const char *dest,
{
int ret = -1;
struct rsync_data_char rdata = {0};
- char cmd_output[MAXPATHLEN] = {0};
+ char cmd_output[PATH_MAX] = {0};
rdata.src = (char *)src;
rdata.dest = (char *)dest;
diff --git a/src/lxc/storage/rbd.c b/src/lxc/storage/rbd.c
index daeb76e70..e02a629b9 100644
--- a/src/lxc/storage/rbd.c
+++ b/src/lxc/storage/rbd.c
@@ -104,7 +104,7 @@ int rbd_create(struct lxc_storage *bdev, const char *dest, const char *n,
int ret, len;
char sz[24];
const char *cmd_args[2];
- char cmd_output[MAXPATHLEN];
+ char cmd_output[PATH_MAX];
const char *rbdname = n;
struct rbd_args args = {0};
@@ -198,7 +198,7 @@ int rbd_destroy(struct lxc_storage *orig)
int ret;
const char *src;
char *rbdfullname;
- char cmd_output[MAXPATHLEN];
+ char cmd_output[PATH_MAX];
struct rbd_args args = {0};
size_t len;
diff --git a/src/lxc/storage/storage.c b/src/lxc/storage/storage.c
index 3a1053ea2..0a93a4d34 100644
--- a/src/lxc/storage/storage.c
+++ b/src/lxc/storage/storage.c
@@ -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 *oldname = c->name;
const char *oldpath = c->config_path;
- char cmd_output[MAXPATHLEN] = {0};
+ char cmd_output[PATH_MAX] = {0};
struct rsync_data data = {0};
if (!src) {
diff --git a/src/lxc/storage/storage_utils.c b/src/lxc/storage/storage_utils.c
index 9efc939b1..67da0f9be 100644
--- a/src/lxc/storage/storage_utils.c
+++ b/src/lxc/storage/storage_utils.c
@@ -186,7 +186,7 @@ int detect_fs(struct lxc_storage *bdev, char *type, int len)
FILE *f;
char *sp1, *sp2, *sp3;
const char *l, *srcdev;
- char devpath[MAXPATHLEN];
+ char devpath[PATH_MAX];
char *line = NULL;
if (!bdev || !bdev->src || !bdev->dest)
@@ -415,11 +415,11 @@ const char *linkderef(const char *path, char *dest)
if (!S_ISLNK(sbuf.st_mode))
return path;
- ret = readlink(path, dest, MAXPATHLEN);
+ ret = readlink(path, dest, PATH_MAX);
if (ret < 0) {
SYSERROR("error reading link %s", path);
return NULL;
- } else if (ret >= MAXPATHLEN) {
+ } else if (ret >= PATH_MAX) {
ERROR("link in %s too long", path);
return NULL;
}
diff --git a/src/lxc/storage/zfs.c b/src/lxc/storage/zfs.c
index a948755db..ba104da54 100644
--- a/src/lxc/storage/zfs.c
+++ b/src/lxc/storage/zfs.c
@@ -134,7 +134,7 @@ bool zfs_detect(const char *path)
int ret;
char *dataset;
struct zfs_args cmd_args = {0};
- char cmd_output[MAXPATHLEN] = {0};
+ char cmd_output[PATH_MAX] = {0};
if (!strncmp(path, "zfs:", 4))
return true;
@@ -185,7 +185,7 @@ int zfs_mount(struct lxc_storage *bdev)
char *mntdata, *tmp;
const char *src;
unsigned long mntflags;
- char cmd_output[MAXPATHLEN] = {0};
+ char cmd_output[PATH_MAX] = {0};
if (strcmp(bdev->type, "zfs"))
return -22;
@@ -287,7 +287,7 @@ bool zfs_copy(struct lxc_conf *conf, struct lxc_storage *orig,
struct lxc_storage *new, uint64_t newsize)
{
int ret;
- char cmd_output[MAXPATHLEN], option[MAXPATHLEN];
+ char cmd_output[PATH_MAX], option[PATH_MAX];
struct rsync_data data = {0, 0};
struct zfs_args cmd_args = {0};
const char *argv[] = {"zfs", /* 0 */
@@ -299,8 +299,8 @@ bool zfs_copy(struct lxc_conf *conf, struct lxc_storage *orig,
NULL};
/* mountpoint */
- ret = snprintf(option, MAXPATHLEN, "mountpoint=%s", new->dest);
- if (ret < 0 || ret >= MAXPATHLEN) {
+ ret = snprintf(option, PATH_MAX, "mountpoint=%s", new->dest);
+ if (ret < 0 || ret >= PATH_MAX) {
ERROR("Failed to create string");
return false;
}
@@ -348,7 +348,7 @@ bool zfs_snapshot(struct lxc_conf *conf, struct lxc_storage *orig,
char *tmp, *snap_name, *snapshot;
const char *orig_src;
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);
if (*orig_src == '/') {
@@ -423,8 +423,8 @@ bool zfs_snapshot(struct lxc_conf *conf, struct lxc_storage *orig,
TRACE("Created zfs snapshot \"%s\"", snapshot);
}
- ret = snprintf(option, MAXPATHLEN, "mountpoint=%s", new->dest);
- if (ret < 0 || ret >= MAXPATHLEN) {
+ ret = snprintf(option, PATH_MAX, "mountpoint=%s", new->dest);
+ if (ret < 0 || ret >= PATH_MAX) {
ERROR("Failed to create string");
free(snapshot);
return -1;
@@ -455,7 +455,7 @@ int zfs_clonepaths(struct lxc_storage *orig, struct lxc_storage *new,
char *dataset, *tmp;
const char *orig_src;
size_t dataset_len, len;
- char cmd_output[MAXPATHLEN] = {0};
+ char cmd_output[PATH_MAX] = {0};
if (!orig->src || !orig->dest)
return -1;
@@ -586,7 +586,7 @@ int zfs_destroy(struct lxc_storage *orig)
bool found;
char *parent_snapshot = NULL;
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);
@@ -714,7 +714,7 @@ int zfs_create(struct lxc_storage *bdev, const char *dest, const char *n,
int ret;
size_t len;
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 */
"create", /* 1 */
"-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);
- ret = snprintf(option, MAXPATHLEN, "mountpoint=%s", bdev->dest);
- if (ret < 0 || ret >= MAXPATHLEN) {
+ ret = snprintf(option, PATH_MAX, "mountpoint=%s", bdev->dest);
+ if (ret < 0 || ret >= PATH_MAX) {
ERROR("Failed to create string");
return -1;
}
From 3a5996ff0c3d06be182d1410a3eec5aac1a8934b Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Sun, 7 Oct 2018 10:09:00 +0200
Subject: [PATCH 15/15] tools: s/MAXPATHLEN/PATH_MAX/g
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/tools/lxc_cgroup.c | 4 ++--
src/lxc/tools/lxc_copy.c | 20 ++++++++++----------
src/lxc/tools/lxc_destroy.c | 20 ++++++++++----------
src/lxc/tools/lxc_execute.c | 4 ++--
src/lxc/tools/lxc_unshare.c | 2 +-
5 files changed, 25 insertions(+), 25 deletions(-)
diff --git a/src/lxc/tools/lxc_cgroup.c b/src/lxc/tools/lxc_cgroup.c
index eb9bf7d66..b2cdaf05e 100644
--- a/src/lxc/tools/lxc_cgroup.c
+++ b/src/lxc/tools/lxc_cgroup.c
@@ -137,10 +137,10 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
} else {
- char buffer[MAXPATHLEN];
+ char buffer[PATH_MAX];
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) {
ERROR("Failed to retrieve value of '%s' for '%s:%s'",
state_object, my_args.lxcpath[0], my_args.name);
diff --git a/src/lxc/tools/lxc_copy.c b/src/lxc/tools/lxc_copy.c
index b9e647e5c..3492be99f 100644
--- a/src/lxc/tools/lxc_copy.c
+++ b/src/lxc/tools/lxc_copy.c
@@ -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)
{
- char upperdir[MAXPATHLEN];
- char workdir[MAXPATHLEN];
+ char upperdir[PATH_MAX];
+ char workdir[PATH_MAX];
unsigned int i;
int ret;
struct mnts *m = NULL;
for (i = 0, m = mnts; i < num; i++, m++) {
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);
- if (ret < 0 || ret >= MAXPATHLEN)
+ if (ret < 0 || ret >= PATH_MAX)
return -1;
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) {
- ret = snprintf(workdir, MAXPATHLEN, "%s/%s/work#XXXXXX",
+ ret = snprintf(workdir, PATH_MAX, "%s/%s/work#XXXXXX",
arg->newpath, arg->newname);
- if (ret < 0 || ret >= MAXPATHLEN)
+ if (ret < 0 || ret >= PATH_MAX)
return -1;
if (!mkdtemp(workdir))
@@ -381,7 +381,7 @@ static int do_clone_ephemeral(struct lxc_container *c,
struct lxc_arguments *arg, char **args, int flags)
{
char *premount;
- char randname[MAXPATHLEN];
+ char randname[PATH_MAX];
unsigned int i;
int ret = 0;
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;
if (!arg->newname) {
- ret = snprintf(randname, MAXPATHLEN, "%s/%s_XXXXXX", arg->newpath, arg->name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(randname, PATH_MAX, "%s/%s_XXXXXX", arg->newpath, arg->name);
+ if (ret < 0 || ret >= PATH_MAX)
return -1;
if (!mkdtemp(randname))
@@ -481,7 +481,7 @@ static int do_clone_ephemeral(struct lxc_container *c,
if (started)
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"))
clone->destroy(clone);
diff --git a/src/lxc/tools/lxc_destroy.c b/src/lxc/tools/lxc_destroy.c
index 6669300d5..6c06b8546 100644
--- a/src/lxc/tools/lxc_destroy.c
+++ b/src/lxc/tools/lxc_destroy.c
@@ -84,11 +84,11 @@ static bool do_destroy(struct lxc_container *c)
{
int ret;
bool bret = true;
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
/* First check whether the container has dependent clones or snapshots. */
- ret = snprintf(path, MAXPATHLEN, "%s/%s/lxc_snapshots", c->config_path, c->name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(path, PATH_MAX, "%s/%s/lxc_snapshots", c->config_path, c->name);
+ if (ret < 0 || ret >= PATH_MAX)
return false;
if (file_exists(path)) {
@@ -96,8 +96,8 @@ static bool do_destroy(struct lxc_container *c)
return false;
}
- ret = snprintf(path, MAXPATHLEN, "%s/%s/snaps", c->config_path, c->name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(path, PATH_MAX, "%s/%s/snaps", c->config_path, c->name);
+ if (ret < 0 || ret >= PATH_MAX)
return false;
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 stat fbuf;
bool bret = false;
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
char *buf = NULL;
char *lxcpath = NULL;
char *lxcname = NULL;
@@ -147,8 +147,8 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
ssize_t bytes;
/* Destroy clones. */
- ret = snprintf(path, MAXPATHLEN, "%s/%s/lxc_snapshots", c->config_path, c->name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(path, PATH_MAX, "%s/%s/lxc_snapshots", c->config_path, c->name);
+ if (ret < 0 || ret >= PATH_MAX)
return false;
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. */
- ret = snprintf(path, MAXPATHLEN, "%s/%s/snaps", c->config_path, c->name);
- if (ret < 0 || ret >= MAXPATHLEN)
+ ret = snprintf(path, PATH_MAX, "%s/%s/snaps", c->config_path, c->name);
+ if (ret < 0 || ret >= PATH_MAX)
return false;
if (rmdir(path) < 0 && errno != ENOENT)
diff --git a/src/lxc/tools/lxc_execute.c b/src/lxc/tools/lxc_execute.c
index 09d20e7bb..b552f4714 100644
--- a/src/lxc/tools/lxc_execute.c
+++ b/src/lxc/tools/lxc_execute.c
@@ -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)
{
int ret;
- char buf[MAXPATHLEN];
+ char buf[PATH_MAX];
char **components, **p;
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)
return false;
diff --git a/src/lxc/tools/lxc_unshare.c b/src/lxc/tools/lxc_unshare.c
index 295464e9d..cc00dc0df 100644
--- a/src/lxc/tools/lxc_unshare.c
+++ b/src/lxc/tools/lxc_unshare.c
@@ -182,7 +182,7 @@ static int get_namespace_flags(char *namespaces)
static bool lookup_user(const char *optarg, uid_t *uid)
{
- char name[MAXPATHLEN];
+ char name[PATH_MAX];
struct passwd pwent;
struct passwd *pwentp = NULL;
char *buf;
More information about the lxc-devel
mailing list