mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 09:53:10 +00:00
log: include hostname in initial log message
On the very first log message we send to any output, we include the libvirt version number and package string. In some bug reports we have been given libvirtd.log files that came from a different host than the corresponding /var/log/libvirt/qemu log files. So extend the initial log message to include the hostname too. eg on first log message we would now see: $ libvirtd 2015-12-04 17:35:36.610+0000: 20917: info : libvirt version: 1.3.0 2015-12-04 17:35:36.610+0000: 20917: info : hostname: dhcp-1-180.lcy.redhat.com 2015-12-04 17:35:36.610+0000: 20917: error : qemuMonitorIO:687 : internal error: End of file from monitor Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
a523770c32
commit
1ce929603b
@ -2393,6 +2393,7 @@ virGetGroupID;
|
|||||||
virGetGroupList;
|
virGetGroupList;
|
||||||
virGetGroupName;
|
virGetGroupName;
|
||||||
virGetHostname;
|
virGetHostname;
|
||||||
|
virGetHostnameQuiet;
|
||||||
virGetListenFDs;
|
virGetListenFDs;
|
||||||
virGetSCSIHostNameByParentaddr;
|
virGetSCSIHostNameByParentaddr;
|
||||||
virGetSCSIHostNumber;
|
virGetSCSIHostNumber;
|
||||||
|
@ -94,7 +94,7 @@ static int virLogNbFilters;
|
|||||||
* after filtering, multiple output can be used simultaneously
|
* after filtering, multiple output can be used simultaneously
|
||||||
*/
|
*/
|
||||||
struct _virLogOutput {
|
struct _virLogOutput {
|
||||||
bool logVersion;
|
bool logInitMessage;
|
||||||
void *data;
|
void *data;
|
||||||
virLogOutputFunc f;
|
virLogOutputFunc f;
|
||||||
virLogCloseFunc c;
|
virLogCloseFunc c;
|
||||||
@ -402,7 +402,7 @@ virLogDefineOutput(virLogOutputFunc f,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
ret = virLogNbOutputs++;
|
ret = virLogNbOutputs++;
|
||||||
virLogOutputs[ret].logVersion = true;
|
virLogOutputs[ret].logInitMessage = true;
|
||||||
virLogOutputs[ret].f = f;
|
virLogOutputs[ret].f = f;
|
||||||
virLogOutputs[ret].c = c;
|
virLogOutputs[ret].c = c;
|
||||||
virLogOutputs[ret].data = data;
|
virLogOutputs[ret].data = data;
|
||||||
@ -452,6 +452,32 @@ virLogVersionString(const char **rawmsg,
|
|||||||
return virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, VIR_LOG_VERSION_STRING);
|
return virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, VIR_LOG_VERSION_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Similar to virGetHostname() but avoids use of error
|
||||||
|
* reporting APIs or logging APIs, to prevent recursion
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
virLogHostnameString(const char **rawmsg,
|
||||||
|
char **msg)
|
||||||
|
{
|
||||||
|
char *hostname = virGetHostnameQuiet();
|
||||||
|
char *hoststr;
|
||||||
|
|
||||||
|
if (!hostname)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (virAsprintfQuiet(&hoststr, "hostname: %s", hostname) < 0) {
|
||||||
|
VIR_FREE(hostname);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (virLogFormatString(msg, 0, NULL, VIR_LOG_INFO, hoststr) < 0) {
|
||||||
|
VIR_FREE(hoststr);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*rawmsg = hoststr;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
virLogSourceUpdate(virLogSourcePtr source)
|
virLogSourceUpdate(virLogSourcePtr source)
|
||||||
@ -533,7 +559,7 @@ virLogVMessage(virLogSourcePtr source,
|
|||||||
const char *fmt,
|
const char *fmt,
|
||||||
va_list vargs)
|
va_list vargs)
|
||||||
{
|
{
|
||||||
static bool logVersionStderr = true;
|
static bool logInitMessageStderr = true;
|
||||||
char *str = NULL;
|
char *str = NULL;
|
||||||
char *msg = NULL;
|
char *msg = NULL;
|
||||||
char timestamp[VIR_TIME_STRING_BUFLEN];
|
char timestamp[VIR_TIME_STRING_BUFLEN];
|
||||||
@ -583,16 +609,22 @@ virLogVMessage(virLogSourcePtr source,
|
|||||||
*/
|
*/
|
||||||
for (i = 0; i < virLogNbOutputs; i++) {
|
for (i = 0; i < virLogNbOutputs; i++) {
|
||||||
if (priority >= virLogOutputs[i].priority) {
|
if (priority >= virLogOutputs[i].priority) {
|
||||||
if (virLogOutputs[i].logVersion) {
|
if (virLogOutputs[i].logInitMessage) {
|
||||||
const char *rawver;
|
const char *rawinitmsg;
|
||||||
char *ver = NULL;
|
char *initmsg = NULL;
|
||||||
if (virLogVersionString(&rawver, &ver) >= 0)
|
if (virLogVersionString(&rawinitmsg, &initmsg) >= 0)
|
||||||
virLogOutputs[i].f(&virLogSelf, VIR_LOG_INFO,
|
virLogOutputs[i].f(&virLogSelf, VIR_LOG_INFO,
|
||||||
__FILE__, __LINE__, __func__,
|
__FILE__, __LINE__, __func__,
|
||||||
timestamp, NULL, 0, rawver, ver,
|
timestamp, NULL, 0, rawinitmsg, initmsg,
|
||||||
virLogOutputs[i].data);
|
virLogOutputs[i].data);
|
||||||
VIR_FREE(ver);
|
VIR_FREE(initmsg);
|
||||||
virLogOutputs[i].logVersion = false;
|
if (virLogHostnameString(&rawinitmsg, &initmsg) >= 0)
|
||||||
|
virLogOutputs[i].f(&virLogSelf, VIR_LOG_INFO,
|
||||||
|
__FILE__, __LINE__, __func__,
|
||||||
|
timestamp, NULL, 0, rawinitmsg, initmsg,
|
||||||
|
virLogOutputs[i].data);
|
||||||
|
VIR_FREE(initmsg);
|
||||||
|
virLogOutputs[i].logInitMessage = false;
|
||||||
}
|
}
|
||||||
virLogOutputs[i].f(source, priority,
|
virLogOutputs[i].f(source, priority,
|
||||||
filename, linenr, funcname,
|
filename, linenr, funcname,
|
||||||
@ -601,16 +633,22 @@ virLogVMessage(virLogSourcePtr source,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (virLogNbOutputs == 0) {
|
if (virLogNbOutputs == 0) {
|
||||||
if (logVersionStderr) {
|
if (logInitMessageStderr) {
|
||||||
const char *rawver;
|
const char *rawinitmsg;
|
||||||
char *ver = NULL;
|
char *initmsg = NULL;
|
||||||
if (virLogVersionString(&rawver, &ver) >= 0)
|
if (virLogVersionString(&rawinitmsg, &initmsg) >= 0)
|
||||||
virLogOutputToFd(&virLogSelf, VIR_LOG_INFO,
|
virLogOutputToFd(&virLogSelf, VIR_LOG_INFO,
|
||||||
__FILE__, __LINE__, __func__,
|
__FILE__, __LINE__, __func__,
|
||||||
timestamp, NULL, 0, rawver, ver,
|
timestamp, NULL, 0, rawinitmsg, initmsg,
|
||||||
(void *) STDERR_FILENO);
|
(void *) STDERR_FILENO);
|
||||||
VIR_FREE(ver);
|
VIR_FREE(initmsg);
|
||||||
logVersionStderr = false;
|
if (virLogHostnameString(&rawinitmsg, &initmsg) >= 0)
|
||||||
|
virLogOutputToFd(&virLogSelf, VIR_LOG_INFO,
|
||||||
|
__FILE__, __LINE__, __func__,
|
||||||
|
timestamp, NULL, 0, rawinitmsg, initmsg,
|
||||||
|
(void *) STDERR_FILENO);
|
||||||
|
VIR_FREE(initmsg);
|
||||||
|
logInitMessageStderr = false;
|
||||||
}
|
}
|
||||||
virLogOutputToFd(source, priority,
|
virLogOutputToFd(source, priority,
|
||||||
filename, linenr, funcname,
|
filename, linenr, funcname,
|
||||||
|
@ -662,16 +662,18 @@ char *virIndexToDiskName(int idx, const char *prefix)
|
|||||||
* we got from getaddrinfo(). Return the value from gethostname()
|
* we got from getaddrinfo(). Return the value from gethostname()
|
||||||
* and hope for the best.
|
* and hope for the best.
|
||||||
*/
|
*/
|
||||||
char *virGetHostname(void)
|
static char *
|
||||||
|
virGetHostnameImpl(bool quiet)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
char hostname[HOST_NAME_MAX+1], *result;
|
char hostname[HOST_NAME_MAX+1], *result = NULL;
|
||||||
struct addrinfo hints, *info;
|
struct addrinfo hints, *info;
|
||||||
|
|
||||||
r = gethostname(hostname, sizeof(hostname));
|
r = gethostname(hostname, sizeof(hostname));
|
||||||
if (r == -1) {
|
if (r == -1) {
|
||||||
virReportSystemError(errno,
|
if (!quiet)
|
||||||
"%s", _("failed to determine host name"));
|
virReportSystemError(errno,
|
||||||
|
"%s", _("failed to determine host name"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
NUL_TERMINATE(hostname);
|
NUL_TERMINATE(hostname);
|
||||||
@ -683,7 +685,7 @@ char *virGetHostname(void)
|
|||||||
* string as-is; it's up to callers to check whether "localhost"
|
* string as-is; it's up to callers to check whether "localhost"
|
||||||
* is allowed.
|
* is allowed.
|
||||||
*/
|
*/
|
||||||
ignore_value(VIR_STRDUP(result, hostname));
|
ignore_value(VIR_STRDUP_QUIET(result, hostname));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -696,9 +698,10 @@ char *virGetHostname(void)
|
|||||||
hints.ai_family = AF_UNSPEC;
|
hints.ai_family = AF_UNSPEC;
|
||||||
r = getaddrinfo(hostname, NULL, &hints, &info);
|
r = getaddrinfo(hostname, NULL, &hints, &info);
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
VIR_WARN("getaddrinfo failed for '%s': %s",
|
if (!quiet)
|
||||||
hostname, gai_strerror(r));
|
VIR_WARN("getaddrinfo failed for '%s': %s",
|
||||||
ignore_value(VIR_STRDUP(result, hostname));
|
hostname, gai_strerror(r));
|
||||||
|
ignore_value(VIR_STRDUP_QUIET(result, hostname));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -711,18 +714,34 @@ char *virGetHostname(void)
|
|||||||
* localhost. Ignore the canonicalized name and just return the
|
* localhost. Ignore the canonicalized name and just return the
|
||||||
* original hostname
|
* original hostname
|
||||||
*/
|
*/
|
||||||
ignore_value(VIR_STRDUP(result, hostname));
|
ignore_value(VIR_STRDUP_QUIET(result, hostname));
|
||||||
else
|
else
|
||||||
/* Caller frees this string. */
|
/* Caller frees this string. */
|
||||||
ignore_value(VIR_STRDUP(result, info->ai_canonname));
|
ignore_value(VIR_STRDUP_QUIET(result, info->ai_canonname));
|
||||||
|
|
||||||
freeaddrinfo(info);
|
freeaddrinfo(info);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
if (!result)
|
||||||
|
virReportOOMError();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *
|
||||||
|
virGetHostname(void)
|
||||||
|
{
|
||||||
|
return virGetHostnameImpl(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *
|
||||||
|
virGetHostnameQuiet(void)
|
||||||
|
{
|
||||||
|
return virGetHostnameImpl(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
char *
|
char *
|
||||||
virGetUserDirectory(void)
|
virGetUserDirectory(void)
|
||||||
{
|
{
|
||||||
|
@ -132,6 +132,7 @@ static inline int pthread_sigmask(int how,
|
|||||||
# endif
|
# endif
|
||||||
|
|
||||||
char *virGetHostname(void);
|
char *virGetHostname(void);
|
||||||
|
char *virGetHostnameQuiet(void);
|
||||||
|
|
||||||
char *virGetUserDirectory(void);
|
char *virGetUserDirectory(void);
|
||||||
char *virGetUserDirectoryByUID(uid_t uid);
|
char *virGetUserDirectoryByUID(uid_t uid);
|
||||||
|
Loading…
Reference in New Issue
Block a user