#include <net/if.h>
#include "error.h"
+
#include <lxc/lxc.h>
+#include <lxc/log.h>
+
+lxc_log_define(lxc_cgroup, lxc);
#define MTAB "/etc/mtab"
file = setmntent(mtab, "r");
if (!file) {
- lxc_log_syserror("failed to open %s", mtab);
+ SYSERROR("failed to open %s", mtab);
goto out;
}
int ret;
if (get_cgroup_mount(MTAB, cgroup)) {
- lxc_log_info("cgroup is not mounted");
+ INFO("cgroup is not mounted");
return -1;
}
unlink(lxc);
ret = symlink(nsgroup, lxc);
if (ret)
- lxc_log_syserror("failed to create symlink %s->%s",
+ SYSERROR("failed to create symlink %s->%s",
nsgroup, lxc);
return ret;
}
#include "lxc_plugin.h"
#include <lxc.h>
+#include <lxc/log.h>
+
+lxc_log_define(lxc_checkpoint, lxc);
+
#define MAXPIDLEN 20
int lxc_checkpoint(const char *name, const char *statefile,
snprintf(init, MAXPATHLEN, LXCPATH "/%s/init", name);
fd = open(init, O_RDONLY);
if (fd < 0) {
- lxc_log_syserror("failed to open init file for %s", name);
+ SYSERROR("failed to open init file for %s", name);
goto out_close;
}
if (read(fd, val, sizeof(val)) < 0) {
- lxc_log_syserror("failed to read %s", init);
+ SYSERROR("failed to read %s", init);
goto out_close;
}
pid = atoi(val);
if (lxc_plugin_checkpoint(pid, statefile, flags) < 0) {
- lxc_log_syserror("failed to checkpoint %zd", pid);
+ SYSERROR("failed to checkpoint %zd", pid);
goto out_close;
}
#include "parse.h"
#include <lxc/lxc.h>
+#include <lxc/log.h>
+
+lxc_log_define(lxc_conf, lxc);
#define MAXHWLEN 18
#define MAXINDEXLEN 20
int err = -1;
if (!inet_ntop(AF_INET, &in->addr, addr, sizeof(addr))) {
- lxc_log_syserror("failed to convert ipv4 address");
+ SYSERROR("failed to convert ipv4 address");
goto err;
}
if (!inet_ntop(AF_INET, &in->bcast, bcast, sizeof(bcast))) {
- lxc_log_syserror("failed to convert ipv4 broadcast");
+ SYSERROR("failed to convert ipv4 broadcast");
goto err;
}
snprintf(line, MAXLINELEN, "%s %s\n", addr, bcast);
if (write(fd, line, strlen(line)) < 0) {
- lxc_log_syserror("failed to write address info");
+ SYSERROR("failed to write address info");
goto err;
}
int err = -1;
if (!inet_ntop(AF_INET6, &in6->addr, addr, sizeof(addr))) {
- lxc_log_syserror("failed to convert ipv4 address");
+ SYSERROR("failed to convert ipv4 address");
goto err;
}
snprintf(line, MAXLINELEN, "%s/%d\n", addr, in6->prefix?in6->prefix:64);
if (write(fd, line, strlen(line)) < 0) {
- lxc_log_syserror("failed to write address info");
+ SYSERROR("failed to write address info");
goto err;
}
int fd, err = -1;
if (mkdir(path, 0755)) {
- lxc_log_syserror("failed to create directory %s", path);
+ SYSERROR("failed to create directory %s", path);
return -1;
}
snprintf(file, MAXPATHLEN, "%s/addresses", path);
fd = creat(file, 0755);
if (fd < 0) {
- lxc_log_syserror("failed to create %s file", file);
+ SYSERROR("failed to create %s file", file);
goto err;
}
char dir[MAXPATHLEN];
if (mkdir(path, 0755)) {
- lxc_log_syserror("failed to create %s directory", path);
+ SYSERROR("failed to create %s directory", path);
return -1;
}
snprintf(path, MAXPATHLEN, LXCPATH "/%s", name);
if (write_info(path, "utsname", utsname->nodename)) {
- lxc_log_error("failed to write the utsname info");
+ ERROR("failed to write the utsname info");
return -1;
}
snprintf(networkpath, MAXPATHLEN, LXCPATH "/%s/network", name);
if (mkdir(networkpath, 0755)) {
- lxc_log_syserror("failed to create %s directory", networkpath);
+ SYSERROR("failed to create %s directory", networkpath);
goto out;
}
n = iterator->elem;
if (n->type < 0 || n->type > MAXCONFTYPE) {
- lxc_log_error("invalid network configuration type '%d'",
+ ERROR("invalid network configuration type '%d'",
n->type);
goto out;
}
netdev_conf[n->type].count++);
if (configure_netdev(path, lxc_list_first_elem(&n->netdev))) {
- lxc_log_error("failed to configure network type %s",
+ ERROR("failed to configure network type %s",
netdev_conf[n->type].type);
goto out;
}
file = fopen(path, "w+");
if (!file) {
- lxc_log_syserror("failed to open '%s'", path);
+ SYSERROR("failed to open '%s'", path);
return -1;
}
int ret;
if (asprintf(&nbtty, "%d", tty) < 0) {
- lxc_log_error("failed to convert tty number");
+ ERROR("failed to convert tty number");
return -1;
}
ret = write_info(path, "tty", nbtty);
if (ret)
- lxc_log_error("failed to write the tty info");
+ ERROR("failed to write the tty info");
free(nbtty);
cbarg.testdir = tempnam("/tmp", "lxc-");
if (!cbarg.testdir) {
- lxc_log_syserror("failed to build a temp name");
+ SYSERROR("failed to build a temp name");
return -1;
}
if (mkdir(cbarg.testdir, 0755)) {
- lxc_log_syserror("failed to create temporary directory");
+ SYSERROR("failed to create temporary directory");
return -1;
}
buffer, sizeof(buffer), &cbarg);
if (found < 0) {
- lxc_log_syserror("failed to read '%s'", fsfile[i]);
+ SYSERROR("failed to read '%s'", fsfile[i]);
goto out;
}
}
if (!found) {
- lxc_log_error("failed to determine fs type for '%s'", rootfs);
+ ERROR("failed to determine fs type for '%s'", rootfs);
goto out;
}
char fstype[MAXPATHLEN];
if (configure_find_fstype(absrootfs, fstype, 0)) {
- lxc_log_error("failed to configure mount for block device '%s'",
+ ERROR("failed to configure mount for block device '%s'",
absrootfs);
return -1;
}
};
if (!realpath(rootfs, absrootfs)) {
- lxc_log_syserror("failed to get real path for '%s'", rootfs);
+ SYSERROR("failed to get real path for '%s'", rootfs);
return -1;
}
snprintf(path, MAXPATHLEN, LXCPATH "/%s/rootfs", name);
if (mkdir(path, 0755)) {
- lxc_log_syserror("failed to create the '%s' directory", path);
+ SYSERROR("failed to create the '%s' directory", path);
return -1;
}
if (access(absrootfs, F_OK)) {
- lxc_log_syserror("'%s' is not accessible", absrootfs);
+ SYSERROR("'%s' is not accessible", absrootfs);
return -1;
}
if (stat(absrootfs, &s)) {
- lxc_log_syserror("failed to stat '%s'", absrootfs);
+ SYSERROR("failed to stat '%s'", absrootfs);
return -1;
}
f = fopen(fstab, "a+");
if (!f) {
- lxc_log_syserror("failed to open fstab file");
+ SYSERROR("failed to open fstab file");
return -1;
}
fclose(f);
if (ret < 0) {
- lxc_log_error("failed to add rootfs mount in fstab");
+ ERROR("failed to add rootfs mount in fstab");
return -1;
}
return symlink(absrootfs, path);
}
- lxc_log_error("unsupported rootfs type for '%s'", absrootfs);
+ ERROR("unsupported rootfs type for '%s'", absrootfs);
return -1;
}
int ret;
if (asprintf(&maxpts, "%d", pts) < 0) {
- lxc_log_error("failed to convert max pts number");
+ ERROR("failed to convert max pts number");
return -1;
}
ret = write_info(path, "pts", maxpts);
if (ret)
- lxc_log_error("failed to write the pts info");
+ ERROR("failed to write the pts info");
free(maxpts);
outfd = open(path, O_RDWR|O_CREAT|O_EXCL, 0640);
if (outfd < 0) {
- lxc_log_syserror("failed to creat '%s'", path);
+ SYSERROR("failed to creat '%s'", path);
goto out;
}
infd = open(fstab, O_RDONLY);
if (infd < 0) {
- lxc_log_syserror("failed to open '%s'", fstab);
+ SYSERROR("failed to open '%s'", fstab);
goto out_open;
}
if (fstat(infd, &stat)) {
- lxc_log_syserror("failed to stat '%s'", fstab);
+ SYSERROR("failed to stat '%s'", fstab);
goto out_open2;
}
if (lseek(outfd, stat.st_size - 1, SEEK_SET) < 0) {
- lxc_log_syserror("failed to seek dest file '%s'", path);
+ SYSERROR("failed to seek dest file '%s'", path);
goto out_open2;
}
/* fixup length */
if (write(outfd, &c, 1) < 0) {
- lxc_log_syserror("failed to write to '%s'", path);
+ SYSERROR("failed to write to '%s'", path);
goto out_open2;
}
src = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, infd, 0L);
if (src == MAP_FAILED) {
- lxc_log_syserror("failed to mmap '%s'", fstab);
+ SYSERROR("failed to mmap '%s'", fstab);
goto out_open2;
}
dst = mmap(NULL, stat.st_size, PROT_WRITE, MAP_SHARED, outfd, 0L);
if (dst == MAP_FAILED) {
- lxc_log_syserror("failed to mmap '%s'", path);
+ SYSERROR("failed to mmap '%s'", path);
goto out_mmap;
}
snprintf(filename, MAXPATHLEN, LXCPATH "/%s/cgroup", name);
if (stat(filename, &s)) {
- lxc_log_syserror("failed to stat '%s'", filename);
+ SYSERROR("failed to stat '%s'", filename);
return -1;
}
ret = read_info(path, "utsname", utsname.nodename,
sizeof(utsname.nodename));
if (ret < 0) {
- lxc_log_syserror("failed to read utsname info");
+ SYSERROR("failed to read utsname info");
return -1;
}
if (!ret && sethostname(utsname.nodename, strlen(utsname.nodename))) {
- lxc_log_syserror("failed to set the hostname to '%s'",
+ SYSERROR("failed to set the hostname to '%s'",
utsname.nodename);
return -1;
}
* with EACCES errno and I don't know why :( */
if (mount(pty_info->name, path, "none", MS_BIND, 0)) {
- lxc_log_warning("failed to mount '%s'->'%s'",
+ WARN("failed to mount '%s'->'%s'",
pty_info->name, path);
continue;
}
snprintf(path, MAXPATHLEN, LXCPATH "/%s/rootfs", name);
if (chroot(path)) {
- lxc_log_syserror("failed to set chroot %s", path);
+ SYSERROR("failed to set chroot %s", path);
return -1;
}
if (chdir(getenv("HOME")) && chdir("/")) {
- lxc_log_syserror("failed to change to home directory");
+ SYSERROR("failed to change to home directory");
return -1;
}
char mountname[MAXPATHLEN];
if (!access("/dev/pts/ptmx", F_OK) && umount("/dev/pts")) {
- lxc_log_syserror("failed to umount 'dev/pts'");
+ SYSERROR("failed to umount 'dev/pts'");
return -1;
}
snprintf(mountname, MAXPATHLEN, "%spts", name);
if (mount(mountname, "/dev/pts", "devpts", MS_MGC_VAL, "newinstance")) {
- lxc_log_syserror("failed to mount a new instance of '/dev/pts'");
+ SYSERROR("failed to mount a new instance of '/dev/pts'");
return -1;
}
if (chmod("/dev/pts/ptmx", 0666)) {
- lxc_log_syserror("failed to set permission for '/dev/pts/ptmx'");
+ SYSERROR("failed to set permission for '/dev/pts/ptmx'");
return -1;
}
if (access("/dev/ptmx", F_OK)) {
if (!symlink("/dev/pts/ptmx", "/dev/ptmx"))
goto out;
- lxc_log_syserror("failed to symlink '/dev/pts/ptmx'->'/dev/ptmx'");
+ SYSERROR("failed to symlink '/dev/pts/ptmx'->'/dev/ptmx'");
return -1;
}
/* fallback here, /dev/pts/ptmx exists just mount bind */
if (mount("/dev/pts/ptmx", "/dev/ptmx", "none", MS_BIND, 0)) {
- lxc_log_syserror("mount failed '/dev/pts/ptmx'->'/dev/ptmx'");
+ SYSERROR("mount failed '/dev/pts/ptmx'->'/dev/ptmx'");
return -1;
}
out:
return 0;
if (mount(tty, console, "none", MS_BIND, 0)) {
- lxc_log_error("failed to mount the console");
+ ERROR("failed to mount the console");
return -1;
}
ret = lxc_cgroup_set(name, key, value);
if (ret)
- lxc_log_syserror("failed to set cgroup '%s' = '%s' for '%s'",
+ SYSERROR("failed to set cgroup '%s' = '%s' for '%s'",
key, value, name);
return ret;
}
char line[MAXPATHLEN];
if (read_info(directory, file, line, MAXPATHLEN)) {
- lxc_log_error("failed to read %s", file);
+ ERROR("failed to read %s", file);
return -1;
}
snprintf(filename, MAXPATHLEN, LXCPATH "/%s/cgroup", name);
if (stat(filename, &s)) {
- lxc_log_syserror("failed to stat '%s'", filename);
+ SYSERROR("failed to stat '%s'", filename);
return -1;
}
if (S_ISDIR(s.st_mode)) {
if (setup_convert_cgroup(name, filename)) {
- lxc_log_error("failed to convert old cgroup configuration");
+ ERROR("failed to convert old cgroup configuration");
return -1;
}
}
s = strdup(mntent->mnt_opts);
if (!s) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
return -1;
}
data = malloc(strlen(s) + 1);
if (!data) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
free(s);
return -1;
}
if (!file) {
if (errno == ENOENT)
return 0;
- lxc_log_syserror("failed to open '%s'", path);
+ SYSERROR("failed to open '%s'", path);
goto out;
}
mntflags = 0;
mntdata = NULL;
if (parse_mntopts(mntent, &mntflags, &mntdata) < 0) {
- lxc_log_error("failed to parse mount option '%s'",
+ ERROR("failed to parse mount option '%s'",
mntent->mnt_opts);
goto out;
}
if (mount(mntent->mnt_fsname, mntent->mnt_dir,
mntent->mnt_type, mntflags, mntdata)) {
- lxc_log_syserror("failed to mount '%s' on '%s'",
+ SYSERROR("failed to mount '%s' on '%s'",
mntent->mnt_fsname, mntent->mnt_dir);
goto out;
}
p = atoi(prefix);
if (lxc_ip_addr_add(ifname, addr, p, bcast)) {
- lxc_log_error("failed to set %s to addr %s/%d %s", ifname,
+ ERROR("failed to set %s to addr %s/%d %s", ifname,
addr, p, bcast?bcast:"");
return -1;
}
p = atoi(prefix);
if (lxc_ip6_addr_add(ifname, addr, p, bcast)) {
- lxc_log_error("failed to set %s to addr %s/%d %s", ifname,
+ ERROR("failed to set %s to addr %s/%d %s", ifname,
addr, p, bcast?bcast:"");
return -1;
}
snprintf(path, MAXPATHLEN, "%s/%s", directory, file);
if (read_info(path, "ifindex", strindex, sizeof(strindex))) {
- lxc_log_error("failed to read ifindex info");
+ ERROR("failed to read ifindex info");
return -1;
}
if (!ifindex) {
if (!read_info(path, "up", strindex, sizeof(strindex)))
if (lxc_device_up("lo")) {
- lxc_log_error("failed to set the loopback up");
+ ERROR("failed to set the loopback up");
return -1;
}
return 0;
}
if (!if_indextoname(ifindex, current_ifname)) {
- lxc_log_error("no interface corresponding to index '%d'",
+ ERROR("no interface corresponding to index '%d'",
ifindex);
return -1;
}
if (!read_info(path, "name", newname, sizeof(newname))) {
if (lxc_device_rename(ifname, newname)) {
- lxc_log_error("failed to rename %s->%s",
+ ERROR("failed to rename %s->%s",
ifname, newname);
return -1;
}
if (!read_info(path, "hwaddr", hwaddr, sizeof(hwaddr))) {
if (setup_hw_addr(hwaddr, current_ifname)) {
- lxc_log_error("failed to setup hw address for '%s'",
+ ERROR("failed to setup hw address for '%s'",
current_ifname);
return -1;
}
}
if (setup_ip_addr(path, current_ifname)) {
- lxc_log_error("failed to setup ip addresses for '%s'",
+ ERROR("failed to setup ip addresses for '%s'",
ifname);
return -1;
}
if (setup_ip6_addr(path, current_ifname)) {
- lxc_log_error("failed to setup ipv6 addresses for '%s'",
+ ERROR("failed to setup ipv6 addresses for '%s'",
ifname);
return -1;
}
if (!read_info(path, "up", strindex, sizeof(strindex))) {
if (lxc_device_up(current_ifname)) {
- lxc_log_error("failed to set '%s' up", current_ifname);
+ ERROR("failed to set '%s' up", current_ifname);
return -1;
}
/* the network is up, make the loopback up too */
if (lxc_device_up("lo")) {
- lxc_log_error("failed to set the loopback up");
+ ERROR("failed to set the loopback up");
return -1;
}
}
goto out;
}
- lxc_log_syserror("failed to stat %s info", info);
+ SYSERROR("failed to stat %s info", info);
out:
return ret;
}
return 0;
if (conf->utsname && configure_utsname(name, conf->utsname)) {
- lxc_log_error("failed to configure the utsname");
+ ERROR("failed to configure the utsname");
return -LXC_ERROR_CONF_UTSNAME;
}
if (configure_cgroup(name, &conf->cgroup)) {
- lxc_log_error("failed to configure the control group");
+ ERROR("failed to configure the control group");
return -LXC_ERROR_CONF_CGROUP;
}
if (configure_network(name, &conf->networks)) {
- lxc_log_error("failed to configure the network");
+ ERROR("failed to configure the network");
return -LXC_ERROR_CONF_NETWORK;
}
if (conf->tty && configure_tty(name, conf->tty)) {
- lxc_log_error("failed to configure the tty");
+ ERROR("failed to configure the tty");
return -LXC_ERROR_CONF_TTY;
}
if (conf->fstab && configure_mount(name, conf->fstab)) {
- lxc_log_error("failed to configure the mount points");
+ ERROR("failed to configure the mount points");
return -LXC_ERROR_CONF_MOUNT;
}
if (conf->rootfs && configure_rootfs(name, conf->rootfs)) {
- lxc_log_error("failed to configure the rootfs");
+ ERROR("failed to configure the rootfs");
return -LXC_ERROR_CONF_ROOTFS;
}
if (conf->pts && configure_pts(name, conf->pts)) {
- lxc_log_error("failed to configure a new pts instance");
+ ERROR("failed to configure a new pts instance");
return -LXC_ERROR_CONF_PTS;
}
int lxc_unconfigure(const char *name)
{
if (conf_has_utsname(name) && unconfigure_utsname(name))
- lxc_log_error("failed to cleanup utsname");
+ ERROR("failed to cleanup utsname");
if (conf_has_network(name) && unconfigure_network(name))
- lxc_log_error("failed to cleanup the network");
+ ERROR("failed to cleanup the network");
if (conf_has_cgroup(name) && unconfigure_cgroup(name))
- lxc_log_error("failed to cleanup cgroup");
+ ERROR("failed to cleanup cgroup");
if (conf_has_tty(name) && unconfigure_tty(name))
- lxc_log_error("failed to cleanup tty");
+ ERROR("failed to cleanup tty");
if (conf_has_rootfs(name) && unconfigure_rootfs(name))
- lxc_log_error("failed to cleanup rootfs");
+ ERROR("failed to cleanup rootfs");
if (conf_has_fstab(name) && unconfigure_mount(name))
- lxc_log_error("failed to cleanup mount");
+ ERROR("failed to cleanup mount");
if (conf_has_pts(name) && unconfigure_pts(name))
- lxc_log_error("failed to cleanup pts");
+ ERROR("failed to cleanup pts");
return 0;
}
if (!asprintf(&veth1, "%s_%d", file, pid) ||
!asprintf(&veth2, "%s~%d", file, pid) ||
!asprintf(&path, "%s/%s", directory, file)) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
goto out;
}
if (read_info(path, "link", bridge, IFNAMSIZ)) {
- lxc_log_error("failed to read bridge info");
+ ERROR("failed to read bridge info");
goto out;
}
if (lxc_veth_create(veth1, veth2)) {
- lxc_log_error("failed to create %s-%s/%s", veth1, veth2, bridge);
+ ERROR("failed to create %s-%s/%s", veth1, veth2, bridge);
goto out;
}
if (!read_info(path, "mtu", strmtu, MAXMTULEN)) {
if (sscanf(strmtu, "%u", &mtu) < 1) {
- lxc_log_error("invalid mtu size '%d'", mtu);
+ ERROR("invalid mtu size '%d'", mtu);
goto out_delete;
}
if (lxc_device_set_mtu(veth1, mtu)) {
- lxc_log_error("failed to set mtu for '%s'", veth1);
+ ERROR("failed to set mtu for '%s'", veth1);
goto out_delete;
}
if (lxc_device_set_mtu(veth2, mtu)) {
- lxc_log_error("failed to set mtu for '%s'", veth2);
+ ERROR("failed to set mtu for '%s'", veth2);
goto out_delete;
}
}
if (lxc_bridge_attach(bridge, veth1)) {
- lxc_log_error("failed to attach '%s' to the bridge '%s'",
+ ERROR("failed to attach '%s' to the bridge '%s'",
veth1, bridge);
goto out_delete;
}
ifindex = if_nametoindex(veth2);
if (!ifindex) {
- lxc_log_error("failed to retrieve the index for %s", veth2);
+ ERROR("failed to retrieve the index for %s", veth2);
goto out_delete;
}
if (!asprintf(&strindex, "%d", ifindex)) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
goto out_delete;
}
if (write_info(path, "ifindex", strindex)) {
- lxc_log_error("failed to write interface index to %s", path);
+ ERROR("failed to write interface index to %s", path);
goto out_delete;
}
if (!read_info(path, "up", strindex, sizeof(strindex))) {
if (lxc_device_up(veth1)) {
- lxc_log_error("failed to set %s up", veth1);
+ ERROR("failed to set %s up", veth1);
goto out_delete;
}
}
int ifindex, ret = -1;
if (!asprintf(&peer, "%s~%d", file, pid)) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
return -1;
}
snprintf(path, MAXPATHLEN, "%s/%s", directory, file);
if (read_info(path, "link", link, IFNAMSIZ)) {
- lxc_log_error("failed to read bridge info");
+ ERROR("failed to read bridge info");
goto out;
}
if (lxc_macvlan_create(link, peer)) {
- lxc_log_error("failed to create macvlan interface '%s' on '%s'",
+ ERROR("failed to create macvlan interface '%s' on '%s'",
peer, link);
goto out;
}
ifindex = if_nametoindex(peer);
if (!ifindex) {
- lxc_log_error("failed to retrieve the index for %s", peer);
+ ERROR("failed to retrieve the index for %s", peer);
goto out;
}
if (!asprintf(&strindex, "%d", ifindex)) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
return -1;
}
if (write_info(path, "ifindex", strindex)) {
- lxc_log_error("failed to write interface index to %s", path);
+ ERROR("failed to write interface index to %s", path);
goto out;
}
snprintf(path, MAXPATHLEN, "%s/%s", directory, file);
if (read_info(path, "link", link, IFNAMSIZ)) {
- lxc_log_error("failed to read link info");
+ ERROR("failed to read link info");
goto out;
}
ifindex = if_nametoindex(link);
if (!ifindex) {
- lxc_log_error("failed to retrieve the index for %s", link);
+ ERROR("failed to retrieve the index for %s", link);
goto out;
}
if (!asprintf(&strindex, "%d", ifindex)) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
return -1;
}
if (write_info(path, "ifindex", strindex)) {
- lxc_log_error("failed to write interface index to %s", path);
+ ERROR("failed to write interface index to %s", path);
goto out;
}
snprintf(path, MAXPATHLEN, "%s/%s", directory, file);
if (!asprintf(&strindex, "%d", 0)) {
- lxc_log_error("not enough memory");
+ ERROR("not enough memory");
return -1;
}
if (write_info(path, "ifindex", strindex)) {
- lxc_log_error("failed to write interface index to %s", path);
+ ERROR("failed to write interface index to %s", path);
goto out;
}
snprintf(path, MAXPATHLEN, "%s/%s", directory, file);
if (read_info(path, "ifindex", strindex, MAXINDEXLEN) < 0) {
- lxc_log_error("failed to read index to from %s", path);
+ ERROR("failed to read index to from %s", path);
return -1;
}
return 0;
if (!if_indextoname(ifindex, ifname)) {
- lxc_log_error("interface with index %d does not exist",
+ ERROR("interface with index %d does not exist",
ifindex);
return -1;
}
if (lxc_device_move(ifname, *pid)) {
- lxc_log_error("failed to move %s to %d", ifname, *pid);
+ ERROR("failed to move %s to %d", ifname, *pid);
return -1;
}
int conf_create_network(const char *name, pid_t pid)
{
if (instanciate_netdev(name, pid)) {
- lxc_log_error("failed to instantiate the network devices");
+ ERROR("failed to instantiate the network devices");
return -1;
}
if (move_netdev(name, pid)) {
- lxc_log_error("failed to move the netdev to the container");
+ ERROR("failed to move the netdev to the container");
return -1;
}
snprintf(path, MAXPATHLEN, "%s/%s", directory, file);
if (read_info(path, "ifindex", strindex, MAXINDEXLEN)) {
- lxc_log_error("failed to read ifindex info");
+ ERROR("failed to read ifindex info");
return -1;
}
/* do not delete a physical network device */
if (strncmp("phys", file, strlen("phys")))
if (lxc_device_delete(ifname)) {
- lxc_log_error("failed to remove the netdev %s", ifname);
+ ERROR("failed to remove the netdev %s", ifname);
}
delete_info(path, "ifindex");
snprintf(directory, MAXPATHLEN, LXCPATH "/%s/network", name);
if (lxc_dir_for_each(name, directory, delete_netdev_cb, NULL)) {
- lxc_log_error("failed to remove the network devices");
+ ERROR("failed to remove the network devices");
return -1;
}
#endif
snprintf(path, MAXPATHLEN, LXCPATH "/%s", name);
if (read_info(path, "tty", tty, sizeof(tty)) < 0) {
- lxc_log_syserror("failed to read tty info");
+ SYSERROR("failed to read tty info");
goto out;
}
malloc(sizeof(*tty_info->pty_info)*tty_info->nbtty);
if (!tty_info->pty_info) {
- lxc_log_syserror("failed to allocate pty_info");
+ SYSERROR("failed to allocate pty_info");
goto out;
}
if (openpty(&pty_info->master, &pty_info->slave,
pty_info->name, NULL, NULL)) {
- lxc_log_syserror("failed to create pty #%d", i);
+ SYSERROR("failed to create pty #%d", i);
goto out_free;
}
long flags = make_conf_flagset(name, cons, tty_info);
if (conf_is_set(flags, utsname) && setup_utsname(name)) {
- lxc_log_error("failed to setup the utsname for '%s'", name);
+ ERROR("failed to setup the utsname for '%s'", name);
return -LXC_ERROR_SETUP_UTSNAME;
}
if (conf_is_set(flags, network) && setup_network(name)) {
- lxc_log_error("failed to setup the network for '%s'", name);
+ ERROR("failed to setup the network for '%s'", name);
return -LXC_ERROR_SETUP_NETWORK;
}
if (conf_is_set(flags, cgroup) && setup_cgroup(name)) {
- lxc_log_error("failed to setup the cgroups for '%s'", name);
+ ERROR("failed to setup the cgroups for '%s'", name);
return -LXC_ERROR_SETUP_CGROUP;
}
if (conf_is_set(flags, fstab) && setup_mount(name)) {
- lxc_log_error("failed to setup the mounts for '%s'", name);
+ ERROR("failed to setup the mounts for '%s'", name);
return -LXC_ERROR_SETUP_MOUNT;
}
if (conf_is_set(flags, console) && setup_console(name, cons)) {
- lxc_log_error("failed to setup the console for '%s'", name);
+ ERROR("failed to setup the console for '%s'", name);
return -LXC_ERROR_SETUP_CONSOLE;
}
if (conf_is_set(flags, tty) && setup_tty(name, tty_info)) {
- lxc_log_error("failed to setup the ttys for '%s'", name);
+ ERROR("failed to setup the ttys for '%s'", name);
return -LXC_ERROR_SETUP_TTY;
}
if (conf_is_set(flags, rootfs) && setup_rootfs(name)) {
- lxc_log_error("failed to set rootfs for '%s'", name);
+ ERROR("failed to set rootfs for '%s'", name);
return -LXC_ERROR_SETUP_ROOTFS;
}
if (conf_is_set(flags, pts) && setup_pts(name)) {
- lxc_log_error("failed to setup the new pts instance");
+ ERROR("failed to setup the new pts instance");
return -LXC_ERROR_SETUP_PTS;
}
#include "parse.h"
#include <lxc/lxc.h>
+#include <lxc/log.h>
+
+lxc_log_define(lxc_confile, lxc);
static int config_pts(const char *, char *, struct lxc_conf *);
static int config_tty(const char *, char *, struct lxc_conf *);
network = malloc(sizeof(*network));
if (!network) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
return -1;
}
netdev = malloc(sizeof(*netdev));
if (!netdev) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
return -1;
}
ndlist = malloc(sizeof(*ndlist));
if (!ndlist) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
return -1;
}
list = malloc(sizeof(*list));
if (!list) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
return -1;
}
else if (!strcmp(value, "empty"))
network->type = EMPTY;
else {
- lxc_log_error("invalid network type %s", value);
+ ERROR("invalid network type %s", value);
return -1;
}
return 0;
struct lxc_netdev *netdev;
if (lxc_list_empty(networks)) {
- lxc_log_error("network is not created for '%s' option", value);
+ ERROR("network is not created for '%s' option", value);
return -1;
}
network = lxc_list_first_elem(networks);
if (!network) {
- lxc_log_error("no network defined for '%s' option", value);
+ ERROR("no network defined for '%s' option", value);
return -1;
}
struct lxc_netdev *netdev;
if (lxc_list_empty(networks)) {
- lxc_log_error("network is not created for %s", value);
+ ERROR("network is not created for %s", value);
return -1;
}
network = lxc_list_first_elem(networks);
if (!network) {
- lxc_log_error("no network defined for %s", value);
+ ERROR("no network defined for %s", value);
return -1;
}
if (strlen(value) > IFNAMSIZ) {
- lxc_log_error("invalid interface name: %s", value);
+ ERROR("invalid interface name: %s", value);
return -1;
}
struct lxc_netdev *netdev;
if (lxc_list_empty(networks)) {
- lxc_log_error("network is not created for %s", value);
+ ERROR("network is not created for %s", value);
return -1;
}
network = lxc_list_first_elem(networks);
if (!network) {
- lxc_log_error("no network defined for %s", value);
+ ERROR("no network defined for %s", value);
return -1;
}
if (strlen(value) > IFNAMSIZ) {
- lxc_log_error("invalid interface name: %s", value);
+ ERROR("invalid interface name: %s", value);
return -1;
}
struct lxc_netdev *netdev;
if (lxc_list_empty(networks)) {
- lxc_log_error("network is not created for %s", value);
+ ERROR("network is not created for %s", value);
return -1;
}
network = lxc_list_first_elem(networks);
if (!network) {
- lxc_log_error("no network defined for %s", value);
+ ERROR("no network defined for %s", value);
return -1;
}
struct lxc_netdev *netdev;
if (lxc_list_empty(networks)) {
- lxc_log_error("network is not created for %s", value);
+ ERROR("network is not created for %s", value);
return -1;
}
network = lxc_list_first_elem(networks);
if (!network) {
- lxc_log_error("no network defined for %s", value);
+ ERROR("no network defined for %s", value);
return -1;
}
char *cursor, *slash, *addr = NULL, *bcast = NULL, *prefix = NULL;
if (lxc_list_empty(networks)) {
- lxc_log_error("network is not created for '%s'", value);
+ ERROR("network is not created for '%s'", value);
return -1;
}
network = lxc_list_first_elem(networks);
if (!network) {
- lxc_log_error("no network defined for '%s'", value);
+ ERROR("no network defined for '%s'", value);
return -1;
}
netdev = lxc_list_first_elem(&network->netdev);
if (!netdev) {
- lxc_log_error("no netdev defined for '%s'", value);
+ ERROR("no netdev defined for '%s'", value);
}
inetdev = malloc(sizeof(*inetdev));
if (!inetdev) {
- lxc_log_syserror("failed to allocate ipv4 address");
+ SYSERROR("failed to allocate ipv4 address");
return -1;
}
memset(inetdev, 0, sizeof(*inetdev));
list = malloc(sizeof(*list));
if (!list) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
return -1;
}
}
if (!addr) {
- lxc_log_error("no address specified");
+ ERROR("no address specified");
return -1;
}
if (!inet_pton(AF_INET, addr, &inetdev->addr)) {
- lxc_log_syserror("invalid ipv4 address: %s", value);
+ SYSERROR("invalid ipv4 address: %s", value);
return -1;
}
if (bcast)
if (!inet_pton(AF_INET, bcast, &inetdev->bcast)) {
- lxc_log_syserror("invalid ipv4 address: %s", value);
+ SYSERROR("invalid ipv4 address: %s", value);
return -1;
}
char *netmask;
if (lxc_list_empty(networks)) {
- lxc_log_error("network is not created for %s", value);
+ ERROR("network is not created for %s", value);
return -1;
}
network = lxc_list_first_elem(networks);
if (!network) {
- lxc_log_error("no network defined for %s", value);
+ ERROR("no network defined for %s", value);
return -1;
}
inet6dev = malloc(sizeof(*inet6dev));
if (!inet6dev) {
- lxc_log_syserror("failed to allocate ipv6 address");
+ SYSERROR("failed to allocate ipv6 address");
return -1;
}
memset(inet6dev, 0, sizeof(*inet6dev));
list = malloc(sizeof(*list));
if (!list) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
return -1;
}
}
if (!inet_pton(AF_INET6, value, &inet6dev->addr)) {
- lxc_log_syserror("invalid ipv6 address: %s", value);
+ SYSERROR("invalid ipv6 address: %s", value);
return -1;
}
static int config_mount(const char *key, char *value, struct lxc_conf *lxc_conf)
{
if (strlen(value) >= MAXPATHLEN) {
- lxc_log_error("%s path is too long", value);
+ ERROR("%s path is too long", value);
return -1;
}
lxc_conf->fstab = strdup(value);
if (!lxc_conf->fstab) {
- lxc_log_syserror("failed to duplicate string %s", value);
+ SYSERROR("failed to duplicate string %s", value);
return -1;
}
static int config_rootfs(const char *key, char *value, struct lxc_conf *lxc_conf)
{
if (strlen(value) >= MAXPATHLEN) {
- lxc_log_error("%s path is too long", value);
+ ERROR("%s path is too long", value);
return -1;
}
lxc_conf->rootfs = strdup(value);
if (!lxc_conf->rootfs) {
- lxc_log_syserror("failed to duplicate string %s", value);
+ SYSERROR("failed to duplicate string %s", value);
return -1;
}
utsname = malloc(sizeof(*utsname));
if (!utsname) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
return -1;
}
if (strlen(value) >= sizeof(utsname->nodename)) {
- lxc_log_error("node name '%s' is too long",
+ ERROR("node name '%s' is too long",
utsname->nodename);
return -1;
}
dot = strstr(line, "=");
if (!dot) {
- lxc_log_error("invalid configuration line: %s", line);
+ ERROR("invalid configuration line: %s", line);
return -1;
}
config = getconfig(key);
if (!config) {
- lxc_log_error("unknow key %s", key);
+ ERROR("unknow key %s", key);
return -1;
}
#include "af_unix.h"
#include "error.h"
+#include <lxc/log.h>
+
+lxc_log_define(lxc_console, lxc);
+
extern int lxc_console(const char *name, int ttynum, int *fd)
{
struct sockaddr_un addr = { 0 };
sock = lxc_af_unix_connect(addr.sun_path);
if (sock < 0) {
- lxc_log_error("failed to connect to the tty service");
+ ERROR("failed to connect to the tty service");
goto out_err;
}
ret = lxc_af_unix_send_credential(sock, &ttynum, sizeof(ttynum));
if (ret < 0) {
- lxc_log_syserror("failed to send credentials");
+ SYSERROR("failed to send credentials");
goto out_err;
}
ret = lxc_af_unix_recv_fd(sock, fd, NULL, 0);
if (ret < 0) {
- lxc_log_error("failed to connect to the tty");
+ ERROR("failed to connect to the tty");
goto out_err;
}
if (!ret) {
- lxc_log_error("tty%d denied by '%s'", ttynum, name);
+ ERROR("tty%d denied by '%s'", ttynum, name);
ret = -LXC_ERROR_TTY_DENIED;
goto out_err;
}
#include "error.h"
#include <lxc.h>
+#include <lxc/log.h>
+
+lxc_log_define(lxc_columbia, lxc);
+
+
#if __i386__
# define __NR_checkpoint 333
fd = open(statefile, O_RDWR);
if (fd < 0) {
- lxc_log_syserror("failed to open init file for %s", statefile);
+ SYSERROR("failed to open init file for %s", statefile);
return -1;
}
ret = sys_checkpoint(pid, fd, flags);
if (ret < 0) {
- lxc_log_syserror("failed to checkpoint %d", pid);
+ SYSERROR("failed to checkpoint %d", pid);
goto out_close;
}
fd = open(statefile, O_RDONLY);
if (fd < 0) {
- lxc_log_syserror("failed to open init file for %s", statefile);
+ SYSERROR("failed to open init file for %s", statefile);
return -1;
}
sys_restart(pid, fd, flags);
- lxc_log_syserror("failed to restart %d", pid);
+ SYSERROR("failed to restart %d", pid);
close(fd);
return -1;
}
#include "error.h"
#include <lxc/lxc.h>
+#include <lxc/log.h>
+
+lxc_log_define(lxc_create, lxc);
static int dir_filter(const struct dirent *dirent)
{
n = scandir(dirname, &namelist, dir_filter, alphasort);
if (n < 0)
- lxc_log_syserror("failed to scan %s directory", dirname);
+ SYSERROR("failed to scan %s directory", dirname);
return n == 0;
}
char path[MAXPATHLEN];
if (mkdir(LXCPATH, 0755) && errno != EEXIST) {
- lxc_log_syserror("failed to create %s directory", LXCPATH);
+ SYSERROR("failed to create %s directory", LXCPATH);
return -errno;
}
sprintf(path, LXCPATH "/%s", dirname);
if (mkdir(path, 0755)) {
- lxc_log_syserror("failed to create %s directory", path);
+ SYSERROR("failed to create %s directory", path);
return -errno;
}
sprintf(path, LXCPATH "/%s", dirname);
if (rmdir(path)) {
- lxc_log_syserror("failed to remove %s directory", path);
+ SYSERROR("failed to remove %s directory", path);
return -1;
}
if (is_empty_directory(LXCPATH)) {
if (rmdir(LXCPATH)) {
- lxc_log_syserror("failed to remove %s directory", LXCPATH);
+ SYSERROR("failed to remove %s directory", LXCPATH);
return -1;
}
}
err = LXC_ERROR_INTERNAL;
if (lxc_mkstate(name)) {
- lxc_log_error("failed to create the state file for %s", name);
+ ERROR("failed to create the state file for %s", name);
goto err;
}
if (lxc_setstate(name, STOPPED)) {
- lxc_log_error("failed to set state for %s", name);
+ ERROR("failed to set state for %s", name);
goto err_state;
}
err = lxc_configure(name, conf);
if (err) {
- lxc_log_error("failed to set configuration for %s", name);
+ ERROR("failed to set configuration for %s", name);
goto err_state;
}
lxc_unconfigure(name);
if (lxc_rmstate(name))
- lxc_log_error("failed to remove state file for %s", name);
+ ERROR("failed to remove state file for %s", name);
err:
if (remove_lxc_directory(name))
- lxc_log_error("failed to cleanup lxc directory for %s", name);
+ ERROR("failed to cleanup lxc directory for %s", name);
goto out;
}
#include "error.h"
#include <lxc/lxc.h>
+#include <lxc/log.h>
+
+lxc_log_define(lxc_destroy, lxc);
static int remove_lxc_directory(const char *dirname)
{
sprintf(path, LXCPATH "/%s", dirname);
if (rmdir(path)) {
- lxc_log_syserror("failed to remove %s directory", path);
+ SYSERROR("failed to remove %s directory", path);
return -1;
}
return lock;
if (lxc_rmstate(name)) {
- lxc_log_error("failed to remove state file for %s", name);
+ ERROR("failed to remove state file for %s", name);
goto out_lock;
}
lxc_unlink_nsgroup(name);
if (lxc_unconfigure(name)) {
- lxc_log_error("failed to cleanup %s", name);
+ ERROR("failed to cleanup %s", name);
goto out_lock;
}
if (remove_lxc_directory(name)) {
- lxc_log_syserror("failed to remove '%s'", name);
+ SYSERROR("failed to remove '%s'", name);
goto out_lock;
}
#include "error.h"
#include <lxc/lxc.h>
+#include <lxc/log.h>
+
+lxc_log_define(lxc_freezer, lxc);
static int freeze_unfreeze(const char *name, int freeze)
{
fd = open(freezer, O_WRONLY);
if (fd < 0) {
- lxc_log_syserror("failed to open freezer for '%s'", name);
+ SYSERROR("failed to open freezer for '%s'", name);
return -1;
}
close(fd);
if (ret)
- lxc_log_syserror("failed to write to '%s'", freezer);
+ SYSERROR("failed to write to '%s'", freezer);
return 0;
}
#include "error.h"
#include "lxc.h"
+#include <lxc/log.h>
+
+lxc_log_define(lxc_console, lxc);
void usage(char *cmd)
{
/* Get current termios */
if (tcgetattr(0, &tios)) {
- lxc_log_error("failed to get current terminal settings");
+ ERROR("failed to get current terminal settings");
fprintf(stderr, "%s\n", lxc_strerror(err));
return 1;
}
/* Set new attributes */
if (tcsetattr(0, TCSAFLUSH, &tios)) {
- lxc_log_syserror("failed to set new terminal settings");
+ SYSERROR("failed to set new terminal settings");
fprintf(stderr, "%s\n", lxc_strerror(err));
return 1;
}
if (poll(pfd, 2, -1) < 0) {
if (errno == EINTR)
continue;
- lxc_log_syserror("failed to poll");
+ SYSERROR("failed to poll");
goto out_err;
}
*/
if (pfd[0].revents & POLLIN) {
if (read(0, &c, 1) < 0) {
- lxc_log_syserror("failed to read");
+ SYSERROR("failed to read");
goto out_err;
}
wait4q = 0;
if (write(master, &c, 1) < 0) {
- lxc_log_syserror("failed to write");
+ SYSERROR("failed to write");
goto out_err;
}
}
/* read the master and write to "stdout" */
if (pfd[1].revents & POLLIN) {
if (read(master, &c, 1) < 0) {
- lxc_log_syserror("failed to read");
+ SYSERROR("failed to read");
goto out_err;
}
printf("%c", c);
#include <net/if.h>
#include <lxc/lxc.h>
+#include <lxc/log.h>
+
+lxc_log_define(lxc_start, lxc);
void usage(char *cmd)
{
usage(argv[0]);
if (tcgetattr(0, &tios)) {
- lxc_log_error("failed to get current terminal settings");
+ ERROR("failed to get current terminal settings");
fprintf(stderr, "%s\n", lxc_strerror(err));
return 1;
}
}
if (tcsetattr(0, TCSAFLUSH, &tios))
- lxc_log_syserror("failed to restore terminal attributes");
+ SYSERROR("failed to restore terminal attributes");
return err;
}
#include "error.h"
#include <lxc/lxc.h>
+#include <lxc/log.h>
+
+lxc_log_define(lxc_monitor, lxc);
#ifndef UNIX_PATH_MAX
#define UNIX_PATH_MAX 108
nfd = inotify_init();
if (nfd < 0) {
- lxc_log_syserror("failed to initialize inotify");
+ SYSERROR("failed to initialize inotify");
return -1;
}
wfd = inotify_add_watch(nfd, path, IN_DELETE_SELF|IN_CLOSE_WRITE);
if (wfd < 0) {
- lxc_log_syserror("failed to add a watch on %s", path);
+ SYSERROR("failed to add a watch on %s", path);
goto out;
}
struct inotify_event evt;
if (read(nfd, &evt, sizeof(evt)) < 0) {
- lxc_log_syserror("failed to read inotify event");
+ SYSERROR("failed to read inotify event");
goto out;
}
state = lxc_getstate(name);
if (state < 0) {
- lxc_log_error("failed to get the state for %s",
+ ERROR("failed to get the state for %s",
name);
goto out;
}
if (write(output_fd, &state, sizeof(state)) < 0) {
- lxc_log_syserror("failed to send state to %d",
+ SYSERROR("failed to send state to %d",
output_fd);
goto out;
}
goto out;
}
- lxc_log_error("unknown evt for inotity (%d)", evt.mask);
+ ERROR("unknown evt for inotity (%d)", evt.mask);
goto out;
}
fd = socket(PF_NETLINK, SOCK_RAW, 0);
if (fd < 0) {
- lxc_log_syserror("failed to create notification socket");
+ SYSERROR("failed to create notification socket");
return;
}
fd = socket(PF_NETLINK, SOCK_RAW, 0);
if (fd < 0) {
- lxc_log_syserror("failed to create notification socket");
+ SYSERROR("failed to create notification socket");
return -LXC_ERROR_INTERNAL;
}
addr.nl_groups = MONITOR_MCGROUP;
if (bind(fd, (const struct sockaddr *)&addr, sizeof(addr))) {
- lxc_log_syserror("failed to bind to multicast group '%d'",
+ SYSERROR("failed to bind to multicast group '%d'",
addr.nl_groups);
close(fd);
return -1;
ret = recvfrom(fd, msg, sizeof(*msg), 0,
(struct sockaddr *)&from, &len);
if (ret < 0) {
- lxc_log_syserror("failed to received state");
+ SYSERROR("failed to received state");
return -LXC_ERROR_INTERNAL;
}
#include "parse.h"
#include "log.h"
+#include <lxc/log.h>
+
+lxc_log_define(lxc_parse, lxc);
static int dir_filter(const struct dirent *dirent)
{
n = scandir(directory, &namelist, dir_filter, alphasort);
if (n < 0) {
- lxc_log_syserror("failed to scan %s directory", directory);
+ SYSERROR("failed to scan %s directory", directory);
return -1;
}
while (n--) {
if (callback(name, directory, namelist[n]->d_name, data)) {
- lxc_log_error("callback failed");
+ ERROR("callback failed");
free(namelist[n]);
return -1;
}
f = fopen(file, "r");
if (!f) {
- lxc_log_syserror("failed to open %s", file);
+ SYSERROR("failed to open %s", file);
return -1;
}
#include "error.h"
#include "lxc_plugin.h"
#include <lxc/lxc.h>
+#include <lxc/log.h>
+
+lxc_log_define(lxc_restart, lxc);
LXC_TTY_HANDLER(SIGINT);
LXC_TTY_HANDLER(SIGQUIT);
/* Begin the set the state to STARTING*/
if (lxc_setstate(name, STARTING)) {
- lxc_log_error("failed to set state %s",
+ ERROR("failed to set state %s",
lxc_state2str(STARTING));
goto out;
}
if (ttyname_r(0, tty, sizeof(tty))) {
tty[0] = '\0';
- lxc_log_warning("failed to get tty name");
+ WARN("failed to get tty name");
}
/* Synchro socketpair */
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sv)) {
- lxc_log_syserror("failed to create communication socketpair");
+ SYSERROR("failed to create communication socketpair");
goto out;
}
/* Create a process in a new set of namespaces */
pid = fork_ns(clone_flags);
if (pid < 0) {
- lxc_log_syserror("failed to fork into a new namespace");
+ SYSERROR("failed to fork into a new namespace");
goto err_fork_ns;
}
/* Tell our father he can begin to configure the container */
if (write(sv[0], &sync, sizeof(sync)) < 0) {
- lxc_log_syserror("failed to write socket");
+ SYSERROR("failed to write socket");
return 1;
}
/* Wait for the father to finish the configuration */
if (read(sv[0], &sync, sizeof(sync)) < 0) {
- lxc_log_syserror("failed to read socket");
+ SYSERROR("failed to read socket");
return 1;
}
/* Setup the container, ip, names, utsname, ... */
if (lxc_setup(name, tty, &tty_info)) {
- lxc_log_error("failed to setup the container");
+ ERROR("failed to setup the container");
if (write(sv[0], &sync, sizeof(sync)) < 0)
- lxc_log_syserror("failed to write the socket");
+ SYSERROR("failed to write the socket");
return -1;
}
lxc_plugin_restart(getpid(), statefile, flags);
- lxc_log_syserror("failed to restart");
+ SYSERROR("failed to restart");
/* If the exec fails, tell that to our father */
if (write(sv[0], &sync, sizeof(sync)) < 0)
- lxc_log_syserror("failed to write the socket");
+ SYSERROR("failed to write the socket");
exit(1);
}
/* Wait for the child to be ready */
if (read(sv[1], &sync, sizeof(sync)) < 0) {
- lxc_log_syserror("failed to read the socket");
+ SYSERROR("failed to read the socket");
goto err_pipe_read;
}
/* Create the network configuration */
if (clone_flags & CLONE_NEWNET && conf_create_network(name, pid)) {
- lxc_log_error("failed to create the configured network");
+ ERROR("failed to create the configured network");
goto err_create_network;
}
/* Tell the child to continue its initialization */
if (write(sv[1], &sync, sizeof(sync)) < 0) {
- lxc_log_syserror("failed to write the socket");
+ SYSERROR("failed to write the socket");
goto err_pipe_write;
}
/* Wait for the child to exec or returning an error */
err = read(sv[1], &sync, sizeof(sync));
if (err < 0) {
- lxc_log_error("failed to read the socket");
+ ERROR("failed to read the socket");
goto err_pipe_read2;
}
if (err > 0) {
- lxc_log_error("something went wrong with %d", pid);
+ ERROR("something went wrong with %d", pid);
/* TODO : check status etc ... */
waitpid(pid, NULL, 0);
goto err_child_failed;
}
if (!asprintf(&val, "%d\n", pid)) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
goto err_child_failed;
}
if (!asprintf(&init, LXCPATH "/%s/init", name)) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
goto err_child_failed;
}
fd = open(init, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
if (fd < 0) {
- lxc_log_syserror("failed to open '%s'", init);
+ SYSERROR("failed to open '%s'", init);
goto err_write;
}
if (write(fd, val, strlen(val)) < 0) {
- lxc_log_syserror("failed to write the init pid");
+ SYSERROR("failed to write the init pid");
goto err_write;
}
close(fd);
if (lxc_link_nsgroup(name, pid))
- lxc_log_warning("cgroupfs not found: cgroup disabled");
+ WARN("cgroupfs not found: cgroup disabled");
if (lxc_setstate(name, RUNNING)) {
- lxc_log_error("failed to set state to %s",
+ ERROR("failed to set state to %s",
lxc_state2str(RUNNING));
goto err_state_failed;
}
if (waitpid(pid, NULL, 0) < 0) {
if (errno == EINTR)
goto wait_again;
- lxc_log_syserror("failed to wait the pid %d", pid);
+ SYSERROR("failed to wait the pid %d", pid);
goto err_waitpid_failed;
}
if (lxc_setstate(name, STOPPING))
- lxc_log_error("failed to set state %s", lxc_state2str(STOPPING));
+ ERROR("failed to set state %s", lxc_state2str(STOPPING));
if (clone_flags & CLONE_NEWNET && conf_destroy_network(name))
- lxc_log_error("failed to destroy the network");
+ ERROR("failed to destroy the network");
err = 0;
out:
if (lxc_setstate(name, STOPPED))
- lxc_log_error("failed to set state %s", lxc_state2str(STOPPED));
+ ERROR("failed to set state %s", lxc_state2str(STOPPED));
lxc_unlink_nsgroup(name);
unlink(init);
err_pipe_read:
err_waitpid_failed:
if (lxc_setstate(name, ABORTING))
- lxc_log_error("failed to set state %s", lxc_state2str(STOPPED));
+ ERROR("failed to set state %s", lxc_state2str(STOPPED));
kill(pid, SIGKILL);
err_fork_ns:
#include "mainloop.h"
#include <lxc/lxc.h>
+#include <lxc/log.h>
+
+lxc_log_define(lxc_start, lxc);
+
LXC_TTY_HANDLER(SIGINT);
LXC_TTY_HANDLER(SIGQUIT);
int fd;
if (sigprocmask(SIG_BLOCK, NULL, &mask)) {
- lxc_log_syserror("failed to get mask signal");
+ SYSERROR("failed to get mask signal");
return -1;
}
if (sigaddset(&mask, SIGCHLD) || sigprocmask(SIG_BLOCK, &mask, oldmask)) {
- lxc_log_syserror("failed to set mask signal");
+ SYSERROR("failed to set mask signal");
return -1;
}
fd = signalfd(-1, &mask, 0);
if (fd < 0) {
- lxc_log_syserror("failed to create the signal fd");
+ SYSERROR("failed to create the signal fd");
return -1;
}
if (fcntl(fd, F_SETFD, FD_CLOEXEC)) {
- lxc_log_syserror("failed to set sigfd to close-on-exec");
+ SYSERROR("failed to set sigfd to close-on-exec");
close(fd);
return -1;
}
return -1;
if (fcntl(fd, F_SETFD, FD_CLOEXEC)) {
- lxc_log_syserror("failed to close-on-exec flag");
+ SYSERROR("failed to close-on-exec flag");
close(fd);
return -1;
}
conn = accept(fd, NULL, 0);
if (conn < 0) {
- lxc_log_syserror("failed to accept tty client");
+ SYSERROR("failed to accept tty client");
return -1;
}
if (setsockopt(conn, SOL_SOCKET, SO_PASSCRED, &val, sizeof(val))) {
- lxc_log_syserror("failed to enable credential on socket");
+ SYSERROR("failed to enable credential on socket");
goto out_close;
}
if (lxc_af_unix_send_fd(conn, tty_info->pty_info[ttynum].master,
NULL, 0) < 0) {
- lxc_log_error("failed to send tty to client");
+ ERROR("failed to send tty to client");
goto out_close;
}
if (lxc_mainloop_add_handler(descr, conn,
ttyclient_handler, tty_info)) {
- lxc_log_error("failed to add tty client handler");
+ ERROR("failed to add tty client handler");
goto out_close;
}
struct lxc_epoll_descr descr;
if (tty_info->nbtty && setup_tty_service(name, &ttyfd)) {
- lxc_log_error("failed to create the tty service point");
+ ERROR("failed to create the tty service point");
goto out_sigfd;
}
nfds = tty_info->nbtty + 1 + tty_info->nbtty ? 1 : 0;
if (lxc_mainloop_open(nfds, &descr)) {
- lxc_log_error("failed to create mainloop");
+ ERROR("failed to create mainloop");
goto out_ttyfd;
}
if (lxc_mainloop_add_handler(&descr, sigfd, sigchld_handler, &pid)) {
- lxc_log_error("failed to add handler for the signal");
+ ERROR("failed to add handler for the signal");
goto out_mainloop_open;
}
if (lxc_mainloop_add_handler(&descr, ttyfd,
ttyservice_handler,
(void *)tty_info)) {
- lxc_log_error("failed to add handler for the tty");
+ ERROR("failed to add handler for the tty");
goto out_mainloop_open;
}
}
/* Begin the set the state to STARTING*/
if (lxc_setstate(name, STARTING)) {
- lxc_log_error("failed to set state '%s'",
+ ERROR("failed to set state '%s'",
lxc_state2str(STARTING));
goto out;
}
tty[0] = '\0';
if (lxc_create_tty(name, &tty_info)) {
- lxc_log_error("failed to create the ttys");
+ ERROR("failed to create the ttys");
goto out;
}
* the event will be lost and the command will be stuck */
sigfd = setup_sigchld_fd(&oldmask);
if (sigfd < 0) {
- lxc_log_error("failed to set sigchild fd handler");
+ ERROR("failed to set sigchild fd handler");
return -1;
}
/* Synchro socketpair */
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sv)) {
- lxc_log_syserror("failed to create communication socketpair");
+ SYSERROR("failed to create communication socketpair");
goto out;
}
/* Create a process in a new set of namespaces */
pid = fork_ns(clone_flags);
if (pid < 0) {
- lxc_log_syserror("failed to fork into a new namespace");
+ SYSERROR("failed to fork into a new namespace");
goto err_fork_ns;
}
if (!pid) {
if (sigprocmask(SIG_SETMASK, &oldmask, NULL)) {
- lxc_log_syserror("failed to set sigprocmask");
+ SYSERROR("failed to set sigprocmask");
return -1;
}
/* Tell our father he can begin to configure the container */
if (write(sv[0], &sync, sizeof(sync)) < 0) {
- lxc_log_syserror("failed to write socket");
+ SYSERROR("failed to write socket");
goto out_child;
}
/* Wait for the father to finish the configuration */
if (read(sv[0], &sync, sizeof(sync)) < 0) {
- lxc_log_syserror("failed to read socket");
+ SYSERROR("failed to read socket");
goto out_child;
}
/* Setup the container, ip, names, utsname, ... */
err = lxc_setup(name, tty, &tty_info);
if (err) {
- lxc_log_error("failed to setup the container");
+ ERROR("failed to setup the container");
if (write(sv[0], &err, sizeof(err)) < 0)
- lxc_log_syserror("failed to write the socket");
+ SYSERROR("failed to write the socket");
goto out_child;
}
if (prctl(PR_CAPBSET_DROP, CAP_SYS_BOOT, 0, 0, 0)) {
- lxc_log_syserror("failed to remove CAP_SYS_BOOT capability");
+ SYSERROR("failed to remove CAP_SYS_BOOT capability");
goto out_child;
}
execvp(argv[0], argv);
- lxc_log_syserror("failed to exec %s", argv[0]);
+ SYSERROR("failed to exec %s", argv[0]);
err = LXC_ERROR_WRONG_COMMAND;
/* If the exec fails, tell that to our father */
if (write(sv[0], &err, sizeof(err)) < 0)
- lxc_log_syserror("failed to write the socket");
+ SYSERROR("failed to write the socket");
out_child:
exit(err);
/* Wait for the child to be ready */
if (read(sv[1], &sync, sizeof(sync)) < 0) {
- lxc_log_syserror("failed to read the socket");
+ SYSERROR("failed to read the socket");
goto err_pipe_read;
}
if (lxc_link_nsgroup(name, pid))
- lxc_log_warning("cgroupfs not found: cgroup disabled");
+ WARN("cgroupfs not found: cgroup disabled");
/* Create the network configuration */
if (clone_flags & CLONE_NEWNET && conf_create_network(name, pid)) {
- lxc_log_error("failed to create the configured network");
+ ERROR("failed to create the configured network");
goto err_create_network;
}
/* Tell the child to continue its initialization */
if (write(sv[1], &sync, sizeof(sync)) < 0) {
- lxc_log_syserror("failed to write the socket");
+ SYSERROR("failed to write the socket");
goto err_pipe_write;
}
/* Wait for the child to exec or returning an error */
err = read(sv[1], &sync, sizeof(sync));
if (err < 0) {
- lxc_log_error("failed to read the socket");
+ ERROR("failed to read the socket");
goto err_pipe_read2;
}
}
if (!asprintf(&val, "%d\n", pid)) {
- lxc_log_syserror("failed to allocate memory");
+ SYSERROR("failed to allocate memory");
goto err_child_failed;
}
fd = open(init, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
if (fd < 0) {
- lxc_log_syserror("failed to open '%s'", init);
+ SYSERROR("failed to open '%s'", init);
goto err_write;
}
if (write(fd, val, strlen(val)) < 0) {
- lxc_log_syserror("failed to write the init pid");
+ SYSERROR("failed to write the init pid");
goto err_write;
}
close(fd);
if (lxc_setstate(name, RUNNING)) {
- lxc_log_error("failed to set state to %s",
+ ERROR("failed to set state to %s",
lxc_state2str(RUNNING));
goto err_state_failed;
}
if (mainloop(name, pid, sigfd, &tty_info)) {
- lxc_log_error("mainloop exited with an error");
+ ERROR("mainloop exited with an error");
goto err_mailoop_failed;
}
if (lxc_setstate(name, STOPPING))
- lxc_log_error("failed to set state %s", lxc_state2str(STOPPING));
+ ERROR("failed to set state %s", lxc_state2str(STOPPING));
if (clone_flags & CLONE_NEWNET && conf_destroy_network(name))
- lxc_log_error("failed to destroy the network");
+ ERROR("failed to destroy the network");
err = 0;
out:
if (lxc_setstate(name, STOPPED))
- lxc_log_error("failed to set state %s", lxc_state2str(STOPPED));
+ ERROR("failed to set state %s", lxc_state2str(STOPPED));
lxc_delete_tty(&tty_info);
lxc_unlink_nsgroup(name);
err_pipe_read:
err_mailoop_failed:
if (lxc_setstate(name, ABORTING))
- lxc_log_error("failed to set state %s", lxc_state2str(STOPPED));
+ ERROR("failed to set state %s", lxc_state2str(STOPPED));
kill(pid, SIGKILL);
err_fork_ns:
#include <sys/file.h>
#include <lxc/lxc.h>
+#include <lxc/log.h>
+
+lxc_log_define(lxc_state, lxc);
static char *strstate[] = {
"STOPPED", "STARTING", "RUNNING", "STOPPING",
fd = open(file, O_WRONLY);
if (fd < 0) {
- lxc_log_syserror("failed to open %s file", file);
+ SYSERROR("failed to open %s file", file);
return -1;
}
if (flock(fd, LOCK_EX)) {
- lxc_log_syserror("failed to take the lock to %s", file);
+ SYSERROR("failed to take the lock to %s", file);
goto out;
}
if (ftruncate(fd, 0)) {
- lxc_log_syserror("failed to truncate the file %s", file);
+ SYSERROR("failed to truncate the file %s", file);
goto out;
}
if (write(fd, str, strlen(str)) < 0) {
- lxc_log_syserror("failed to write state to %s", file);
+ SYSERROR("failed to write state to %s", file);
goto out;
}
snprintf(file, MAXPATHLEN, LXCPATH "/%s/state", name);
fd = creat(file, S_IRUSR|S_IWUSR);
if (fd < 0) {
- lxc_log_syserror("failed to create file %s", file);
+ SYSERROR("failed to create file %s", file);
return -1;
}
close(fd);
fd = open(file, O_RDONLY);
if (fd < 0) {
- lxc_log_syserror("failed to open %s", file);
+ SYSERROR("failed to open %s", file);
return -1;
}
if (flock(fd, LOCK_SH)) {
- lxc_log_syserror("failed to take the lock to %s", file);
+ SYSERROR("failed to take the lock to %s", file);
close(fd);
return -1;
}
err = read(fd, file, strlen(file));
if (err < 0) {
- lxc_log_syserror("failed to read file %s", file);
+ SYSERROR("failed to read file %s", file);
close(fd);
return -1;
}
fclose(file);
if (err == EOF) {
- lxc_log_syserror("failed to read %s", freezer);
+ SYSERROR("failed to read %s", freezer);
return -1;
}
#include <fcntl.h>
#include <lxc/lxc.h>
+#include <lxc/log.h>
+
+lxc_log_define(lxc_stop, lxc);
#define MAXPIDLEN 20
snprintf(init, MAXPATHLEN, LXCPATH "/%s/init", name);
fd = open(init, O_RDONLY);
if (fd < 0) {
- lxc_log_syserror("failed to open init file for %s", name);
+ SYSERROR("failed to open init file for %s", name);
goto out_close;
}
if (read(fd, val, sizeof(val)) < 0) {
- lxc_log_syserror("failed to read %s", init);
+ SYSERROR("failed to read %s", init);
goto out_close;
}
pid = atoi(val);
if (kill(pid, SIGKILL)) {
- lxc_log_syserror("failed to kill %zd", pid);
+ SYSERROR("failed to kill %zd", pid);
goto out_close;
}