static int sigwrite = -1; /* Signal handler pipe */
static int ipsock = 0; /* -l Listen for TCP/IP */
+/* Defaults for logging */
+static int log_level = 3;
+static char *log_filters = NULL;
+static char *log_outputs = NULL;
+
/* Defaults for configuration file elements */
static int listen_tls = 1;
static int listen_tcp = 0;
{
struct stat sb;
if (stat(file, &sb) < 0) {
- qemudLog (QEMUD_ERR, _("Cannot access %s '%s': %s (%d)"),
+ ERROR(_("Cannot access %s '%s': %s (%d)"),
type, file, strerror(errno), errno);
return -1;
}
err = gnutls_certificate_allocate_credentials (&x509_cred);
if (err) {
- qemudLog (QEMUD_ERR, _("gnutls_certificate_allocate_credentials: %s"),
+ ERROR(_("gnutls_certificate_allocate_credentials: %s"),
gnutls_strerror (err));
return -1;
}
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"),
+ ERROR(_("gnutls_certificate_set_x509_trust_file: %s"),
gnutls_strerror (err));
return -1;
}
if (remoteCheckCertFile("CA revocation list", crl_file) < 0)
return -1;
- qemudDebug ("loading CRL from %s", crl_file);
+ DEBUG("loading CRL from %s", crl_file);
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"),
+ ERROR(_("gnutls_certificate_set_x509_crl_file: %s"),
gnutls_strerror (err));
return -1;
}
return -1;
if (remoteCheckCertFile("server key", key_file) < 0)
return -1;
- qemudDebug ("loading cert and key from %s and %s",
- cert_file, key_file);
+ DEBUG("loading cert and key from %s and %s", cert_file, key_file);
err =
gnutls_certificate_set_x509_key_file (x509_cred,
cert_file, key_file,
GNUTLS_X509_FMT_PEM);
if (err < 0) {
- qemudLog (QEMUD_ERR, _("gnutls_certificate_set_x509_key_file: %s"),
+ ERROR(_("gnutls_certificate_set_x509_key_file: %s"),
gnutls_strerror (err));
return -1;
}
*/
err = gnutls_dh_params_init (&dh_params);
if (err < 0) {
- qemudLog (QEMUD_ERR, _("gnutls_dh_params_init: %s"),
- gnutls_strerror (err));
+ ERROR(_("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"),
- gnutls_strerror (err));
+ ERROR(_("gnutls_dh_params_generate2: %s"), gnutls_strerror (err));
return -1;
}
pthread_mutex_lock(&server->lock);
if (saferead(server->sigread, &siginfo, sizeof(siginfo)) != sizeof(siginfo)) {
- qemudLog(QEMUD_ERR, _("Failed to read from signal pipe: %s"),
- strerror(errno));
+ ERROR(_("Failed to read from signal pipe: %s"), strerror(errno));
pthread_mutex_unlock(&server->lock);
return;
}
switch (siginfo.si_signo) {
case SIGHUP:
- qemudLog(QEMUD_INFO, "%s", _("Reloading configuration on SIGHUP"));
+ INFO0(_("Reloading configuration on SIGHUP"));
if (virStateReload() < 0)
- qemudLog(QEMUD_WARN, "%s", _("Error while reloading drivers"));
+ WARN0(_("Error while reloading drivers"));
break;
case SIGINT:
case SIGQUIT:
case SIGTERM:
- qemudLog(QEMUD_WARN, _("Shutting down on signal %d"),
- siginfo.si_signo);
+ WARN(_("Shutting down on signal %d"), siginfo.si_signo);
server->shutdown = 1;
break;
default:
- qemudLog(QEMUD_INFO, _("Received unexpected signal %d"),
- siginfo.si_signo);
+ INFO(_("Received unexpected signal %d"), siginfo.si_signo);
break;
}
goto error;
return 0;
error:
- qemudLog(QEMUD_ERR,
- "%s", _("Failed to set close-on-exec file descriptor flag"));
+ ERROR0(_("Failed to set close-on-exec file descriptor flag"));
return -1;
}
goto error;
return 0;
error:
- qemudLog(QEMUD_ERR,
- "%s", _("Failed to set non-blocking file descriptor flag"));
+ ERROR0(_("Failed to set non-blocking file descriptor flag"));
return -1;
}
-void qemudLog(int priority, const char *fmt, ...)
-{
- va_list args;
-
- va_start(args, fmt);
-
- if (godaemon) {
- int sysprio = -1;
-
- switch(priority) {
- case QEMUD_ERR:
- sysprio = LOG_ERR;
- break;
- case QEMUD_WARN:
- sysprio = LOG_WARNING;
- break;
- case QEMUD_INFO:
- if (verbose)
- sysprio = LOG_INFO;
- break;
-#ifdef ENABLE_DEBUG
- case QEMUD_DEBUG:
- if (verbose)
- sysprio = LOG_DEBUG;
- break;
-#endif
- default:
- break;
- }
-
- if (sysprio != -1)
- vsyslog(sysprio, fmt, args);
- } else {
- switch(priority) {
- case QEMUD_ERR:
- case QEMUD_WARN:
- vfprintf(stderr, fmt, args);
- fputc('\n', stderr);
- break;
-
- case QEMUD_INFO:
- if (verbose) {
- vprintf(fmt, args);
- fputc('\n', stdout);
- }
- break;
-
-#ifdef ENABLE_DEBUG
- case QEMUD_DEBUG:
- if (verbose) {
- vprintf(fmt, args);
- fputc('\n', stdout);
- }
- break;
-#endif
- default:
- break;
- }
- }
-
- va_end(args);
-}
-
static int qemudGoDaemon(void) {
int pid = fork();
switch (pid) {
return 0;
if ((fd = open(pidFile, O_WRONLY|O_CREAT|O_EXCL, 0644)) < 0) {
- qemudLog(QEMUD_ERR, _("Failed to open pid file '%s' : %s"),
+ ERROR(_("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"),
+ ERROR(_("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"),
+ ERROR(_("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"),
+ ERROR(_("Failed to close pid file '%s' : %s"),
pidFile, strerror(errno));
return -1;
}
gid_t oldgrp;
if (VIR_ALLOC(sock) < 0) {
- qemudLog(QEMUD_ERR,
- "%s", _("Failed to allocate memory for struct qemud_socket"));
+ ERROR("%s", _("Failed to allocate memory for struct qemud_socket"));
return -1;
}
sock->auth = auth;
if ((sock->fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) {
- qemudLog(QEMUD_ERR, _("Failed to create socket: %s"),
+ ERROR(_("Failed to create socket: %s"),
strerror(errno));
goto cleanup;
}
setgid(unix_sock_gid);
if (bind(sock->fd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
- qemudLog(QEMUD_ERR, _("Failed to bind socket to '%s': %s"),
+ ERROR(_("Failed to bind socket to '%s': %s"),
path, strerror(errno));
goto cleanup;
}
setgid(oldgrp);
if (listen(sock->fd, 30) < 0) {
- qemudLog(QEMUD_ERR, _("Failed to listen for connections on '%s': %s"),
+ ERROR(_("Failed to listen for connections on '%s': %s"),
path, strerror(errno));
goto cleanup;
}
VIR_EVENT_HANDLE_HANGUP,
qemudDispatchServerEvent,
server, NULL)) < 0) {
- qemudLog(QEMUD_ERR, "%s",
- _("Failed to add server event callback"));
+ ERROR0(_("Failed to add server event callback"));
goto cleanup;
}
int e = getaddrinfo (node, service, &hints, &ai);
if (e != 0) {
- qemudLog (QEMUD_ERR, _("getaddrinfo: %s\n"), gai_strerror (e));
+ ERROR(_("getaddrinfo: %s\n"), gai_strerror (e));
return -1;
}
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));
+ ERROR(_("socket: %s"), strerror (errno));
return -1;
}
if (bind (fds[*nfds_r], runp->ai_addr, runp->ai_addrlen) == -1) {
if (errno != EADDRINUSE) {
- qemudLog (QEMUD_ERR, _("bind: %s"), strerror (errno));
+ ERROR(_("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));
+ ERROR(_("listen: %s"), strerror (errno));
return -1;
}
++*nfds_r;
socklen_t salen = sizeof(sa);
if (VIR_ALLOC(sock) < 0) {
- qemudLog (QEMUD_ERR,
- _("remoteListenTCP: calloc: %s"), strerror (errno));
+ ERROR(_("remoteListenTCP: calloc: %s"), strerror (errno));
goto cleanup;
}
goto cleanup;
if (listen (sock->fd, 30) < 0) {
- qemudLog (QEMUD_ERR,
- _("remoteListenTCP: listen: %s"), strerror (errno));
+ ERROR(_("remoteListenTCP: listen: %s"), strerror (errno));
goto cleanup;
}
VIR_EVENT_HANDLE_HANGUP,
qemudDispatchServerEvent,
server, NULL)) < 0) {
- qemudLog(QEMUD_ERR, "%s", _("Failed to add server event callback"));
+ ERROR0(_("Failed to add server event callback"));
goto cleanup;
}
struct passwd *pw;
if (!(pw = getpwuid(uid))) {
- qemudLog(QEMUD_ERR, _("Failed to find user record for uid '%d': %s"),
+ ERROR(_("Failed to find user record for uid '%d': %s"),
uid, strerror(errno));
return -1;
}
return 0;
snprintf_error:
- qemudLog(QEMUD_ERR,
- "%s", _("Resulting path too long for buffer in qemudInitPaths()"));
+ ERROR("%s", _("Resulting path too long for buffer in qemudInitPaths()"));
return -1;
}
struct qemud_server *server;
if (VIR_ALLOC(server) < 0) {
- qemudLog(QEMUD_ERR, "%s", _("Failed to allocate struct qemud_server"));
+ ERROR0(_("Failed to allocate struct qemud_server"));
return NULL;
}
server->sigread = sigread;
if (virEventInit() < 0) {
- qemudLog(QEMUD_ERR, "%s", _("Failed to initialize event system"));
+ ERROR0(_("Failed to initialize event system"));
VIR_FREE(server);
return NULL;
}
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"),
+ ERROR(_("Failed to initialize SASL authentication %s"),
sasl_errstring(err, NULL, NULL));
goto cleanup;
}
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"),
+ ERROR(_("Failed to connect to system bus for PolicyKit auth: %s"),
derr.message);
dbus_error_free(&derr);
goto cleanup;
return session;
failed:
- qemudLog (QEMUD_ERR, _("remoteInitializeTLSSession: %s"),
+ ERROR(_("remoteInitializeTLSSession: %s"),
gnutls_strerror (err));
return NULL;
}
err = gnutls_x509_crt_get_dn (cert, name, &namesize);
if (err != 0) {
- qemudLog (QEMUD_ERR,
- _("remoteCheckDN: gnutls_x509_cert_get_dn: %s"),
+ ERROR(_("remoteCheckDN: gnutls_x509_cert_get_dn: %s"),
gnutls_strerror (err));
return 0;
}
wildcards++;
}
-#ifdef ENABLE_DEBUG
/* Print the client's DN. */
- qemudLog (QEMUD_DEBUG,
- _("remoteCheckDN: failed: client DN is %s"), name);
-#endif
+ DEBUG(_("remoteCheckDN: failed: client DN is %s"), name);
return 0; // Not found.
}
time_t now;
if ((ret = gnutls_certificate_verify_peers2 (session, &status)) < 0){
- qemudLog (QEMUD_ERR, _("remoteCheckCertificate: verify failed: %s"),
+ ERROR(_("remoteCheckCertificate: verify failed: %s"),
gnutls_strerror (ret));
return -1;
}
if (status != 0) {
if (status & GNUTLS_CERT_INVALID)
- qemudLog (QEMUD_ERR, "%s",
- _("remoteCheckCertificate: "
- "the client certificate is not trusted."));
+ ERROR0(_("remoteCheckCertificate: "
+ "the client certificate is not trusted."));
if (status & GNUTLS_CERT_SIGNER_NOT_FOUND)
- qemudLog (QEMUD_ERR, "%s",
- _("remoteCheckCertificate: the client "
- "certificate has unknown issuer."));
+ ERROR0(_("remoteCheckCertificate: the client "
+ "certificate has unknown issuer."));
if (status & GNUTLS_CERT_REVOKED)
- qemudLog (QEMUD_ERR, "%s",
- _("remoteCheckCertificate: "
- "the client certificate has been revoked."));
+ ERROR0(_("remoteCheckCertificate: "
+ "the client certificate has been revoked."));
#ifndef GNUTLS_1_0_COMPAT
if (status & GNUTLS_CERT_INSECURE_ALGORITHM)
- qemudLog (QEMUD_ERR, "%s",
- _("remoteCheckCertificate: the client certificate"
- " uses an insecure algorithm."));
+ ERROR0(_("remoteCheckCertificate: the client certificate"
+ " uses an insecure algorithm."));
#endif
return -1;
}
if (gnutls_certificate_type_get (session) != GNUTLS_CRT_X509) {
- qemudLog (QEMUD_ERR,
- "%s", _("remoteCheckCertificate: certificate is not X.509"));
+ ERROR0(_("remoteCheckCertificate: certificate is not X.509"));
return -1;
}
if (!(certs = gnutls_certificate_get_peers(session, &nCerts))) {
- qemudLog (QEMUD_ERR, "%s", _("remoteCheckCertificate: no peers"));
+ ERROR0(_("remoteCheckCertificate: no peers"));
return -1;
}
gnutls_x509_crt_t cert;
if (gnutls_x509_crt_init (&cert) < 0) {
- qemudLog (QEMUD_ERR, "%s",
- _("remoteCheckCertificate: gnutls_x509_crt_init failed"));
+ ERROR0(_("remoteCheckCertificate: gnutls_x509_crt_init failed"));
return -1;
}
}
if (gnutls_x509_crt_get_expiration_time (cert) < now) {
- qemudLog (QEMUD_ERR, "%s", _("remoteCheckCertificate: "
- "the client certificate has expired"));
+ ERROR0(_("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, "%s", _("remoteCheckCertificate: the client "
- "certificate is not yet activated"));
+ ERROR0(_("remoteCheckCertificate: the client "
+ "certificate is not yet activated"));
gnutls_x509_crt_deinit (cert);
return -1;
}
if (i == 0) {
if (!remoteCheckDN (cert)) {
/* This is the most common error: make it informative. */
- qemudLog (QEMUD_ERR, "%s", _("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."));
+ ERROR0(_("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;
}
{
/* Verify client certificate. */
if (remoteCheckCertificate (client->tlssession) == -1) {
- qemudLog (QEMUD_ERR, "%s",
- _("remoteCheckCertificate: "
- "failed to verify client's certificate"));
+ ERROR0(_("remoteCheckCertificate: "
+ "failed to verify client's certificate"));
if (!tls_no_verify_certificate) return -1;
- else qemudLog (QEMUD_INFO, "%s",
- _("remoteCheckCertificate: tls_no_verify_certificate "
- "is set so the bad certificate is ignored"));
+ else INFO0(_("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
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"),
+ ERROR(_("Failed to verify client credentials: %s"),
strerror(errno));
return -1;
}
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));
+ ERROR(_("Failed to accept connection: %s"), strerror(errno));
return -1;
}
if (server->nclients >= max_clients) {
- qemudLog(QEMUD_ERR, "%s", _("Too many active clients, dropping connection"));
+ ERROR0(_("Too many active clients, dropping connection"));
close(fd);
return -1;
}
if (VIR_REALLOC_N(server->clients, server->nclients+1) < 0) {
- qemudLog(QEMUD_ERR, "%s", _("Out of memory allocating clients"));
+ ERROR0(_("Out of memory allocating clients"));
close(fd);
return -1;
}
/* Client is running as root, so disable auth */
if (uid == 0) {
- qemudLog(QEMUD_INFO, _("Turn off polkit auth for privileged client %d"), pid);
+ INFO(_("Turn off polkit auth for privileged client %d"), pid);
client->auth = REMOTE_AUTH_NONE;
}
}
if (qemudRegisterClientEvent (server, client, 0) < 0)
goto cleanup;
} else {
- qemudLog (QEMUD_ERR, _("TLS handshake failed: %s"),
+ ERROR(_("TLS handshake failed: %s"),
gnutls_strerror (ret));
goto cleanup;
}
/* Deregister event delivery callback */
if(client->conn) {
- qemudDebug("Deregistering to relay remote events");
+ DEBUG0("Deregistering to relay remote events");
virConnectDomainEventDeregister(client->conn, remoteRelayDomainEvent);
}
if ((ret = read (client->fd, data, len)) <= 0) {
if (ret == 0 || errno != EAGAIN) {
if (ret != 0)
- qemudLog (QEMUD_ERR, _("read: %s"), strerror (errno));
+ ERROR(_("read: %s"), strerror (errno));
qemudDispatchClientFailure(server, client);
}
return -1;
if (ret == 0 || (ret != GNUTLS_E_AGAIN &&
ret != GNUTLS_E_INTERRUPTED)) {
if (ret != 0)
- qemudLog (QEMUD_ERR, _("gnutls_record_recv: %s"),
+ ERROR(_("gnutls_record_recv: %s"),
gnutls_strerror (ret));
qemudDispatchClientFailure (server, client);
}
if (!xdr_u_int(&x, &len)) {
xdr_destroy (&x);
- qemudDebug("Failed to decode packet length");
+ DEBUG0("Failed to decode packet length");
qemudDispatchClientFailure(server, client);
return;
}
xdr_destroy (&x);
if (len > REMOTE_MESSAGE_MAX) {
- qemudDebug("Packet length %u too large", len);
+ DEBUG("Packet length %u too large", len);
qemudDispatchClientFailure(server, client);
return;
}
/* Length include length of the length field itself, so
* check minimum size requirements */
if (len <= REMOTE_MESSAGE_HEADER_XDR_LEN) {
- qemudDebug("Packet length %u too small", len);
+ DEBUG("Packet length %u too small", len);
qemudDispatchClientFailure(server, client);
return;
}
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"),
+ ERROR(_("TLS handshake failed: %s"),
gnutls_strerror (ret));
qemudDispatchClientFailure (server, client);
} else {
}
default:
- qemudDebug("Got unexpected data read while in %d mode", client->mode);
+ DEBUG("Got unexpected data read while in %d mode", client->mode);
qemudDispatchClientFailure(server, client);
}
}
int ret;
if (!client->tlssession) {
if ((ret = safewrite(client->fd, data, len)) == -1) {
- qemudLog (QEMUD_ERR, _("write: %s"), strerror (errno));
+ ERROR(_("write: %s"), strerror (errno));
qemudDispatchClientFailure(server, client);
return -1;
}
qemudDispatchClientFailure (server, client);
else if (ret < 0) {
if (ret != GNUTLS_E_INTERRUPTED && ret != GNUTLS_E_AGAIN) {
- qemudLog (QEMUD_ERR, _("gnutls_record_send: %s"),
- gnutls_strerror (ret));
+ ERROR(_("gnutls_record_send: %s"), gnutls_strerror (ret));
qemudDispatchClientFailure (server, client);
}
return -1;
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"),
- gnutls_strerror (ret));
+ ERROR(_("TLS handshake failed: %s"), gnutls_strerror (ret));
qemudDispatchClientFailure (server, client);
} else {
if (qemudRegisterClientEvent (server, client, 1))
}
default:
- qemudDebug("Got unexpected data write while in %d mode", client->mode);
+ DEBUG("Got unexpected data write while in %d mode", client->mode);
qemudDispatchClientFailure(server, client);
}
}
errors = sig_errors;
if (errors) {
sig_errors -= errors;
- qemudLog (QEMUD_ERR,
- _("Signal handler reported %d errors: last error: %s"),
+ ERROR(_("Signal handler reported %d errors: last error: %s"),
errors, strerror (sig_lasterrno));
return -1;
}
static void qemudInactiveTimer(int timer ATTRIBUTE_UNUSED, void *data) {
struct qemud_server *server = (struct qemud_server *)data;
- qemudDebug("Got inactive timer expiry");
+ DEBUG0("Got inactive timer expiry");
if (!virStateActive()) {
- qemudDebug("No state active, shutting down");
+ DEBUG0("No state active, shutting down");
server->shutdown = 1;
}
}
server->nworkers = min_workers;
if (VIR_ALLOC_N(server->workers, server->nworkers) < 0) {
- qemudLog(QEMUD_ERR, "%s", _("Failed to allocate workers"));
+ ERROR0(_("Failed to allocate workers"));
return -1;
}
timerid = virEventAddTimeoutImpl(timeout*1000,
qemudInactiveTimer,
server, NULL);
- qemudDebug("Scheduling shutdown timer %d", timerid);
+ DEBUG("Scheduling shutdown timer %d", timerid);
}
pthread_mutex_unlock(&server->lock);
* just had an event processed
*/
if (timerid != -1) {
- qemudDebug("Removing shutdown timer %d", timerid);
+ DEBUG("Removing shutdown timer %d", timerid);
virEventRemoveTimeoutImpl(timerid);
timerid = -1;
}
switch (p->type) {
case VIR_CONF_STRING:
if (VIR_ALLOC_N(list, 2) < 0) {
- qemudLog (QEMUD_ERR,
- _("failed to allocate memory for %s config list"), key);
+ ERROR(_("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"),
+ ERROR(_("failed to allocate memory for %s config list value"),
key);
VIR_FREE(list);
return -1;
for (pp = p->list; pp; pp = pp->next)
len++;
if (VIR_ALLOC_N(list, 1+len) < 0) {
- qemudLog (QEMUD_ERR,
- _("failed to allocate memory for %s config list"), key);
+ ERROR(_("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:"
+ ERROR(_("remoteReadConfigFile: %s: %s:"
" must be a string or list of strings\n"),
filename, key);
VIR_FREE(list);
for (j = 0 ; j < i ; j++)
VIR_FREE(list[j]);
VIR_FREE(list);
- qemudLog (QEMUD_ERR, _("failed to allocate memory"
- " for %s config list value"), key);
+ ERROR(_("failed to allocate memory for %s config list value"),
+ key);
return -1;
}
}
default:
- qemudLog (QEMUD_ERR, _("remoteReadConfigFile: %s: %s:"
- " must be a string or list of strings\n"),
+ ERROR(_("remoteReadConfigFile: %s: %s:"
+ " must be a string or list of strings\n"),
filename, key);
return -1;
}
const char *key, virConfType required_type)
{
if (p->type != required_type) {
- qemudLog (QEMUD_ERR,
- _("remoteReadConfigFile: %s: %s: invalid type:"
+ ERROR(_("remoteReadConfigFile: %s: %s: invalid type:"
" got %s; expected %s\n"), filename, key,
virConfTypeName (p->type),
virConfTypeName (required_type));
goto free_and_fail; \
(var_name) = strdup (p->str); \
if ((var_name) == NULL) { \
- qemudLog (QEMUD_ERR, _("remoteReadConfigFile: %s\n"), \
- strerror (errno)); \
+ ERROR(_("remoteReadConfigFile: %s\n"),strerror (errno));\
goto free_and_fail; \
} \
} \
*auth = REMOTE_AUTH_POLKIT;
#endif
} else {
- qemudLog (QEMUD_ERR,
- _("remoteReadConfigFile: %s: %s: unsupported auth %s\n"),
+ ERROR(_("remoteReadConfigFile: %s: %s: unsupported auth %s\n"),
filename, key, p->str);
return -1;
}
}
#endif
+/*
+ * Set up the logging environment
+ * By default if daemonized all errors go to syslog and the logging
+ * is also saved onto the logfile libvird.log, but if verbose or error
+ * debugging is asked for then output informations or debug.
+ */
+static void
+qemudSetLogging(virConfPtr conf, const char *filename) {
+ virLogReset();
+
+ /* look for default logging level */
+ GET_CONF_INT (conf, filename, log_level);
+ if ((verbose) && (log_level >= VIR_LOG_WARN))
+ log_level = VIR_LOG_INFO;
+ virLogSetDefaultPriority(log_level);
+
+ /* there is no default filters */
+ GET_CONF_STR (conf, filename, log_filters);
+ virLogParseFilters(log_filters);
+
+ /*
+ * by default save all warning and errors to syslog or
+ * all logs to stderr if not running as daemon
+ */
+ GET_CONF_STR (conf, filename, log_outputs);
+ if (log_outputs == NULL) {
+ if (godaemon)
+ virLogParseOutputs("3:syslog:libvirtd");
+ else
+ virLogParseOutputs("0:stderr:libvirtd");
+ } else
+ virLogParseOutputs(log_outputs);
+free_and_fail:
+ VIR_FREE(log_filters);
+ VIR_FREE(log_outputs);
+}
/* Read the config file if it exists.
* Only used in the remote case, hence the name.
conf = virConfReadFile (filename);
if (!conf) return 0;
+ /*
+ * First get all the logging settings and activate them
+ */
+ qemudSetLogging(conf, filename);
+
GET_CONF_INT (conf, filename, listen_tcp);
GET_CONF_INT (conf, filename, listen_tls);
GET_CONF_STR (conf, filename, tls_port);
GET_CONF_STR (conf, filename, unix_sock_group);
if (unix_sock_group) {
if (getuid() != 0) {
- qemudLog (QEMUD_WARN,
- "%s", _("Cannot set group when not running as root"));
+ WARN0(_("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'"),
- unix_sock_group);
+ ERROR(_("Failed to lookup group '%s'"), unix_sock_group);
goto free_and_fail;
}
unix_sock_gid = grp->gr_gid;
GET_CONF_STR (conf, filename, unix_sock_ro_perms);
if (unix_sock_ro_perms) {
if (virStrToLong_i (unix_sock_ro_perms, NULL, 8, &unix_sock_ro_mask) != 0) {
- qemudLog (QEMUD_ERR, _("Failed to parse mode '%s'"),
- unix_sock_ro_perms);
+ ERROR(_("Failed to parse mode '%s'"), unix_sock_ro_perms);
goto free_and_fail;
}
free (unix_sock_ro_perms);
GET_CONF_STR (conf, filename, unix_sock_rw_perms);
if (unix_sock_rw_perms) {
if (virStrToLong_i (unix_sock_rw_perms, NULL, 8, &unix_sock_rw_mask) != 0) {
- qemudLog (QEMUD_ERR, _("Failed to parse mode '%s'"),
- unix_sock_rw_perms);
+ ERROR(_("Failed to parse mode '%s'"), unix_sock_rw_perms);
goto free_and_fail;
}
free (unix_sock_rw_perms);
}
if (godaemon) {
- openlog("libvirtd", 0, 0);
if (qemudGoDaemon() < 0) {
- qemudLog(QEMUD_ERR, _("Failed to fork as daemon: %s"),
- strerror(errno));
+ ERROR(_("Failed to fork as daemon: %s"), strerror(errno));
goto error1;
}
}
qemudSetNonBlock(sigpipe[1]) < 0 ||
qemudSetCloseExec(sigpipe[0]) < 0 ||
qemudSetCloseExec(sigpipe[1]) < 0) {
- qemudLog(QEMUD_ERR, _("Failed to create pipe: %s"),
- strerror(errno));
+ ERROR(_("Failed to create pipe: %s"), strerror(errno));
goto error2;
}
sigwrite = sigpipe[1];
const char *sockdirname = LOCAL_STATE_DIR "/run/libvirt";
if (chown(sockdirname, -1, unix_sock_gid) < 0)
- qemudLog(QEMUD_ERR, _("Failed to change group ownership of %s"),
- sockdirname);
+ ERROR(_("Failed to change group ownership of %s"), sockdirname);
}
if (virEventAddHandleImpl(sigpipe[0],
VIR_EVENT_HANDLE_READABLE,
qemudDispatchSignalEvent,
server, NULL) < 0) {
- qemudLog(QEMUD_ERR,
- "%s", _("Failed to register callback for signal pipe"));
+ ERROR0(_("Failed to register callback for signal pipe"));
ret = 3;
goto error2;
}
close(sigwrite);
error1:
- if (godaemon)
- closelog();
+ virLogShutdown();
return ret;
}