mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
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:
parent
b8c370a96e
commit
a2405a889e
@ -962,8 +962,6 @@ journalAddInt(struct journalState *state, const char *field, int value)
|
|||||||
state->iov += 4;
|
state->iov += 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int journalfd = -1;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
virLogOutputToJournald(virLogSourcePtr source,
|
virLogOutputToJournald(virLogSourcePtr source,
|
||||||
virLogPriority priority,
|
virLogPriority priority,
|
||||||
@ -975,10 +973,11 @@ virLogOutputToJournald(virLogSourcePtr source,
|
|||||||
unsigned int flags,
|
unsigned int flags,
|
||||||
const char *rawstr,
|
const char *rawstr,
|
||||||
const char *str ATTRIBUTE_UNUSED,
|
const char *str ATTRIBUTE_UNUSED,
|
||||||
void *data ATTRIBUTE_UNUSED)
|
void *data)
|
||||||
{
|
{
|
||||||
virCheckFlags(VIR_LOG_STACK_TRACE,);
|
virCheckFlags(VIR_LOG_STACK_TRACE,);
|
||||||
int buffd = -1;
|
int buffd = -1;
|
||||||
|
int journalfd = (intptr_t) data;
|
||||||
struct msghdr mh;
|
struct msghdr mh;
|
||||||
struct sockaddr_un sa;
|
struct sockaddr_un sa;
|
||||||
union {
|
union {
|
||||||
@ -1084,24 +1083,23 @@ virLogOutputToJournald(virLogSourcePtr source,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void virLogCloseJournald(void *data ATTRIBUTE_UNUSED)
|
|
||||||
{
|
|
||||||
VIR_LOG_CLOSE(journalfd);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int virLogAddOutputToJournald(int priority)
|
static int virLogAddOutputToJournald(int priority)
|
||||||
{
|
{
|
||||||
|
int journalfd;
|
||||||
|
|
||||||
if ((journalfd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0)
|
if ((journalfd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (virSetInherit(journalfd, false) < 0) {
|
if (virSetInherit(journalfd, false) < 0) {
|
||||||
VIR_LOG_CLOSE(journalfd);
|
VIR_LOG_CLOSE(journalfd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (virLogDefineOutput(virLogOutputToJournald, virLogCloseJournald, NULL,
|
if (virLogDefineOutput(virLogOutputToJournald, virLogCloseFd,
|
||||||
priority, VIR_LOG_TO_JOURNALD, NULL, 0) < 0) {
|
(void *)(intptr_t) journalfd, priority,
|
||||||
|
VIR_LOG_TO_JOURNALD, NULL, 0) < 0) {
|
||||||
|
VIR_LOG_CLOSE(journalfd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
# endif /* USE_JOURNALD */
|
# endif /* USE_JOURNALD */
|
||||||
|
Loading…
Reference in New Issue
Block a user