int ret;
int len;
char *dest;
- const char *rundir;
+ char *rundir;
/* lockfile will be:
* "/run" + "/lock/lxc/$lxcpath/$lxcname + '\0' if root
return NULL;
len += strlen(rundir);
- if ((dest = malloc(len)) == NULL)
+ if ((dest = malloc(len)) == NULL) {
+ free(rundir);
return NULL;
+ }
ret = snprintf(dest, len, "%s/lock/lxc/%s", rundir, p);
if (ret < 0 || ret >= len) {
free(dest);
+ free(rundir);
return NULL;
}
ret = mkdir_p(dest, 0755);
d = realloc(dest, l2);
if (!d) {
free(dest);
+ free(rundir);
return NULL;
}
len = l2;
ret = snprintf(dest, len, "/tmp/%d/lxc/%s", geteuid(), p);
if (ret < 0 || ret >= len) {
free(dest);
+ free(rundir);
return NULL;
}
ret = snprintf(dest, len, "/tmp/%d/lxc/%s/%s", geteuid(), p, n);
} else
ret = snprintf(dest, len, "%s/lock/lxc/%s/%s", rundir, p, n);
+ free(rundir);
+
if (ret < 0 || ret >= len) {
free(dest);
return NULL;
int do_mkdirp)
{
int ret;
- const char *rundir;
+ char *rundir;
rundir = get_rundir();
if (!rundir)
ret = snprintf(fifo_path, fifo_path_sz, "%s/lxc/%s", rundir, lxcpath);
if (ret < 0 || ret >= fifo_path_sz) {
ERROR("rundir/lxcpath (%s/%s) too long for monitor fifo", rundir, lxcpath);
+ free(rundir);
return -1;
}
ret = mkdir_p(fifo_path, 0755);
if (ret < 0) {
ERROR("unable to create monitor fifo dir %s", fifo_path);
+ free(rundir);
return ret;
}
}
ret = snprintf(fifo_path, fifo_path_sz, "%s/lxc/%s/monitor-fifo", rundir, lxcpath);
if (ret < 0 || ret >= fifo_path_sz) {
ERROR("rundir/lxcpath (%s/%s) too long for monitor fifo", rundir, lxcpath);
+ free(rundir);
return -1;
}
+ free(rundir);
return 0;
}
return values[i];
}
-const char *get_rundir()
+char *get_rundir()
{
char *rundir;
const char *homedir;
}
rundir = getenv("XDG_RUNTIME_DIR");
- if (!rundir) {
- INFO("XDG_RUNTIME_DIR isn't set in the environment.");
- homedir = getenv("HOME");
- if (!homedir) {
- ERROR("HOME isn't set in the environment.");
- return NULL;
- }
+ if (rundir) {
+ rundir = strdup(rundir);
+ return rundir;
+ }
- rundir = malloc(sizeof(char) * (17 + strlen(homedir)));
- sprintf(rundir, "%s/.cache/lxc/run/", homedir);
+ INFO("XDG_RUNTIME_DIR isn't set in the environment.");
+ homedir = getenv("HOME");
+ if (!homedir) {
+ ERROR("HOME isn't set in the environment.");
+ return NULL;
}
+ rundir = malloc(sizeof(char) * (17 + strlen(homedir)));
+ sprintf(rundir, "%s/.cache/lxc/run/", homedir);
+
return rundir;
}