virLogDefineOutputs: Fix build without syslog.h

Not every system out there has syslog, that's why we check for it
in our configure script. However, in 640b58abdf while fixing
another issue, some variables and functions are called that are
defined only when syslog.h is present. But these function
calls/variables were not guarded by #ifdef-s.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Michal Privoznik 2016-10-14 10:09:03 +08:00
parent cf9a423cbd
commit a564568f06

View File

@ -1362,9 +1362,10 @@ virLogFindOutput(virLogOutputPtr *outputs, size_t noutputs,
int int
virLogDefineOutputs(virLogOutputPtr *outputs, size_t noutputs) virLogDefineOutputs(virLogOutputPtr *outputs, size_t noutputs)
{ {
int ret = -1; #if HAVE_SYSLOG_H
int id; int id;
char *tmp = NULL; char *tmp = NULL;
#endif /* HAVE_SYSLOG_H */
if (virLogInitialize() < 0) if (virLogInitialize() < 0)
return -1; return -1;
@ -1372,6 +1373,7 @@ virLogDefineOutputs(virLogOutputPtr *outputs, size_t noutputs)
virLogLock(); virLogLock();
virLogResetOutputs(); virLogResetOutputs();
#if HAVE_SYSLOG_H
/* syslog needs to be special-cased, since it keeps the fd in private */ /* syslog needs to be special-cased, since it keeps the fd in private */
if ((id = virLogFindOutput(outputs, noutputs, VIR_LOG_TO_SYSLOG, if ((id = virLogFindOutput(outputs, noutputs, VIR_LOG_TO_SYSLOG,
current_ident)) != -1) { current_ident)) != -1) {
@ -1379,20 +1381,21 @@ virLogDefineOutputs(virLogOutputPtr *outputs, size_t noutputs)
* holding the lock so it's safe to call openlog and change the message * holding the lock so it's safe to call openlog and change the message
* tag * tag
*/ */
if (VIR_STRDUP_QUIET(tmp, outputs[id]->name) < 0) if (VIR_STRDUP_QUIET(tmp, outputs[id]->name) < 0) {
goto cleanup; virLogUnlock();
return -1;
}
VIR_FREE(current_ident); VIR_FREE(current_ident);
current_ident = tmp; current_ident = tmp;
openlog(current_ident, 0, 0); openlog(current_ident, 0, 0);
} }
#endif /* HAVE_SYSLOG_H */
virLogOutputs = outputs; virLogOutputs = outputs;
virLogNbOutputs = noutputs; virLogNbOutputs = noutputs;
ret = 0;
cleanup:
virLogUnlock(); virLogUnlock();
return ret; return 0;
} }