virlog: Store the journald fd within the output object

There is really no reason why we could not keep journald's fd within the
journald output object the same way as we do for regular file-based outputs.
By doing this we later won't have to special case the journald-based output
(due to the fd being globally shared) when replacing the existing set of outputs
with a new one. Additionally, by making this change, we don't need the
virLogCloseJournald routine anymore, plain virLogCloseFd will suffice.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
Erik Skultety 2016-08-17 17:20:35 +02:00
parent b8c370a96e
commit a2405a889e

View File

@ -962,8 +962,6 @@ journalAddInt(struct journalState *state, const char *field, int value)
state->iov += 4;
}
static int journalfd = -1;
static void
virLogOutputToJournald(virLogSourcePtr source,
virLogPriority priority,
@ -975,10 +973,11 @@ virLogOutputToJournald(virLogSourcePtr source,
unsigned int flags,
const char *rawstr,
const char *str ATTRIBUTE_UNUSED,
void *data ATTRIBUTE_UNUSED)
void *data)
{
virCheckFlags(VIR_LOG_STACK_TRACE,);
int buffd = -1;
int journalfd = (intptr_t) data;
struct msghdr mh;
struct sockaddr_un sa;
union {
@ -1084,24 +1083,23 @@ virLogOutputToJournald(virLogSourcePtr source,
}
static void virLogCloseJournald(void *data ATTRIBUTE_UNUSED)
{
VIR_LOG_CLOSE(journalfd);
}
static int virLogAddOutputToJournald(int priority)
{
int journalfd;
if ((journalfd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0)
return -1;
if (virSetInherit(journalfd, false) < 0) {
VIR_LOG_CLOSE(journalfd);
return -1;
}
if (virLogDefineOutput(virLogOutputToJournald, virLogCloseJournald, NULL,
priority, VIR_LOG_TO_JOURNALD, NULL, 0) < 0) {
if (virLogDefineOutput(virLogOutputToJournald, virLogCloseFd,
(void *)(intptr_t) journalfd, priority,
VIR_LOG_TO_JOURNALD, NULL, 0) < 0) {
VIR_LOG_CLOSE(journalfd);
return -1;
}
return 0;
}
# endif /* USE_JOURNALD */