sd-journal: introduce has_runtime_files and has_persistent_files

Also introduce sd_journal_has_runtime_files() and
sd_journal_has_persistent_files() to the public API. These functions
can be used to easily find out if the open journal files are runtime
and/or persistent.
This commit is contained in:
Jan Synacek
2016-02-01 11:59:27 +01:00
parent c25bf528a1
commit 39fd5b08a7
6 changed files with 131 additions and 2 deletions
+2
View File
@@ -115,6 +115,8 @@ struct sd_journal {
removed, and there were no more
files, so sd_j_enumerate_unique
will return a value equal to 0. */
bool has_runtime_files:1;
bool has_persistent_files:1;
size_t data_threshold;
+18
View File
@@ -1292,6 +1292,12 @@ static int add_file(sd_journal *j, const char *prefix, const char *filename) {
return 0;
path = strjoina(prefix, "/", filename);
if (!j->has_runtime_files && path_startswith(path, "/run/log/journal"))
j->has_runtime_files = true;
else if (!j->has_persistent_files && path_startswith(path, "/var/log/journal"))
j->has_persistent_files = true;
return add_any_file(j, path);
}
@@ -2630,3 +2636,15 @@ _public_ int sd_journal_get_data_threshold(sd_journal *j, size_t *sz) {
*sz = j->data_threshold;
return 0;
}
_public_ int sd_journal_has_runtime_files(sd_journal *j) {
assert_return(j, -EINVAL);
return j->has_runtime_files;
}
_public_ int sd_journal_has_persistent_files(sd_journal *j) {
assert_return(j, -EINVAL);
return j->has_persistent_files;
}
+3
View File
@@ -139,6 +139,9 @@ int sd_journal_reliable_fd(sd_journal *j);
int sd_journal_get_catalog(sd_journal *j, char **text);
int sd_journal_get_catalog_for_message_id(sd_id128_t id, char **text);
int sd_journal_has_runtime_files(sd_journal *j);
int sd_journal_has_persistent_files(sd_journal *j);
/* the inverse condition avoids ambiguity of danling 'else' after the macro */
#define SD_JOURNAL_FOREACH(j) \
if (sd_journal_seek_head(j) < 0) { } \