提交 a2405a88 编写于 作者: E Erik Skultety

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: NErik Skultety <eskultet@redhat.com>
上级 b8c370a9
......@@ -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 */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册