int ret, fd;
if (lxc_convert_mac(hwaddr, &sockaddr)) {
- fprintf(stderr, "conversion has failed\n");
+ ERROR("conversion has failed");
return -1;
}
fd = socket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0) {
- perror("socket");
+ ERROR("socket failure : %s", strerror(errno));
return -1;
}
ret = ioctl(fd, SIOCSIFHWADDR, &ifr);
close(fd);
if (ret)
- perror("ioctl");
+ ERROR("ioctl failure : %s", strerror(errno));
return ret;
}
#include <lxc/lxc.h>
+lxc_log_define(lxc_cgroup, lxc);
+
void usage(char *cmd)
{
fprintf(stderr, "%s <subsystem> [value]\n", basename(cmd));
if (value) {
if (lxc_cgroup_set(name, subsystem, value)) {
- fprintf(stderr, "failed to assign '%s' value to '%s' for '%s'\n",
+ ERROR("failed to assign '%s' value to '%s' for '%s'\n",
value, subsystem, name);
return 1;
}
const unsigned long len = 4096;
char buffer[len];
if (lxc_cgroup_get(name, subsystem, buffer, len)) {
- fprintf(stderr, "failed to retrieve value of '%s' for '%s'\n",
+ ERROR("failed to retrieve value of '%s' for '%s'\n",
subsystem, name);
return 1;
}
if (!argv[1])
usage(argv[0]);
- if (lxc_freeze(name)) {
- fprintf(stderr, "failed to freeze '%s'\n", name);
+ if (lxc_freeze(name))
return -1;
- }
- if (lxc_checkpoint(name, argv[1], 0)) {
- fprintf(stderr, "failed to checkpoint %s\n", name);
+ if (lxc_checkpoint(name, argv[1], 0))
goto out;
- }
if (stop) {
- if (lxc_stop(name)) {
- fprintf(stderr, "failed to stop '%s'\n", name);
+ if (lxc_stop(name))
goto out;
- }
}
ret = 0;
out:
- if (lxc_unfreeze(name)) {
- fprintf(stderr, "failed to unfreeze '%s'\n", name);
+ if (lxc_unfreeze(name))
return 1;
- }
return ret;
}
/* Get current termios */
if (tcgetattr(0, &tios)) {
- ERROR("failed to get current terminal settings");
- fprintf(stderr, "%s\n", lxc_strerror(err));
+ ERROR("failed to get current terminal settings : %s",
+ strerror(errno));
return 1;
}
/* Set new attributes */
if (tcsetattr(0, TCSAFLUSH, &tios)) {
- SYSERROR("failed to set new terminal settings");
- fprintf(stderr, "%s\n", lxc_strerror(err));
+ ERROR("failed to set new terminal settings : %s",
+ strerror(errno));
return 1;
}
err = lxc_console(name, ttynum, &master);
- if (err) {
- fprintf(stderr, "%s\n", lxc_strerror(err));
+ if (err)
goto out;
- }
fprintf(stderr, "\nType <Ctrl+a q> to exit the console\n");
return err;
out_err:
- fprintf(stderr, "%s\n", lxc_strerror(-LXC_ERROR_INTERNAL));
err = 1;
goto out;
}
if (!name)
usage(argv[0]);
- if (lxc_conf_init(&lxc_conf)) {
- fprintf(stderr, "failed to initialize the configuration\n");
- return 1;
- }
- if (file && lxc_config_read(file, &lxc_conf)) {
- fprintf(stderr, "invalid configuration file\n");
+ if (file && lxc_config_read(file, &lxc_conf))
return 1;
- }
err = lxc_create(name, &lxc_conf);
- if (err) {
- fprintf(stderr, "%s\n", lxc_strerror(err));
+ if (err)
return 1;
- }
return 0;
}
usage(argv[0]);
err = lxc_destroy(name);
- if (err) {
- fprintf(stderr, "%s\n", lxc_strerror(err));
+ if (err)
return 1;
- }
return 0;
}
#include <lxc/lxc.h>
#include "confile.h"
+lxc_log_define(lxc_execute, lxc);
+
void usage(char *cmd)
{
fprintf(stderr, "%s <command>\n", basename(cmd));
argc -= nbargs;
- if (lxc_conf_init(&lxc_conf)) {
- fprintf(stderr, "failed to initialize the configuration\n");
+ if (lxc_conf_init(&lxc_conf))
goto out;
- }
- if (file && lxc_config_read(file, &lxc_conf)) {
- fprintf(stderr, "invalid configuration file\n");
+ if (file && lxc_config_read(file, &lxc_conf))
goto out;
- }
snprintf(path, MAXPATHLEN, LXCPATH "/%s", name);
if (access(path, R_OK)) {
- if (lxc_create(name, &lxc_conf)) {
- fprintf(stderr, "failed to create the container '%s'\n", name);
+ if (lxc_create(name, &lxc_conf))
goto out;
- }
autodestroy = 1;
}
/* lxc-init --mount-procfs -- .... */
args = malloc((argc + 3)*sizeof(*args));
if (!args) {
- fprintf(stderr, "failed to allocate memory for '%s'\n", name);
+ ERROR("failed to allocate memory for '%s'\n", name);
goto out;
}
ret = lxc_start(name, args);
if (ret) {
- fprintf(stderr, "%s\n", lxc_strerror(ret));
+ ERROR("failed to start '%s': %s\n", name,
+ lxc_strerror(ret));
goto out;
}
out:
if (autodestroy) {
if (lxc_destroy(name)) {
- fprintf(stderr, "failed to destroy '%s'\n", name);
+ ERROR("failed to destroy '%s': %s\n",
+ name, lxc_strerror(ret));
ret = 1;
}
}
if (!name)
usage(argv[0]);
- if (lxc_freeze(name)) {
- fprintf(stderr, "failed to freeze '%s'\n", name);
+ if (lxc_freeze(name))
return 1;
- }
return 0;
}
usage(argv[0]);
state = lxc_getstate(name);
- if (state < 0) {
- fprintf(stderr, "failed to freeze '%s'\n", name);
+ if (state < 0)
return 1;
- }
printf("'%s' is %s\n", name, lxc_state2str(state));
#include <lxc/lxc.h>
+lxc_log_define(monitor, lxc);
+
void usage(char *cmd)
{
fprintf(stderr, "%s <command>\n", basename(cmd));
sprintf(regexp, "^%s$", name);
if (regcomp(&preg, regexp, REG_NOSUB|REG_EXTENDED)) {
- fprintf(stderr, "failed to compile the regex '%s'\n",
- name);
+ ERROR("failed to compile the regex '%s'", name);
return 1;
}
fd = lxc_monitor_open();
- if (fd < 0) {
- fprintf(stderr, "failed to open monitor for '%s'\n", name);
+ if (fd < 0)
return -1;
- }
for (;;) {
- if (lxc_monitor_read(fd, &msg) < 0) {
- fprintf(stderr,
- "failed to read monitor's message for '%s'\n",
- name);
+ if (lxc_monitor_read(fd, &msg) < 0)
return -1;
- }
if (regexec(&preg, msg.name, 0, NULL, 0))
continue;
#include <lxc.h>
+lxc_log_define(lxc_restart, lxc);
+
void usage(char *cmd)
{
fprintf(stderr, "%s <statefile>\n", basename(cmd));
usage(argv[0]);
if (lxc_restart(name, argv[1], 0)) {
- fprintf(stderr, "failed to restart %s\n", name);
+ ERROR("failed to restart %s", name);
return 1;
}
usage(argv[0]);
if (tcgetattr(0, &tios)) {
- ERROR("failed to get current terminal settings");
- fprintf(stderr, "%s\n", lxc_strerror(err));
+ ERROR("failed to get current terminal settings : %s",
+ strerror(errno));
return 1;
}
err = lxc_start(name, args);
if (err) {
- fprintf(stderr, "%s\n", lxc_strerror(err));
+ ERROR("failed to start : %s\n", lxc_strerror(err));
err = 1;
}
if (tcsetattr(0, TCSAFLUSH, &tios))
- SYSERROR("failed to restore terminal attributes");
+ ERROR("failed to restore terminal settings : %s",
+ strerror(errno));
return err;
}
if (!name)
usage(argv[0]);
- if (lxc_unfreeze(name)) {
- fprintf(stderr, "failed to freeze '%s'\n", name);
+ if (lxc_unfreeze(name))
return 1;
- }
return 0;
}
#include <lxc/lxc.h>
+lxc_log_define(lxc_wait, lxc);
+
void usage(char *cmd)
{
fprintf(stderr, "%s <command>\n", basename(cmd));
usage(argv[0]);
if (fillwaitedstates(states, s)) {
- fprintf(stderr, "invalid states specified\n");
usage(argv[0]);
}
fd = lxc_monitor_open();
- if (fd < 0) {
- fprintf(stderr, "failed to open monitor for '%s'\n", name);
+ if (fd < 0)
return -1;
- }
for (;;) {
- if (lxc_monitor_read(fd, &msg) < 0) {
- fprintf(stderr,
- "failed to read monitor's message for '%s'\n",
- name);
+ if (lxc_monitor_read(fd, &msg) < 0)
return -1;
- }
if (strcmp(name, msg.name))
continue;
switch (msg.type) {
case lxc_msg_state:
if (msg.value < 0 || msg.value >= MAX_STATE) {
- fprintf(stderr, "Receive an invalid state number '%d'\n",
+ ERROR("Receive an invalid state number '%d'",
msg.value);
return -1;
}
ret = recvfrom(fd, msg, sizeof(*msg), 0,
(struct sockaddr *)&from, &len);
if (ret < 0) {
- SYSERROR("failed to received state");
+ SYSERROR("failed to receive state");
return -LXC_ERROR_INTERNAL;
}
for (i = 0; i < len; i++)
if (!strcmp(strstate[i], state))
return i;
+
+ ERROR("invalid specified state %s", state);
return -1;
}