cleanup of some direct stderr logging

* qemud/qemud.c src/console.c src/network_driver.c
  src/node_device_conf.c src/node_device_hal.c src/storage_conf.c
  src/util.c: cleanup of some direct stderr logging
daniel
This commit is contained in:
Daniel Veillard 2009-05-20 13:37:30 +00:00
parent d879d360eb
commit e8da987570
8 changed files with 56 additions and 69 deletions

View File

@ -1,3 +1,9 @@
Wed May 20 15:35:35 CEST 2009 Daniel Veillard <veillard@redhat.com>
* qemud/qemud.c src/console.c src/network_driver.c
src/node_device_conf.c src/node_device_hal.c src/storage_conf.c
src/util.c: cleanup of some direct stderr logging
Wed May 20 15:33:27 CEST 2009 Daniel Veillard <veillard@redhat.com> Wed May 20 15:33:27 CEST 2009 Daniel Veillard <veillard@redhat.com>
* src/pci.c: small portability patch * src/pci.c: small portability patch

View File

@ -2673,13 +2673,13 @@ qemudSetupPrivs (void)
if (__init_daemon_priv (PU_RESETGROUPS | PU_CLEARLIMITSET, if (__init_daemon_priv (PU_RESETGROUPS | PU_CLEARLIMITSET,
SYSTEM_UID, SYSTEM_UID, PRIV_XVM_CONTROL, NULL)) { SYSTEM_UID, SYSTEM_UID, PRIV_XVM_CONTROL, NULL)) {
fprintf (stderr, "additional privileges are required\n"); VIR_ERROR0(_("additional privileges are required\n"));
return -1; return -1;
} }
if (priv_set (PRIV_OFF, PRIV_ALLSETS, PRIV_FILE_LINK_ANY, PRIV_PROC_INFO, if (priv_set (PRIV_OFF, PRIV_ALLSETS, PRIV_FILE_LINK_ANY, PRIV_PROC_INFO,
PRIV_PROC_SESSION, PRIV_PROC_EXEC, PRIV_PROC_FORK, NULL)) { PRIV_PROC_SESSION, PRIV_PROC_EXEC, PRIV_PROC_FORK, NULL)) {
fprintf (stderr, "failed to set reduced privileges\n"); VIR_ERROR0(_("failed to set reduced privileges\n"));
return -1; return -1;
} }

View File

