Commit 36eb9bde by Cedric Le Goater Committed by Daniel Lezcano

lxc: use new logging system

This patch defines a new log category in each file using logging and replaced the former logging routines with the new ones. Signed-off-by: 's avatarCedric Le Goater <legoater@free.fr> Acked-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com> Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com>
parent cb8c5720
...@@ -37,7 +37,11 @@ ...@@ -37,7 +37,11 @@
#include <net/if.h> #include <net/if.h>
#include "error.h" #include "error.h"
#include <lxc/lxc.h> #include <lxc/lxc.h>
#include <lxc/log.h>
lxc_log_define(lxc_cgroup, lxc);
#define MTAB "/etc/mtab" #define MTAB "/etc/mtab"
...@@ -49,7 +53,7 @@ static int get_cgroup_mount(const char *mtab, char *mnt) ...@@ -49,7 +53,7 @@ static int get_cgroup_mount(const char *mtab, char *mnt)
file = setmntent(mtab, "r"); file = setmntent(mtab, "r");
if (!file) { if (!file) {
lxc_log_syserror("failed to open %s", mtab); SYSERROR("failed to open %s", mtab);
goto out; goto out;
} }
...@@ -74,7 +78,7 @@ int lxc_link_nsgroup(const char *name, pid_t pid) ...@@ -74,7 +78,7 @@ int lxc_link_nsgroup(const char *name, pid_t pid)
int ret; int ret;
if (get_cgroup_mount(MTAB, cgroup)) { if (get_cgroup_mount(MTAB, cgroup)) {
lxc_log_info("cgroup is not mounted"); INFO("cgroup is not mounted");
return -1; return -1;
} }
...@@ -84,7 +88,7 @@ int lxc_link_nsgroup(const char *name, pid_t pid) ...@@ -84,7 +88,7 @@ int lxc_link_nsgroup(const char *name, pid_t pid)
unlink(lxc); unlink(lxc);
ret = symlink(nsgroup, lxc); ret = symlink(nsgroup, lxc);
if (ret) if (ret)
lxc_log_syserror("failed to create symlink %s->%s", SYSERROR("failed to create symlink %s->%s",
nsgroup, lxc); nsgroup, lxc);
return ret; return ret;
} }
......
...@@ -40,6 +40,10 @@ ...@@ -40,6 +40,10 @@
#include "lxc_plugin.h" #include "lxc_plugin.h"
#include <lxc.h> #include <lxc.h>
#include <lxc/log.h>
lxc_log_define(lxc_checkpoint, lxc);
#define MAXPIDLEN 20 #define MAXPIDLEN 20
int lxc_checkpoint(const char *name, const char *statefile, int lxc_checkpoint(const char *name, const char *statefile,
...@@ -62,19 +66,19 @@ int lxc_checkpoint(const char *name, const char *statefile, ...@@ -62,19 +66,19 @@ int lxc_checkpoint(const char *name, const char *statefile,
snprintf(init, MAXPATHLEN, LXCPATH "/%s/init", name); snprintf(init, MAXPATHLEN, LXCPATH "/%s/init", name);
fd = open(init, O_RDONLY); fd = open(init, O_RDONLY);
if (fd < 0) { 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; goto out_close;
} }
if (read(fd, val, sizeof(val)) < 0) { if (read(fd, val, sizeof(val)) < 0) {
lxc_log_syserror("failed to read %s", init); SYSERROR("failed to read %s", init);
goto out_close; goto out_close;
} }
pid = atoi(val); pid = atoi(val);
if (lxc_plugin_checkpoint(pid, statefile, flags) < 0) { 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; goto out_close;
} }
......
...@@ -50,6 +50,9 @@ ...@@ -50,6 +50,9 @@
#include "parse.h" #include "parse.h"
#include <lxc/lxc.h> #include <lxc/lxc.h>
#include <lxc/log.h>
lxc_log_define(lxc_conf, lxc);
#define MAXHWLEN 18 #define MAXHWLEN 18
#define MAXINDEXLEN 20 #define MAXINDEXLEN 20
...@@ -180,12 +183,12 @@ static int configure_ip4addr(int fd, struct lxc_inetdev *in) ...@@ -180,12 +183,12 @@ static int configure_ip4addr(int fd, struct lxc_inetdev *in)
int err = -1; int err = -1;
if (!inet_ntop(AF_INET, &in->addr, addr, sizeof(addr))) { 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; goto err;
} }
if (!inet_ntop(AF_INET, &in->bcast, bcast, sizeof(bcast))) { 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; goto err;
} }
...@@ -195,7 +198,7 @@ static int configure_ip4addr(int fd, struct lxc_inetdev *in) ...@@ -195,7 +198,7 @@ static int configure_ip4addr(int fd, struct lxc_inetdev *in)
snprintf(line, MAXLINELEN, "%s %s\n", addr, bcast); snprintf(line, MAXLINELEN, "%s %s\n", addr, bcast);
if (write(fd, line, strlen(line)) < 0) { if (write(fd, line, strlen(line)) < 0) {
lxc_log_syserror("failed to write address info"); SYSERROR("failed to write address info");
goto err; goto err;
} }
...@@ -211,14 +214,14 @@ static int configure_ip6addr(int fd, struct lxc_inet6dev *in6) ...@@ -211,14 +214,14 @@ static int configure_ip6addr(int fd, struct lxc_inet6dev *in6)
int err = -1; int err = -1;
if (!inet_ntop(AF_INET6, &in6->addr, addr, sizeof(addr))) { 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; goto err;
} }
snprintf(line, MAXLINELEN, "%s/%d\n", addr, in6->prefix?in6->prefix:64); snprintf(line, MAXLINELEN, "%s/%d\n", addr, in6->prefix?in6->prefix:64);
if (write(fd, line, strlen(line)) < 0) { if (write(fd, line, strlen(line)) < 0) {
lxc_log_syserror("failed to write address info"); SYSERROR("failed to write address info");
goto err; goto err;
} }
...@@ -234,14 +237,14 @@ static int configure_ip_address(const char *path, struct lxc_list *ip, int famil ...@@ -234,14 +237,14 @@ static int configure_ip_address(const char *path, struct lxc_list *ip, int famil
int fd, err = -1; int fd, err = -1;
if (mkdir(path, 0755)) { if (mkdir(path, 0755)) {
lxc_log_syserror("failed to create directory %s", path); SYSERROR("failed to create directory %s", path);
return -1; return -1;
} }
snprintf(file, MAXPATHLEN, "%s/addresses", path); snprintf(file, MAXPATHLEN, "%s/addresses", path);
fd = creat(file, 0755); fd = creat(file, 0755);
if (fd < 0) { if (fd < 0) {
lxc_log_syserror("failed to create %s file", file); SYSERROR("failed to create %s file", file);
goto err; goto err;
} }
...@@ -267,7 +270,7 @@ static int configure_netdev(const char *path, struct lxc_netdev *netdev) ...@@ -267,7 +270,7 @@ static int configure_netdev(const char *path, struct lxc_netdev *netdev)
char dir[MAXPATHLEN]; char dir[MAXPATHLEN];
if (mkdir(path, 0755)) { if (mkdir(path, 0755)) {
lxc_log_syserror("failed to create %s directory", path); SYSERROR("failed to create %s directory", path);
return -1; return -1;
} }
...@@ -334,7 +337,7 @@ static int configure_utsname(const char *name, struct utsname *utsname) ...@@ -334,7 +337,7 @@ static int configure_utsname(const char *name, struct utsname *utsname)
snprintf(path, MAXPATHLEN, LXCPATH "/%s", name); snprintf(path, MAXPATHLEN, LXCPATH "/%s", name);
if (write_info(path, "utsname", utsname->nodename)) { 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; return -1;
} }
...@@ -354,7 +357,7 @@ static int configure_network(const char *name, struct lxc_list *network) ...@@ -354,7 +357,7 @@ static int configure_network(const char *name, struct lxc_list *network)
snprintf(networkpath, MAXPATHLEN, LXCPATH "/%s/network", name); snprintf(networkpath, MAXPATHLEN, LXCPATH "/%s/network", name);
if (mkdir(networkpath, 0755)) { if (mkdir(networkpath, 0755)) {
lxc_log_syserror("failed to create %s directory", networkpath); SYSERROR("failed to create %s directory", networkpath);
goto out; goto out;
} }
...@@ -363,7 +366,7 @@ static int configure_network(const char *name, struct lxc_list *network) ...@@ -363,7 +366,7 @@ static int configure_network(const char *name, struct lxc_list *network)
n = iterator->elem; n = iterator->elem;
if (n->type < 0 || n->type > MAXCONFTYPE) { if (n->type < 0 || n->type > MAXCONFTYPE) {
lxc_log_error("invalid network configuration type '%d'", ERROR("invalid network configuration type '%d'",
n->type); n->type);
goto out; goto out;
} }
...@@ -373,7 +376,7 @@ static int configure_network(const char *name, struct lxc_list *network) ...@@ -373,7 +376,7 @@ static int configure_network(const char *name, struct lxc_list *network)
netdev_conf[n->type].count++); netdev_conf[n->type].count++);
if (configure_netdev(path, lxc_list_first_elem(&n->netdev))) { 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); netdev_conf[n->type].type);
goto out; goto out;
} }
...@@ -398,7 +401,7 @@ static int configure_cgroup(const char *name, struct lxc_list *cgroup) ...@@ -398,7 +401,7 @@ static int configure_cgroup(const char *name, struct lxc_list *cgroup)
file = fopen(path, "w+"); file = fopen(path, "w+");
if (!file) { if (!file) {
lxc_log_syserror("failed to open '%s'", path); SYSERROR("failed to open '%s'", path);
return -1; return -1;
} }
...@@ -419,7 +422,7 @@ static int configure_tty(const char *name, int tty) ...@@ -419,7 +422,7 @@ static int configure_tty(const char *name, int tty)
int ret; int ret;
if (asprintf(&nbtty, "%d", tty) < 0) { if (asprintf(&nbtty, "%d", tty) < 0) {
lxc_log_error("failed to convert tty number"); ERROR("failed to convert tty number");
return -1; return -1;
} }
...@@ -427,7 +430,7 @@ static int configure_tty(const char *name, int tty) ...@@ -427,7 +430,7 @@ static int configure_tty(const char *name, int tty)
ret = write_info(path, "tty", nbtty); ret = write_info(path, "tty", nbtty);
if (ret) if (ret)
lxc_log_error("failed to write the tty info"); ERROR("failed to write the tty info");
free(nbtty); free(nbtty);
...@@ -490,12 +493,12 @@ static int configure_find_fstype(const char *rootfs, char *fstype, int mntopt) ...@@ -490,12 +493,12 @@ static int configure_find_fstype(const char *rootfs, char *fstype, int mntopt)
cbarg.testdir = tempnam("/tmp", "lxc-"); cbarg.testdir = tempnam("/tmp", "lxc-");
if (!cbarg.testdir) { if (!cbarg.testdir) {
lxc_log_syserror("failed to build a temp name"); SYSERROR("failed to build a temp name");
return -1; return -1;
} }
if (mkdir(cbarg.testdir, 0755)) { if (mkdir(cbarg.testdir, 0755)) {
lxc_log_syserror("failed to create temporary directory"); SYSERROR("failed to create temporary directory");
return -1; return -1;
} }
...@@ -506,7 +509,7 @@ static int configure_find_fstype(const char *rootfs, char *fstype, int mntopt) ...@@ -506,7 +509,7 @@ static int configure_find_fstype(const char *rootfs, char *fstype, int mntopt)
buffer, sizeof(buffer), &cbarg); buffer, sizeof(buffer), &cbarg);
if (found < 0) { if (found < 0) {
lxc_log_syserror("failed to read '%s'", fsfile[i]); SYSERROR("failed to read '%s'", fsfile[i]);
goto out; goto out;
} }
...@@ -515,7 +518,7 @@ static int configure_find_fstype(const char *rootfs, char *fstype, int mntopt) ...@@ -515,7 +518,7 @@ static int configure_find_fstype(const char *rootfs, char *fstype, int mntopt)
} }
if (!found) { if (!found) {
lxc_log_error("failed to determine fs type for '%s'", rootfs); ERROR("failed to determine fs type for '%s'", rootfs);
goto out; goto out;
} }
...@@ -536,7 +539,7 @@ static int configure_rootfs_blk_cb(const char *rootfs, const char *absrootfs, ...@@ -536,7 +539,7 @@ static int configure_rootfs_blk_cb(const char *rootfs, const char *absrootfs,
char fstype[MAXPATHLEN]; char fstype[MAXPATHLEN];
if (configure_find_fstype(absrootfs, fstype, 0)) { 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); absrootfs);
return -1; return -1;
} }
...@@ -564,24 +567,24 @@ static int configure_rootfs(const char *name, const char *rootfs) ...@@ -564,24 +567,24 @@ static int configure_rootfs(const char *name, const char *rootfs)
}; };
if (!realpath(rootfs, absrootfs)) { 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; return -1;
} }
snprintf(path, MAXPATHLEN, LXCPATH "/%s/rootfs", name); snprintf(path, MAXPATHLEN, LXCPATH "/%s/rootfs", name);
if (mkdir(path, 0755)) { if (mkdir(path, 0755)) {
lxc_log_syserror("failed to create the '%s' directory", path); SYSERROR("failed to create the '%s' directory", path);
return -1; return -1;
} }
if (access(absrootfs, F_OK)) { if (access(absrootfs, F_OK)) {
lxc_log_syserror("'%s' is not accessible", absrootfs); SYSERROR("'%s' is not accessible", absrootfs);
return -1; return -1;
} }
if (stat(absrootfs, &s)) { if (stat(absrootfs, &s)) {
lxc_log_syserror("failed to stat '%s'", absrootfs); SYSERROR("failed to stat '%s'", absrootfs);
return -1; return -1;
} }
...@@ -594,7 +597,7 @@ static int configure_rootfs(const char *name, const char *rootfs) ...@@ -594,7 +597,7 @@ static int configure_rootfs(const char *name, const char *rootfs)
f = fopen(fstab, "a+"); f = fopen(fstab, "a+");
if (!f) { if (!f) {
lxc_log_syserror("failed to open fstab file"); SYSERROR("failed to open fstab file");
return -1; return -1;
} }
...@@ -603,7 +606,7 @@ static int configure_rootfs(const char *name, const char *rootfs) ...@@ -603,7 +606,7 @@ static int configure_rootfs(const char *name, const char *rootfs)
fclose(f); fclose(f);
if (ret < 0) { if (ret < 0) {
lxc_log_error("failed to add rootfs mount in fstab"); ERROR("failed to add rootfs mount in fstab");
return -1; return -1;
} }
...@@ -612,7 +615,7 @@ static int configure_rootfs(const char *name, const char *rootfs) ...@@ -612,7 +615,7 @@ static int configure_rootfs(const char *name, const char *rootfs)
return symlink(absrootfs, path); return symlink(absrootfs, path);
} }
lxc_log_error("unsupported rootfs type for '%s'", absrootfs); ERROR("unsupported rootfs type for '%s'", absrootfs);
return -1; return -1;
} }
...@@ -623,7 +626,7 @@ static int configure_pts(const char *name, int pts) ...@@ -623,7 +626,7 @@ static int configure_pts(const char *name, int pts)
int ret; int ret;
if (asprintf(&maxpts, "%d", pts) < 0) { if (asprintf(&maxpts, "%d", pts) < 0) {
lxc_log_error("failed to convert max pts number"); ERROR("failed to convert max pts number");
return -1; return -1;
} }
...@@ -631,7 +634,7 @@ static int configure_pts(const char *name, int pts) ...@@ -631,7 +634,7 @@ static int configure_pts(const char *name, int pts)
ret = write_info(path, "pts", maxpts); ret = write_info(path, "pts", maxpts);
if (ret) if (ret)
lxc_log_error("failed to write the pts info"); ERROR("failed to write the pts info");
free(maxpts); free(maxpts);
...@@ -651,41 +654,41 @@ static int configure_mount(const char *name, const char *fstab) ...@@ -651,41 +654,41 @@ static int configure_mount(const char *name, const char *fstab)
outfd = open(path, O_RDWR|O_CREAT|O_EXCL, 0640); outfd = open(path, O_RDWR|O_CREAT|O_EXCL, 0640);
if (outfd < 0) { if (outfd < 0) {
lxc_log_syserror("failed to creat '%s'", path); SYSERROR("failed to creat '%s'", path);
goto out; goto out;
} }
infd = open(fstab, O_RDONLY); infd = open(fstab, O_RDONLY);
if (infd < 0) { if (infd < 0) {
lxc_log_syserror("failed to open '%s'", fstab); SYSERROR("failed to open '%s'", fstab);
goto out_open; goto out_open;
} }
if (fstat(infd, &stat)) { if (fstat(infd, &stat)) {
lxc_log_syserror("failed to stat '%s'", fstab); SYSERROR("failed to stat '%s'", fstab);
goto out_open2; goto out_open2;
} }
if (lseek(outfd, stat.st_size - 1, SEEK_SET) < 0) { 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; goto out_open2;
} }
/* fixup length */ /* fixup length */
if (write(outfd, &c, 1) < 0) { 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; goto out_open2;
} }
src = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, infd, 0L); src = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, infd, 0L);
if (src == MAP_FAILED) { if (src == MAP_FAILED) {
lxc_log_syserror("failed to mmap '%s'", fstab); SYSERROR("failed to mmap '%s'", fstab);
goto out_open2; goto out_open2;
} }
dst = mmap(NULL, stat.st_size, PROT_WRITE, MAP_SHARED, outfd, 0L); dst = mmap(NULL, stat.st_size, PROT_WRITE, MAP_SHARED, outfd, 0L);
if (dst == MAP_FAILED) { if (dst == MAP_FAILED) {
lxc_log_syserror("failed to mmap '%s'", path); SYSERROR("failed to mmap '%s'", path);
goto out_mmap; goto out_mmap;
} }
...@@ -767,7 +770,7 @@ static int unconfigure_cgroup(const char *name) ...@@ -767,7 +770,7 @@ static int unconfigure_cgroup(const char *name)
snprintf(filename, MAXPATHLEN, LXCPATH "/%s/cgroup", name); snprintf(filename, MAXPATHLEN, LXCPATH "/%s/cgroup", name);
if (stat(filename, &s)) { if (stat(filename, &s)) {
lxc_log_syserror("failed to stat '%s'", filename); SYSERROR("failed to stat '%s'", filename);
return -1; return -1;
} }
...@@ -849,12 +852,12 @@ static int setup_utsname(const char *name) ...@@ -849,12 +852,12 @@ static int setup_utsname(const char *name)
ret = read_info(path, "utsname", utsname.nodename, ret = read_info(path, "utsname", utsname.nodename,
sizeof(utsname.nodename)); sizeof(utsname.nodename));
if (ret < 0) { if (ret < 0) {
lxc_log_syserror("failed to read utsname info"); SYSERROR("failed to read utsname info");
return -1; return -1;
} }
if (!ret && sethostname(utsname.nodename, strlen(utsname.nodename))) { 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); utsname.nodename);
return -1; return -1;
} }
...@@ -882,7 +885,7 @@ static int setup_tty(const char *name, const struct lxc_tty_info *tty_info) ...@@ -882,7 +885,7 @@ static int setup_tty(const char *name, const struct lxc_tty_info *tty_info)
* with EACCES errno and I don't know why :( */ * with EACCES errno and I don't know why :( */
if (mount(pty_info->name, path, "none", MS_BIND, 0)) { 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); pty_info->name, path);
continue; continue;
} }
...@@ -898,12 +901,12 @@ static int setup_rootfs(const char *name) ...@@ -898,12 +901,12 @@ static int setup_rootfs(const char *name)
snprintf(path, MAXPATHLEN, LXCPATH "/%s/rootfs", name); snprintf(path, MAXPATHLEN, LXCPATH "/%s/rootfs", name);
if (chroot(path)) { if (chroot(path)) {
lxc_log_syserror("failed to set chroot %s", path); SYSERROR("failed to set chroot %s", path);
return -1; return -1;
} }
if (chdir(getenv("HOME")) && chdir("/")) { if (chdir(getenv("HOME")) && chdir("/")) {
lxc_log_syserror("failed to change to home directory"); SYSERROR("failed to change to home directory");
return -1; return -1;
} }
...@@ -915,32 +918,32 @@ static int setup_pts(const char *name) ...@@ -915,32 +918,32 @@ static int setup_pts(const char *name)
char mountname[MAXPATHLEN]; char mountname[MAXPATHLEN];
if (!access("/dev/pts/ptmx", F_OK) && umount("/dev/pts")) { 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; return -1;
} }
snprintf(mountname, MAXPATHLEN, "%spts", name); snprintf(mountname, MAXPATHLEN, "%spts", name);
if (mount(mountname, "/dev/pts", "devpts", MS_MGC_VAL, "newinstance")) { 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; return -1;
} }
if (chmod("/dev/pts/ptmx", 0666)) { 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; return -1;
} }
if (access("/dev/ptmx", F_OK)) { if (access("/dev/ptmx", F_OK)) {
if (!symlink("/dev/pts/ptmx", "/dev/ptmx")) if (!symlink("/dev/pts/ptmx", "/dev/ptmx"))
goto out; goto out;
lxc_log_syserror("failed to symlink '/dev/pts/ptmx'->'/dev/ptmx'"); SYSERROR("failed to symlink '/dev/pts/ptmx'->'/dev/ptmx'");
return -1; return -1;
} }
/* fallback here, /dev/pts/ptmx exists just mount bind */ /* fallback here, /dev/pts/ptmx exists just mount bind */
if (mount("/dev/pts/ptmx", "/dev/ptmx", "none", MS_BIND, 0)) { 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; return -1;
} }
out: out:
...@@ -957,7 +960,7 @@ static int setup_console(const char *name, const char *tty) ...@@ -957,7 +960,7 @@ static int setup_console(const char *name, const char *tty)
return 0; return 0;
if (mount(tty, console, "none", MS_BIND, 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; return -1;
} }
...@@ -979,7 +982,7 @@ static int setup_cgroup_cb(void* buffer, void *data) ...@@ -979,7 +982,7 @@ static int setup_cgroup_cb(void* buffer, void *data)
ret = lxc_cgroup_set(name, key, value); ret = lxc_cgroup_set(name, key, value);
if (ret) 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); key, value, name);
return ret; return ret;
} }
...@@ -991,7 +994,7 @@ static int setup_convert_cgroup_cb(const char *name, const char *directory, ...@@ -991,7 +994,7 @@ static int setup_convert_cgroup_cb(const char *name, const char *directory,
char line[MAXPATHLEN]; char line[MAXPATHLEN];
if (read_info(directory, file, 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; return -1;
} }
...@@ -1041,13 +1044,13 @@ static int setup_cgroup(const char *name) ...@@ -1041,13 +1044,13 @@ static int setup_cgroup(const char *name)
snprintf(filename, MAXPATHLEN, LXCPATH "/%s/cgroup", name); snprintf(filename, MAXPATHLEN, LXCPATH "/%s/cgroup", name);
if (stat(filename, &s)) { if (stat(filename, &s)) {
lxc_log_syserror("failed to stat '%s'", filename); SYSERROR("failed to stat '%s'", filename);
return -1; return -1;
} }
if (S_ISDIR(s.st_mode)) { if (S_ISDIR(s.st_mode)) {
if (setup_convert_cgroup(name, filename)) { if (setup_convert_cgroup(name, filename)) {
lxc_log_error("failed to convert old cgroup configuration"); ERROR("failed to convert old cgroup configuration");
return -1; return -1;
} }
} }
...@@ -1089,13 +1092,13 @@ static int parse_mntopts(struct mntent *mntent, unsigned long *mntflags, ...@@ -1089,13 +1092,13 @@ static int parse_mntopts(struct mntent *mntent, unsigned long *mntflags,
s = strdup(mntent->mnt_opts); s = strdup(mntent->mnt_opts);
if (!s) { if (!s) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
return -1; return -1;
} }
data = malloc(strlen(s) + 1); data = malloc(strlen(s) + 1);
if (!data) { if (!data) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
free(s); free(s);
return -1; return -1;
} }
...@@ -1129,7 +1132,7 @@ static int setup_mount(const char *name) ...@@ -1129,7 +1132,7 @@ static int setup_mount(const char *name)
if (!file) { if (!file) {
if (errno == ENOENT) if (errno == ENOENT)
return 0; return 0;
lxc_log_syserror("failed to open '%s'", path); SYSERROR("failed to open '%s'", path);
goto out; goto out;
} }
...@@ -1137,14 +1140,14 @@ static int setup_mount(const char *name) ...@@ -1137,14 +1140,14 @@ static int setup_mount(const char *name)
mntflags = 0; mntflags = 0;
mntdata = NULL; mntdata = NULL;
if (parse_mntopts(mntent, &mntflags, &mntdata) < 0) { 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); mntent->mnt_opts);
goto out; goto out;
} }
if (mount(mntent->mnt_fsname, mntent->mnt_dir, if (mount(mntent->mnt_fsname, mntent->mnt_dir,
mntent->mnt_type, mntflags, mntdata)) { 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); mntent->mnt_fsname, mntent->mnt_dir);
goto out; goto out;
} }
...@@ -1183,7 +1186,7 @@ static int setup_ipv4_addr_cb(void *buffer, void *data) ...@@ -1183,7 +1186,7 @@ static int setup_ipv4_addr_cb(void *buffer, void *data)
p = atoi(prefix); p = atoi(prefix);
if (lxc_ip_addr_add(ifname, addr, p, bcast)) { 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:""); addr, p, bcast?bcast:"");
return -1; return -1;
} }
...@@ -1217,7 +1220,7 @@ static int setup_ipv6_addr_cb(void *buffer, void *data) ...@@ -1217,7 +1220,7 @@ static int setup_ipv6_addr_cb(void *buffer, void *data)
p = atoi(prefix); p = atoi(prefix);
if (lxc_ip6_addr_add(ifname, addr, p, bcast)) { 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:""); addr, p, bcast?bcast:"");
return -1; return -1;
} }
...@@ -1293,7 +1296,7 @@ static int setup_network_cb(const char *name, const char *directory, ...@@ -1293,7 +1296,7 @@ static int setup_network_cb(const char *name, const char *directory,
snprintf(path, MAXPATHLEN, "%s/%s", directory, file); snprintf(path, MAXPATHLEN, "%s/%s", directory, file);
if (read_info(path, "ifindex", strindex, sizeof(strindex))) { if (read_info(path, "ifindex", strindex, sizeof(strindex))) {
lxc_log_error("failed to read ifindex info"); ERROR("failed to read ifindex info");
return -1; return -1;
} }
...@@ -1301,21 +1304,21 @@ static int setup_network_cb(const char *name, const char *directory, ...@@ -1301,21 +1304,21 @@ static int setup_network_cb(const char *name, const char *directory,
if (!ifindex) { if (!ifindex) {
if (!read_info(path, "up", strindex, sizeof(strindex))) if (!read_info(path, "up", strindex, sizeof(strindex)))
if (lxc_device_up("lo")) { if (lxc_device_up("lo")) {
lxc_log_error("failed to set the loopback up"); ERROR("failed to set the loopback up");
return -1; return -1;
} }
return 0; return 0;
} }
if (!if_indextoname(ifindex, current_ifname)) { if (!if_indextoname(ifindex, current_ifname)) {
lxc_log_error("no interface corresponding to index '%d'", ERROR("no interface corresponding to index '%d'",
ifindex); ifindex);
return -1; return -1;
} }
if (!read_info(path, "name", newname, sizeof(newname))) { if (!read_info(path, "name", newname, sizeof(newname))) {
if (lxc_device_rename(ifname, newname)) { if (lxc_device_rename(ifname, newname)) {
lxc_log_error("failed to rename %s->%s", ERROR("failed to rename %s->%s",
ifname, newname); ifname, newname);
return -1; return -1;
} }
...@@ -1324,33 +1327,33 @@ static int setup_network_cb(const char *name, const char *directory, ...@@ -1324,33 +1327,33 @@ static int setup_network_cb(const char *name, const char *directory,
if (!read_info(path, "hwaddr", hwaddr, sizeof(hwaddr))) { if (!read_info(path, "hwaddr", hwaddr, sizeof(hwaddr))) {
if (setup_hw_addr(hwaddr, current_ifname)) { 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); current_ifname);
return -1; return -1;
} }
} }
if (setup_ip_addr(path, current_ifname)) { 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); ifname);
return -1; return -1;
} }
if (setup_ip6_addr(path, current_ifname)) { 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); ifname);
return -1; return -1;
} }
if (!read_info(path, "up", strindex, sizeof(strindex))) { if (!read_info(path, "up", strindex, sizeof(strindex))) {
if (lxc_device_up(current_ifname)) { 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; return -1;
} }
/* the network is up, make the loopback up too */ /* the network is up, make the loopback up too */
if (lxc_device_up("lo")) { if (lxc_device_up("lo")) {
lxc_log_error("failed to set the loopback up"); ERROR("failed to set the loopback up");
return -1; return -1;
} }
} }
...@@ -1384,7 +1387,7 @@ int conf_has(const char *name, const char *info) ...@@ -1384,7 +1387,7 @@ int conf_has(const char *name, const char *info)
goto out; goto out;
} }
lxc_log_syserror("failed to stat %s info", info); SYSERROR("failed to stat %s info", info);
out: out:
return ret; return ret;
} }
...@@ -1407,37 +1410,37 @@ int lxc_configure(const char *name, struct lxc_conf *conf) ...@@ -1407,37 +1410,37 @@ int lxc_configure(const char *name, struct lxc_conf *conf)
return 0; return 0;
if (conf->utsname && configure_utsname(name, conf->utsname)) { 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; return -LXC_ERROR_CONF_UTSNAME;
} }
if (configure_cgroup(name, &conf->cgroup)) { 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; return -LXC_ERROR_CONF_CGROUP;
} }
if (configure_network(name, &conf->networks)) { 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; return -LXC_ERROR_CONF_NETWORK;
} }
if (conf->tty && configure_tty(name, conf->tty)) { 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; return -LXC_ERROR_CONF_TTY;
} }
if (conf->fstab && configure_mount(name, conf->fstab)) { 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; return -LXC_ERROR_CONF_MOUNT;
} }
if (conf->rootfs && configure_rootfs(name, conf->rootfs)) { 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; return -LXC_ERROR_CONF_ROOTFS;
} }
if (conf->pts && configure_pts(name, conf->pts)) { 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; return -LXC_ERROR_CONF_PTS;
} }
...@@ -1447,25 +1450,25 @@ int lxc_configure(const char *name, struct lxc_conf *conf) ...@@ -1447,25 +1450,25 @@ int lxc_configure(const char *name, struct lxc_conf *conf)
int lxc_unconfigure(const char *name) int lxc_unconfigure(const char *name)
{ {
if (conf_has_utsname(name) && unconfigure_utsname(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)) 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)) 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)) 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)) 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)) 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)) if (conf_has_pts(name) && unconfigure_pts(name))
lxc_log_error("failed to cleanup pts"); ERROR("failed to cleanup pts");
return 0; return 0;
} }
...@@ -1480,62 +1483,62 @@ static int instanciate_veth(const char *directory, const char *file, pid_t pid) ...@@ -1480,62 +1483,62 @@ static int instanciate_veth(const char *directory, const char *file, pid_t pid)
if (!asprintf(&veth1, "%s_%d", file, pid) || if (!asprintf(&veth1, "%s_%d", file, pid) ||
!asprintf(&veth2, "%s~%d", file, pid) || !asprintf(&veth2, "%s~%d", file, pid) ||
!asprintf(&path, "%s/%s", directory, file)) { !asprintf(&path, "%s/%s", directory, file)) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
goto out; goto out;
} }
if (read_info(path, "link", bridge, IFNAMSIZ)) { if (read_info(path, "link", bridge, IFNAMSIZ)) {
lxc_log_error("failed to read bridge info"); ERROR("failed to read bridge info");
goto out; goto out;
} }
if (lxc_veth_create(veth1, veth2)) { 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; goto out;
} }
if (!read_info(path, "mtu", strmtu, MAXMTULEN)) { if (!read_info(path, "mtu", strmtu, MAXMTULEN)) {
if (sscanf(strmtu, "%u", &mtu) < 1) { if (sscanf(strmtu, "%u", &mtu) < 1) {
lxc_log_error("invalid mtu size '%d'", mtu); ERROR("invalid mtu size '%d'", mtu);
goto out_delete; goto out_delete;
} }
if (lxc_device_set_mtu(veth1, mtu)) { 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; goto out_delete;
} }
if (lxc_device_set_mtu(veth2, mtu)) { 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; goto out_delete;
} }
} }
if (lxc_bridge_attach(bridge, veth1)) { 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); veth1, bridge);
goto out_delete; goto out_delete;
} }
ifindex = if_nametoindex(veth2); ifindex = if_nametoindex(veth2);
if (!ifindex) { 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; goto out_delete;
} }
if (!asprintf(&strindex, "%d", ifindex)) { if (!asprintf(&strindex, "%d", ifindex)) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
goto out_delete; goto out_delete;
} }
if (write_info(path, "ifindex", strindex)) { 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; goto out_delete;
} }
if (!read_info(path, "up", strindex, sizeof(strindex))) { if (!read_info(path, "up", strindex, sizeof(strindex))) {
if (lxc_device_up(veth1)) { if (lxc_device_up(veth1)) {
lxc_log_error("failed to set %s up", veth1); ERROR("failed to set %s up", veth1);
goto out_delete; goto out_delete;
} }
} }
...@@ -1559,35 +1562,35 @@ static int instanciate_macvlan(const char *directory, const char *file, pid_t pi ...@@ -1559,35 +1562,35 @@ static int instanciate_macvlan(const char *directory, const char *file, pid_t pi
int ifindex, ret = -1; int ifindex, ret = -1;
if (!asprintf(&peer, "%s~%d", file, pid)) { if (!asprintf(&peer, "%s~%d", file, pid)) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
return -1; return -1;
} }
snprintf(path, MAXPATHLEN, "%s/%s", directory, file); snprintf(path, MAXPATHLEN, "%s/%s", directory, file);
if (read_info(path, "link", link, IFNAMSIZ)) { if (read_info(path, "link", link, IFNAMSIZ)) {
lxc_log_error("failed to read bridge info"); ERROR("failed to read bridge info");
goto out; goto out;
} }
if (lxc_macvlan_create(link, peer)) { 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); peer, link);
goto out; goto out;
} }
ifindex = if_nametoindex(peer); ifindex = if_nametoindex(peer);
if (!ifindex) { if (!ifindex) {
lxc_log_error("failed to retrieve the index for %s", peer); ERROR("failed to retrieve the index for %s", peer);
goto out; goto out;
} }
if (!asprintf(&strindex, "%d", ifindex)) { if (!asprintf(&strindex, "%d", ifindex)) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
return -1; return -1;
} }
if (write_info(path, "ifindex", strindex)) { 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; goto out;
} }
...@@ -1606,23 +1609,23 @@ static int instanciate_phys(const char *directory, const char *file, pid_t pid) ...@@ -1606,23 +1609,23 @@ static int instanciate_phys(const char *directory, const char *file, pid_t pid)
snprintf(path, MAXPATHLEN, "%s/%s", directory, file); snprintf(path, MAXPATHLEN, "%s/%s", directory, file);
if (read_info(path, "link", link, IFNAMSIZ)) { if (read_info(path, "link", link, IFNAMSIZ)) {
lxc_log_error("failed to read link info"); ERROR("failed to read link info");
goto out; goto out;
} }
ifindex = if_nametoindex(link); ifindex = if_nametoindex(link);
if (!ifindex) { if (!ifindex) {
lxc_log_error("failed to retrieve the index for %s", link); ERROR("failed to retrieve the index for %s", link);
goto out; goto out;
} }
if (!asprintf(&strindex, "%d", ifindex)) { if (!asprintf(&strindex, "%d", ifindex)) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
return -1; return -1;
} }
if (write_info(path, "ifindex", strindex)) { 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; goto out;
} }
...@@ -1639,12 +1642,12 @@ static int instanciate_empty(const char *directory, const char *file, pid_t pid) ...@@ -1639,12 +1642,12 @@ static int instanciate_empty(const char *directory, const char *file, pid_t pid)
snprintf(path, MAXPATHLEN, "%s/%s", directory, file); snprintf(path, MAXPATHLEN, "%s/%s", directory, file);
if (!asprintf(&strindex, "%d", 0)) { if (!asprintf(&strindex, "%d", 0)) {
lxc_log_error("not enough memory"); ERROR("not enough memory");
return -1; return -1;
} }
if (write_info(path, "ifindex", strindex)) { 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; goto out;
} }
...@@ -1688,7 +1691,7 @@ static int move_netdev_cb(const char *name, const char *directory, ...@@ -1688,7 +1691,7 @@ static int move_netdev_cb(const char *name, const char *directory,
snprintf(path, MAXPATHLEN, "%s/%s", directory, file); snprintf(path, MAXPATHLEN, "%s/%s", directory, file);
if (read_info(path, "ifindex", strindex, MAXINDEXLEN) < 0) { 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 -1;
} }
...@@ -1697,13 +1700,13 @@ static int move_netdev_cb(const char *name, const char *directory, ...@@ -1697,13 +1700,13 @@ static int move_netdev_cb(const char *name, const char *directory,
return 0; return 0;
if (!if_indextoname(ifindex, ifname)) { if (!if_indextoname(ifindex, ifname)) {
lxc_log_error("interface with index %d does not exist", ERROR("interface with index %d does not exist",
ifindex); ifindex);
return -1; return -1;
} }
if (lxc_device_move(ifname, *pid)) { 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; return -1;
} }
...@@ -1720,12 +1723,12 @@ static int move_netdev(const char *name, pid_t pid) ...@@ -1720,12 +1723,12 @@ static int move_netdev(const char *name, pid_t pid)
int conf_create_network(const char *name, pid_t pid) int conf_create_network(const char *name, pid_t pid)
{ {
if (instanciate_netdev(name, pid)) { if (instanciate_netdev(name, pid)) {
lxc_log_error("failed to instantiate the network devices"); ERROR("failed to instantiate the network devices");
return -1; return -1;
} }
if (move_netdev(name, pid)) { 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; return -1;
} }
...@@ -1744,7 +1747,7 @@ static int delete_netdev_cb(const char *name, const char *directory, ...@@ -1744,7 +1747,7 @@ static int delete_netdev_cb(const char *name, const char *directory,
snprintf(path, MAXPATHLEN, "%s/%s", directory, file); snprintf(path, MAXPATHLEN, "%s/%s", directory, file);
if (read_info(path, "ifindex", strindex, MAXINDEXLEN)) { if (read_info(path, "ifindex", strindex, MAXINDEXLEN)) {
lxc_log_error("failed to read ifindex info"); ERROR("failed to read ifindex info");
return -1; return -1;
} }
...@@ -1766,7 +1769,7 @@ static int delete_netdev_cb(const char *name, const char *directory, ...@@ -1766,7 +1769,7 @@ static int delete_netdev_cb(const char *name, const char *directory,
/* do not delete a physical network device */ /* do not delete a physical network device */
if (strncmp("phys", file, strlen("phys"))) if (strncmp("phys", file, strlen("phys")))
if (lxc_device_delete(ifname)) { 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"); delete_info(path, "ifindex");
...@@ -1783,7 +1786,7 @@ int conf_destroy_network(const char *name) ...@@ -1783,7 +1786,7 @@ int conf_destroy_network(const char *name)
snprintf(directory, MAXPATHLEN, LXCPATH "/%s/network", name); snprintf(directory, MAXPATHLEN, LXCPATH "/%s/network", name);
if (lxc_dir_for_each(name, directory, delete_netdev_cb, NULL)) { 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; return -1;
} }
#endif #endif
...@@ -1804,7 +1807,7 @@ int lxc_create_tty(const char *name, struct lxc_tty_info *tty_info) ...@@ -1804,7 +1807,7 @@ int lxc_create_tty(const char *name, struct lxc_tty_info *tty_info)
snprintf(path, MAXPATHLEN, LXCPATH "/%s", name); snprintf(path, MAXPATHLEN, LXCPATH "/%s", name);
if (read_info(path, "tty", tty, sizeof(tty)) < 0) { 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; goto out;
} }
...@@ -1813,7 +1816,7 @@ int lxc_create_tty(const char *name, struct lxc_tty_info *tty_info) ...@@ -1813,7 +1816,7 @@ int lxc_create_tty(const char *name, struct lxc_tty_info *tty_info)
malloc(sizeof(*tty_info->pty_info)*tty_info->nbtty); malloc(sizeof(*tty_info->pty_info)*tty_info->nbtty);
if (!tty_info->pty_info) { if (!tty_info->pty_info) {
lxc_log_syserror("failed to allocate pty_info"); SYSERROR("failed to allocate pty_info");
goto out; goto out;
} }
...@@ -1823,7 +1826,7 @@ int lxc_create_tty(const char *name, struct lxc_tty_info *tty_info) ...@@ -1823,7 +1826,7 @@ int lxc_create_tty(const char *name, struct lxc_tty_info *tty_info)
if (openpty(&pty_info->master, &pty_info->slave, if (openpty(&pty_info->master, &pty_info->slave,
pty_info->name, NULL, NULL)) { pty_info->name, NULL, NULL)) {
lxc_log_syserror("failed to create pty #%d", i); SYSERROR("failed to create pty #%d", i);
goto out_free; goto out_free;
} }
...@@ -1911,42 +1914,42 @@ int lxc_setup(const char *name, const char *cons, ...@@ -1911,42 +1914,42 @@ int lxc_setup(const char *name, const char *cons,
long flags = make_conf_flagset(name, cons, tty_info); long flags = make_conf_flagset(name, cons, tty_info);
if (conf_is_set(flags, utsname) && setup_utsname(name)) { 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; return -LXC_ERROR_SETUP_UTSNAME;
} }
if (conf_is_set(flags, network) && setup_network(name)) { 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; return -LXC_ERROR_SETUP_NETWORK;
} }
if (conf_is_set(flags, cgroup) && setup_cgroup(name)) { 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; return -LXC_ERROR_SETUP_CGROUP;
} }
if (conf_is_set(flags, fstab) && setup_mount(name)) { 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; return -LXC_ERROR_SETUP_MOUNT;
} }
if (conf_is_set(flags, console) && setup_console(name, cons)) { 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; return -LXC_ERROR_SETUP_CONSOLE;
} }
if (conf_is_set(flags, tty) && setup_tty(name, tty_info)) { 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; return -LXC_ERROR_SETUP_TTY;
} }
if (conf_is_set(flags, rootfs) && setup_rootfs(name)) { 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; return -LXC_ERROR_SETUP_ROOTFS;
} }
if (conf_is_set(flags, pts) && setup_pts(name)) { 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; return -LXC_ERROR_SETUP_PTS;
} }
......
...@@ -35,6 +35,9 @@ ...@@ -35,6 +35,9 @@
#include "parse.h" #include "parse.h"
#include <lxc/lxc.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_pts(const char *, char *, struct lxc_conf *);
static int config_tty(const char *, char *, struct lxc_conf *); static int config_tty(const char *, char *, struct lxc_conf *);
...@@ -99,7 +102,7 @@ static int config_network_type(const char *key, char *value, struct lxc_conf *lx ...@@ -99,7 +102,7 @@ static int config_network_type(const char *key, char *value, struct lxc_conf *lx
network = malloc(sizeof(*network)); network = malloc(sizeof(*network));
if (!network) { if (!network) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
return -1; return -1;
} }
...@@ -107,7 +110,7 @@ static int config_network_type(const char *key, char *value, struct lxc_conf *lx ...@@ -107,7 +110,7 @@ static int config_network_type(const char *key, char *value, struct lxc_conf *lx
netdev = malloc(sizeof(*netdev)); netdev = malloc(sizeof(*netdev));
if (!netdev) { if (!netdev) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
return -1; return -1;
} }
...@@ -118,7 +121,7 @@ static int config_network_type(const char *key, char *value, struct lxc_conf *lx ...@@ -118,7 +121,7 @@ static int config_network_type(const char *key, char *value, struct lxc_conf *lx
ndlist = malloc(sizeof(*ndlist)); ndlist = malloc(sizeof(*ndlist));
if (!ndlist) { if (!ndlist) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
return -1; return -1;
} }
...@@ -128,7 +131,7 @@ static int config_network_type(const char *key, char *value, struct lxc_conf *lx ...@@ -128,7 +131,7 @@ static int config_network_type(const char *key, char *value, struct lxc_conf *lx
list = malloc(sizeof(*list)); list = malloc(sizeof(*list));
if (!list) { if (!list) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
return -1; return -1;
} }
...@@ -146,7 +149,7 @@ static int config_network_type(const char *key, char *value, struct lxc_conf *lx ...@@ -146,7 +149,7 @@ static int config_network_type(const char *key, char *value, struct lxc_conf *lx
else if (!strcmp(value, "empty")) else if (!strcmp(value, "empty"))
network->type = EMPTY; network->type = EMPTY;
else { else {
lxc_log_error("invalid network type %s", value); ERROR("invalid network type %s", value);
return -1; return -1;
} }
return 0; return 0;
...@@ -159,13 +162,13 @@ static int config_network_flags(const char *key, char *value, struct lxc_conf *l ...@@ -159,13 +162,13 @@ static int config_network_flags(const char *key, char *value, struct lxc_conf *l
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
if (lxc_list_empty(networks)) { 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; return -1;
} }
network = lxc_list_first_elem(networks); network = lxc_list_first_elem(networks);
if (!network) { if (!network) {
lxc_log_error("no network defined for '%s' option", value); ERROR("no network defined for '%s' option", value);
return -1; return -1;
} }
...@@ -181,18 +184,18 @@ static int config_network_link(const char *key, char *value, struct lxc_conf *lx ...@@ -181,18 +184,18 @@ static int config_network_link(const char *key, char *value, struct lxc_conf *lx
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
if (lxc_list_empty(networks)) { 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; return -1;
} }
network = lxc_list_first_elem(networks); network = lxc_list_first_elem(networks);
if (!network) { if (!network) {
lxc_log_error("no network defined for %s", value); ERROR("no network defined for %s", value);
return -1; return -1;
} }
if (strlen(value) > IFNAMSIZ) { if (strlen(value) > IFNAMSIZ) {
lxc_log_error("invalid interface name: %s", value); ERROR("invalid interface name: %s", value);
return -1; return -1;
} }
...@@ -208,18 +211,18 @@ static int config_network_name(const char *key, char *value, struct lxc_conf *lx ...@@ -208,18 +211,18 @@ static int config_network_name(const char *key, char *value, struct lxc_conf *lx
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
if (lxc_list_empty(networks)) { 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; return -1;
} }
network = lxc_list_first_elem(networks); network = lxc_list_first_elem(networks);
if (!network) { if (!network) {
lxc_log_error("no network defined for %s", value); ERROR("no network defined for %s", value);
return -1; return -1;
} }
if (strlen(value) > IFNAMSIZ) { if (strlen(value) > IFNAMSIZ) {
lxc_log_error("invalid interface name: %s", value); ERROR("invalid interface name: %s", value);
return -1; return -1;
} }
...@@ -235,13 +238,13 @@ static int config_network_hwaddr(const char *key, char *value, struct lxc_conf * ...@@ -235,13 +238,13 @@ static int config_network_hwaddr(const char *key, char *value, struct lxc_conf *
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
if (lxc_list_empty(networks)) { 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; return -1;
} }
network = lxc_list_first_elem(networks); network = lxc_list_first_elem(networks);
if (!network) { if (!network) {
lxc_log_error("no network defined for %s", value); ERROR("no network defined for %s", value);
return -1; return -1;
} }
...@@ -257,13 +260,13 @@ static int config_network_mtu(const char *key, char *value, struct lxc_conf *lxc ...@@ -257,13 +260,13 @@ static int config_network_mtu(const char *key, char *value, struct lxc_conf *lxc
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
if (lxc_list_empty(networks)) { 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; return -1;
} }
network = lxc_list_first_elem(networks); network = lxc_list_first_elem(networks);
if (!network) { if (!network) {
lxc_log_error("no network defined for %s", value); ERROR("no network defined for %s", value);
return -1; return -1;
} }
...@@ -282,31 +285,31 @@ static int config_network_ipv4(const char *key, char *value, struct lxc_conf *lx ...@@ -282,31 +285,31 @@ static int config_network_ipv4(const char *key, char *value, struct lxc_conf *lx
char *cursor, *slash, *addr = NULL, *bcast = NULL, *prefix = NULL; char *cursor, *slash, *addr = NULL, *bcast = NULL, *prefix = NULL;
if (lxc_list_empty(networks)) { 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; return -1;
} }
network = lxc_list_first_elem(networks); network = lxc_list_first_elem(networks);
if (!network) { if (!network) {
lxc_log_error("no network defined for '%s'", value); ERROR("no network defined for '%s'", value);
return -1; return -1;
} }
netdev = lxc_list_first_elem(&network->netdev); netdev = lxc_list_first_elem(&network->netdev);
if (!netdev) { if (!netdev) {
lxc_log_error("no netdev defined for '%s'", value); ERROR("no netdev defined for '%s'", value);
} }
inetdev = malloc(sizeof(*inetdev)); inetdev = malloc(sizeof(*inetdev));
if (!inetdev) { if (!inetdev) {
lxc_log_syserror("failed to allocate ipv4 address"); SYSERROR("failed to allocate ipv4 address");
return -1; return -1;
} }
memset(inetdev, 0, sizeof(*inetdev)); memset(inetdev, 0, sizeof(*inetdev));
list = malloc(sizeof(*list)); list = malloc(sizeof(*list));
if (!list) { if (!list) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
return -1; return -1;
} }
...@@ -328,18 +331,18 @@ static int config_network_ipv4(const char *key, char *value, struct lxc_conf *lx ...@@ -328,18 +331,18 @@ static int config_network_ipv4(const char *key, char *value, struct lxc_conf *lx
} }
if (!addr) { if (!addr) {
lxc_log_error("no address specified"); ERROR("no address specified");
return -1; return -1;
} }
if (!inet_pton(AF_INET, addr, &inetdev->addr)) { if (!inet_pton(AF_INET, addr, &inetdev->addr)) {
lxc_log_syserror("invalid ipv4 address: %s", value); SYSERROR("invalid ipv4 address: %s", value);
return -1; return -1;
} }
if (bcast) if (bcast)
if (!inet_pton(AF_INET, bcast, &inetdev->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; return -1;
} }
...@@ -362,26 +365,26 @@ static int config_network_ipv6(const char *key, char *value, struct lxc_conf *lx ...@@ -362,26 +365,26 @@ static int config_network_ipv6(const char *key, char *value, struct lxc_conf *lx
char *netmask; char *netmask;
if (lxc_list_empty(networks)) { 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; return -1;
} }
network = lxc_list_first_elem(networks); network = lxc_list_first_elem(networks);
if (!network) { if (!network) {
lxc_log_error("no network defined for %s", value); ERROR("no network defined for %s", value);
return -1; return -1;
} }
inet6dev = malloc(sizeof(*inet6dev)); inet6dev = malloc(sizeof(*inet6dev));
if (!inet6dev) { if (!inet6dev) {
lxc_log_syserror("failed to allocate ipv6 address"); SYSERROR("failed to allocate ipv6 address");
return -1; return -1;
} }
memset(inet6dev, 0, sizeof(*inet6dev)); memset(inet6dev, 0, sizeof(*inet6dev));
list = malloc(sizeof(*list)); list = malloc(sizeof(*list));
if (!list) { if (!list) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
return -1; return -1;
} }
...@@ -396,7 +399,7 @@ static int config_network_ipv6(const char *key, char *value, struct lxc_conf *lx ...@@ -396,7 +399,7 @@ static int config_network_ipv6(const char *key, char *value, struct lxc_conf *lx
} }
if (!inet_pton(AF_INET6, value, &inet6dev->addr)) { if (!inet_pton(AF_INET6, value, &inet6dev->addr)) {
lxc_log_syserror("invalid ipv6 address: %s", value); SYSERROR("invalid ipv6 address: %s", value);
return -1; return -1;
} }
...@@ -467,13 +470,13 @@ static int config_cgroup(const char *key, char *value, struct lxc_conf *lxc_conf ...@@ -467,13 +470,13 @@ static int config_cgroup(const char *key, char *value, struct lxc_conf *lxc_conf
static int config_mount(const char *key, char *value, struct lxc_conf *lxc_conf) static int config_mount(const char *key, char *value, struct lxc_conf *lxc_conf)
{ {
if (strlen(value) >= MAXPATHLEN) { if (strlen(value) >= MAXPATHLEN) {
lxc_log_error("%s path is too long", value); ERROR("%s path is too long", value);
return -1; return -1;
} }
lxc_conf->fstab = strdup(value); lxc_conf->fstab = strdup(value);
if (!lxc_conf->fstab) { if (!lxc_conf->fstab) {
lxc_log_syserror("failed to duplicate string %s", value); SYSERROR("failed to duplicate string %s", value);
return -1; return -1;
} }
...@@ -483,13 +486,13 @@ static int config_mount(const char *key, char *value, struct lxc_conf *lxc_conf) ...@@ -483,13 +486,13 @@ static int config_mount(const char *key, char *value, struct lxc_conf *lxc_conf)
static int config_rootfs(const char *key, char *value, struct lxc_conf *lxc_conf) static int config_rootfs(const char *key, char *value, struct lxc_conf *lxc_conf)
{ {
if (strlen(value) >= MAXPATHLEN) { if (strlen(value) >= MAXPATHLEN) {
lxc_log_error("%s path is too long", value); ERROR("%s path is too long", value);
return -1; return -1;
} }
lxc_conf->rootfs = strdup(value); lxc_conf->rootfs = strdup(value);
if (!lxc_conf->rootfs) { if (!lxc_conf->rootfs) {
lxc_log_syserror("failed to duplicate string %s", value); SYSERROR("failed to duplicate string %s", value);
return -1; return -1;
} }
...@@ -502,12 +505,12 @@ static int config_utsname(const char *key, char *value, struct lxc_conf *lxc_con ...@@ -502,12 +505,12 @@ static int config_utsname(const char *key, char *value, struct lxc_conf *lxc_con
utsname = malloc(sizeof(*utsname)); utsname = malloc(sizeof(*utsname));
if (!utsname) { if (!utsname) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
return -1; return -1;
} }
if (strlen(value) >= sizeof(utsname->nodename)) { if (strlen(value) >= sizeof(utsname->nodename)) {
lxc_log_error("node name '%s' is too long", ERROR("node name '%s' is too long",
utsname->nodename); utsname->nodename);
return -1; return -1;
} }
...@@ -535,7 +538,7 @@ static int parse_line(void *buffer, void *data) ...@@ -535,7 +538,7 @@ static int parse_line(void *buffer, void *data)
dot = strstr(line, "="); dot = strstr(line, "=");
if (!dot) { if (!dot) {
lxc_log_error("invalid configuration line: %s", line); ERROR("invalid configuration line: %s", line);
return -1; return -1;
} }
...@@ -550,7 +553,7 @@ static int parse_line(void *buffer, void *data) ...@@ -550,7 +553,7 @@ static int parse_line(void *buffer, void *data)
config = getconfig(key); config = getconfig(key);
if (!config) { if (!config) {
lxc_log_error("unknow key %s", key); ERROR("unknow key %s", key);
return -1; return -1;
} }
......
...@@ -31,6 +31,10 @@ ...@@ -31,6 +31,10 @@
#include "af_unix.h" #include "af_unix.h"
#include "error.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) extern int lxc_console(const char *name, int ttynum, int *fd)
{ {
struct sockaddr_un addr = { 0 }; struct sockaddr_un addr = { 0 };
...@@ -41,24 +45,24 @@ extern int lxc_console(const char *name, int ttynum, int *fd) ...@@ -41,24 +45,24 @@ extern int lxc_console(const char *name, int ttynum, int *fd)
sock = lxc_af_unix_connect(addr.sun_path); sock = lxc_af_unix_connect(addr.sun_path);
if (sock < 0) { if (sock < 0) {
lxc_log_error("failed to connect to the tty service"); ERROR("failed to connect to the tty service");
goto out_err; goto out_err;
} }
ret = lxc_af_unix_send_credential(sock, &ttynum, sizeof(ttynum)); ret = lxc_af_unix_send_credential(sock, &ttynum, sizeof(ttynum));
if (ret < 0) { if (ret < 0) {
lxc_log_syserror("failed to send credentials"); SYSERROR("failed to send credentials");
goto out_err; goto out_err;
} }
ret = lxc_af_unix_recv_fd(sock, fd, NULL, 0); ret = lxc_af_unix_recv_fd(sock, fd, NULL, 0);
if (ret < 0) { if (ret < 0) {
lxc_log_error("failed to connect to the tty"); ERROR("failed to connect to the tty");
goto out_err; goto out_err;
} }
if (!ret) { 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; ret = -LXC_ERROR_TTY_DENIED;
goto out_err; goto out_err;
} }
......
...@@ -36,6 +36,11 @@ ...@@ -36,6 +36,11 @@
#include "error.h" #include "error.h"
#include <lxc.h> #include <lxc.h>
#include <lxc/log.h>
lxc_log_define(lxc_columbia, lxc);
#if __i386__ #if __i386__
# define __NR_checkpoint 333 # define __NR_checkpoint 333
...@@ -82,13 +87,13 @@ int lxc_plugin_checkpoint(pid_t pid, const char *statefile, unsigned long flags) ...@@ -82,13 +87,13 @@ int lxc_plugin_checkpoint(pid_t pid, const char *statefile, unsigned long flags)
fd = open(statefile, O_RDWR); fd = open(statefile, O_RDWR);
if (fd < 0) { 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; return -1;
} }
ret = sys_checkpoint(pid, fd, flags); ret = sys_checkpoint(pid, fd, flags);
if (ret < 0) { if (ret < 0) {
lxc_log_syserror("failed to checkpoint %d", pid); SYSERROR("failed to checkpoint %d", pid);
goto out_close; goto out_close;
} }
...@@ -105,12 +110,12 @@ int lxc_plugin_restart(pid_t pid, const char *statefile, unsigned long flags) ...@@ -105,12 +110,12 @@ int lxc_plugin_restart(pid_t pid, const char *statefile, unsigned long flags)
fd = open(statefile, O_RDONLY); fd = open(statefile, O_RDONLY);
if (fd < 0) { 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; return -1;
} }
sys_restart(pid, fd, flags); sys_restart(pid, fd, flags);
lxc_log_syserror("failed to restart %d", pid); SYSERROR("failed to restart %d", pid);
close(fd); close(fd);
return -1; return -1;
} }
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
#include "error.h" #include "error.h"
#include <lxc/lxc.h> #include <lxc/lxc.h>
#include <lxc/log.h>
lxc_log_define(lxc_create, lxc);
static int dir_filter(const struct dirent *dirent) static int dir_filter(const struct dirent *dirent)
{ {
...@@ -48,7 +51,7 @@ static int is_empty_directory(const char *dirname) ...@@ -48,7 +51,7 @@ static int is_empty_directory(const char *dirname)
n = scandir(dirname, &namelist, dir_filter, alphasort); n = scandir(dirname, &namelist, dir_filter, alphasort);
if (n < 0) if (n < 0)
lxc_log_syserror("failed to scan %s directory", dirname); SYSERROR("failed to scan %s directory", dirname);
return n == 0; return n == 0;
} }
...@@ -57,14 +60,14 @@ static int create_lxc_directory(const char *dirname) ...@@ -57,14 +60,14 @@ static int create_lxc_directory(const char *dirname)
char path[MAXPATHLEN]; char path[MAXPATHLEN];
if (mkdir(LXCPATH, 0755) && errno != EEXIST) { if (mkdir(LXCPATH, 0755) && errno != EEXIST) {
lxc_log_syserror("failed to create %s directory", LXCPATH); SYSERROR("failed to create %s directory", LXCPATH);
return -errno; return -errno;
} }
sprintf(path, LXCPATH "/%s", dirname); sprintf(path, LXCPATH "/%s", dirname);
if (mkdir(path, 0755)) { if (mkdir(path, 0755)) {
lxc_log_syserror("failed to create %s directory", path); SYSERROR("failed to create %s directory", path);
return -errno; return -errno;
} }
...@@ -78,13 +81,13 @@ static int remove_lxc_directory(const char *dirname) ...@@ -78,13 +81,13 @@ static int remove_lxc_directory(const char *dirname)
sprintf(path, LXCPATH "/%s", dirname); sprintf(path, LXCPATH "/%s", dirname);
if (rmdir(path)) { if (rmdir(path)) {
lxc_log_syserror("failed to remove %s directory", path); SYSERROR("failed to remove %s directory", path);
return -1; return -1;
} }
if (is_empty_directory(LXCPATH)) { if (is_empty_directory(LXCPATH)) {
if (rmdir(LXCPATH)) { if (rmdir(LXCPATH)) {
lxc_log_syserror("failed to remove %s directory", LXCPATH); SYSERROR("failed to remove %s directory", LXCPATH);
return -1; return -1;
} }
} }
...@@ -107,18 +110,18 @@ int lxc_create(const char *name, struct lxc_conf *conf) ...@@ -107,18 +110,18 @@ int lxc_create(const char *name, struct lxc_conf *conf)
err = LXC_ERROR_INTERNAL; err = LXC_ERROR_INTERNAL;
if (lxc_mkstate(name)) { 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; goto err;
} }
if (lxc_setstate(name, STOPPED)) { 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; goto err_state;
} }
err = lxc_configure(name, conf); err = lxc_configure(name, conf);
if (err) { if (err) {
lxc_log_error("failed to set configuration for %s", name); ERROR("failed to set configuration for %s", name);
goto err_state; goto err_state;
} }
...@@ -131,9 +134,9 @@ err_state: ...@@ -131,9 +134,9 @@ err_state:
lxc_unconfigure(name); lxc_unconfigure(name);
if (lxc_rmstate(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: err:
if (remove_lxc_directory(name)) 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; goto out;
} }
...@@ -31,6 +31,9 @@ ...@@ -31,6 +31,9 @@
#include "error.h" #include "error.h"
#include <lxc/lxc.h> #include <lxc/lxc.h>
#include <lxc/log.h>
lxc_log_define(lxc_destroy, lxc);
static int remove_lxc_directory(const char *dirname) static int remove_lxc_directory(const char *dirname)
{ {
...@@ -39,7 +42,7 @@ static int remove_lxc_directory(const char *dirname) ...@@ -39,7 +42,7 @@ static int remove_lxc_directory(const char *dirname)
sprintf(path, LXCPATH "/%s", dirname); sprintf(path, LXCPATH "/%s", dirname);
if (rmdir(path)) { if (rmdir(path)) {
lxc_log_syserror("failed to remove %s directory", path); SYSERROR("failed to remove %s directory", path);
return -1; return -1;
} }
...@@ -56,7 +59,7 @@ int lxc_destroy(const char *name) ...@@ -56,7 +59,7 @@ int lxc_destroy(const char *name)
return lock; return lock;
if (lxc_rmstate(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);
goto out_lock; goto out_lock;
} }
...@@ -65,12 +68,12 @@ int lxc_destroy(const char *name) ...@@ -65,12 +68,12 @@ int lxc_destroy(const char *name)
lxc_unlink_nsgroup(name); lxc_unlink_nsgroup(name);
if (lxc_unconfigure(name)) { if (lxc_unconfigure(name)) {
lxc_log_error("failed to cleanup %s", name); ERROR("failed to cleanup %s", name);
goto out_lock; goto out_lock;
} }
if (remove_lxc_directory(name)) { if (remove_lxc_directory(name)) {
lxc_log_syserror("failed to remove '%s'", name); SYSERROR("failed to remove '%s'", name);
goto out_lock; goto out_lock;
} }
......
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
#include "error.h" #include "error.h"
#include <lxc/lxc.h> #include <lxc/lxc.h>
#include <lxc/log.h>
lxc_log_define(lxc_freezer, lxc);
static int freeze_unfreeze(const char *name, int freeze) static int freeze_unfreeze(const char *name, int freeze)
{ {
...@@ -44,7 +47,7 @@ static int freeze_unfreeze(const char *name, int freeze) ...@@ -44,7 +47,7 @@ static int freeze_unfreeze(const char *name, int freeze)
fd = open(freezer, O_WRONLY); fd = open(freezer, O_WRONLY);
if (fd < 0) { if (fd < 0) {
lxc_log_syserror("failed to open freezer for '%s'", name); SYSERROR("failed to open freezer for '%s'", name);
return -1; return -1;
} }
...@@ -64,7 +67,7 @@ static int freeze_unfreeze(const char *name, int freeze) ...@@ -64,7 +67,7 @@ static int freeze_unfreeze(const char *name, int freeze)
close(fd); close(fd);
if (ret) if (ret)
lxc_log_syserror("failed to write to '%s'", freezer); SYSERROR("failed to write to '%s'", freezer);
return 0; return 0;
} }
......
...@@ -39,6 +39,9 @@ ...@@ -39,6 +39,9 @@
#include "error.h" #include "error.h"
#include "lxc.h" #include "lxc.h"
#include <lxc/log.h>
lxc_log_define(lxc_console, lxc);
void usage(char *cmd) void usage(char *cmd)
{ {
...@@ -77,7 +80,7 @@ int main(int argc, char *argv[]) ...@@ -77,7 +80,7 @@ int main(int argc, char *argv[])
/* Get current termios */ /* Get current termios */
if (tcgetattr(0, &tios)) { 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)); fprintf(stderr, "%s\n", lxc_strerror(err));
return 1; return 1;
} }
...@@ -94,7 +97,7 @@ int main(int argc, char *argv[]) ...@@ -94,7 +97,7 @@ int main(int argc, char *argv[])
/* Set new attributes */ /* Set new attributes */
if (tcsetattr(0, TCSAFLUSH, &tios)) { 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)); fprintf(stderr, "%s\n", lxc_strerror(err));
return 1; return 1;
} }
...@@ -126,7 +129,7 @@ int main(int argc, char *argv[]) ...@@ -126,7 +129,7 @@ int main(int argc, char *argv[])
if (poll(pfd, 2, -1) < 0) { if (poll(pfd, 2, -1) < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
lxc_log_syserror("failed to poll"); SYSERROR("failed to poll");
goto out_err; goto out_err;
} }
...@@ -134,7 +137,7 @@ int main(int argc, char *argv[]) ...@@ -134,7 +137,7 @@ int main(int argc, char *argv[])
*/ */
if (pfd[0].revents & POLLIN) { if (pfd[0].revents & POLLIN) {
if (read(0, &c, 1) < 0) { if (read(0, &c, 1) < 0) {
lxc_log_syserror("failed to read"); SYSERROR("failed to read");
goto out_err; goto out_err;
} }
...@@ -149,7 +152,7 @@ int main(int argc, char *argv[]) ...@@ -149,7 +152,7 @@ int main(int argc, char *argv[])
wait4q = 0; wait4q = 0;
if (write(master, &c, 1) < 0) { if (write(master, &c, 1) < 0) {
lxc_log_syserror("failed to write"); SYSERROR("failed to write");
goto out_err; goto out_err;
} }
} }
...@@ -161,7 +164,7 @@ int main(int argc, char *argv[]) ...@@ -161,7 +164,7 @@ int main(int argc, char *argv[])
/* read the master and write to "stdout" */ /* read the master and write to "stdout" */
if (pfd[1].revents & POLLIN) { if (pfd[1].revents & POLLIN) {
if (read(master, &c, 1) < 0) { if (read(master, &c, 1) < 0) {
lxc_log_syserror("failed to read"); SYSERROR("failed to read");
goto out_err; goto out_err;
} }
printf("%c", c); printf("%c", c);
......
...@@ -35,6 +35,9 @@ ...@@ -35,6 +35,9 @@
#include <net/if.h> #include <net/if.h>
#include <lxc/lxc.h> #include <lxc/lxc.h>
#include <lxc/log.h>
lxc_log_define(lxc_start, lxc);
void usage(char *cmd) void usage(char *cmd)
{ {
...@@ -76,7 +79,7 @@ int main(int argc, char *argv[]) ...@@ -76,7 +79,7 @@ int main(int argc, char *argv[])
usage(argv[0]); usage(argv[0]);
if (tcgetattr(0, &tios)) { 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)); fprintf(stderr, "%s\n", lxc_strerror(err));
return 1; return 1;
} }
...@@ -88,7 +91,7 @@ int main(int argc, char *argv[]) ...@@ -88,7 +91,7 @@ int main(int argc, char *argv[])
} }
if (tcsetattr(0, TCSAFLUSH, &tios)) if (tcsetattr(0, TCSAFLUSH, &tios))
lxc_log_syserror("failed to restore terminal attributes"); SYSERROR("failed to restore terminal attributes");
return err; return err;
} }
......
...@@ -38,6 +38,9 @@ ...@@ -38,6 +38,9 @@
#include "error.h" #include "error.h"
#include <lxc/lxc.h> #include <lxc/lxc.h>
#include <lxc/log.h>
lxc_log_define(lxc_monitor, lxc);
#ifndef UNIX_PATH_MAX #ifndef UNIX_PATH_MAX
#define UNIX_PATH_MAX 108 #define UNIX_PATH_MAX 108
...@@ -59,7 +62,7 @@ int lxc_monitor(const char *name, int output_fd) ...@@ -59,7 +62,7 @@ int lxc_monitor(const char *name, int output_fd)
nfd = inotify_init(); nfd = inotify_init();
if (nfd < 0) { if (nfd < 0) {
lxc_log_syserror("failed to initialize inotify"); SYSERROR("failed to initialize inotify");
return -1; return -1;
} }
...@@ -67,7 +70,7 @@ int lxc_monitor(const char *name, int output_fd) ...@@ -67,7 +70,7 @@ int lxc_monitor(const char *name, int output_fd)
wfd = inotify_add_watch(nfd, path, IN_DELETE_SELF|IN_CLOSE_WRITE); wfd = inotify_add_watch(nfd, path, IN_DELETE_SELF|IN_CLOSE_WRITE);
if (wfd < 0) { 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; goto out;
} }
...@@ -75,7 +78,7 @@ int lxc_monitor(const char *name, int output_fd) ...@@ -75,7 +78,7 @@ int lxc_monitor(const char *name, int output_fd)
struct inotify_event evt; struct inotify_event evt;
if (read(nfd, &evt, sizeof(evt)) < 0) { if (read(nfd, &evt, sizeof(evt)) < 0) {
lxc_log_syserror("failed to read inotify event"); SYSERROR("failed to read inotify event");
goto out; goto out;
} }
...@@ -83,13 +86,13 @@ int lxc_monitor(const char *name, int output_fd) ...@@ -83,13 +86,13 @@ int lxc_monitor(const char *name, int output_fd)
state = lxc_getstate(name); state = lxc_getstate(name);
if (state < 0) { if (state < 0) {
lxc_log_error("failed to get the state for %s", ERROR("failed to get the state for %s",
name); name);
goto out; goto out;
} }
if (write(output_fd, &state, sizeof(state)) < 0) { 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); output_fd);
goto out; goto out;
} }
...@@ -102,7 +105,7 @@ int lxc_monitor(const char *name, int output_fd) ...@@ -102,7 +105,7 @@ int lxc_monitor(const char *name, int 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; goto out;
} }
...@@ -119,7 +122,7 @@ static void lxc_monitor_send(struct lxc_msg *msg) ...@@ -119,7 +122,7 @@ static void lxc_monitor_send(struct lxc_msg *msg)
fd = socket(PF_NETLINK, SOCK_RAW, 0); fd = socket(PF_NETLINK, SOCK_RAW, 0);
if (fd < 0) { if (fd < 0) {
lxc_log_syserror("failed to create notification socket"); SYSERROR("failed to create notification socket");
return; return;
} }
...@@ -151,7 +154,7 @@ int lxc_monitor_open(void) ...@@ -151,7 +154,7 @@ int lxc_monitor_open(void)
fd = socket(PF_NETLINK, SOCK_RAW, 0); fd = socket(PF_NETLINK, SOCK_RAW, 0);
if (fd < 0) { if (fd < 0) {
lxc_log_syserror("failed to create notification socket"); SYSERROR("failed to create notification socket");
return -LXC_ERROR_INTERNAL; return -LXC_ERROR_INTERNAL;
} }
...@@ -162,7 +165,7 @@ int lxc_monitor_open(void) ...@@ -162,7 +165,7 @@ int lxc_monitor_open(void)
addr.nl_groups = MONITOR_MCGROUP; addr.nl_groups = MONITOR_MCGROUP;
if (bind(fd, (const struct sockaddr *)&addr, sizeof(addr))) { 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); addr.nl_groups);
close(fd); close(fd);
return -1; return -1;
...@@ -180,7 +183,7 @@ int lxc_monitor_read(int fd, struct lxc_msg *msg) ...@@ -180,7 +183,7 @@ int lxc_monitor_read(int fd, struct lxc_msg *msg)
ret = recvfrom(fd, msg, sizeof(*msg), 0, ret = recvfrom(fd, msg, sizeof(*msg), 0,
(struct sockaddr *)&from, &len); (struct sockaddr *)&from, &len);
if (ret < 0) { if (ret < 0) {
lxc_log_syserror("failed to received state"); SYSERROR("failed to received state");
return -LXC_ERROR_INTERNAL; return -LXC_ERROR_INTERNAL;
} }
......
...@@ -28,6 +28,9 @@ ...@@ -28,6 +28,9 @@
#include "parse.h" #include "parse.h"
#include "log.h" #include "log.h"
#include <lxc/log.h>
lxc_log_define(lxc_parse, lxc);
static int dir_filter(const struct dirent *dirent) static int dir_filter(const struct dirent *dirent)
{ {
...@@ -45,13 +48,13 @@ int lxc_dir_for_each(const char *name, const char *directory, ...@@ -45,13 +48,13 @@ int lxc_dir_for_each(const char *name, const char *directory,
n = scandir(directory, &namelist, dir_filter, alphasort); n = scandir(directory, &namelist, dir_filter, alphasort);
if (n < 0) { if (n < 0) {
lxc_log_syserror("failed to scan %s directory", directory); SYSERROR("failed to scan %s directory", directory);
return -1; return -1;
} }
while (n--) { while (n--) {
if (callback(name, directory, namelist[n]->d_name, data)) { if (callback(name, directory, namelist[n]->d_name, data)) {
lxc_log_error("callback failed"); ERROR("callback failed");
free(namelist[n]); free(namelist[n]);
return -1; return -1;
} }
...@@ -69,7 +72,7 @@ int lxc_file_for_each_line(const char *file, lxc_file_cb callback, ...@@ -69,7 +72,7 @@ int lxc_file_for_each_line(const char *file, lxc_file_cb callback,
f = fopen(file, "r"); f = fopen(file, "r");
if (!f) { if (!f) {
lxc_log_syserror("failed to open %s", file); SYSERROR("failed to open %s", file);
return -1; return -1;
} }
......
...@@ -40,6 +40,9 @@ ...@@ -40,6 +40,9 @@
#include "error.h" #include "error.h"
#include "lxc_plugin.h" #include "lxc_plugin.h"
#include <lxc/lxc.h> #include <lxc/lxc.h>
#include <lxc/log.h>
lxc_log_define(lxc_restart, lxc);
LXC_TTY_HANDLER(SIGINT); LXC_TTY_HANDLER(SIGINT);
LXC_TTY_HANDLER(SIGQUIT); LXC_TTY_HANDLER(SIGQUIT);
...@@ -60,19 +63,19 @@ int lxc_restart(const char *name, const char *statefile, ...@@ -60,19 +63,19 @@ int lxc_restart(const char *name, const char *statefile,
/* Begin the set the state to STARTING*/ /* Begin the set the state to STARTING*/
if (lxc_setstate(name, STARTING)) { if (lxc_setstate(name, STARTING)) {
lxc_log_error("failed to set state %s", ERROR("failed to set state %s",
lxc_state2str(STARTING)); lxc_state2str(STARTING));
goto out; goto out;
} }
if (ttyname_r(0, tty, sizeof(tty))) { if (ttyname_r(0, tty, sizeof(tty))) {
tty[0] = '\0'; tty[0] = '\0';
lxc_log_warning("failed to get tty name"); WARN("failed to get tty name");
} }
/* Synchro socketpair */ /* Synchro socketpair */
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sv)) { if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sv)) {
lxc_log_syserror("failed to create communication socketpair"); SYSERROR("failed to create communication socketpair");
goto out; goto out;
} }
...@@ -89,7 +92,7 @@ int lxc_restart(const char *name, const char *statefile, ...@@ -89,7 +92,7 @@ int lxc_restart(const char *name, const char *statefile,
/* Create a process in a new set of namespaces */ /* Create a process in a new set of namespaces */
pid = fork_ns(clone_flags); pid = fork_ns(clone_flags);
if (pid < 0) { 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; goto err_fork_ns;
} }
...@@ -102,30 +105,30 @@ int lxc_restart(const char *name, const char *statefile, ...@@ -102,30 +105,30 @@ int lxc_restart(const char *name, const char *statefile,
/* Tell our father he can begin to configure the container */ /* Tell our father he can begin to configure the container */
if (write(sv[0], &sync, sizeof(sync)) < 0) { if (write(sv[0], &sync, sizeof(sync)) < 0) {
lxc_log_syserror("failed to write socket"); SYSERROR("failed to write socket");
return 1; return 1;
} }
/* Wait for the father to finish the configuration */ /* Wait for the father to finish the configuration */
if (read(sv[0], &sync, sizeof(sync)) < 0) { if (read(sv[0], &sync, sizeof(sync)) < 0) {
lxc_log_syserror("failed to read socket"); SYSERROR("failed to read socket");
return 1; return 1;
} }
/* Setup the container, ip, names, utsname, ... */ /* Setup the container, ip, names, utsname, ... */
if (lxc_setup(name, tty, &tty_info)) { 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) if (write(sv[0], &sync, sizeof(sync)) < 0)
lxc_log_syserror("failed to write the socket"); SYSERROR("failed to write the socket");
return -1; return -1;
} }
lxc_plugin_restart(getpid(), statefile, flags); 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 the exec fails, tell that to our father */
if (write(sv[0], &sync, sizeof(sync)) < 0) if (write(sv[0], &sync, sizeof(sync)) < 0)
lxc_log_syserror("failed to write the socket"); SYSERROR("failed to write the socket");
exit(1); exit(1);
} }
...@@ -134,62 +137,62 @@ int lxc_restart(const char *name, const char *statefile, ...@@ -134,62 +137,62 @@ int lxc_restart(const char *name, const char *statefile,
/* Wait for the child to be ready */ /* Wait for the child to be ready */
if (read(sv[1], &sync, sizeof(sync)) < 0) { 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; goto err_pipe_read;
} }
/* Create the network configuration */ /* Create the network configuration */
if (clone_flags & CLONE_NEWNET && conf_create_network(name, pid)) { 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; goto err_create_network;
} }
/* Tell the child to continue its initialization */ /* Tell the child to continue its initialization */
if (write(sv[1], &sync, sizeof(sync)) < 0) { 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; goto err_pipe_write;
} }
/* Wait for the child to exec or returning an error */ /* Wait for the child to exec or returning an error */
err = read(sv[1], &sync, sizeof(sync)); err = read(sv[1], &sync, sizeof(sync));
if (err < 0) { if (err < 0) {
lxc_log_error("failed to read the socket"); ERROR("failed to read the socket");
goto err_pipe_read2; goto err_pipe_read2;
} }
if (err > 0) { if (err > 0) {
lxc_log_error("something went wrong with %d", pid); ERROR("something went wrong with %d", pid);
/* TODO : check status etc ... */ /* TODO : check status etc ... */
waitpid(pid, NULL, 0); waitpid(pid, NULL, 0);
goto err_child_failed; goto err_child_failed;
} }
if (!asprintf(&val, "%d\n", pid)) { if (!asprintf(&val, "%d\n", pid)) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
goto err_child_failed; goto err_child_failed;
} }
if (!asprintf(&init, LXCPATH "/%s/init", name)) { if (!asprintf(&init, LXCPATH "/%s/init", name)) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
goto err_child_failed; goto err_child_failed;
} }
fd = open(init, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); fd = open(init, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
if (fd < 0) { if (fd < 0) {
lxc_log_syserror("failed to open '%s'", init); SYSERROR("failed to open '%s'", init);
goto err_write; goto err_write;
} }
if (write(fd, val, strlen(val)) < 0) { 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; goto err_write;
} }
close(fd); close(fd);
if (lxc_link_nsgroup(name, pid)) 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)) { if (lxc_setstate(name, RUNNING)) {
lxc_log_error("failed to set state to %s", ERROR("failed to set state to %s",
lxc_state2str(RUNNING)); lxc_state2str(RUNNING));
goto err_state_failed; goto err_state_failed;
} }
...@@ -198,20 +201,20 @@ wait_again: ...@@ -198,20 +201,20 @@ wait_again:
if (waitpid(pid, NULL, 0) < 0) { if (waitpid(pid, NULL, 0) < 0) {
if (errno == EINTR) if (errno == EINTR)
goto wait_again; 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; goto err_waitpid_failed;
} }
if (lxc_setstate(name, STOPPING)) 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)) 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; err = 0;
out: out:
if (lxc_setstate(name, STOPPED)) 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); lxc_unlink_nsgroup(name);
unlink(init); unlink(init);
...@@ -234,7 +237,7 @@ err_create_network: ...@@ -234,7 +237,7 @@ err_create_network:
err_pipe_read: err_pipe_read:
err_waitpid_failed: err_waitpid_failed:
if (lxc_setstate(name, ABORTING)) 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); kill(pid, SIGKILL);
err_fork_ns: err_fork_ns:
......
...@@ -91,6 +91,10 @@ int signalfd(int fd, const sigset_t *mask, int flags) ...@@ -91,6 +91,10 @@ int signalfd(int fd, const sigset_t *mask, int flags)
#include "mainloop.h" #include "mainloop.h"
#include <lxc/lxc.h> #include <lxc/lxc.h>
#include <lxc/log.h>
lxc_log_define(lxc_start, lxc);
LXC_TTY_HANDLER(SIGINT); LXC_TTY_HANDLER(SIGINT);
LXC_TTY_HANDLER(SIGQUIT); LXC_TTY_HANDLER(SIGQUIT);
...@@ -101,23 +105,23 @@ static int setup_sigchld_fd(sigset_t *oldmask) ...@@ -101,23 +105,23 @@ static int setup_sigchld_fd(sigset_t *oldmask)
int fd; int fd;
if (sigprocmask(SIG_BLOCK, NULL, &mask)) { if (sigprocmask(SIG_BLOCK, NULL, &mask)) {
lxc_log_syserror("failed to get mask signal"); SYSERROR("failed to get mask signal");
return -1; return -1;
} }
if (sigaddset(&mask, SIGCHLD) || sigprocmask(SIG_BLOCK, &mask, oldmask)) { 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; return -1;
} }
fd = signalfd(-1, &mask, 0); fd = signalfd(-1, &mask, 0);
if (fd < 0) { if (fd < 0) {
lxc_log_syserror("failed to create the signal fd"); SYSERROR("failed to create the signal fd");
return -1; return -1;
} }
if (fcntl(fd, F_SETFD, FD_CLOEXEC)) { 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); close(fd);
return -1; return -1;
} }
...@@ -139,7 +143,7 @@ static int setup_tty_service(const char *name, int *ttyfd) ...@@ -139,7 +143,7 @@ static int setup_tty_service(const char *name, int *ttyfd)
return -1; return -1;
if (fcntl(fd, F_SETFD, FD_CLOEXEC)) { 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); close(fd);
return -1; return -1;
} }
...@@ -186,12 +190,12 @@ static int ttyservice_handler(int fd, void *data, ...@@ -186,12 +190,12 @@ static int ttyservice_handler(int fd, void *data,
conn = accept(fd, NULL, 0); conn = accept(fd, NULL, 0);
if (conn < 0) { if (conn < 0) {
lxc_log_syserror("failed to accept tty client"); SYSERROR("failed to accept tty client");
return -1; return -1;
} }
if (setsockopt(conn, SOL_SOCKET, SO_PASSCRED, &val, sizeof(val))) { 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; goto out_close;
} }
...@@ -209,13 +213,13 @@ static int ttyservice_handler(int fd, void *data, ...@@ -209,13 +213,13 @@ static int ttyservice_handler(int fd, void *data,
if (lxc_af_unix_send_fd(conn, tty_info->pty_info[ttynum].master, if (lxc_af_unix_send_fd(conn, tty_info->pty_info[ttynum].master,
NULL, 0) < 0) { NULL, 0) < 0) {
lxc_log_error("failed to send tty to client"); ERROR("failed to send tty to client");
goto out_close; goto out_close;
} }
if (lxc_mainloop_add_handler(descr, conn, if (lxc_mainloop_add_handler(descr, conn,
ttyclient_handler, tty_info)) { ttyclient_handler, tty_info)) {
lxc_log_error("failed to add tty client handler"); ERROR("failed to add tty client handler");
goto out_close; goto out_close;
} }
...@@ -237,7 +241,7 @@ static int mainloop(const char *name, pid_t pid, int sigfd, ...@@ -237,7 +241,7 @@ static int mainloop(const char *name, pid_t pid, int sigfd,
struct lxc_epoll_descr descr; struct lxc_epoll_descr descr;
if (tty_info->nbtty && setup_tty_service(name, &ttyfd)) { 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; goto out_sigfd;
} }
...@@ -246,12 +250,12 @@ static int mainloop(const char *name, pid_t pid, int sigfd, ...@@ -246,12 +250,12 @@ static int mainloop(const char *name, pid_t pid, int sigfd,
nfds = tty_info->nbtty + 1 + tty_info->nbtty ? 1 : 0; nfds = tty_info->nbtty + 1 + tty_info->nbtty ? 1 : 0;
if (lxc_mainloop_open(nfds, &descr)) { if (lxc_mainloop_open(nfds, &descr)) {
lxc_log_error("failed to create mainloop"); ERROR("failed to create mainloop");
goto out_ttyfd; goto out_ttyfd;
} }
if (lxc_mainloop_add_handler(&descr, sigfd, sigchld_handler, &pid)) { 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; goto out_mainloop_open;
} }
...@@ -259,7 +263,7 @@ static int mainloop(const char *name, pid_t pid, int sigfd, ...@@ -259,7 +263,7 @@ static int mainloop(const char *name, pid_t pid, int sigfd,
if (lxc_mainloop_add_handler(&descr, ttyfd, if (lxc_mainloop_add_handler(&descr, ttyfd,
ttyservice_handler, ttyservice_handler,
(void *)tty_info)) { (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; goto out_mainloop_open;
} }
} }
...@@ -295,7 +299,7 @@ int lxc_start(const char *name, char *argv[]) ...@@ -295,7 +299,7 @@ int lxc_start(const char *name, char *argv[])
/* Begin the set the state to STARTING*/ /* Begin the set the state to STARTING*/
if (lxc_setstate(name, STARTING)) { if (lxc_setstate(name, STARTING)) {
lxc_log_error("failed to set state '%s'", ERROR("failed to set state '%s'",
lxc_state2str(STARTING)); lxc_state2str(STARTING));
goto out; goto out;
} }
...@@ -305,7 +309,7 @@ int lxc_start(const char *name, char *argv[]) ...@@ -305,7 +309,7 @@ int lxc_start(const char *name, char *argv[])
tty[0] = '\0'; tty[0] = '\0';
if (lxc_create_tty(name, &tty_info)) { if (lxc_create_tty(name, &tty_info)) {
lxc_log_error("failed to create the ttys"); ERROR("failed to create the ttys");
goto out; goto out;
} }
...@@ -314,13 +318,13 @@ int lxc_start(const char *name, char *argv[]) ...@@ -314,13 +318,13 @@ int lxc_start(const char *name, char *argv[])
* the event will be lost and the command will be stuck */ * the event will be lost and the command will be stuck */
sigfd = setup_sigchld_fd(&oldmask); sigfd = setup_sigchld_fd(&oldmask);
if (sigfd < 0) { if (sigfd < 0) {
lxc_log_error("failed to set sigchild fd handler"); ERROR("failed to set sigchild fd handler");
return -1; return -1;
} }
/* Synchro socketpair */ /* Synchro socketpair */
if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sv)) { if (socketpair(AF_LOCAL, SOCK_STREAM, 0, sv)) {
lxc_log_syserror("failed to create communication socketpair"); SYSERROR("failed to create communication socketpair");
goto out; goto out;
} }
...@@ -337,14 +341,14 @@ int lxc_start(const char *name, char *argv[]) ...@@ -337,14 +341,14 @@ int lxc_start(const char *name, char *argv[])
/* Create a process in a new set of namespaces */ /* Create a process in a new set of namespaces */
pid = fork_ns(clone_flags); pid = fork_ns(clone_flags);
if (pid < 0) { 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; goto err_fork_ns;
} }
if (!pid) { if (!pid) {
if (sigprocmask(SIG_SETMASK, &oldmask, NULL)) { if (sigprocmask(SIG_SETMASK, &oldmask, NULL)) {
lxc_log_syserror("failed to set sigprocmask"); SYSERROR("failed to set sigprocmask");
return -1; return -1;
} }
...@@ -355,37 +359,37 @@ int lxc_start(const char *name, char *argv[]) ...@@ -355,37 +359,37 @@ int lxc_start(const char *name, char *argv[])
/* Tell our father he can begin to configure the container */ /* Tell our father he can begin to configure the container */
if (write(sv[0], &sync, sizeof(sync)) < 0) { if (write(sv[0], &sync, sizeof(sync)) < 0) {
lxc_log_syserror("failed to write socket"); SYSERROR("failed to write socket");
goto out_child; goto out_child;
} }
/* Wait for the father to finish the configuration */ /* Wait for the father to finish the configuration */
if (read(sv[0], &sync, sizeof(sync)) < 0) { if (read(sv[0], &sync, sizeof(sync)) < 0) {
lxc_log_syserror("failed to read socket"); SYSERROR("failed to read socket");
goto out_child; goto out_child;
} }
/* Setup the container, ip, names, utsname, ... */ /* Setup the container, ip, names, utsname, ... */
err = lxc_setup(name, tty, &tty_info); err = lxc_setup(name, tty, &tty_info);
if (err) { if (err) {
lxc_log_error("failed to setup the container"); ERROR("failed to setup the container");
if (write(sv[0], &err, sizeof(err)) < 0) 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; goto out_child;
} }
if (prctl(PR_CAPBSET_DROP, CAP_SYS_BOOT, 0, 0, 0)) { 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; goto out_child;
} }
execvp(argv[0], argv); 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; err = LXC_ERROR_WRONG_COMMAND;
/* If the exec fails, tell that to our father */ /* If the exec fails, tell that to our father */
if (write(sv[0], &err, sizeof(err)) < 0) if (write(sv[0], &err, sizeof(err)) < 0)
lxc_log_syserror("failed to write the socket"); SYSERROR("failed to write the socket");
out_child: out_child:
exit(err); exit(err);
...@@ -395,29 +399,29 @@ int lxc_start(const char *name, char *argv[]) ...@@ -395,29 +399,29 @@ int lxc_start(const char *name, char *argv[])
/* Wait for the child to be ready */ /* Wait for the child to be ready */
if (read(sv[1], &sync, sizeof(sync)) < 0) { 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; goto err_pipe_read;
} }
if (lxc_link_nsgroup(name, pid)) if (lxc_link_nsgroup(name, pid))
lxc_log_warning("cgroupfs not found: cgroup disabled"); WARN("cgroupfs not found: cgroup disabled");
/* Create the network configuration */ /* Create the network configuration */
if (clone_flags & CLONE_NEWNET && conf_create_network(name, pid)) { 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; goto err_create_network;
} }
/* Tell the child to continue its initialization */ /* Tell the child to continue its initialization */
if (write(sv[1], &sync, sizeof(sync)) < 0) { 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; goto err_pipe_write;
} }
/* Wait for the child to exec or returning an error */ /* Wait for the child to exec or returning an error */
err = read(sv[1], &sync, sizeof(sync)); err = read(sv[1], &sync, sizeof(sync));
if (err < 0) { if (err < 0) {
lxc_log_error("failed to read the socket"); ERROR("failed to read the socket");
goto err_pipe_read2; goto err_pipe_read2;
} }
...@@ -428,7 +432,7 @@ int lxc_start(const char *name, char *argv[]) ...@@ -428,7 +432,7 @@ int lxc_start(const char *name, char *argv[])
} }
if (!asprintf(&val, "%d\n", pid)) { if (!asprintf(&val, "%d\n", pid)) {
lxc_log_syserror("failed to allocate memory"); SYSERROR("failed to allocate memory");
goto err_child_failed; goto err_child_failed;
} }
...@@ -436,38 +440,38 @@ int lxc_start(const char *name, char *argv[]) ...@@ -436,38 +440,38 @@ int lxc_start(const char *name, char *argv[])
fd = open(init, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); fd = open(init, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR);
if (fd < 0) { if (fd < 0) {
lxc_log_syserror("failed to open '%s'", init); SYSERROR("failed to open '%s'", init);
goto err_write; goto err_write;
} }
if (write(fd, val, strlen(val)) < 0) { 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; goto err_write;
} }
close(fd); close(fd);
if (lxc_setstate(name, RUNNING)) { if (lxc_setstate(name, RUNNING)) {
lxc_log_error("failed to set state to %s", ERROR("failed to set state to %s",
lxc_state2str(RUNNING)); lxc_state2str(RUNNING));
goto err_state_failed; goto err_state_failed;
} }
if (mainloop(name, pid, sigfd, &tty_info)) { 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; goto err_mailoop_failed;
} }
if (lxc_setstate(name, STOPPING)) 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)) 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; err = 0;
out: out:
if (lxc_setstate(name, STOPPED)) 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_delete_tty(&tty_info);
lxc_unlink_nsgroup(name); lxc_unlink_nsgroup(name);
...@@ -492,7 +496,7 @@ err_create_network: ...@@ -492,7 +496,7 @@ err_create_network:
err_pipe_read: err_pipe_read:
err_mailoop_failed: err_mailoop_failed:
if (lxc_setstate(name, ABORTING)) 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); kill(pid, SIGKILL);
err_fork_ns: err_fork_ns:
......
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
#include <sys/file.h> #include <sys/file.h>
#include <lxc/lxc.h> #include <lxc/lxc.h>
#include <lxc/log.h>
lxc_log_define(lxc_state, lxc);
static char *strstate[] = { static char *strstate[] = {
"STOPPED", "STARTING", "RUNNING", "STOPPING", "STOPPED", "STARTING", "RUNNING", "STOPPING",
...@@ -68,22 +71,22 @@ int lxc_setstate(const char *name, lxc_state_t state) ...@@ -68,22 +71,22 @@ int lxc_setstate(const char *name, lxc_state_t state)
fd = open(file, O_WRONLY); fd = open(file, O_WRONLY);
if (fd < 0) { if (fd < 0) {
lxc_log_syserror("failed to open %s file", file); SYSERROR("failed to open %s file", file);
return -1; return -1;
} }
if (flock(fd, LOCK_EX)) { 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; goto out;
} }
if (ftruncate(fd, 0)) { if (ftruncate(fd, 0)) {
lxc_log_syserror("failed to truncate the file %s", file); SYSERROR("failed to truncate the file %s", file);
goto out; goto out;
} }
if (write(fd, str, strlen(str)) < 0) { 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; goto out;
} }
...@@ -104,7 +107,7 @@ int lxc_mkstate(const char *name) ...@@ -104,7 +107,7 @@ int lxc_mkstate(const char *name)
snprintf(file, MAXPATHLEN, LXCPATH "/%s/state", name); snprintf(file, MAXPATHLEN, LXCPATH "/%s/state", name);
fd = creat(file, S_IRUSR|S_IWUSR); fd = creat(file, S_IRUSR|S_IWUSR);
if (fd < 0) { if (fd < 0) {
lxc_log_syserror("failed to create file %s", file); SYSERROR("failed to create file %s", file);
return -1; return -1;
} }
close(fd); close(fd);
...@@ -128,19 +131,19 @@ lxc_state_t lxc_getstate(const char *name) ...@@ -128,19 +131,19 @@ lxc_state_t lxc_getstate(const char *name)
fd = open(file, O_RDONLY); fd = open(file, O_RDONLY);
if (fd < 0) { if (fd < 0) {
lxc_log_syserror("failed to open %s", file); SYSERROR("failed to open %s", file);
return -1; return -1;
} }
if (flock(fd, LOCK_SH)) { 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); close(fd);
return -1; return -1;
} }
err = read(fd, file, strlen(file)); err = read(fd, file, strlen(file));
if (err < 0) { if (err < 0) {
lxc_log_syserror("failed to read file %s", file); SYSERROR("failed to read file %s", file);
close(fd); close(fd);
return -1; return -1;
} }
...@@ -168,7 +171,7 @@ static int freezer_state(const char *name) ...@@ -168,7 +171,7 @@ static int freezer_state(const char *name)
fclose(file); fclose(file);
if (err == EOF) { if (err == EOF) {
lxc_log_syserror("failed to read %s", freezer); SYSERROR("failed to read %s", freezer);
return -1; return -1;
} }
......
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,9 @@
#include <fcntl.h> #include <fcntl.h>
#include <lxc/lxc.h> #include <lxc/lxc.h>
#include <lxc/log.h>
lxc_log_define(lxc_stop, lxc);
#define MAXPIDLEN 20 #define MAXPIDLEN 20
...@@ -54,19 +57,19 @@ int lxc_stop(const char *name) ...@@ -54,19 +57,19 @@ int lxc_stop(const char *name)
snprintf(init, MAXPATHLEN, LXCPATH "/%s/init", name); snprintf(init, MAXPATHLEN, LXCPATH "/%s/init", name);
fd = open(init, O_RDONLY); fd = open(init, O_RDONLY);
if (fd < 0) { 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; goto out_close;
} }
if (read(fd, val, sizeof(val)) < 0) { if (read(fd, val, sizeof(val)) < 0) {
lxc_log_syserror("failed to read %s", init); SYSERROR("failed to read %s", init);
goto out_close; goto out_close;
} }
pid = atoi(val); pid = atoi(val);
if (kill(pid, SIGKILL)) { if (kill(pid, SIGKILL)) {
lxc_log_syserror("failed to kill %zd", pid); SYSERROR("failed to kill %zd", pid);
goto out_close; goto out_close;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment