#include "storage/overlay.h"
#include "storage_utils.h"
#include "sync.h"
+#include "syscall_wrappers.h"
#include "terminal.h"
#include "utils.h"
#include "version.h"
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;
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
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;
}
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. */
static bool has_snapshots(struct lxc_container *c)
{
- char path[MAXPATHLEN];
+ char path[PATH_MAX];
struct dirent *direntp;
int count=0;
DIR *dir;
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;
}
/* 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);
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;
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;
}
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;
}
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");
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;
}
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))
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;
if (container_mem_lock(c))
return NULL;
-
- if (!is_stopped(c)) {
- ERROR("error: Original container (%s) is running", c->name);
+ if (!is_stopped(c) && !(flags & LXC_CLONE_ALLOW_RUNNING)) {
+ ERROR("error: Original container (%s) is running. Use --allowrunning if you want to force a snapshot of the running container.", c->name);
goto out;
}
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;
}
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;
}
* 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;
* 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;
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;
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");
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;
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;
}
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;
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;
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;
int ret;
char *tmp;
pid_t pid;
- char chrootpath[MAXPATHLEN];
+ char chrootpath[PATH_MAX];
char *directory_path = NULL;
pid = fork();
}
/* 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);
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;