@ -37,6 +37,7 @@
#include "console.h" #include "console.h"
#include "internal.h" #include "internal.h"
#include "logging.h"
#include "util.h" #include "util.h"
/* ie Ctrl-] as per telnet */ /* ie Ctrl-] as per telnet */
@ -72,8 +73,8 @@ int vshRunConsole(const char *tty) {
/* We do not want this to become the controlling TTY */ /* We do not want this to become the controlling TTY */
if ((ttyfd = open(tty, O_NOCTTY | O_RDWR)) < 0) { if ((ttyfd = open(tty, O_NOCTTY | O_RDWR)) < 0) {
fprintf(stderr, _("unable to open tty %s: %s\n"), VIR_ERROR(_("unable to open tty %s: %s\n"),
tty, strerror(errno)); tty, strerror(errno));
return -1; return -1;
} }
@ -83,8 +84,8 @@ int vshRunConsole(const char *tty) {
also ensure Ctrl-C, etc is blocked, and misc also ensure Ctrl-C, etc is blocked, and misc
other bits */ other bits */
if (tcgetattr(STDIN_FILENO, &ttyattr) < 0) { if (tcgetattr(STDIN_FILENO, &ttyattr) < 0) {
fprintf(stderr, _("unable to get tty attributes: %s\n"), VIR_ERROR(_("unable to get tty attributes: %s\n"),
strerror(errno)); strerror(errno));
goto closetty; goto closetty;
} }
@ -92,8 +93,8 @@ int vshRunConsole(const char *tty) {
cfmakeraw(&rawattr); cfmakeraw(&rawattr);
if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &rawattr) < 0) { if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &rawattr) < 0) {
fprintf(stderr, _("unable to set tty attributes: %s\n"), VIR_ERROR(_("unable to set tty attributes: %s\n"),
strerror(errno)); strerror(errno));
goto closetty; goto closetty;
} }
@ -127,8 +128,7 @@ int vshRunConsole(const char *tty) {
if (errno == EINTR || errno == EAGAIN) if (errno == EINTR || errno == EAGAIN)
continue; continue;
fprintf(stderr, _("failure waiting for I/O: %s\n"), VIR_ERROR(_("failure waiting for I/O: %s\n"), strerror(errno));
strerror(errno));
goto cleanup; goto cleanup;
} }
@ -142,8 +142,8 @@ int vshRunConsole(const char *tty) {
int got, sent = 0, destfd; int got, sent = 0, destfd;
if ((got = read(fds[i].fd, buf, sizeof(buf))) < 0) { if ((got = read(fds[i].fd, buf, sizeof(buf))) < 0) {
fprintf(stderr, _("failure reading input: %s\n"), VIR_ERROR(_("failure reading input: %s\n"),
strerror(errno)); strerror(errno));
goto cleanup; goto cleanup;
} }
@ -164,8 +164,8 @@ int vshRunConsole(const char *tty) {
int done; int done;
if ((done = safewrite(destfd, buf + sent, got - sent)) if ((done = safewrite(destfd, buf + sent, got - sent))
<= 0) { <= 0) {
fprintf(stderr, _("failure writing output: %s\n"), VIR_ERROR(_("failure writing output: %s\n"),
strerror(errno)); strerror(errno));
goto cleanup; goto cleanup;
} }
sent += done; sent += done;

View File

@ -56,6 +56,7 @@
#include "uuid.h" #include "uuid.h"
#include "iptables.h" #include "iptables.h"
#include "bridge.h" #include "bridge.h"
#include "logging.h"
#define NETWORK_PID_DIR LOCAL_STATE_DIR "/run/libvirt/network" #define NETWORK_PID_DIR LOCAL_STATE_DIR "/run/libvirt/network"
#define NETWORK_STATE_DIR LOCAL_STATE_DIR "/lib/libvirt/network" #define NETWORK_STATE_DIR LOCAL_STATE_DIR "/lib/libvirt/network"
@ -87,10 +88,6 @@ static void networkDriverUnlock(struct network_driver *driver)
static int networkShutdown(void); static int networkShutdown(void);
/* networkDebug statements should be changed to use this macro instead. */
#define networkLog(level, msg...) fprintf(stderr, msg)
static int networkStartNetworkDaemon(virConnectPtr conn, static int networkStartNetworkDaemon(virConnectPtr conn,
struct network_driver *driver, struct network_driver *driver,
virNetworkObjPtr network); virNetworkObjPtr network);
@ -173,10 +170,7 @@ networkAutostartConfigs(struct network_driver *driver) {
if (driver->networks.objs[i]->autostart && if (driver->networks.objs[i]->autostart &&
!virNetworkIsActive(driver->networks.objs[i]) && !virNetworkIsActive(driver->networks.objs[i]) &&
networkStartNetworkDaemon(NULL, driver, driver->networks.objs[i]) < 0) { networkStartNetworkDaemon(NULL, driver, driver->networks.objs[i]) < 0) {
virErrorPtr err = virGetLastError(); /* failed to start but already logged */
networkLog(NETWORK_ERR, _("Failed to autostart network '%s': %s\n"),
driver->networks.objs[i]->def->name,
err ? err->message : NULL);
} }
virNetworkObjUnlock(driver->networks.objs[i]); virNetworkObjUnlock(driver->networks.objs[i]);
} }
@ -247,8 +241,7 @@ networkStartup(void) {
} }
if (!(driverState->iptables = iptablesContextNew())) { if (!(driverState->iptables = iptablesContextNew())) {
virReportOOMError(NULL); goto out_of_memory;
goto error;
} }
@ -266,8 +259,7 @@ networkStartup(void) {
return 0; return 0;
out_of_memory: out_of_memory:
networkLog (NETWORK_ERR, virReportOOMError(NULL);
"%s", _("networkStartup: out of memory\n"));
error: error:
if (driverState) if (driverState)
@ -296,8 +288,7 @@ networkReload(void) {
driverState->networkAutostartDir); driverState->networkAutostartDir);
if (driverState->iptables) { if (driverState->iptables) {
networkLog(NETWORK_INFO, VIR_INFO0(_("Reloading iptables rules\n"));
"%s", _("Reloading iptables rules\n"));
iptablesReloadRules(driverState->iptables); iptablesReloadRules(driverState->iptables);
} }
@ -879,14 +870,14 @@ static int networkStartNetworkDaemon(virConnectPtr conn,
err_delbr1: err_delbr1:
if ((err = brSetInterfaceUp(driver->brctl, network->def->bridge, 0))) { if ((err = brSetInterfaceUp(driver->brctl, network->def->bridge, 0))) {
char ebuf[1024]; char ebuf[1024];
networkLog(NETWORK_WARN, _("Failed to bring down bridge '%s' : %s\n"), VIR_WARN(_("Failed to bring down bridge '%s' : %s\n"),
network->def->bridge, virStrerror(err, ebuf, sizeof ebuf)); network->def->bridge, virStrerror(err, ebuf, sizeof ebuf));
} }
err_delbr: err_delbr:
if ((err = brDeleteBridge(driver->brctl, network->def->bridge))) { if ((err = brDeleteBridge(driver->brctl, network->def->bridge))) {
char ebuf[1024]; char ebuf[1024];
networkLog(NETWORK_WARN, _("Failed to delete bridge '%s' : %s\n"), VIR_WARN(_("Failed to delete bridge '%s' : %s\n"),
network->def->bridge, virStrerror(err, ebuf, sizeof ebuf)); network->def->bridge, virStrerror(err, ebuf, sizeof ebuf));
} }
@ -900,7 +891,7 @@ static int networkShutdownNetworkDaemon(virConnectPtr conn,
int err; int err;
char *stateFile; char *stateFile;
networkLog(NETWORK_INFO, _("Shutting down network '%s'\n"), network->def->name); VIR_INFO(_("Shutting down network '%s'\n"), network->def->name);
if (!virNetworkIsActive(network)) if (!virNetworkIsActive(network))
return 0; return 0;
@ -919,12 +910,12 @@ static int networkShutdownNetworkDaemon(virConnectPtr conn,
char ebuf[1024]; char ebuf[1024];
if ((err = brSetInterfaceUp(driver->brctl, network->def->bridge, 0))) { if ((err = brSetInterfaceUp(driver->brctl, network->def->bridge, 0))) {
networkLog(NETWORK_WARN, _("Failed to bring down bridge '%s' : %s\n"), VIR_WARN(_("Failed to bring down bridge '%s' : %s\n"),
network->def->bridge, virStrerror(err, ebuf, sizeof ebuf)); network->def->bridge, virStrerror(err, ebuf, sizeof ebuf));
} }
if ((err = brDeleteBridge(driver->brctl, network->def->bridge))) { if ((err = brDeleteBridge(driver->brctl, network->def->bridge))) {
networkLog(NETWORK_WARN, _("Failed to delete bridge '%s' : %s\n"), VIR_WARN(_("Failed to delete bridge '%s' : %s\n"),
network->def->bridge, virStrerror(err, ebuf, sizeof ebuf)); network->def->bridge, virStrerror(err, ebuf, sizeof ebuf));
} }

View File

@ -53,9 +53,6 @@ VIR_ENUM_IMPL(virNodeDevNetCap, VIR_NODE_DEV_CAP_NET_LAST,
"80203", "80203",
"80211") "80211")
#define virNodeDeviceLog(msg...) fprintf(stderr, msg)
virNodeDeviceObjPtr virNodeDeviceFindByName(const virNodeDeviceObjListPtr devs, virNodeDeviceObjPtr virNodeDeviceFindByName(const virNodeDeviceObjListPtr devs,
const char *name) const char *name)
{ {

View File

@ -689,23 +689,22 @@ static int halDeviceMonitorStartup(void)
dbus_error_init(&err); dbus_error_init(&err);
hal_ctx = libhal_ctx_new(); hal_ctx = libhal_ctx_new();
if (hal_ctx == NULL) { if (hal_ctx == NULL) {
fprintf(stderr, "%s: libhal_ctx_new returned NULL\n", __FUNCTION__); VIR_ERROR0("libhal_ctx_new returned NULL\n");
goto failure; goto failure;
} }
dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err); dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
if (dbus_conn == NULL) { if (dbus_conn == NULL) {
fprintf(stderr, "%s: dbus_bus_get failed\n", __FUNCTION__); VIR_ERROR0("dbus_bus_get failed\n");
goto failure; goto failure;
} }
dbus_connection_set_exit_on_disconnect(dbus_conn, FALSE); dbus_connection_set_exit_on_disconnect(dbus_conn, FALSE);
if (!libhal_ctx_set_dbus_connection(hal_ctx, dbus_conn)) { if (!libhal_ctx_set_dbus_connection(hal_ctx, dbus_conn)) {
fprintf(stderr, "%s: libhal_ctx_set_dbus_connection failed\n", VIR_ERROR0("libhal_ctx_set_dbus_connection failed\n");
__FUNCTION__);
goto failure; goto failure;
} }
if (!libhal_ctx_init(hal_ctx, &err)) { if (!libhal_ctx_init(hal_ctx, &err)) {
fprintf(stderr, "%s: libhal_ctx_init failed\n", __FUNCTION__); VIR_ERROR0("libhal_ctx_init failed\n");
goto failure; goto failure;
} }
@ -715,8 +714,7 @@ static int halDeviceMonitorStartup(void)
remove_dbus_watch, remove_dbus_watch,
toggle_dbus_watch, toggle_dbus_watch,
NULL, NULL)) { NULL, NULL)) {
fprintf(stderr, "%s: dbus_connection_set_watch_functions failed\n", VIR_ERROR0("dbus_connection_set_watch_functions failed\n");
__FUNCTION__);
goto failure; goto failure;
} }
@ -726,8 +724,8 @@ static int halDeviceMonitorStartup(void)
!libhal_ctx_set_device_new_capability(hal_ctx, device_cap_added) || !libhal_ctx_set_device_new_capability(hal_ctx, device_cap_added) ||
!libhal_ctx_set_device_lost_capability(hal_ctx, device_cap_lost) || !libhal_ctx_set_device_lost_capability(hal_ctx, device_cap_lost) ||
!libhal_ctx_set_device_property_modified(hal_ctx, device_prop_modified) || !libhal_ctx_set_device_property_modified(hal_ctx, device_prop_modified) ||
!libhal_device_property_watch_all(hal_ctx, &err)) { !libhal_device_property_watch_all(hal_ctx, &err)) {
fprintf(stderr, "%s: setting up HAL callbacks failed\n", __FUNCTION__); VIR_ERROR0("setting up HAL callbacks failed\n");
goto failure; goto failure;
} }
@ -737,7 +735,7 @@ static int halDeviceMonitorStartup(void)
nodeDeviceUnlock(driverState); nodeDeviceUnlock(driverState);
udi = libhal_get_all_devices(hal_ctx, &num_devs, &err); udi = libhal_get_all_devices(hal_ctx, &num_devs, &err);
if (udi == NULL) { if (udi == NULL) {
fprintf(stderr, "%s: libhal_get_all_devices failed\n", __FUNCTION__); VIR_ERROR0("libhal_get_all_devices failed\n");
goto failure; goto failure;
} }
for (i = 0; i < num_devs; i++) { for (i = 0; i < num_devs; i++) {
@ -750,7 +748,7 @@ static int halDeviceMonitorStartup(void)
failure: failure:
if (dbus_error_is_set(&err)) { if (dbus_error_is_set(&err)) {
fprintf(stderr, "\t%s: %s\n", err.name, err.message); VIR_ERROR("%s: %s\n", err.name, err.message);
dbus_error_free(&err); dbus_error_free(&err);
} }
virNodeDeviceObjListFree(&driverState->devs); virNodeDeviceObjListFree(&driverState->devs);

View File

@ -50,7 +50,9 @@
# define ULLONG_MAX ULONG_LONG_MAX # define ULLONG_MAX ULONG_LONG_MAX
#endif #endif
#define virStorageLog(msg...) fprintf(stderr, msg) #define virStorageError(conn, code, fmt...) \
virReportErrorHelper(conn, VIR_FROM_STORAGE, code, __FILE__,\
__FUNCTION__, __LINE__, fmt)
VIR_ENUM_IMPL(virStoragePool, VIR_ENUM_IMPL(virStoragePool,
VIR_STORAGE_POOL_LAST, VIR_STORAGE_POOL_LAST,
@ -1332,34 +1334,31 @@ virStoragePoolObjLoad(virConnectPtr conn,
virStoragePoolObjPtr pool; virStoragePoolObjPtr pool;
if (!(def = virStoragePoolDefParse(NULL, xml, file))) { if (!(def = virStoragePoolDefParse(NULL, xml, file))) {
virErrorPtr err = virGetLastError();
virStorageLog("Error parsing storage pool config '%s' : %s",
path, err ? err->message : NULL);
return NULL; return NULL;
} }
if (!virFileMatchesNameSuffix(file, def->name, ".xml")) { if (!virFileMatchesNameSuffix(file, def->name, ".xml")) {
virStorageLog("Storage pool config filename '%s' does not match pool name '%s'", virStorageError(conn, VIR_ERR_INVALID_STORAGE_POOL,
"Storage pool config filename '%s' does not match pool name '%s'",
path, def->name); path, def->name);
virStoragePoolDefFree(def); virStoragePoolDefFree(def);
return NULL; return NULL;
} }
if (!(pool = virStoragePoolObjAssignDef(conn, pools, def))) { if (!(pool = virStoragePoolObjAssignDef(conn, pools, def))) {
virStorageLog("Failed to load storage pool config '%s': out of memory", path);
virStoragePoolDefFree(def); virStoragePoolDefFree(def);
return NULL; return NULL;
} }
pool->configFile = strdup(path); pool->configFile = strdup(path);
if (pool->configFile == NULL) { if (pool->configFile == NULL) {
virStorageLog("Failed to load storage pool config '%s': out of memory", path); virReportOOMError(conn);
virStoragePoolDefFree(def); virStoragePoolDefFree(def);
return NULL; return NULL;
} }
pool->autostartLink = strdup(autostartLink); pool->autostartLink = strdup(autostartLink);
if (pool->autostartLink == NULL) { if (pool->autostartLink == NULL) {
virStorageLog("Failed to load storage pool config '%s': out of memory", path); virReportOOMError(conn);
virStoragePoolDefFree(def); virStoragePoolDefFree(def);
return NULL; return NULL;
} }
@ -1380,11 +1379,10 @@ virStoragePoolLoadAllConfigs(virConnectPtr conn,
struct dirent *entry; struct dirent *entry;
if (!(dir = opendir(configDir))) { if (!(dir = opendir(configDir))) {
char ebuf[1024];
if (errno == ENOENT) if (errno == ENOENT)
return 0; return 0;
virStorageLog("Failed to open dir '%s': %s", virReportSystemError(conn, errno, _("Failed to open dir '%s'"),
configDir, virStrerror(errno, ebuf, sizeof ebuf)); configDir);
return -1; return -1;
} }
@ -1402,15 +1400,17 @@ virStoragePoolLoadAllConfigs(virConnectPtr conn,
if (virFileBuildPath(configDir, entry->d_name, if (virFileBuildPath(configDir, entry->d_name,
NULL, path, PATH_MAX) < 0) { NULL, path, PATH_MAX) < 0) {
virStorageLog("Config filename '%s/%s' is too long", virStorageError(conn, VIR_ERR_INTERNAL_ERROR,
configDir, entry->d_name); "Config filename '%s/%s' is too long",
configDir, entry->d_name);
continue; continue;
} }
if (virFileBuildPath(autostartDir, entry->d_name, if (virFileBuildPath(autostartDir, entry->d_name,
NULL, autostartLink, PATH_MAX) < 0) { NULL, autostartLink, PATH_MAX) < 0) {
virStorageLog("Autostart link path '%s/%s' is too long", virStorageError(conn, VIR_ERR_INTERNAL_ERROR,
autostartDir, entry->d_name); "Autostart link path '%s/%s' is too long",
autostartDir, entry->d_name);
continue; continue;
} }

View File

@ -73,8 +73,6 @@
# define MIN(a, b) ((a) < (b) ? (a) : (b)) # define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif #endif
#define virLog(msg...) fprintf(stderr, msg)
#define VIR_FROM_THIS VIR_FROM_NONE #define VIR_FROM_THIS VIR_FROM_NONE
#define ReportError(conn, code, fmt...) \ #define ReportError(conn, code, fmt...) \
@ -938,19 +936,16 @@ int virFileReadLimFD(int fd_arg, int maxlen, char **buf)
int virFileReadAll(const char *path, int maxlen, char **buf) int virFileReadAll(const char *path, int maxlen, char **buf)
{ {
char ebuf[1024];
FILE *fh = fopen(path, "r"); FILE *fh = fopen(path, "r");
if (fh == NULL) { if (fh == NULL) {
virLog("Failed to open file '%s': %s\n", virReportSystemError(NULL, errno, _("Failed to open file '%s'"), path);
path, virStrerror(errno, ebuf, sizeof ebuf));
return -1; return -1;
} }
int len = virFileReadLimFP (fh, maxlen, buf); int len = virFileReadLimFP (fh, maxlen, buf);
fclose(fh); fclose(fh);
if (len < 0) { if (len < 0) {
virLog("Failed to read '%s': %s\n", path, virReportSystemError(NULL, errno, _("Failed to read file '%s'"), path);
virStrerror(errno, ebuf, sizeof ebuf));
return -1; return -1;
} }