remove fprintf to stderr and replace by ERROR call when needed

do it in all cli, except:
* the usage functions that will be removed by another patch
* the lxc_init that need more work
* the lxc_priority that is not used anymore

Signed-off-by: Michel Normand <normand@fr.ibm.com>
Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
Michel Normand 2009-05-14 15:52:03 +02:00 committed by Daniel Lezcano
parent 2e71498422
commit 3ab87b66af
16 changed files with 53 additions and 85 deletions

View File

@ -1235,7 +1235,7 @@ static int setup_hw_addr(char *hwaddr, const char *ifname)
int ret, fd;
if (lxc_convert_mac(hwaddr, &sockaddr)) {
fprintf(stderr, "conversion has failed\n");
ERROR("conversion has failed");
return -1;
}
@ -1244,14 +1244,14 @@ static int setup_hw_addr(char *hwaddr, const char *ifname)
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;
}

View File

@ -28,6 +28,8 @@
#include <lxc/lxc.h>
lxc_log_define(lxc_cgroup, lxc);
void usage(char *cmd)
{
fprintf(stderr, "%s <subsystem> [value]\n", basename(cmd));
@ -62,7 +64,7 @@ int main(int argc, char *argv[])
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;
}
@ -70,7 +72,7 @@ int main(int argc, char *argv[])
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;
}

View File

@ -61,30 +61,22 @@ int main(int argc, char *argv[])
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;
}

View File

@ -81,8 +81,8 @@ int main(int argc, char *argv[])
/* 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;
}
@ -98,16 +98,14 @@ int main(int argc, char *argv[])
/* 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");
@ -184,7 +182,6 @@ out:
return err;
out_err:
fprintf(stderr, "%s\n", lxc_strerror(-LXC_ERROR_INTERNAL));
err = 1;
goto out;
}

View File

@ -62,21 +62,13 @@ int main(int argc, char *argv[])
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;
}

View File

@ -55,10 +55,8 @@ int main(int argc, char *argv[])
usage(argv[0]);
err = lxc_destroy(name);
if (err) {
fprintf(stderr, "%s\n", lxc_strerror(err));
if (err)
return 1;
}
return 0;
}

View File

@ -33,6 +33,8 @@
#include <lxc/lxc.h>
#include "confile.h"
lxc_log_define(lxc_execute, lxc);
void usage(char *cmd)
{
fprintf(stderr, "%s <command>\n", basename(cmd));
@ -70,29 +72,23 @@ int main(int argc, char *argv[])
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;
}
@ -106,7 +102,8 @@ int main(int argc, char *argv[])
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;
}
@ -114,7 +111,8 @@ int main(int argc, char *argv[])
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;
}
}

View File

@ -54,10 +54,8 @@ int main(int argc, char *argv[])
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;
}

View File

@ -53,10 +53,8 @@ int main(int argc, char *argv[])
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));

View File

@ -29,6 +29,8 @@
#include <lxc/lxc.h>
lxc_log_define(monitor, lxc);
void usage(char *cmd)
{
fprintf(stderr, "%s <command>\n", basename(cmd));
@ -59,24 +61,17 @@ int main(int argc, char *argv[])
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;

View File

@ -27,6 +27,8 @@
#include <lxc.h>
lxc_log_define(lxc_restart, lxc);
void usage(char *cmd)
{
fprintf(stderr, "%s <statefile>\n", basename(cmd));
@ -56,7 +58,7 @@ int main(int argc, char *argv[])
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;
}

View File

@ -79,19 +79,20 @@ int main(int argc, char *argv[])
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;
}

View File

@ -52,10 +52,8 @@ int main(int argc, char *argv[])
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;
}

View File

@ -28,6 +28,8 @@
#include <lxc/lxc.h>
lxc_log_define(lxc_wait, lxc);
void usage(char *cmd)
{
fprintf(stderr, "%s <command>\n", basename(cmd));
@ -77,24 +79,17 @@ int main(int argc, char *argv[])
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;
@ -102,7 +97,7 @@ int main(int argc, char *argv[])
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;
}

View File

@ -183,7 +183,7 @@ int lxc_monitor_read(int fd, struct lxc_msg *msg)
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;
}

View File

@ -55,6 +55,8 @@ lxc_state_t lxc_str2state(const char *state)
for (i = 0; i < len; i++)
if (!strcmp(strstate[i], state))
return i;
ERROR("invalid specified state %s", state);
return -1;
}