-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Journal probe rework #7
Changes from 5 commits
d4261b5
8780f3c
1f2083b
0adfc63
9dcdc0d
9834e9f
7dee764
4e79ea1
bf3dc47
15bdcf0
35b6ca2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/* | ||
* This program is part of the Clear Linux Project | ||
* | ||
* Copyright 2015 Intel Corporation | ||
* Copyright 2015-2017 Intel Corporation | ||
* | ||
* This program is free software; you can redistribute it and/or modify it under | ||
* the terms and conditions of the GNU Lesser General Public License, as | ||
|
@@ -61,11 +61,11 @@ static inline void tm_journal_match_err(int ret) | |
static void add_to_payload(const void *data, size_t length) | ||
{ | ||
if (payload != NULL) { | ||
g_string_append_printf(payload, "%.*s", (int)length, | ||
g_string_append_printf(payload, "%.*s\n", (int)length, | ||
(char *)data); | ||
} else { | ||
payload = g_string_new(NULL); | ||
g_string_printf(payload, "%.*s", (int)length, | ||
g_string_printf(payload, "%.*s\n", (int)length, | ||
(char *)data); | ||
} | ||
} | ||
|
@@ -77,7 +77,7 @@ static bool send_data(char *class) | |
|
||
if ((ret = tm_create_record(&handle, severity, class, | ||
payload_version)) < 0) { | ||
telem_log(LOG_ERR, "Failed to create record: %s", | ||
telem_log(LOG_ERR, "Failed to create record: %s\n", | ||
strerror(-ret)); | ||
goto fail; | ||
} | ||
|
@@ -86,7 +86,7 @@ static bool send_data(char *class) | |
payload = NULL; | ||
|
||
if ((ret = tm_set_payload(handle, (char *)payload_str)) < 0) { | ||
telem_log(LOG_ERR, "Failed to set payload: %s", strerror(-ret)); | ||
telem_log(LOG_ERR, "Failed to set payload: %s\n", strerror(-ret)); | ||
free(payload_str); | ||
tm_free_record(handle); | ||
goto fail; | ||
|
@@ -95,7 +95,7 @@ static bool send_data(char *class) | |
free(payload_str); | ||
|
||
if ((ret = tm_send_record(handle)) < 0) { | ||
telem_log(LOG_ERR, "Failed to send record: %s", strerror(-ret)); | ||
telem_log(LOG_ERR, "Failed to send record: %s\n", strerror(-ret)); | ||
tm_free_record(handle); | ||
goto fail; | ||
} | ||
|
@@ -148,7 +148,8 @@ static bool process_existing_entries(sd_journal *journal) | |
return false; | ||
} | ||
|
||
if (!read_new_entries(journal)) { | ||
ret = read_new_entries(journal); | ||
if (ret < 0) { | ||
return false; | ||
} | ||
|
||
|
@@ -185,6 +186,33 @@ static bool get_boot_id(char **data) | |
return true; | ||
} | ||
|
||
#define JOURNAL_MATCH(data) \ | ||
do { \ | ||
r = sd_journal_add_match(journal, data, 0); \ | ||
if (r < 0) { \ | ||
tm_journal_match_err(r); \ | ||
return false; \ | ||
} \ | ||
} while (0); | ||
|
||
#define JOURNAL_AND \ | ||
do { \ | ||
r = sd_journal_add_conjunction(journal); \ | ||
if (r < 0) { \ | ||
tm_journal_match_err(r); \ | ||
return false; \ | ||
} \ | ||
} while (0); | ||
|
||
#define JOURNAL_OR \ | ||
do { \ | ||
r = sd_journal_add_disjunction(journal); \ | ||
if (r < 0) { \ | ||
tm_journal_match_err(r); \ | ||
return false; \ | ||
} \ | ||
} while (0); | ||
|
||
static bool add_filters(sd_journal *journal) | ||
{ | ||
char *data = NULL; | ||
|
@@ -201,7 +229,13 @@ static bool add_filters(sd_journal *journal) | |
} | ||
free(data); | ||
|
||
r = sd_journal_add_match(journal, "SYSLOG_IDENTIFIER=crashprobe", 0); | ||
r = sd_journal_add_match(journal, "PRIORITY=1", 0); | ||
if (r < 0) { | ||
tm_journal_match_err(r); | ||
return false; | ||
} | ||
|
||
r = sd_journal_add_match(journal, "PRIORITY=2", 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I sense a configuration option and a loop eventually for this code ala: telemetrics.conf: journal-log-level = X kind of thing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A config option would be helpful, I agree. I opened #12 for tracking. |
||
if (r < 0) { | ||
tm_journal_match_err(r); | ||
return false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always a little scary when the macro can return in some cases but in this case it seems reasonable enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. In this case,
sd_journal_add_match
and friends returning an error is very unlikely, so I figured the returns here would be acceptable for unlikely conditions.