[Libvir] [PATCH] Fix the function that remove the element of the hash table.
by Hiroyuki Kaguchi
There are two logic error and a unnecessary else-statement
in virHashRemoveSet function.
This patch fix the following.
(1/3) The logic error that use released memory area.
(2/3) The logic error that doesn't remove elements.
(3/3) Unnecessary else-statement.
(1/3) The logic error that use released memory area.
This bug causes the crash of virt-manager or virsh.
If "virsh undefine" command is executed, "Segmentation Fault" is caused.
The result of executing "valgrind virsh" command is:
virsh # list --all
==3337== Invalid read of size 4
==3337== at 0x4016A21: virHashRemoveSet (hash.c:562)
==3337== by 0x403ACF4: xenXMConfigCacheRefresh (xm_internal.c:458)
==3337== by 0x4040D58: xenXMNumOfDefinedDomains (xm_internal.c:2518)
==3337== by 0x40245C3: xenUnifiedNumOfDefinedDomains (xen_unified.c:1004)
==3337== by 0x4013730: virConnectNumOfDefinedDomains (libvirt.c:2446)
==3337== by 0x804AE81: cmdList (virsh.c:577)
==3337== by 0x8052E6E: vshCommandRun (virsh.c:4052)
==3337== by 0x8054E2D: main (virsh.c:5036)
==3337== Address 0x4282AB8 is 0 bytes inside a block of size 16 free'd
==3337== at 0x4004FDA: free (vg_replace_malloc.c:233)
==3337== by 0x40169A0: virHashRemoveSet (hash.c:545)
==3337== by 0x403ACF4: xenXMConfigCacheRefresh (xm_internal.c:458)
==3337== by 0x4040D58: xenXMNumOfDefinedDomains (xm_internal.c:2518)
==3337== by 0x40245C3: xenUnifiedNumOfDefinedDomains (xen_unified.c:1004)
==3337== by 0x4013730: virConnectNumOfDefinedDomains (libvirt.c:2446)
==3337== by 0x804AE81: cmdList (virsh.c:577)
==3337== by 0x8052E6E: vshCommandRun (virsh.c:4052)
==3337== by 0x8054E2D: main (virsh.c:5036)
The current removing logic is:
1. search for node that be removed in the hash table.
The removing cursor(pointer) point to "element-B".
+-hash table---+
| +----------+ | +----------+ +----------+
| |element-A |-|-->|element-B |-->|element-C |
| +----------+ | +----------+ +----------+
| |element-D | |
| +----------+ |
| . |
| . |
+--------------+
2. free "element-B".
The removing cursor point to invalid address
+-hash table---+
| +----------+ | +----------+
| |element-A |-|-->|element-C |
| +----------+ | +----------+
| |element-D | |
| +----------+ |
| . |
| . |
+--------------+
3. try to move the removing cursor to next node.
At this time, the error occurs.
(2/3) The logic error that doesn't remove elements.
The current removing logic is:
1. search for node that will be removed in the hash table.
The removing cursor point to "element-A".
+-hash table---+
| +----------+ | +----------+ +----------+
| |element-A |-|-->|element-B |-->|element-C |
| +----------+ | +----------+ +----------+
| |element-D | |
| +----------+ |
| . |
| . |
+--------------+
2. copy "element-B" to "element-A".
+-hash table---+
| +----------+ | +----------+ +----------+
| |element-B'|-|-->|element-B |-->|element-C |
| +----------+ | +----------+ +----------+
| |element-D | |
| +----------+ |
| . |
| . |
+--------------+
3. remove "element-B"
The removing cursor point to "element-D".
"element-C" is skipped.
+-hash table---+
| +----------+ | +----------+
| |element-B'|-|-->|element-C |
| +----------+ | +----------+
| |element-D | |
| +----------+ |
| . |
| . |
+--------------+
(3/3) Unnecessary else-statement.
There is else-statement that set NULL to the NULL pointer.
Thanks,
Hiroyuki Kaguchi
Index: hash.c
===================================================================
RCS file: /data/cvs/libvirt/src/hash.c,v
retrieving revision 1.27
diff -u -r1.27 hash.c
--- hash.c 21 Jan 2008 16:29:10 -0000 1.27
+++ hash.c 28 Jan 2008 06:48:09 -0000
@@ -543,6 +543,7 @@
if (prev) {
prev->next = entry->next;
free(entry);
+ entry = prev;
} else {
if (entry->next == NULL) {
entry->valid = 0;
@@ -553,6 +554,7 @@
sizeof(virHashEntry));
free(entry);
entry = NULL;
+ i--;
}
}
table->nbElems--;
@@ -560,8 +562,6 @@
prev = entry;
if (entry) {
entry = entry->next;
- } else {
- entry = NULL;
}
}
}
16 years, 9 months
Re: [Libvir] [patch 3/3] Do not inline xstrtol functions
by Daniel Veillard
On Wed, Feb 06, 2008 at 11:07:55PM +0000, Mark McLoughlin wrote:
> Our strtol() variants are all marked "static inline"
> and with gcc 4.3 we get:
>
> internal.h:272: error: inlining failed in call to 'xstrtol_i': call is unlikely and code size would grow
>
> This patch renames them to virStrToLong() and exports
> them from the library as private symbols.
Hum, I don't like too much adding more exported symbols
> Alternative is to not build with -Winline.
That sounds a weak way to try to avoid a problem, we should
not rely on just compiler options to get the code to compile and link.
My preference would be to use the patch to make them real internal
APIs without exporting all the functions, I think only xstrtol_i is
used by external programs (virsh and qemud), and maybe we can add only
that one to the list of exported symbols.
Daniel
--
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard | virtualization library http://libvirt.org/
veillard(a)redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
16 years, 9 months
[Libvir] [PATCH] Mark all qemudLog diagnostics for translation.
by Jim Meyering
Subject: [PATCH] Mark all qemudLog diagnostics for translation.
* po/POTFILES.in: Add names of many new files.
* Makefile.maint (err_func_re): Add qemudLog.
Mark diagnostics with _(...). Split some long lines.
* qemud/qemud.c (remoteCheckCertFile, remoteInitializeGnuTLS):
(qemudDispatchSignalEvent, qemudSetCloseExec, qemudSetNonBlock):
(qemudWritePidFile, qemudListenUnix, remoteMakeSockets):
(remoteListenTCP, qemudInitPaths, qemudInitialize):
(qemudNetworkInit, remoteInitializeTLSSession, remoteCheckDN):
(remoteCheckCertificate, remoteCheckAccess, qemudDispatchServer):
(qemudClientReadBuf, qemudDispatchClientRead):
(qemudClientWriteBuf, qemudDispatchClientWrite, qemudOneLoop):
(remoteConfigGetStringList, checkType, GET_CONF_STR):
(remoteConfigGetAuth, remoteReadConfigFile, main):
* qemud/remote.c (remoteDispatchAuthSaslInit, remoteSASLCheckSSF):
(remoteSASLCheckAccess, remoteDispatchAuthSaslStart):
(remoteDispatchAuthSaslStep, remoteDispatchAuthSaslInit):
(remoteDispatchAuthSaslStart, remoteDispatchAuthSaslStep):
(qemudGetSocketIdentity, remoteDispatchAuthPolkit):
* src/iptables.c (notifyRulesUpdated, MAX_FILE_LEN, iptRulesSave):
(iptRulesReload):
* src/qemu_conf.c (qemudExtractVersionInfo, qemudLoadConfig):
(qemudLoadNetworkConfig, qemudScanConfigDir):
* src/qemu_driver.c (qemudSetCloseExec, qemudSetNonBlock):
(qemudAutostartConfigs, qemudStartup, qemudReload):
(qemudWaitForMonitor, qemudStartVMDaemon, qemudVMData):
(qemudShutdownVMDaemon, qemudStartNetworkDaemon):
(qemudShutdownNetworkDaemon, qemudMonitorCommand):
(qemudDomainUndefine, qemudNetworkUndefine):
* src/uuid.c (virUUIDGenerate):
* src/xm_internal.c (xenXMAttachInterface):
---
Makefile.maint | 2 +-
po/POTFILES.in | 6 ++
qemud/qemud.c | 176 +++++++++++++++++++++++++++++------------------------
qemud/remote.c | 94 +++++++++++++++++------------
src/iptables.c | 21 ++++---
src/qemu_conf.c | 40 ++++++++----
src/qemu_driver.c | 56 +++++++++--------
src/uuid.c | 7 +-
src/xm_internal.c | 10 ++--
9 files changed, 234 insertions(+), 178 deletions(-)
diff --git a/Makefile.maint b/Makefile.maint
index 9d41bd2..8624328 100644
--- a/Makefile.maint
+++ b/Makefile.maint
@@ -289,7 +289,7 @@ sc_two_space_separator_in_usage:
1>&2; exit 1; } || :
err_func_re = \
-(DISABLE_fprintf|(xmlRpc|vir(Xend|XML|Hash|Conf|Test|LibConn))Error)
+(DISABLE_fprintf|qemudLog|(xmlRpc|vir(Xend|XML|Hash|Conf|Test|LibConn))Error)
# Look for diagnostics that aren't marked for translation.
# This won't find any for which error's format string is on a separate line.
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b4b9cd2..a1e78fa 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,12 +1,18 @@
gnulib/lib/gai_strerror.c
+qemud/remote.c
+qemud/qemud.c
src/conf.c
src/console.c
src/hash.c
+src/iptables.c
src/libvirt.c
src/proxy_internal.c
+src/qemu_conf.c
+src/qemu_driver.c
src/remote_internal.c
src/sexpr.c
src/test.c
+src/uuid.c
src/virsh.c
src/virterror.c
src/xen_internal.c
diff --git a/qemud/qemud.c b/qemud/qemud.c
index e853538..b0e2558 100644
--- a/qemud/qemud.c
+++ b/qemud/qemud.c
@@ -1,7 +1,7 @@
/*
* qemud.c: daemon start of day, guest process & i/o management
*
- * Copyright (C) 2006, 2007 Red Hat, Inc.
+ * Copyright (C) 2006, 2007, 2008 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@@ -137,7 +137,7 @@ remoteCheckCertFile(const char *type, const char *file)
{
struct stat sb;
if (stat(file, &sb) < 0) {
- qemudLog (QEMUD_ERR, "Cannot access %s '%s': %s (%d)",
+ qemudLog (QEMUD_ERR, _("Cannot access %s '%s': %s (%d)"),
type, file, strerror(errno), errno);
return -1;
}
@@ -154,7 +154,7 @@ remoteInitializeGnuTLS (void)
err = gnutls_certificate_allocate_credentials (&x509_cred);
if (err) {
- qemudLog (QEMUD_ERR, "gnutls_certificate_allocate_credentials: %s",
+ qemudLog (QEMUD_ERR, _("gnutls_certificate_allocate_credentials: %s"),
gnutls_strerror (err));
return -1;
}
@@ -167,7 +167,7 @@ remoteInitializeGnuTLS (void)
err = gnutls_certificate_set_x509_trust_file (x509_cred, ca_file,
GNUTLS_X509_FMT_PEM);
if (err < 0) {
- qemudLog (QEMUD_ERR, "gnutls_certificate_set_x509_trust_file: %s",
+ qemudLog (QEMUD_ERR, _("gnutls_certificate_set_x509_trust_file: %s"),
gnutls_strerror (err));
return -1;
}
@@ -181,7 +181,7 @@ remoteInitializeGnuTLS (void)
err = gnutls_certificate_set_x509_crl_file (x509_cred, crl_file,
GNUTLS_X509_FMT_PEM);
if (err < 0) {
- qemudLog (QEMUD_ERR, "gnutls_certificate_set_x509_crl_file: %s",
+ qemudLog (QEMUD_ERR, _("gnutls_certificate_set_x509_crl_file: %s"),
gnutls_strerror (err));
return -1;
}
@@ -199,7 +199,7 @@ remoteInitializeGnuTLS (void)
cert_file, key_file,
GNUTLS_X509_FMT_PEM);
if (err < 0) {
- qemudLog (QEMUD_ERR, "gnutls_certificate_set_x509_key_file: %s",
+ qemudLog (QEMUD_ERR, _("gnutls_certificate_set_x509_key_file: %s"),
gnutls_strerror (err));
return -1;
}
@@ -212,13 +212,13 @@ remoteInitializeGnuTLS (void)
*/
err = gnutls_dh_params_init (&dh_params);
if (err < 0) {
- qemudLog (QEMUD_ERR, "gnutls_dh_params_init: %s",
+ qemudLog (QEMUD_ERR, _("gnutls_dh_params_init: %s"),
gnutls_strerror (err));
return -1;
}
err = gnutls_dh_params_generate2 (dh_params, DH_BITS);
if (err < 0) {
- qemudLog (QEMUD_ERR, "gnutls_dh_params_generate2: %s",
+ qemudLog (QEMUD_ERR, _("gnutls_dh_params_generate2: %s"),
gnutls_strerror (err));
return -1;
}
@@ -236,7 +236,7 @@ static void qemudDispatchSignalEvent(int fd ATTRIBUTE_UNUSED,
int ret;
if (read(server->sigread, &sigc, 1) != 1) {
- qemudLog(QEMUD_ERR, "Failed to read from signal pipe: %s",
+ qemudLog(QEMUD_ERR, _("Failed to read from signal pipe: %s"),
strerror(errno));
return;
}
@@ -245,15 +245,15 @@ static void qemudDispatchSignalEvent(int fd ATTRIBUTE_UNUSED,
switch (sigc) {
case SIGHUP:
- qemudLog(QEMUD_INFO, "Reloading configuration on SIGHUP");
+ qemudLog(QEMUD_INFO, _("Reloading configuration on SIGHUP"));
if (virStateReload() < 0)
- qemudLog(QEMUD_WARN, "Error while reloading drivers");
+ qemudLog(QEMUD_WARN, _("Error while reloading drivers"));
break;
case SIGINT:
case SIGQUIT:
case SIGTERM:
- qemudLog(QEMUD_WARN, "Shutting down on signal %d", sigc);
+ qemudLog(QEMUD_WARN, _("Shutting down on signal %d"), sigc);
server->shutdown = 1;
break;
@@ -274,7 +274,7 @@ static int qemudSetCloseExec(int fd) {
goto error;
return 0;
error:
- qemudLog(QEMUD_ERR, "Failed to set close-on-exec file descriptor flag");
+ qemudLog(QEMUD_ERR, _("Failed to set close-on-exec file descriptor flag"));
return -1;
}
@@ -288,7 +288,7 @@ static int qemudSetNonBlock(int fd) {
goto error;
return 0;
error:
- qemudLog(QEMUD_ERR, "Failed to set non-blocking file descriptor flag");
+ qemudLog(QEMUD_ERR, _("Failed to set non-blocking file descriptor flag"));
return -1;
}
@@ -430,27 +430,27 @@ static int qemudWritePidFile(const char *pidFile) {
return 0;
if ((fd = open(pidFile, O_WRONLY|O_CREAT|O_EXCL, 0644)) < 0) {
- qemudLog(QEMUD_ERR, "Failed to open pid file '%s' : %s",
+ qemudLog(QEMUD_ERR, _("Failed to open pid file '%s' : %s"),
pidFile, strerror(errno));
return -1;
}
if (!(fh = fdopen(fd, "w"))) {
- qemudLog(QEMUD_ERR, "Failed to fdopen pid file '%s' : %s",
+ qemudLog(QEMUD_ERR, _("Failed to fdopen pid file '%s' : %s"),
pidFile, strerror(errno));
close(fd);
return -1;
}
if (fprintf(fh, "%lu\n", (unsigned long)getpid()) < 0) {
- qemudLog(QEMUD_ERR, "Failed to write to pid file '%s' : %s",
+ qemudLog(QEMUD_ERR, _("Failed to write to pid file '%s' : %s"),
pidFile, strerror(errno));
close(fd);
return -1;
}
if (fclose(fh) == EOF) {
- qemudLog(QEMUD_ERR, "Failed to close pid file '%s' : %s",
+ qemudLog(QEMUD_ERR, _("Failed to close pid file '%s' : %s"),
pidFile, strerror(errno));
return -1;
}
@@ -466,7 +466,8 @@ static int qemudListenUnix(struct qemud_server *server,
gid_t oldgrp;
if (!sock) {
- qemudLog(QEMUD_ERR, "Failed to allocate memory for struct qemud_socket");
+ qemudLog(QEMUD_ERR,
+ _("Failed to allocate memory for struct qemud_socket"));
return -1;
}
@@ -476,7 +477,7 @@ static int qemudListenUnix(struct qemud_server *server,
sock->auth = auth;
if ((sock->fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
- qemudLog(QEMUD_ERR, "Failed to create socket: %s",
+ qemudLog(QEMUD_ERR, _("Failed to create socket: %s"),
strerror(errno));
goto cleanup;
}
@@ -498,7 +499,7 @@ static int qemudListenUnix(struct qemud_server *server,
setgid(unix_sock_gid);
if (bind(sock->fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
- qemudLog(QEMUD_ERR, "Failed to bind socket to '%s': %s",
+ qemudLog(QEMUD_ERR, _("Failed to bind socket to '%s': %s"),
path, strerror(errno));
goto cleanup;
}
@@ -507,7 +508,7 @@ static int qemudListenUnix(struct qemud_server *server,
setgid(oldgrp);
if (listen(sock->fd, 30) < 0) {
- qemudLog(QEMUD_ERR, "Failed to listen for connections on '%s': %s",
+ qemudLog(QEMUD_ERR, _("Failed to listen for connections on '%s': %s"),
path, strerror(errno));
goto cleanup;
}
@@ -516,7 +517,7 @@ static int qemudListenUnix(struct qemud_server *server,
POLLIN| POLLERR | POLLHUP,
qemudDispatchServerEvent,
server) < 0) {
- qemudLog(QEMUD_ERR, "Failed to add server event callback");
+ qemudLog(QEMUD_ERR, _("Failed to add server event callback"));
goto cleanup;
}
@@ -545,7 +546,7 @@ remoteMakeSockets (int *fds, int max_fds, int *nfds_r, const char *service)
int e = getaddrinfo (NULL, service, &hints, &ai);
if (e != 0) {
- qemudLog (QEMUD_ERR, "getaddrinfo: %s\n", gai_strerror (e));
+ qemudLog (QEMUD_ERR, _("getaddrinfo: %s\n"), gai_strerror (e));
return -1;
}
@@ -554,7 +555,7 @@ remoteMakeSockets (int *fds, int max_fds, int *nfds_r, const char *service)
fds[*nfds_r] = socket (runp->ai_family, runp->ai_socktype,
runp->ai_protocol);
if (fds[*nfds_r] == -1) {
- qemudLog (QEMUD_ERR, "socket: %s", strerror (errno));
+ qemudLog (QEMUD_ERR, _("socket: %s"), strerror (errno));
return -1;
}
@@ -563,14 +564,14 @@ remoteMakeSockets (int *fds, int max_fds, int *nfds_r, const char *service)
if (bind (fds[*nfds_r], runp->ai_addr, runp->ai_addrlen) == -1) {
if (errno != EADDRINUSE) {
- qemudLog (QEMUD_ERR, "bind: %s", strerror (errno));
+ qemudLog (QEMUD_ERR, _("bind: %s"), strerror (errno));
return -1;
}
close (fds[*nfds_r]);
}
else {
if (listen (fds[*nfds_r], SOMAXCONN) == -1) {
- qemudLog (QEMUD_ERR, "listen: %s", strerror (errno));
+ qemudLog (QEMUD_ERR, _("listen: %s"), strerror (errno));
return -1;
}
++*nfds_r;
@@ -607,7 +608,7 @@ remoteListenTCP (struct qemud_server *server,
if (!sock) {
qemudLog (QEMUD_ERR,
- "remoteListenTCP: calloc: %s", strerror (errno));
+ _("remoteListenTCP: calloc: %s"), strerror (errno));
return -1;
}
@@ -638,7 +639,7 @@ remoteListenTCP (struct qemud_server *server,
if (listen (sock->fd, 30) < 0) {
qemudLog (QEMUD_ERR,
- "remoteListenTCP: listen: %s", strerror (errno));
+ _("remoteListenTCP: listen: %s"), strerror (errno));
return -1;
}
@@ -646,7 +647,7 @@ remoteListenTCP (struct qemud_server *server,
POLLIN| POLLERR | POLLHUP,
qemudDispatchServerEvent,
server) < 0) {
- qemudLog(QEMUD_ERR, "Failed to add server event callback");
+ qemudLog(QEMUD_ERR, _("Failed to add server event callback"));
return -1;
}
@@ -680,7 +681,7 @@ static int qemudInitPaths(struct qemud_server *server,
struct passwd *pw;
if (!(pw = getpwuid(uid))) {
- qemudLog(QEMUD_ERR, "Failed to find user record for uid '%d': %s",
+ qemudLog(QEMUD_ERR, _("Failed to find user record for uid '%d': %s"),
uid, strerror(errno));
return -1;
}
@@ -696,7 +697,8 @@ static int qemudInitPaths(struct qemud_server *server,
return 0;
snprintf_error:
- qemudLog(QEMUD_ERR, "Resulting path to long for buffer in qemudInitPaths()");
+ qemudLog(QEMUD_ERR,
+ _("Resulting path to long for buffer in qemudInitPaths()"));
return -1;
}
@@ -704,7 +706,7 @@ static struct qemud_server *qemudInitialize(int sigread) {
struct qemud_server *server;
if (!(server = calloc(1, sizeof(*server)))) {
- qemudLog(QEMUD_ERR, "Failed to allocate struct qemud_server");
+ qemudLog(QEMUD_ERR, _("Failed to allocate struct qemud_server"));
return NULL;
}
@@ -747,7 +749,8 @@ static struct qemud_server *qemudNetworkInit(struct qemud_server *server) {
auth_tcp == REMOTE_AUTH_SASL ||
auth_tls == REMOTE_AUTH_SASL) {
if ((err = sasl_server_init(NULL, "libvirt")) != SASL_OK) {
- qemudLog(QEMUD_ERR, "Failed to initialize SASL authentication %s",
+ qemudLog(QEMUD_ERR,
+ _("Failed to initialize SASL authentication %s"),
sasl_errstring(err, NULL, NULL));
goto cleanup;
}
@@ -761,7 +764,8 @@ static struct qemud_server *qemudNetworkInit(struct qemud_server *server) {
dbus_error_init(&derr);
server->sysbus = dbus_bus_get(DBUS_BUS_SYSTEM, &derr);
if (!(server->sysbus)) {
- qemudLog(QEMUD_ERR, "Failed to connect to system bus for PolicyKit auth: %s",
+ qemudLog(QEMUD_ERR,
+ _("Failed to connect to system bus for PolicyKit auth: %s"),
derr.message);
dbus_error_free(&derr);
goto cleanup;
@@ -872,7 +876,7 @@ remoteInitializeTLSSession (void)
return session;
failed:
- qemudLog (QEMUD_ERR, "remoteInitializeTLSSession: %s",
+ qemudLog (QEMUD_ERR, _("remoteInitializeTLSSession: %s"),
gnutls_strerror (err));
return NULL;
}
@@ -889,7 +893,7 @@ remoteCheckDN (gnutls_x509_crt_t cert)
err = gnutls_x509_crt_get_dn (cert, name, &namesize);
if (err != 0) {
qemudLog (QEMUD_ERR,
- "remoteCheckDN: gnutls_x509_cert_get_dn: %s",
+ _("remoteCheckDN: gnutls_x509_cert_get_dn: %s"),
gnutls_strerror (err));
return 0;
}
@@ -908,7 +912,7 @@ remoteCheckDN (gnutls_x509_crt_t cert)
#ifdef ENABLE_DEBUG
/* Print the client's DN. */
qemudLog (QEMUD_DEBUG,
- "remoteCheckDN: failed: client DN is %s", name);
+ _("remoteCheckDN: failed: client DN is %s"), name);
#endif
return 0; // Not found.
@@ -924,36 +928,42 @@ remoteCheckCertificate (gnutls_session_t session)
time_t now;
if ((ret = gnutls_certificate_verify_peers2 (session, &status)) < 0){
- qemudLog (QEMUD_ERR, "remoteCheckCertificate: verify failed: %s",
+ qemudLog (QEMUD_ERR, _("remoteCheckCertificate: verify failed: %s"),
gnutls_strerror (ret));
return -1;
}
if (status != 0) {
if (status & GNUTLS_CERT_INVALID)
- qemudLog (QEMUD_ERR, "remoteCheckCertificate: the client certificate is not trusted.");
+ qemudLog (QEMUD_ERR, _("remoteCheckCertificate: "
+ "the client certificate is not trusted."));
if (status & GNUTLS_CERT_SIGNER_NOT_FOUND)
- qemudLog (QEMUD_ERR, "remoteCheckCertificate: the client certificate hasn't got a known issuer.");
+ qemudLog (QEMUD_ERR, _("remoteCheckCertificate: the client "
+ "certificate has unknown issuer."));
if (status & GNUTLS_CERT_REVOKED)
- qemudLog (QEMUD_ERR, "remoteCheckCertificate: the client certificate has been revoked.");
+ qemudLog (QEMUD_ERR, _("remoteCheckCertificate: "
+ "the client certificate has been revoked."));
#ifndef GNUTLS_1_0_COMPAT
if (status & GNUTLS_CERT_INSECURE_ALGORITHM)
- qemudLog (QEMUD_ERR, "remoteCheckCertificate: the client certificate uses an insecure algorithm.");
+ qemudLog (QEMUD_ERR,
+ _("remoteCheckCertificate: the client certificate"
+ " uses an insecure algorithm."));
#endif
return -1;
}
if (gnutls_certificate_type_get (session) != GNUTLS_CRT_X509) {
- qemudLog (QEMUD_ERR, "remoteCheckCertificate: certificate is not X.509");
+ qemudLog (QEMUD_ERR, _("remoteCheckCertificate: "
+ "certificate is not X.509"));
return -1;
}
if (!(certs = gnutls_certificate_get_peers(session, &nCerts))) {
- qemudLog (QEMUD_ERR, "remoteCheckCertificate: no peers");
+ qemudLog (QEMUD_ERR, _("remoteCheckCertificate: no peers"));
return -1;
}
@@ -963,7 +973,8 @@ remoteCheckCertificate (gnutls_session_t session)
gnutls_x509_crt_t cert;
if (gnutls_x509_crt_init (&cert) < 0) {
- qemudLog (QEMUD_ERR, "remoteCheckCertificate: gnutls_x509_crt_init failed");
+ qemudLog (QEMUD_ERR,
+ _("remoteCheckCertificate: gnutls_x509_crt_init failed"));
return -1;
}
@@ -973,13 +984,15 @@ remoteCheckCertificate (gnutls_session_t session)
}
if (gnutls_x509_crt_get_expiration_time (cert) < now) {
- qemudLog (QEMUD_ERR, "remoteCheckCertificate: the client certificate has expired");
+ qemudLog (QEMUD_ERR, _("remoteCheckCertificate: "
+ "the client certificate has expired"));
gnutls_x509_crt_deinit (cert);
return -1;
}
if (gnutls_x509_crt_get_activation_time (cert) > now) {
- qemudLog (QEMUD_ERR, "remoteCheckCertificate: the client certificate is not yet activated");
+ qemudLog (QEMUD_ERR, _("remoteCheckCertificate: the client "
+ "certificate is not yet activated"));
gnutls_x509_crt_deinit (cert);
return -1;
}
@@ -987,7 +1000,7 @@ remoteCheckCertificate (gnutls_session_t session)
if (i == 0) {
if (!remoteCheckDN (cert)) {
/* This is the most common error: make it informative. */
- qemudLog (QEMUD_ERR, "remoteCheckCertificate: client's Distinguished Name is not on the list of allowed clients (tls_allowed_dn_list). Use 'openssl x509 -in clientcert.pem -text' to view the Distinguished Name field in the client certificate, or run this daemon with --verbose option.");
+ qemudLog (QEMUD_ERR, _("remoteCheckCertificate: client's Distinguished Name is not on the list of allowed clients (tls_allowed_dn_list). Use 'openssl x509 -in clientcert.pem -text' to view the Distinguished Name field in the client certificate, or run this daemon with --verbose option."));
gnutls_x509_crt_deinit (cert);
return -1;
}
@@ -1003,9 +1016,9 @@ remoteCheckAccess (struct qemud_client *client)
{
/* Verify client certificate. */
if (remoteCheckCertificate (client->tlssession) == -1) {
- qemudLog (QEMUD_ERR, "remoteCheckCertificate: failed to verify client's certificate");
+ qemudLog (QEMUD_ERR, _("remoteCheckCertificate: failed to verify client's certificate"));
if (!tls_no_verify_certificate) return -1;
- else qemudLog (QEMUD_INFO, "remoteCheckCertificate: tls_no_verify_certificate is set so the bad certificate is ignored");
+ else qemudLog (QEMUD_INFO, _("remoteCheckCertificate: tls_no_verify_certificate is set so the bad certificate is ignored"));
}
/* Checks have succeeded. Write a '\1' byte back to the client to
@@ -1029,7 +1042,7 @@ static int qemudDispatchServer(struct qemud_server *server, struct qemud_socket
if ((fd = accept(sock->fd, (struct sockaddr *)&addr, &addrlen)) < 0) {
if (errno == EAGAIN)
return 0;
- qemudLog(QEMUD_ERR, "Failed to accept connection: %s", strerror(errno));
+ qemudLog(QEMUD_ERR, _("Failed to accept connection: %s"), strerror(errno));
return -1;
}
@@ -1087,7 +1100,7 @@ static int qemudDispatchServer(struct qemud_server *server, struct qemud_socket
if (qemudRegisterClientEvent (server, client, 0) < 0)
goto cleanup;
} else {
- qemudLog (QEMUD_ERR, "TLS handshake failed: %s",
+ qemudLog (QEMUD_ERR, _("TLS handshake failed: %s"),
gnutls_strerror (ret));
goto cleanup;
}
@@ -1152,7 +1165,7 @@ static int qemudClientReadBuf(struct qemud_server *server,
if ((ret = read (client->fd, data, len)) <= 0) {
if (ret == 0 || errno != EAGAIN) {
if (ret != 0)
- qemudLog (QEMUD_ERR, "read: %s", strerror (errno));
+ qemudLog (QEMUD_ERR, _("read: %s"), strerror (errno));
qemudDispatchClientFailure(server, client);
}
return -1;
@@ -1165,7 +1178,7 @@ static int qemudClientReadBuf(struct qemud_server *server,
if (ret == 0 || (ret != GNUTLS_E_AGAIN &&
ret != GNUTLS_E_INTERRUPTED)) {
if (ret != 0)
- qemudLog (QEMUD_ERR, "gnutls_record_recv: %s",
+ qemudLog (QEMUD_ERR, _("gnutls_record_recv: %s"),
gnutls_strerror (ret));
qemudDispatchClientFailure (server, client);
}
@@ -1324,7 +1337,7 @@ static void qemudDispatchClientRead(struct qemud_server *server, struct qemud_cl
else if (qemudRegisterClientEvent (server, client, 1) < 0)
qemudDispatchClientFailure (server, client);
} else if (ret != GNUTLS_E_AGAIN && ret != GNUTLS_E_INTERRUPTED) {
- qemudLog (QEMUD_ERR, "TLS handshake failed: %s",
+ qemudLog (QEMUD_ERR, _("TLS handshake failed: %s"),
gnutls_strerror (ret));
qemudDispatchClientFailure (server, client);
} else {
@@ -1349,7 +1362,7 @@ static int qemudClientWriteBuf(struct qemud_server *server,
if (!client->tlssession) {
if ((ret = write(client->fd, data, len)) == -1) {
if (errno != EAGAIN) {
- qemudLog (QEMUD_ERR, "write: %s", strerror (errno));
+ qemudLog (QEMUD_ERR, _("write: %s"), strerror (errno));
qemudDispatchClientFailure(server, client);
}
return -1;
@@ -1360,7 +1373,7 @@ static int qemudClientWriteBuf(struct qemud_server *server,
qemudDispatchClientFailure (server, client);
else if (ret < 0) {
if (ret != GNUTLS_E_INTERRUPTED && ret != GNUTLS_E_AGAIN) {
- qemudLog (QEMUD_ERR, "gnutls_record_send: %s",
+ qemudLog (QEMUD_ERR, _("gnutls_record_send: %s"),
gnutls_strerror (ret));
qemudDispatchClientFailure (server, client);
}
@@ -1464,7 +1477,7 @@ static void qemudDispatchClientWrite(struct qemud_server *server, struct qemud_c
else if (qemudRegisterClientEvent (server, client, 1))
qemudDispatchClientFailure (server, client);
} else if (ret != GNUTLS_E_AGAIN && ret != GNUTLS_E_INTERRUPTED) {
- qemudLog (QEMUD_ERR, "TLS handshake failed: %s",
+ qemudLog (QEMUD_ERR, _("TLS handshake failed: %s"),
gnutls_strerror (ret));
qemudDispatchClientFailure (server, client);
} else {
@@ -1572,7 +1585,7 @@ static int qemudOneLoop(void) {
if (errors) {
sig_errors -= errors;
qemudLog (QEMUD_ERR,
- "Signal handler reported %d errors: last error: %s",
+ _("Signal handler reported %d errors: last error: %s"),
errors, strerror (sig_lasterrno));
return -1;
}
@@ -1668,14 +1681,14 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg,
list = malloc (2 * sizeof (*list));
if (list == NULL) {
qemudLog (QEMUD_ERR,
- "failed to allocate memory for %s config list", key);
+ _("failed to allocate memory for %s config list"), key);
return -1;
}
list[0] = strdup (p->str);
list[1] = NULL;
if (list[0] == NULL) {
qemudLog (QEMUD_ERR,
- "failed to allocate memory for %s config list value",
+ _("failed to allocate memory for %s config list value"),
key);
free (list);
return -1;
@@ -1690,13 +1703,13 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg,
list = calloc (1+len, sizeof (*list));
if (list == NULL) {
qemudLog (QEMUD_ERR,
- "failed to allocate memory for %s config list", key);
+ _("failed to allocate memory for %s config list"), key);
return -1;
}
for (i = 0, pp = p->list; pp; ++i, pp = pp->next) {
if (pp->type != VIR_CONF_STRING) {
- qemudLog (QEMUD_ERR, "remoteReadConfigFile: %s: %s:"
- " must be a string or list of strings\n",
+ qemudLog (QEMUD_ERR, _("remoteReadConfigFile: %s: %s:"
+ " must be a string or list of strings\n"),
filename, key);
free (list);
return -1;
@@ -1707,8 +1720,8 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg,
for (j = 0 ; j < i ; j++)
free (list[j]);
free (list);
- qemudLog (QEMUD_ERR, "failed to allocate memory"
- " for %s config list value", key);
+ qemudLog (QEMUD_ERR, _("failed to allocate memory"
+ " for %s config list value"), key);
return -1;
}
@@ -1718,8 +1731,8 @@ remoteConfigGetStringList(virConfPtr conf, const char *key, char ***list_arg,
}
default:
- qemudLog (QEMUD_ERR, "remoteReadConfigFile: %s: %s:"
- " must be a string or list of strings\n",
+ qemudLog (QEMUD_ERR, _("remoteReadConfigFile: %s: %s:"
+ " must be a string or list of strings\n"),
filename, key);
return -1;
}
@@ -1735,8 +1748,8 @@ checkType (virConfValuePtr p, const char *filename,
{
if (p->type != required_type) {
qemudLog (QEMUD_ERR,
- "remoteReadConfigFile: %s: %s: invalid type:"
- " got %s; expected %s\n", filename, key,
+ _("remoteReadConfigFile: %s: %s: invalid type:"
+ " got %s; expected %s\n"), filename, key,
virConfTypeName (p->type),
virConfTypeName (required_type));
return -1;
@@ -1756,7 +1769,7 @@ checkType (virConfValuePtr p, const char *filename,
goto free_and_fail; \
(var_name) = strdup (p->str); \
if ((var_name) == NULL) { \
- qemudLog (QEMUD_ERR, "remoteReadConfigFile: %s\n", \
+ qemudLog (QEMUD_ERR, _("remoteReadConfigFile: %s\n"), \
strerror (errno)); \
goto free_and_fail; \
} \
@@ -1799,7 +1812,9 @@ static int remoteConfigGetAuth(virConfPtr conf, const char *key, int *auth, cons
*auth = REMOTE_AUTH_POLKIT;
#endif
} else {
- qemudLog (QEMUD_ERR, "remoteReadConfigFile: %s: %s: unsupported auth %s\n", filename, key, p->str);
+ qemudLog (QEMUD_ERR,
+ _("remoteReadConfigFile: %s: %s: unsupported auth %s\n"),
+ filename, key, p->str);
return -1;
}
@@ -1873,11 +1888,12 @@ remoteReadConfigFile (struct qemud_server *server, const char *filename)
GET_CONF_STR (conf, filename, unix_sock_group);
if (unix_sock_group) {
if (getuid() != 0) {
- qemudLog (QEMUD_WARN, "Cannot set group when not running as root");
+ qemudLog (QEMUD_WARN,
+ _("Cannot set group when not running as root"));
} else {
struct group *grp = getgrnam(unix_sock_group);
if (!grp) {
- qemudLog (QEMUD_ERR, "Failed to lookup group '%s'",
+ qemudLog (QEMUD_ERR, _("Failed to lookup group '%s'"),
unix_sock_group);
goto free_and_fail;
}
@@ -1890,7 +1906,7 @@ remoteReadConfigFile (struct qemud_server *server, const char *filename)
GET_CONF_STR (conf, filename, unix_sock_ro_perms);
if (unix_sock_ro_perms) {
if (xstrtol_i (unix_sock_ro_perms, NULL, 8, &unix_sock_ro_mask) != 0) {
- qemudLog (QEMUD_ERR, "Failed to parse mode '%s'",
+ qemudLog (QEMUD_ERR, _("Failed to parse mode '%s'"),
unix_sock_ro_perms);
goto free_and_fail;
}
@@ -1901,7 +1917,7 @@ remoteReadConfigFile (struct qemud_server *server, const char *filename)
GET_CONF_STR (conf, filename, unix_sock_rw_perms);
if (unix_sock_rw_perms) {
if (xstrtol_i (unix_sock_rw_perms, NULL, 8, &unix_sock_rw_mask) != 0) {
- qemudLog (QEMUD_ERR, "Failed to parse mode '%s'",
+ qemudLog (QEMUD_ERR, _("Failed to parse mode '%s'"),
unix_sock_rw_perms);
goto free_and_fail;
}
@@ -2074,7 +2090,7 @@ int main(int argc, char **argv) {
if (pipe(sigpipe) < 0 ||
qemudSetNonBlock(sigpipe[0]) < 0 ||
qemudSetNonBlock(sigpipe[1]) < 0) {
- qemudLog(QEMUD_ERR, "Failed to create pipe: %s",
+ qemudLog(QEMUD_ERR, _("Failed to create pipe: %s"),
strerror(errno));
goto error1;
}
@@ -2094,7 +2110,7 @@ int main(int argc, char **argv) {
openlog("libvirtd", 0, 0);
pid = qemudGoDaemon();
if (pid < 0) {
- qemudLog(QEMUD_ERR, "Failed to fork as daemon: %s",
+ qemudLog(QEMUD_ERR, _("Failed to fork as daemon: %s"),
strerror(errno));
goto error1;
}
@@ -2128,7 +2144,7 @@ int main(int argc, char **argv) {
POLLIN,
qemudDispatchSignalEvent,
server) < 0) {
- qemudLog(QEMUD_ERR, "Failed to register callback for signal pipe");
+ qemudLog(QEMUD_ERR, _("Failed to register callback for signal pipe"));
ret = 3;
goto error2;
}
diff --git a/qemud/remote.c b/qemud/remote.c
index 57f8f29..f89a490 100644
--- a/qemud/remote.c
+++ b/qemud/remote.c
@@ -1,7 +1,7 @@
/*
* remote.c: code handling remote requests (from remote_internal.c)
*
- * Copyright (C) 2007 Red Hat, Inc.
+ * Copyright (C) 2007, 2008 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -2126,7 +2126,7 @@ remoteDispatchAuthSaslInit (struct qemud_server *server ATTRIBUTE_UNUSED,
REMOTE_DEBUG("Initialize SASL auth %d", client->fd);
if (client->auth != REMOTE_AUTH_SASL ||
client->saslconn != NULL) {
- qemudLog(QEMUD_ERR, "client tried invalid SASL init request");
+ qemudLog(QEMUD_ERR, _("client tried invalid SASL init request"));
remoteDispatchFailAuth(client, req);
return -2;
}
@@ -2166,7 +2166,7 @@ remoteDispatchAuthSaslInit (struct qemud_server *server ATTRIBUTE_UNUSED,
free(localAddr);
free(remoteAddr);
if (err != SASL_OK) {
- qemudLog(QEMUD_ERR, "sasl context setup failed %d (%s)",
+ qemudLog(QEMUD_ERR, _("sasl context setup failed %d (%s)"),
err, sasl_errstring(err, NULL, NULL));
remoteDispatchFailAuth(client, req);
client->saslconn = NULL;
@@ -2180,7 +2180,7 @@ remoteDispatchAuthSaslInit (struct qemud_server *server ATTRIBUTE_UNUSED,
cipher = gnutls_cipher_get(client->tlssession);
if (!(ssf = (sasl_ssf_t)gnutls_cipher_get_key_size(cipher))) {
- qemudLog(QEMUD_ERR, "cannot TLS get cipher size");
+ qemudLog(QEMUD_ERR, _("cannot TLS get cipher size"));
remoteDispatchFailAuth(client, req);
sasl_dispose(&client->saslconn);
client->saslconn = NULL;
@@ -2190,7 +2190,7 @@ remoteDispatchAuthSaslInit (struct qemud_server *server ATTRIBUTE_UNUSED,
err = sasl_setprop(client->saslconn, SASL_SSF_EXTERNAL, &ssf);
if (err != SASL_OK) {
- qemudLog(QEMUD_ERR, "cannot set SASL external SSF %d (%s)",
+ qemudLog(QEMUD_ERR, _("cannot set SASL external SSF %d (%s)"),
err, sasl_errstring(err, NULL, NULL));
remoteDispatchFailAuth(client, req);
sasl_dispose(&client->saslconn);
@@ -2219,7 +2219,7 @@ remoteDispatchAuthSaslInit (struct qemud_server *server ATTRIBUTE_UNUSED,
err = sasl_setprop(client->saslconn, SASL_SEC_PROPS, &secprops);
if (err != SASL_OK) {
- qemudLog(QEMUD_ERR, "cannot set SASL security props %d (%s)",
+ qemudLog(QEMUD_ERR, _("cannot set SASL security props %d (%s)"),
err, sasl_errstring(err, NULL, NULL));
remoteDispatchFailAuth(client, req);
sasl_dispose(&client->saslconn);
@@ -2236,7 +2236,7 @@ remoteDispatchAuthSaslInit (struct qemud_server *server ATTRIBUTE_UNUSED,
NULL,
NULL);
if (err != SASL_OK) {
- qemudLog(QEMUD_ERR, "cannot list SASL mechanisms %d (%s)",
+ qemudLog(QEMUD_ERR, _("cannot list SASL mechanisms %d (%s)"),
err, sasl_errdetail(client->saslconn));
remoteDispatchFailAuth(client, req);
sasl_dispose(&client->saslconn);
@@ -2246,7 +2246,7 @@ remoteDispatchAuthSaslInit (struct qemud_server *server ATTRIBUTE_UNUSED,
REMOTE_DEBUG("Available mechanisms for client: '%s'", mechlist);
ret->mechlist = strdup(mechlist);
if (!ret->mechlist) {
- qemudLog(QEMUD_ERR, "cannot allocate mechlist");
+ qemudLog(QEMUD_ERR, _("cannot allocate mechlist"));
remoteDispatchFailAuth(client, req);
sasl_dispose(&client->saslconn);
client->saslconn = NULL;
@@ -2271,7 +2271,7 @@ remoteSASLCheckSSF (struct qemud_client *client,
err = sasl_getprop(client->saslconn, SASL_SSF, &val);
if (err != SASL_OK) {
- qemudLog(QEMUD_ERR, "cannot query SASL ssf on connection %d (%s)",
+ qemudLog(QEMUD_ERR, _("cannot query SASL ssf on connection %d (%s)"),
err, sasl_errstring(err, NULL, NULL));
remoteDispatchFailAuth(client, req);
sasl_dispose(&client->saslconn);
@@ -2281,7 +2281,7 @@ remoteSASLCheckSSF (struct qemud_client *client,
ssf = *(const int *)val;
REMOTE_DEBUG("negotiated an SSF of %d", ssf);
if (ssf < 56) { /* 56 is good for Kerberos */
- qemudLog(QEMUD_ERR, "negotiated SSF %d was not strong enough", ssf);
+ qemudLog(QEMUD_ERR, _("negotiated SSF %d was not strong enough"), ssf);
remoteDispatchFailAuth(client, req);
sasl_dispose(&client->saslconn);
client->saslconn = NULL;
@@ -2310,7 +2310,8 @@ remoteSASLCheckAccess (struct qemud_server *server,
err = sasl_getprop(client->saslconn, SASL_USERNAME, &val);
if (err != SASL_OK) {
- qemudLog(QEMUD_ERR, "cannot query SASL username on connection %d (%s)",
+ qemudLog(QEMUD_ERR,
+ _("cannot query SASL username on connection %d (%s)"),
err, sasl_errstring(err, NULL, NULL));
remoteDispatchFailAuth(client, req);
sasl_dispose(&client->saslconn);
@@ -2318,7 +2319,7 @@ remoteSASLCheckAccess (struct qemud_server *server,
return -1;
}
if (val == NULL) {
- qemudLog(QEMUD_ERR, "no client username was found");
+ qemudLog(QEMUD_ERR, _("no client username was found"));
remoteDispatchFailAuth(client, req);
sasl_dispose(&client->saslconn);
client->saslconn = NULL;
@@ -2328,7 +2329,7 @@ remoteSASLCheckAccess (struct qemud_server *server,
client->saslUsername = strdup((const char*)val);
if (client->saslUsername == NULL) {
- qemudLog(QEMUD_ERR, "out of memory copying username");
+ qemudLog(QEMUD_ERR, _("out of memory copying username"));
remoteDispatchFailAuth(client, req);
sasl_dispose(&client->saslconn);
client->saslconn = NULL;
@@ -2347,7 +2348,8 @@ remoteSASLCheckAccess (struct qemud_server *server,
}
/* Denied */
- qemudLog(QEMUD_ERR, "SASL client %s not allowed in whitelist", client->saslUsername);
+ qemudLog(QEMUD_ERR, _("SASL client %s not allowed in whitelist"),
+ client->saslUsername);
remoteDispatchFailAuth(client, req);
sasl_dispose(&client->saslconn);
client->saslconn = NULL;
@@ -2372,7 +2374,7 @@ remoteDispatchAuthSaslStart (struct qemud_server *server,
REMOTE_DEBUG("Start SASL auth %d", client->fd);
if (client->auth != REMOTE_AUTH_SASL ||
client->saslconn == NULL) {
- qemudLog(QEMUD_ERR, "client tried invalid SASL start request");
+ qemudLog(QEMUD_ERR, _("client tried invalid SASL start request"));
remoteDispatchFailAuth(client, req);
return -2;
}
@@ -2388,7 +2390,7 @@ remoteDispatchAuthSaslStart (struct qemud_server *server,
&serveroutlen);
if (err != SASL_OK &&
err != SASL_CONTINUE) {
- qemudLog(QEMUD_ERR, "sasl start failed %d (%s)",
+ qemudLog(QEMUD_ERR, _("sasl start failed %d (%s)"),
err, sasl_errdetail(client->saslconn));
sasl_dispose(&client->saslconn);
client->saslconn = NULL;
@@ -2396,7 +2398,8 @@ remoteDispatchAuthSaslStart (struct qemud_server *server,
return -2;
}
if (serveroutlen > REMOTE_AUTH_SASL_DATA_MAX) {
- qemudLog(QEMUD_ERR, "sasl start reply data too long %d", serveroutlen);
+ qemudLog(QEMUD_ERR, _("sasl start reply data too long %d"),
+ serveroutlen);
sasl_dispose(&client->saslconn);
client->saslconn = NULL;
remoteDispatchFailAuth(client, req);
@@ -2451,7 +2454,7 @@ remoteDispatchAuthSaslStep (struct qemud_server *server,
REMOTE_DEBUG("Step SASL auth %d", client->fd);
if (client->auth != REMOTE_AUTH_SASL ||
client->saslconn == NULL) {
- qemudLog(QEMUD_ERR, "client tried invalid SASL start request");
+ qemudLog(QEMUD_ERR, _("client tried invalid SASL start request"));
remoteDispatchFailAuth(client, req);
return -2;
}
@@ -2466,7 +2469,7 @@ remoteDispatchAuthSaslStep (struct qemud_server *server,
&serveroutlen);
if (err != SASL_OK &&
err != SASL_CONTINUE) {
- qemudLog(QEMUD_ERR, "sasl step failed %d (%s)",
+ qemudLog(QEMUD_ERR, _("sasl step failed %d (%s)"),
err, sasl_errdetail(client->saslconn));
sasl_dispose(&client->saslconn);
client->saslconn = NULL;
@@ -2475,7 +2478,8 @@ remoteDispatchAuthSaslStep (struct qemud_server *server,
}
if (serveroutlen > REMOTE_AUTH_SASL_DATA_MAX) {
- qemudLog(QEMUD_ERR, "sasl step reply data too long %d", serveroutlen);
+ qemudLog(QEMUD_ERR, _("sasl step reply data too long %d"),
+ serveroutlen);
sasl_dispose(&client->saslconn);
client->saslconn = NULL;
remoteDispatchFailAuth(client, req);
@@ -2524,7 +2528,7 @@ remoteDispatchAuthSaslInit (struct qemud_server *server ATTRIBUTE_UNUSED,
void *args ATTRIBUTE_UNUSED,
remote_auth_sasl_init_ret *ret ATTRIBUTE_UNUSED)
{
- qemudLog(QEMUD_ERR, "client tried unsupported SASL init request");
+ qemudLog(QEMUD_ERR, _("client tried unsupported SASL init request"));
remoteDispatchFailAuth(client, req);
return -1;
}
@@ -2536,7 +2540,7 @@ remoteDispatchAuthSaslStart (struct qemud_server *server ATTRIBUTE_UNUSED,
remote_auth_sasl_start_args *args ATTRIBUTE_UNUSED,
remote_auth_sasl_start_ret *ret ATTRIBUTE_UNUSED)
{
- qemudLog(QEMUD_ERR, "client tried unsupported SASL start request");
+ qemudLog(QEMUD_ERR, _("client tried unsupported SASL start request"));
remoteDispatchFailAuth(client, req);
return -1;
}
@@ -2548,7 +2552,7 @@ remoteDispatchAuthSaslStep (struct qemud_server *server ATTRIBUTE_UNUSED,
remote_auth_sasl_step_args *args ATTRIBUTE_UNUSED,
remote_auth_sasl_step_ret *ret ATTRIBUTE_UNUSED)
{
- qemudLog(QEMUD_ERR, "client tried unsupported SASL step request");
+ qemudLog(QEMUD_ERR, _("client tried unsupported SASL step request"));
remoteDispatchFailAuth(client, req);
return -1;
}
@@ -2562,7 +2566,8 @@ static int qemudGetSocketIdentity(int fd, uid_t *uid, pid_t *pid) {
unsigned int cr_len = sizeof (cr);
if (getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &cr, &cr_len) < 0) {
- qemudLog(QEMUD_ERR, "Failed to verify client credentials: %s", strerror(errno));
+ qemudLog(QEMUD_ERR, _("Failed to verify client credentials: %s"),
+ strerror(errno));
return -1;
}
@@ -2588,13 +2593,13 @@ remoteDispatchAuthPolkit (struct qemud_server *server ATTRIBUTE_UNUSED,
REMOTE_DEBUG("Start PolicyKit auth %d", client->fd);
if (client->auth != REMOTE_AUTH_POLKIT) {
- qemudLog(QEMUD_ERR, "client tried invalid PolicyKit init request");
+ qemudLog(QEMUD_ERR, _("client tried invalid PolicyKit init request"));
remoteDispatchFailAuth(client, req);
return -2;
}
if (qemudGetSocketIdentity(client->fd, &callerUid, &callerPid) < 0) {
- qemudLog(QEMUD_ERR, "cannot get peer socket identity");
+ qemudLog(QEMUD_ERR, _("cannot get peer socket identity"));
remoteDispatchFailAuth(client, req);
return -2;
}
@@ -2604,7 +2609,7 @@ remoteDispatchAuthPolkit (struct qemud_server *server ATTRIBUTE_UNUSED,
change policykit policy anyway, so its pointless trying
to restrict root */
if (callerUid == 0) {
- qemudLog(QEMUD_INFO, "Allowing PID %d running as root", callerPid);
+ qemudLog(QEMUD_INFO, _("Allowing PID %d running as root"), callerPid);
ret->complete = 1;
client->auth = REMOTE_AUTH_NONE;
} else {
@@ -2618,17 +2623,21 @@ remoteDispatchAuthPolkit (struct qemud_server *server ATTRIBUTE_UNUSED,
"org.libvirt.unix.monitor" :
"org.libvirt.unix.manage";
- qemudLog(QEMUD_INFO, "Checking PID %d running as %d", callerPid, callerUid);
+ qemudLog(QEMUD_INFO, _("Checking PID %d running as %d"),
+ callerPid, callerUid);
dbus_error_init(&err);
- if (!(pkcaller = polkit_caller_new_from_pid(server->sysbus, callerPid, &err))) {
- qemudLog(QEMUD_ERR, "Failed to lookup policy kit caller: %s", err.message);
+ if (!(pkcaller = polkit_caller_new_from_pid(server->sysbus,
+ callerPid, &err))) {
+ qemudLog(QEMUD_ERR, _("Failed to lookup policy kit caller: %s"),
+ err.message);
dbus_error_free(&err);
remoteDispatchFailAuth(client, req);
return -2;
}
if (!(pkaction = polkit_action_new())) {
- qemudLog(QEMUD_ERR, "Failed to create polkit action %s\n", strerror(errno));
+ qemudLog(QEMUD_ERR, _("Failed to create polkit action %s\n"),
+ strerror(errno));
polkit_caller_unref(pkcaller);
remoteDispatchFailAuth(client, req);
return -2;
@@ -2637,8 +2646,9 @@ remoteDispatchAuthPolkit (struct qemud_server *server ATTRIBUTE_UNUSED,
if (!(pkcontext = polkit_context_new()) ||
!polkit_context_init(pkcontext, &pkerr)) {
- qemudLog(QEMUD_ERR, "Failed to create polkit context %s\n",
- pkerr ? polkit_error_get_error_message(pkerr) : strerror(errno));
+ qemudLog(QEMUD_ERR, _("Failed to create polkit context %s\n"),
+ (pkerr ? polkit_error_get_error_message(pkerr)
+ : strerror(errno));
if (pkerr)
polkit_error_free(pkerr);
polkit_caller_unref(pkcaller);
@@ -2648,18 +2658,24 @@ remoteDispatchAuthPolkit (struct qemud_server *server ATTRIBUTE_UNUSED,
return -2;
}
- pkresult = polkit_context_can_caller_do_action(pkcontext, pkaction, pkcaller);
+ pkresult = polkit_context_can_caller_do_action(pkcontext, pkaction,
+ pkcaller);
polkit_context_unref(pkcontext);
polkit_caller_unref(pkcaller);
polkit_action_unref(pkaction);
if (pkresult != POLKIT_RESULT_YES) {
- qemudLog(QEMUD_ERR, "Policy kit denied action %s from pid %d, uid %d, result: %s\n",
- action, callerPid, callerUid, polkit_result_to_string_representation(pkresult));
+ qemudLog(QEMUD_ERR,
+ _("Policy kit denied action %s from pid %d, uid %d,"
+ " result: %s\n"),
+ action, callerPid, callerUid,
+ polkit_result_to_string_representation(pkresult));
remoteDispatchFailAuth(client, req);
return -2;
}
- qemudLog(QEMUD_INFO, "Policy allowed action %s from pid %d, uid %d, result %s",
- action, callerPid, callerUid, polkit_result_to_string_representation(pkresult));
+ qemudLog(QEMUD_INFO,
+ _("Policy allowed action %s from pid %d, uid %d, result %s"),
+ action, callerPid, callerUid,
+ polkit_result_to_string_representation(pkresult));
ret->complete = 1;
client->auth = REMOTE_AUTH_NONE;
}
@@ -2676,7 +2692,7 @@ remoteDispatchAuthPolkit (struct qemud_server *server ATTRIBUTE_UNUSED,
void *args ATTRIBUTE_UNUSED,
remote_auth_polkit_ret *ret ATTRIBUTE_UNUSED)
{
- qemudLog(QEMUD_ERR, "client tried unsupported PolicyKit init request");
+ qemudLog(QEMUD_ERR, _("client tried unsupported PolicyKit init request"));
remoteDispatchFailAuth(client, req);
return -1;
}
diff --git a/src/iptables.c b/src/iptables.c
index dc2225a..1d93bcc 100644
--- a/src/iptables.c
+++ b/src/iptables.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 Red Hat, Inc.
+ * Copyright (C) 2007, 2008 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -100,8 +100,8 @@ notifyRulesUpdated(const char *table,
argv[3] = NULL;
if (virRun(NULL, argv, NULL) < 0)
- qemudLog(QEMUD_WARN, "Failed to run '" LOKKIT_PATH " %s' : %s",
- arg, strerror(errno));
+ qemudLog(QEMUD_WARN, _("Failed to run '" LOKKIT_PATH
+ " %s' : %s"), arg, strerror(errno));
}
static int
@@ -148,7 +148,8 @@ notifyRulesRemoved(const char *table,
len = virFileReadAll(SYSCONF_DIR "/sysconfig/system-config-firewall",
MAX_FILE_LEN, &content);
if (len < 0) {
- qemudLog(QEMUD_WARN, "Failed to read " SYSCONF_DIR "/sysconfig/system-config-firewall");
+ qemudLog(QEMUD_WARN, _("Failed to read " SYSCONF_DIR
+ "/sysconfig/system-config-firewall"));
return;
}
@@ -175,7 +176,8 @@ notifyRulesRemoved(const char *table,
return;
write_error:
- qemudLog(QEMUD_WARN, "Failed to write to " SYSCONF_DIR "/sysconfig/system-config-firewall : %s",
+ qemudLog(QEMUD_WARN, _("Failed to write to " SYSCONF_DIR
+ "/sysconfig/system-config-firewall : %s"),
strerror(errno));
if (f)
fclose(f);
@@ -239,7 +241,7 @@ iptRulesSave(iptRules *rules)
int err;
if ((err = writeRules(rules->path, rules->rules, rules->nrules))) {
- qemudLog(QEMUD_WARN, "Failed to saves iptables rules to %s : %s",
+ qemudLog(QEMUD_WARN, _("Failed to saves iptables rules to %s : %s"),
rules->path, strerror(err));
return;
}
@@ -577,7 +579,9 @@ iptRulesReload(iptRules *rules)
rule->argv[rule->command_idx] = (char *) "--delete";
if (virRun(NULL, rule->argv, NULL) < 0)
- qemudLog(QEMUD_WARN, "Failed to remove iptables rule '%s' from chain '%s' in table '%s': %s",
+ qemudLog(QEMUD_WARN,
+ _("Failed to remove iptables rule '%s'"
+ " from chain '%s' in table '%s': %s"),
rule->rule, rules->chain, rules->table, strerror(errno));
rule->argv[rule->command_idx] = orig;
@@ -585,7 +589,8 @@ iptRulesReload(iptRules *rules)
for (i = 0; i < rules->nrules; i++)
if (virRun(NULL, rules->rules[i].argv, NULL) < 0)
- qemudLog(QEMUD_WARN, "Failed to add iptables rule '%s' to chain '%s' in table '%s': %s",
+ qemudLog(QEMUD_WARN, _("Failed to add iptables rule '%s'"
+ " to chain '%s' in table '%s': %s"),
rules->rules[i].rule, rules->chain, rules->table, strerror(errno));
}
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index aba8890..e39c7bc 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -410,14 +410,18 @@ static int qemudExtractVersionInfo(const char *qemu, int *version, int *flags) {
if (errno == EINTR) {
goto rewait;
}
- qemudLog(QEMUD_ERR, "Unexpected exit status from qemu %d pid %lu", got, (unsigned long)child);
+ qemudLog(QEMUD_ERR,
+ _("Unexpected exit status from qemu %d pid %lu"),
+ got, (unsigned long)child);
ret = -1;
}
/* Check & log unexpected exit status, but don't fail,
* as there's really no need to throw an error if we did
* actually read a valid version number above */
if (WEXITSTATUS(got) != 1) {
- qemudLog(QEMUD_WARN, "Unexpected exit status '%d', qemu probably failed", got);
+ qemudLog(QEMUD_WARN,
+ _("Unexpected exit status '%d', qemu probably failed"),
+ got);
}
return ret;
@@ -2510,21 +2514,25 @@ qemudLoadConfig(struct qemud_driver *driver,
if (!(def = qemudParseVMDef(NULL, driver, xml, file))) {
virErrorPtr err = virGetLastError();
- qemudLog(QEMUD_WARN, "Error parsing QEMU guest config '%s' : %s",
- path, err ? err->message :
- "BUG: unknown error - please report it\n");
+ qemudLog(QEMUD_WARN, _("Error parsing QEMU guest config '%s' : %s"),
+ path, (err ? err->message :
+ _("BUG: unknown error - please report it\n")));
return NULL;
}
if (!virFileMatchesNameSuffix(file, def->name, ".xml")) {
- qemudLog(QEMUD_WARN, "QEMU guest config filename '%s' does not match guest name '%s'",
+ qemudLog(QEMUD_WARN,
+ _("QEMU guest config filename '%s'"
+ " does not match guest name '%s'"),
path, def->name);
qemudFreeVMDef(def);
return NULL;
}
if (!(vm = qemudAssignVMDef(NULL, driver, def))) {
- qemudLog(QEMUD_WARN, "Failed to load QEMU guest config '%s': out of memory", path);
+ qemudLog(QEMUD_WARN,
+ _("Failed to load QEMU guest config '%s': out of memory"),
+ path);
qemudFreeVMDef(def);
return NULL;
}
@@ -2551,20 +2559,23 @@ qemudLoadNetworkConfig(struct qemud_driver *driver,
if (!(def = qemudParseNetworkDef(NULL, driver, xml, file))) {
virErrorPtr err = virGetLastError();
- qemudLog(QEMUD_WARN, "Error parsing network config '%s' : %s",
+ qemudLog(QEMUD_WARN, _("Error parsing network config '%s' : %s"),
path, err->message);
return NULL;
}
if (!virFileMatchesNameSuffix(file, def->name, ".xml")) {
- qemudLog(QEMUD_WARN, "Network config filename '%s' does not match network name '%s'",
+ qemudLog(QEMUD_WARN,
+ _("Network config filename '%s'"
+ " does not match network name '%s'"),
path, def->name);
qemudFreeNetworkDef(def);
return NULL;
}
if (!(network = qemudAssignNetworkDef(NULL, driver, def))) {
- qemudLog(QEMUD_WARN, "Failed to load network config '%s': out of memory", path);
+ qemudLog(QEMUD_WARN,
+ _("Failed to load network config '%s': out of memory"), path);
qemudFreeNetworkDef(def);
return NULL;
}
@@ -2591,7 +2602,7 @@ int qemudScanConfigDir(struct qemud_driver *driver,
if (!(dir = opendir(configDir))) {
if (errno == ENOENT)
return 0;
- qemudLog(QEMUD_ERR, "Failed to open dir '%s': %s",
+ qemudLog(QEMUD_ERR, _("Failed to open dir '%s': %s"),
configDir, strerror(errno));
return -1;
}
@@ -2608,13 +2619,14 @@ int qemudScanConfigDir(struct qemud_driver *driver,
continue;
if (virFileBuildPath(configDir, entry->d_name, NULL, path, PATH_MAX) < 0) {
- qemudLog(QEMUD_WARN, "Config filename '%s/%s' is too long",
+ qemudLog(QEMUD_WARN, _("Config filename '%s/%s' is too long"),
configDir, entry->d_name);
continue;
}
- if (virFileBuildPath(autostartDir, entry->d_name, NULL, autostartLink, PATH_MAX) < 0) {
- qemudLog(QEMUD_WARN, "Autostart link path '%s/%s' is too long",
+ if (virFileBuildPath(autostartDir, entry->d_name, NULL,
+ autostartLink, PATH_MAX) < 0) {
+ qemudLog(QEMUD_WARN, _("Autostart link path '%s/%s' is too long"),
autostartDir, entry->d_name);
continue;
}
diff --git a/src/qemu_driver.c b/src/qemu_driver.c
index 9c24f5b..15cd52c 100644
--- a/src/qemu_driver.c
+++ b/src/qemu_driver.c
@@ -71,7 +71,7 @@ static int qemudSetCloseExec(int fd) {
goto error;
return 0;
error:
- qemudLog(QEMUD_ERR, "Failed to set close-on-exec file descriptor flag");
+ qemudLog(QEMUD_ERR, _("Failed to set close-on-exec file descriptor flag"));
return -1;
}
@@ -85,7 +85,7 @@ static int qemudSetNonBlock(int fd) {
goto error;
return 0;
error:
- qemudLog(QEMUD_ERR, "Failed to set non-blocking file descriptor flag");
+ qemudLog(QEMUD_ERR, _("Failed to set non-blocking file descriptor flag"));
return -1;
}
@@ -123,7 +123,7 @@ void qemudAutostartConfigs(struct qemud_driver *driver) {
!qemudIsActiveNetwork(network) &&
qemudStartNetworkDaemon(NULL, driver, network) < 0) {
virErrorPtr err = virGetLastError();
- qemudLog(QEMUD_ERR, "Failed to autostart network '%s': %s",
+ qemudLog(QEMUD_ERR, _("Failed to autostart network '%s': %s"),
network->def->name, err->message);
}
@@ -138,7 +138,7 @@ void qemudAutostartConfigs(struct qemud_driver *driver) {
!qemudIsActiveVM(vm) &&
qemudStartVMDaemon(NULL, driver, vm) < 0) {
virErrorPtr err = virGetLastError();
- qemudLog(QEMUD_ERR, "Failed to autostart VM '%s': %s",
+ qemudLog(QEMUD_ERR, _("Failed to autostart VM '%s': %s"),
vm->def->name, err->message);
}
@@ -173,7 +173,7 @@ qemudStartup(void) {
goto out_of_memory;
} else {
if (!(pw = getpwuid(uid))) {
- qemudLog(QEMUD_ERR, "Failed to find user record for uid '%d': %s",
+ qemudLog(QEMUD_ERR, _("Failed to find user record for uid '%d': %s"),
uid, strerror(errno));
goto out_of_memory;
}
@@ -182,7 +182,7 @@ qemudStartup(void) {
goto snprintf_error;
if (asprintf (&base, "%s/.libvirt", pw->pw_dir) == -1) {
- qemudLog (QEMUD_ERR, "out of memory in asprintf");
+ qemudLog (QEMUD_ERR, _("out of memory in asprintf"));
goto out_of_memory;
}
}
@@ -223,11 +223,12 @@ qemudStartup(void) {
return 0;
snprintf_error:
- qemudLog(QEMUD_ERR, "Resulting path to long for buffer in qemudInitPaths()");
+ qemudLog(QEMUD_ERR,
+ _("Resulting path to long for buffer in qemudInitPaths()"));
return -1;
out_of_memory:
- qemudLog (QEMUD_ERR, "qemudStartup: out of memory");
+ qemudLog (QEMUD_ERR, _("qemudStartup: out of memory"));
free (base);
free(qemu_driver);
qemu_driver = NULL;
@@ -245,7 +246,7 @@ qemudReload(void) {
qemudScanConfigs(qemu_driver);
if (qemu_driver->iptables) {
- qemudLog(QEMUD_INFO, "Reloading iptables rules");
+ qemudLog(QEMUD_INFO, _("Reloading iptables rules"));
iptablesReloadRules(qemu_driver->iptables);
}
@@ -543,7 +544,7 @@ static int qemudWaitForMonitor(virConnectPtr conn,
/* Log, but ignore failures to write logfile for VM */
if (errno == EINTR)
goto retry;
- qemudLog(QEMUD_WARN, "Unable to log VM console data: %s",
+ qemudLog(QEMUD_WARN, _("Unable to log VM console data: %s"),
strerror(errno));
}
return ret;
@@ -656,15 +657,15 @@ static int qemudStartVMDaemon(virConnectPtr conn,
tmp = argv;
while (*tmp) {
if (write(vm->logfile, *tmp, strlen(*tmp)) < 0)
- qemudLog(QEMUD_WARN, "Unable to write argv to logfile %d: %s",
+ qemudLog(QEMUD_WARN, _("Unable to write argv to logfile %d: %s"),
errno, strerror(errno));
if (write(vm->logfile, " ", 1) < 0)
- qemudLog(QEMUD_WARN, "Unable to write argv to logfile %d: %s",
+ qemudLog(QEMUD_WARN, _("Unable to write argv to logfile %d: %s"),
errno, strerror(errno));
tmp++;
}
if (write(vm->logfile, "\n", 1) < 0)
- qemudLog(QEMUD_WARN, "Unable to write argv to logfile %d: %s",
+ qemudLog(QEMUD_WARN, _("Unable to write argv to logfile %d: %s"),
errno, strerror(errno));
if (virExecNonBlock(conn, argv, &vm->pid,
@@ -737,7 +738,7 @@ static int qemudVMData(struct qemud_driver *driver ATTRIBUTE_UNUSED,
/* Log, but ignore failures to write logfile for VM */
if (errno == EINTR)
goto retry;
- qemudLog(QEMUD_WARN, "Unable to log VM console data: %s",
+ qemudLog(QEMUD_WARN, _("Unable to log VM console data: %s"),
strerror(errno));
}
}
@@ -751,7 +752,7 @@ static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
if (!qemudIsActiveVM(vm))
return;
- qemudLog(QEMUD_INFO, "Shutting down VM '%s'", vm->def->name);
+ qemudLog(QEMUD_INFO, _("Shutting down VM '%s'"), vm->def->name);
kill(vm->pid, SIGTERM);
@@ -762,7 +763,8 @@ static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
virEventRemoveHandle(vm->stderr);
if (close(vm->logfile) < 0)
- qemudLog(QEMUD_WARN, "Unable to close logfile %d: %s", errno, strerror(errno));
+ qemudLog(QEMUD_WARN, _("Unable to close logfile %d: %s"),
+ errno, strerror(errno));
close(vm->stdout);
close(vm->stderr);
if (vm->monitor != -1)
@@ -775,7 +777,7 @@ static void qemudShutdownVMDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
if (waitpid(vm->pid, NULL, WNOHANG) != vm->pid) {
kill(vm->pid, SIGKILL);
if (waitpid(vm->pid, NULL, 0) != vm->pid) {
- qemudLog(QEMUD_WARN, "Got unexpected pid, damn");
+ qemudLog(QEMUD_WARN, _("Got unexpected pid, damn"));
}
}
@@ -1219,13 +1221,13 @@ static int qemudStartNetworkDaemon(virConnectPtr conn,
err_delbr1:
if (network->def->ipAddress[0] &&
(err = brSetInterfaceUp(driver->brctl, network->bridge, 0))) {
- qemudLog(QEMUD_WARN, "Failed to bring down bridge '%s' : %s",
+ qemudLog(QEMUD_WARN, _("Failed to bring down bridge '%s' : %s"),
network->bridge, strerror(err));
}
err_delbr:
if ((err = brDeleteBridge(driver->brctl, network->bridge))) {
- qemudLog(QEMUD_WARN, "Failed to delete bridge '%s' : %s\n",
+ qemudLog(QEMUD_WARN, _("Failed to delete bridge '%s' : %s\n"),
network->bridge, strerror(err));
}
@@ -1238,7 +1240,7 @@ static int qemudShutdownNetworkDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
struct qemud_network *network) {
int err;
- qemudLog(QEMUD_INFO, "Shutting down network '%s'", network->def->name);
+ qemudLog(QEMUD_INFO, _("Shutting down network '%s'"), network->def->name);
if (!qemudIsActiveNetwork(network))
return 0;
@@ -1250,12 +1252,12 @@ static int qemudShutdownNetworkDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
if (network->def->ipAddress[0] &&
(err = brSetInterfaceUp(driver->brctl, network->bridge, 0))) {
- qemudLog(QEMUD_WARN, "Failed to bring down bridge '%s' : %s\n",
+ qemudLog(QEMUD_WARN, _("Failed to bring down bridge '%s' : %s\n"),
network->bridge, strerror(err));
}
if ((err = brDeleteBridge(driver->brctl, network->bridge))) {
- qemudLog(QEMUD_WARN, "Failed to delete bridge '%s' : %s\n",
+ qemudLog(QEMUD_WARN, _("Failed to delete bridge '%s' : %s\n"),
network->bridge, strerror(err));
}
@@ -1263,7 +1265,7 @@ static int qemudShutdownNetworkDaemon(virConnectPtr conn ATTRIBUTE_UNUSED,
waitpid(network->dnsmasqPid, NULL, WNOHANG) != network->dnsmasqPid) {
kill(network->dnsmasqPid, SIGKILL);
if (waitpid(network->dnsmasqPid, NULL, 0) != network->dnsmasqPid)
- qemudLog(QEMUD_WARN, "Got unexpected pid for dnsmasq\n");
+ qemudLog(QEMUD_WARN, _("Got unexpected pid for dnsmasq\n"));
}
network->bridge[0] = '\0';
@@ -1367,7 +1369,7 @@ static int qemudMonitorCommand(struct qemud_driver *driver ATTRIBUTE_UNUSED,
/* Log, but ignore failures to write logfile for VM */
if (safewrite(vm->logfile, buf, strlen(buf)) < 0)
- qemudLog(QEMUD_WARN, "Unable to log VM console data: %s",
+ qemudLog(QEMUD_WARN, _("Unable to log VM console data: %s"),
strerror(errno));
*reply = buf;
@@ -1377,7 +1379,7 @@ static int qemudMonitorCommand(struct qemud_driver *driver ATTRIBUTE_UNUSED,
if (buf) {
/* Log, but ignore failures to write logfile for VM */
if (safewrite(vm->logfile, buf, strlen(buf)) < 0)
- qemudLog(QEMUD_WARN, "Unable to log VM console data: %s",
+ qemudLog(QEMUD_WARN, _("Unable to log VM console data: %s"),
strerror(errno));
free(buf);
}
@@ -2345,7 +2347,7 @@ static int qemudDomainUndefine(virDomainPtr dom) {
return -1;
if (unlink(vm->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR)
- qemudLog(QEMUD_WARN, "Failed to delete autostart link '%s': %s",
+ qemudLog(QEMUD_WARN, _("Failed to delete autostart link '%s': %s"),
vm->autostartLink, strerror(errno));
vm->configFile[0] = '\0';
@@ -2721,7 +2723,7 @@ static int qemudNetworkUndefine(virNetworkPtr net) {
return -1;
if (unlink(network->autostartLink) < 0 && errno != ENOENT && errno != ENOTDIR)
- qemudLog(QEMUD_WARN, "Failed to delete autostart link '%s': %s",
+ qemudLog(QEMUD_WARN, _("Failed to delete autostart link '%s': %s"),
network->autostartLink, strerror(errno));
network->configFile[0] = '\0';
diff --git a/src/uuid.c b/src/uuid.c
index ae30217..78b90e5 100644
--- a/src/uuid.c
+++ b/src/uuid.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 Red Hat, Inc.
+ * Copyright (C) 2007, 2008 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -99,8 +99,8 @@ virUUIDGenerate(unsigned char *uuid)
if ((err = virUUIDGenerateRandomBytes(uuid, VIR_UUID_BUFLEN)))
qemudLog(QEMUD_WARN,
- "Falling back to pseudorandom UUID, "
- "failed to generate random bytes: %s", strerror(err));
+ _("Falling back to pseudorandom UUID,"
+ " failed to generate random bytes: %s"), strerror(err));
return virUUIDGeneratePseudoRandomBytes(uuid, VIR_UUID_BUFLEN);
}
@@ -197,4 +197,3 @@ void virUUIDFormat(const unsigned char *uuid, char *uuidstr)
* tab-width: 4
* End:
*/
-
diff --git a/src/xm_internal.c b/src/xm_internal.c
index fbef462..4a876a4 100644
--- a/src/xm_internal.c
+++ b/src/xm_internal.c
@@ -2523,10 +2523,10 @@ int xenXMNumOfDefinedDomains(virConnectPtr conn) {
* xenXMDomainAttachDevice:
* @domain: pointer to domain object
* @xml: pointer to XML description of device
- *
+ *
* Create a virtual device attachment to backend.
* XML description is translated into config file.
- *
+ *
* Returns 0 in case of success, -1 in case of failure.
*/
static int
@@ -2879,7 +2879,7 @@ xenXMAttachInterface(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
attr_node->children = text_node;
attr_node->last = text_node;
attr_node->parent = node_tmp;
-
+
node_cur->next = node_tmp;
}
if (!(dev = xenXMParseXMLVif(domain->conn, node, hvm)))
@@ -2925,7 +2925,7 @@ xenXMAttachInterface(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
/**
* xenXMAutoAssignMac:
* @mac: pointer to Mac String
- *
+ *
* a mac is assigned automatically.
*
* Returns 0 in case of success, -1 in case of failure.
@@ -2948,7 +2948,7 @@ xenXMAutoAssignMac() {
* xenXMDomainDetachDevice:
* @domain: pointer to domain object
* @xml: pointer to XML description of device
- *
+ *
* Destroy a virtual device attachment to backend.
*
* Returns 0 in case of success, -1 in case of failure.
--
1.5.4.30.g7dbe
16 years, 9 months
[Libvir] Remove more useless if tests before "free"-like functions.
by Jim Meyering
A few new uses of already-checked functions were added recently,
and I've added xmlXPathFreeObject to the list, so that exposed
a bunch more.
-----------------------------------------------------------
Remove more useless if tests before "free"-like functions.
* build-aux/useless-if-before-free: Rename from ...
* build-aux/find-unnecessary-if-before-free: ... this. Remove file.
Also changed it so that new names are no longer hard-coded in the
script. Instead, they're supplied via options:
* Makefile.cfg (useless_free_options): Define.
Add xmlXPathFreeObject to the list of free-like functions it detects.
* Makefile.maint (sc_avoid_if_before_free): Reflect script renaming.
* .x-sc_avoid_if_before_free: Likewise.
* src/openvz_conf.c (openvzParseXML): Remove useless "if"-before-free.
* src/qemu_conf.c (qemudParseXML, qemudParseNetworkXML): Likewise.
* src/virsh.c (cmdVNCDisplay, cmdTTYConsole, cmdDetachInterface):
(cmdDetachDisk): Likewise.
* src/xm_internal.c (xenXMConfigSetIntFromXPath): Likewise.
(xenXMConfigSetStringFromXPath, xenXMParseXMLToConfig): Likewise.
(xenXMDomainAttachDevice, xenXMAttachDisk, xenXMAttachInterface):
(xenXMDomainDetachDevice): Likewise.
* src/xml.c (virXPathString): Likewise.
* tests/xmlrpctest.c (checkRequestValue): Likewise.
Signed-off-by: Jim Meyering <meyering(a)redhat.com>
---
.x-sc_avoid_if_before_free | 2 +-
Makefile.cfg | 5 +
Makefile.maint | 5 +-
build-aux/find-unnecessary-if-before-free | 42 ----------
build-aux/useless-if-before-free | 118 +++++++++++++++++++++++++++++
src/openvz_conf.c | 3 +-
src/qemu_conf.c | 44 ++++-------
src/virsh.c | 12 +--
src/xm_internal.c | 60 +++++----------
src/xml.c | 3 +-
tests/xmlrpctest.c | 5 +-
11 files changed, 170 insertions(+), 129 deletions(-)
delete mode 100755 build-aux/find-unnecessary-if-before-free
create mode 100755 build-aux/useless-if-before-free
diff --git a/.x-sc_avoid_if_before_free b/.x-sc_avoid_if_before_free
index f83ae7b..5093ef6 100644
--- a/.x-sc_avoid_if_before_free
+++ b/.x-sc_avoid_if_before_free
@@ -1,5 +1,5 @@
^gnulib/lib/getaddrinfo\.c$
^gnulib/lib/printf-parse\.c$
^gnulib/lib/vasnprintf\.c$
-^build-aux/find-unnecessary-if-before-free$
+^build-aux/useless-if-before-free$
^ChangeLog$
diff --git a/Makefile.cfg b/Makefile.cfg
index a9578ab..4543ebd 100644
--- a/Makefile.cfg
+++ b/Makefile.cfg
@@ -52,3 +52,8 @@ local-checks-to-skip = \
patch-check \
check-AUTHORS \
changelog-check
+
+useless_free_options = \
+ --name=sexpr_free \
+ --name=xmlXPathFreeContext \
+ --name=xmlXPathFreeObject
diff --git a/Makefile.maint b/Makefile.maint
index 923c422..8624328 100644
--- a/Makefile.maint
+++ b/Makefile.maint
@@ -40,7 +40,8 @@ syntax-check: $(local-check)
## --------------- ##
sc_avoid_if_before_free:
- @$(srcdir)/build-aux/find-unnecessary-if-before-free \
+ @$(srcdir)/build-aux/useless-if-before-free \
+ $(useless_free_options) \
$$($(CVS_LIST_EXCEPT)) && \
{ echo '$(ME): found useless "if" before "free" above' 1>&2; \
exit 1; } || :
@@ -288,7 +289,7 @@ sc_two_space_separator_in_usage:
1>&2; exit 1; } || :
err_func_re = \
-(DISABLE_fprintf|(xmlRpc|vir(Xend|XML|Hash|Conf|Test|LibConn))Error)
+(DISABLE_fprintf|qemudLog|(xmlRpc|vir(Xend|XML|Hash|Conf|Test|LibConn))Error)
# Look for diagnostics that aren't marked for translation.
# This won't find any for which error's format string is on a separate line.
diff --git a/build-aux/find-unnecessary-if-before-free b/build-aux/find-unnecessary-if-before-free
deleted file mode 100755
index 0cd38eb..0000000
--- a/build-aux/find-unnecessary-if-before-free
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/usr/bin/perl
-# Detect instances of "if (p) free (p);".
-# Likewise for "if (p != NULL) free (p);".
-# Exit status is like grep: 0 for no match. 1 for any number.
-
-# Note: giving line numbers isn't practical, since I've reset the
-# input record separator.
-use strict;
-use warnings;
-(my $ME = $0) =~ s|.*/||;
-
-{
- # Use ';' as the input record separator.
- $/ = ';';
-
- my $found_match = 0;
- foreach my $file (@ARGV)
- {
- open FH, '<', $file
- or die "$ME: can't open `$file' for reading: $!\n";
- while (defined (my $line = <FH>))
- {
- if ($line =~
- /\b(if\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)
- \s+(?:xmlXPathFreeContext|(?:sexpr_)?free)\s*\(\s*\2\s*\))/sx)
- {
- print "$file: $1\n";
- $found_match = 1;
- }
- }
- close FH;
- }
- exit !$found_match;
-}
-
-my $foo = <<'EOF';
-# The above is to *find* them.
-# This adjusts them, removing the unnecessary "if (p)" part.
-
-git ls-files -z --exclude=find-unnecessary-if-before-free |xargs -0 \
-perl -0x3b -pi -e 's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)\s+((?:xmlXPathFreeContext|(?:sexpr_)?free)\s*\(\s*\1\s*\))/$2/s'
-EOF
diff --git a/build-aux/useless-if-before-free b/build-aux/useless-if-before-free
new file mode 100755
index 0000000..57040a3
--- /dev/null
+++ b/build-aux/useless-if-before-free
@@ -0,0 +1,118 @@
+#!/usr/bin/perl -T
+# Detect instances of "if (p) free (p);".
+# Likewise for "if (p != NULL) free (p);".
+
+my $VERSION = '2008-02-04 22:25'; # UTC
+# The definition above must lie within the first 8 lines in order
+# for the Emacs time-stamp write hook (at end) to update it.
+# If you change this file with Emacs, please let the write hook
+# do its job. Otherwise, update this string manually.
+
+# Exit status is like grep: 0 for no match. 1 for any number.
+# Note: giving line numbers isn't practical, since I've reset the
+# input record separator.
+use strict;
+use warnings;
+use Getopt::Long;
+
+(my $ME = $0) =~ s|.*/||;
+
+my $debug = 0;
+my $verbose = 0;
+
+sub usage ($)
+{
+ my ($exit_code) = @_;
+ my $STREAM = ($exit_code == 0 ? *STDOUT : *STDERR);
+ if ($exit_code != 0)
+ {
+ print $STREAM "Try `$ME --help' for more information.\n";
+ }
+ else
+ {
+ print $STREAM <<EOF;
+Usage: $ME [OPTIONS] FILE...
+
+OPTIONS:
+
+ --name=N add name N to the list of `free'-like functions to detect;
+ may be repeated
+
+ --help display this help and exit
+ --version output version information and exit
+ --verbose generate verbose output
+
+EXAMPLE:
+
+ git ls-files -z |xargs -0 $ME
+
+EOF
+ }
+ exit $exit_code;
+}
+
+{
+ my @name = qw(free);
+ GetOptions
+ (
+ debug => \$debug,
+ verbose => \$verbose,
+ help => sub { usage 0 },
+ version => sub { print "$ME version $VERSION\n"; exit },
+ 'name=s@' => \@name,
+ ) or usage 1;
+
+ # Make sure we have the right number of non-option arguments.
+ # Always tell the user why we fail.
+ @ARGV < 1
+ and (warn "$ME: missing FILE argument\n"), usage 1;
+
+ my $or = join '|', @name;
+ my $regexp = qr/(?:$or)/;
+
+ # Set the input record separator.
+ $/ = '"';
+
+ my $found_match = 0;
+ foreach my $file (@ARGV)
+ {
+ open FH, '<', $file
+ or die "$ME: can't open `$file' for reading: $!\n";
+ while (defined (my $line = <FH>))
+ {
+ if ($line =~
+ /\b(if\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)
+ (?: \s*$regexp\s*\(\s*\2\s*\)|
+ \s*\{\s*$regexp\s*\(\s*\2\s*\)\s*;\s*\}))/sx)
+ {
+ print "$file: $1\n";
+ $found_match = 1;
+ }
+ }
+ close FH;
+ }
+ exit !$found_match;
+}
+
+my $foo = <<'EOF';
+# The above is to *find* them.
+# This adjusts them, removing the unnecessary "if (p)" part.
+
+# FIXME: do something like this as an option.
+git ls-files -z --exclude=$ME |xargs -0 \
+perl -0x3b -pi -e 's/\bif\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)\s+((?:sexpr_)?free\s*\(\s*\1\s*\))/$2/s'
+
+When modifying files, refuse to process anything other than a regular file.
+
+# Or this one-liner to detect them:
+git ls-files -z |xargs -0 perl -00 -ne '/\b(if\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)(?:\s*(?:sexpr_)?free\s*\(\s*\2\s*\)|\s*\{\s*(?:sexpr_)?free\s*\(\s*\2\s*\)\s*;\s*\}))/sx and print "$1\n"'
+EOF
+
+## Local Variables:
+## indent-tabs-mode: nil
+## eval: (add-hook 'write-file-hooks 'time-stamp)
+## time-stamp-start: "my $VERSION = '"
+## time-stamp-format: "%:y-%02m-%02d %02H:%02M"
+## time-stamp-time-zone: "UTC"
+## time-stamp-end: "'; # UTC"
+## End:
diff --git a/src/openvz_conf.c b/src/openvz_conf.c
index ebed9b2..482de82 100644
--- a/src/openvz_conf.c
+++ b/src/openvz_conf.c
@@ -495,8 +495,7 @@ static struct openvz_vm_def
bail_out:
free(prop);
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt);
openvzFreeVMDef(def);
diff --git a/src/qemu_conf.c b/src/qemu_conf.c
index 39cfdc1..aba8890 100644
--- a/src/qemu_conf.c
+++ b/src/qemu_conf.c
@@ -1,7 +1,7 @@
/*
* config.c: VM configuration management
*
- * Copyright (C) 2006, 2007 Red Hat, Inc.
+ * Copyright (C) 2006, 2007, 2008 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange
*
* This library is free software; you can redistribute it and/or
@@ -1004,8 +1004,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
goto error;
}
}
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
/* Extract domain memory */
@@ -1023,8 +1022,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
goto error;
}
}
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
/* Extract domain vcpu info */
obj = xmlXPathEval(BAD_CAST "string(/domain/vcpu[1])", ctxt);
@@ -1039,8 +1037,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
goto error;
}
}
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
/* See if ACPI feature is requested */
obj = xmlXPathEval(BAD_CAST "/domain/features/acpi", ctxt);
@@ -1062,8 +1059,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
else
def->noReboot = 0;
}
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
/* See if we set clock to localtime */
obj = xmlXPathEval(BAD_CAST "string(/domain/clock/@offset)", ctxt);
@@ -1076,8 +1072,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
else
def->localtime = 0;
}
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
/* Extract OS type info */
@@ -1111,8 +1106,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
}
strcpy(def->os.arch, (const char *)obj->stringval);
}
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST "string(/domain/os/type[1]/@machine)", ctxt);
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
@@ -1134,8 +1128,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
}
strcpy(def->os.machine, (const char *)obj->stringval);
}
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST "string(/domain/os/kernel[1])", ctxt);
@@ -1147,8 +1140,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
}
strcpy(def->os.kernel, (const char *)obj->stringval);
}
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST "string(/domain/os/initrd[1])", ctxt);
@@ -1160,8 +1152,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
}
strcpy(def->os.initrd, (const char *)obj->stringval);
}
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST "string(/domain/os/cmdline[1])", ctxt);
@@ -1173,8 +1164,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
}
strcpy(def->os.cmdline, (const char *)obj->stringval);
}
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
/* analysis of the disk devices */
@@ -1224,8 +1214,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
}
strcpy(def->os.binary, (const char *)obj->stringval);
}
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
obj = xmlXPathEval(BAD_CAST "/domain/devices/graphics", ctxt);
if ((obj == NULL) || (obj->type != XPATH_NODESET) ||
@@ -1382,8 +1371,7 @@ static struct qemud_vm_def *qemudParseXML(virConnectPtr conn,
error:
free(prop);
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt);
qemudFreeVMDef(def);
return NULL;
@@ -2389,10 +2377,8 @@ static struct qemud_network_def *qemudParseNetworkXML(virConnectPtr conn,
error:
/* XXX free all the stuff in the qemud_network struct, or leave it upto
the caller ? */
- if (obj)
- xmlXPathFreeObject(obj);
- if (tmp)
- xmlXPathFreeObject(tmp);
+ xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(tmp);
xmlXPathFreeContext(ctxt);
qemudFreeNetworkDef(def);
return NULL;
diff --git a/src/virsh.c b/src/virsh.c
index 36808ed..9521eff 100644
--- a/src/virsh.c
+++ b/src/virsh.c
@@ -2931,8 +2931,7 @@ cmdVNCDisplay(vshControl * ctl, vshCmd * cmd)
ret = TRUE;
cleanup:
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt);
if (xml)
xmlFreeDoc(xml);
@@ -2993,8 +2992,7 @@ cmdTTYConsole(vshControl * ctl, vshCmd * cmd)
vshPrint(ctl, "%s\n", (const char *)obj->stringval);
cleanup:
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt);
if (xml)
xmlFreeDoc(xml);
@@ -3338,8 +3336,7 @@ cmdDetachInterface(vshControl * ctl, vshCmd * cmd)
cleanup:
if (dom)
virDomainFree(dom);
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt);
if (xml)
xmlFreeDoc(xml);
@@ -3611,8 +3608,7 @@ cmdDetachDisk(vshControl * ctl, vshCmd * cmd)
ret = TRUE;
cleanup:
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt);
if (xml)
xmlFreeDoc(xml);
diff --git a/src/xm_internal.c b/src/xm_internal.c
index b3a9f3a..fbef462 100644
--- a/src/xm_internal.c
+++ b/src/xm_internal.c
@@ -1556,8 +1556,7 @@ int xenXMConfigSetIntFromXPath(virConnectPtr conn,
ret = 0;
error:
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
return ret;
}
@@ -1591,8 +1590,7 @@ int xenXMConfigSetStringFromXPath(virConnectPtr conn,
ret = 0;
error:
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
return ret;
}
@@ -2278,8 +2276,7 @@ virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml) {
virConfFree(conf);
if (prop != NULL)
xmlFree(prop);
- if (obj != NULL)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt);
if (doc != NULL)
xmlFreeDoc(doc);
@@ -2578,8 +2575,7 @@ xenXMDomainAttachDevice(virDomainPtr domain, const char *xml) {
(obj->stringval) && (STREQ((char *)obj->stringval, "hvm")))
hvm = 1;
- if (ctxt)
- xmlXPathFreeContext(ctxt);
+ xmlXPathFreeContext(ctxt);
ctxt = NULL;
if (doc)
xmlFreeDoc(doc);
@@ -2617,12 +2613,9 @@ xenXMDomainAttachDevice(virDomainPtr domain, const char *xml) {
ret = 0;
cleanup:
- if (domxml)
- free(domxml);
- if (obj)
- xmlXPathFreeObject(obj);
- if (ctxt)
- xmlXPathFreeContext(ctxt);
+ free(domxml);
+ xmlXPathFreeObject(obj);
+ xmlXPathFreeContext(ctxt);
if (doc)
xmlFreeDoc(doc);
@@ -2736,8 +2729,7 @@ xenXMAttachDisk(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
prev->next = list_val;
} else {
/* configure */
- if (list_val->str)
- free(list_val->str);
+ free(list_val->str);
list_val->str = dev;
}
@@ -2745,12 +2737,9 @@ xenXMAttachDisk(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
goto cleanup;
cleanup:
- if (type)
- free(type);
- if (source)
- free(source);
- if (target)
- free(target);
+ free(type);
+ free(source);
+ free(target);
return (ret);
}
@@ -2823,8 +2812,7 @@ xenXMAttachInterface(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
if (!(strcmp(dommac, (const char *) mac))) {
if (autoassign) {
- if (mac)
- free(mac);
+ free(mac);
mac = NULL;
if (!(mac = (xmlChar *)xenXMAutoAssignMac()))
goto cleanup;
@@ -2912,8 +2900,7 @@ xenXMAttachInterface(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
prev->next = list_val;
} else {
/* configure */
- if (list_val->str)
- free(list_val->str);
+ free(list_val->str);
list_val->str = dev;
}
@@ -2928,12 +2915,9 @@ xenXMAttachInterface(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
if (text_node)
xmlFree(text_node);
cleanup:
- if (type)
- free(type);
- if (source)
- free(source);
- if (mac)
- free(mac);
+ free(type);
+ free(source);
+ free(mac);
return (ret);
}
@@ -3137,16 +3121,12 @@ xenXMDomainDetachDevice(virDomainPtr domain, const char *xml) {
ret = 0;
cleanup:
- if (ctxt)
- xmlXPathFreeContext(ctxt);
+ xmlXPathFreeContext(ctxt);
if (doc)
xmlFreeDoc(doc);
- if (domdevice)
- free(domdevice);
- if (key)
- free(key);
- if (list_val)
- free(list_val);
+ free(domdevice);
+ free(key);
+ free(list_val);
return (ret);
}
diff --git a/src/xml.c b/src/xml.c
index 614deb0..4ac1765 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -479,8 +479,7 @@ virXPathString(const char *xpath, xmlXPathContextPtr ctxt)
obj = xmlXPathEval(BAD_CAST xpath, ctxt);
if ((obj == NULL) || (obj->type != XPATH_STRING) ||
(obj->stringval == NULL) || (obj->stringval[0] == 0)) {
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
return (NULL);
}
ret = strdup((char *) obj->stringval);
diff --git a/tests/xmlrpctest.c b/tests/xmlrpctest.c
index 9297004..5c16b0b 100644
--- a/tests/xmlrpctest.c
+++ b/tests/xmlrpctest.c
@@ -1,7 +1,7 @@
/*
* xmlrpctest.c: simple client for XML-RPC tests
*
- * Copyright (C) 2005 Red Hat, Inc.
+ * Copyright (C) 2005, 2008 Red Hat, Inc.
*
* See COPYING.LIB for the License of this software
*
@@ -119,8 +119,7 @@ checkRequestValue(const char *xmlstr, const char *xpath, int type, void *expecte
ret = 0;
error:
- if (obj)
- xmlXPathFreeObject(obj);
+ xmlXPathFreeObject(obj);
xmlXPathFreeContext(ctxt);
if (xml)
xmlFreeDoc(xml);
--
1.5.4.30.g7dbe
16 years, 9 months
Re: [Libvir] [patch 1/2] Create directory for saving iptables rules
by Jim Meyering
Mark McLoughlin <markmc(a)redhat.com> wrote:
> The patch which reworked the iptables rules saving
> accidently dropped the call to virFileMakePath()
> resulting in:
>
> Failed to saves iptables rules to /var/lib/libvirt/iptables/filter/INPUT.chain : No such file or directory
>
> Re-instate the virFileMakePath() call.
>
> Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
>
> Index: libvirt/src/iptables.c
> ===================================================================
> --- libvirt.orig/src/iptables.c 2008-02-06 23:14:28.000000000 +0000
> +++ libvirt/src/iptables.c 2008-02-06 23:15:33.000000000 +0000
> @@ -238,6 +238,12 @@
> #ifdef ENABLE_IPTABLES_LOKKIT
> int err;
>
> + if ((err = virFileMakePath(rules->dir))) {
> + qemudLog(QEMUD_WARN "Failed to create directory %s : %s",
> + rules->dir, strerror(err));
> + return;
> + }
> +
> if ((err = writeRules(rules->path, rules->rules, rules->nrules))) {
> qemudLog(QEMUD_WARN, "Failed to saves iptables rules to %s : %s",
> rules->path, strerror(err));
+1, modulo what looks like a missing comma after QEMUD_WARN
16 years, 9 months
Re: [Libvir] [patch 2/2] Dont crash if theres no /sys/hypervisor/capabilities
by Daniel Veillard
On Wed, Feb 06, 2008 at 11:45:59PM +0000, Mark McLoughlin wrote:
> xenHypervisorMakeCapabilitiesXML() can be called with either
> of it's FILE* paramaters NULL; don't crash when the capabilities
> pointer is NULL.
>
> Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
> Index: libvirt/src/xen_internal.c
> ===================================================================
> --- libvirt.orig/src/xen_internal.c 2008-02-06 22:38:06.000000000 +0000
> +++ libvirt/src/xen_internal.c 2008-02-06 23:38:54.000000000 +0000
> @@ -2233,7 +2233,7 @@
> */
>
> /* Expecting one line in this file - ignore any more. */
> - if (fgets (line, sizeof line, capabilities)) {
> + if (capabilities && fgets (line, sizeof line, capabilities)) {
> /* Split the line into tokens. strtok_r is OK here because we "own"
> * this buffer. Parse out the features from each token.
> */
okay, but I still prefer when test expressions are fully parenthetized,
so preferabbly with ()() added, thanks :-)
+1
Daniel
--
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard | virtualization library http://libvirt.org/
veillard(a)redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
16 years, 9 months
[Libvir] [Patch] Compilation cleanup
by Atsushi SAKAI
Hi,
This patch fixes following message in compilation.
===============
xm_internal.h:64: warning: 'xenXMDomainAttachDevice' declared 'static' but never defined
xm_internal.h:65: warning: 'xenXMDomainDetachDevice' declared 'static' but never defined
===============
Signed-off-by: Atsushi SAKAI <sakaia(a)jp.fujitsu.com>
Thanks
Atsushi SAKAI
16 years, 9 months
[Libvir] [PATCH] Print line numbers in unnecessary-if-before-free check
by Mark McLoughlin
The unnecessary-if-before-free doesn't currently print line
numbers, which is a little annoying.
This patch fixes that with some rather hideous perl hacking.
I should have known to let well enough alone rather than
dredge up my long forgotten perl knowledge :-)
Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
Index: libvirt/build-aux/find-unnecessary-if-before-free
===================================================================
--- libvirt.orig/build-aux/find-unnecessary-if-before-free 2008-02-07 09:24:08.000000000 +0000
+++ libvirt/build-aux/find-unnecessary-if-before-free 2008-02-07 09:29:16.000000000 +0000
@@ -18,15 +18,20 @@
{
open FH, '<', $file
or die "$ME: can't open `$file' for reading: $!\n";
+ my $i = 1;
while (defined (my $line = <FH>))
{
- if ($line =~
+ my @matches = ($line =~
/\b(if\s*\(\s*(\S+?)(?:\s*!=\s*NULL)?\s*\)
- \s+(?:xmlXPathFreeContext|(?:sexpr_)?free)\s*\(\s*\2\s*\))/sx)
+ \s+(?:xmlXPathFreeContext|(?:sexpr_)?free)\s*\(\s*\2\s*\))/sx);
+
+ if (@matches)
{
- print "$file: $1\n";
+ my $j = $i + (my @a = split(/\n/, substr($line, 0, index($line, $matches[0])))) - 1;
+ print "$file:$j $1\n";
$found_match = 1;
}
+ $i += (my @a = split(/\n/, $line)) - 1;
}
close FH;
}
--
16 years, 9 months
Re: [Libvir] [patch 1/3] Move static function prototype from header
by Daniel Veillard
On Wed, Feb 06, 2008 at 11:07:53PM +0000, Mark McLoughlin wrote:
> Fixes:
>
> xm_internal.h:64: error: 'xenXMDomainAttachDevice' declared 'static' but never defined
> xm_internal.h:65: error: 'xenXMDomainDetachDevice' declared 'static' but never defined
>
> Signed-off-by: Mark McLoughlin <markmc(a)redhat.com>
>
> Index: libvirt/src/xm_internal.c
> ===================================================================
> --- libvirt.orig/src/xm_internal.c
> +++ libvirt/src/xm_internal.c
> @@ -77,6 +77,8 @@ static int xenXMAttachDisk(virDomainPtr
> xmlNodePtr node, xenXMConfCachePtr entry);
> static int xenXMAttachInterface(virDomainPtr domain, xmlXPathContextPtr ctxt, int hvm,
> xmlNodePtr node, xenXMConfCachePtr entry);
> +static int xenXMDomainAttachDevice(virDomainPtr domain, const char *xml);
> +static int xenXMDomainDetachDevice(virDomainPtr domain, const char *xml);
>
> #define XM_REFRESH_INTERVAL 10
>
> Index: libvirt/src/xm_internal.h
> ===================================================================
> --- libvirt.orig/src/xm_internal.h
> +++ libvirt/src/xm_internal.h
> @@ -61,9 +61,6 @@ int xenXMDomainUndefine(virDomainPtr dom
> virConfPtr xenXMParseXMLToConfig(virConnectPtr conn, const char *xml);
> char *xenXMDomainFormatXML(virConnectPtr conn, virConfPtr conf);
>
> -static int xenXMDomainAttachDevice(virDomainPtr domain, const char *xml);
> -static int xenXMDomainDetachDevice(virDomainPtr domain, const char *xml);
> -
> #ifdef __cplusplus
> }
> #endif
Yup noticed the warning on Tuesday, thanks for chasing it, +1
Daniel
--
Red Hat Virtualization group http://redhat.com/virtualization/
Daniel Veillard | virtualization library http://libvirt.org/
veillard(a)redhat.com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
16 years, 9 months