summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-07-19 03:21:49 +0200
committerLennart Poettering <lennart@poettering.net>2012-07-19 03:21:49 +0200
commit7827b1a10f4dfe2c6771b515f28f7ae22e0ae039 (patch)
tree9c86a45af106ceec2bd26aa470407cd3ad76834f
parenta1a1898f7190a25a579556826379f7486f87459b (diff)
journal: when watching directories actually watch the directories asked for
-rw-r--r--src/journal/journal-internal.h2
-rw-r--r--src/journal/sd-journal.c22
2 files changed, 20 insertions, 4 deletions
diff --git a/src/journal/journal-internal.h b/src/journal/journal-internal.h
index b767901432..04f77540c9 100644
--- a/src/journal/journal-internal.h
+++ b/src/journal/journal-internal.h
@@ -90,6 +90,8 @@ struct Directory {
struct sd_journal {
int flags;
+ char *path;
+
Hashmap *files;
Location current_location;
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
index 4c19fc0ed1..672896d57c 100644
--- a/src/journal/sd-journal.c
+++ b/src/journal/sd-journal.c
@@ -1402,7 +1402,7 @@ static int allocate_inotify(sd_journal *j) {
return 0;
}
-static sd_journal *journal_new(int flags) {
+static sd_journal *journal_new(int flags, const char *path) {
sd_journal *j;
j = new0(sd_journal, 1);
@@ -1412,8 +1412,17 @@ static sd_journal *journal_new(int flags) {
j->inotify_fd = -1;
j->flags = flags;
+ if (path) {
+ j->path = strdup(path);
+ if (!j->path) {
+ free(j);
+ return NULL;
+ }
+ }
+
j->files = hashmap_new(string_hash_func, string_compare_func);
if (!j->files) {
+ free(j->path);
free(j);
return NULL;
}
@@ -1421,6 +1430,7 @@ static sd_journal *journal_new(int flags) {
j->directories_by_path = hashmap_new(string_hash_func, string_compare_func);
if (!j->directories_by_path) {
hashmap_free(j->files);
+ free(j->path);
free(j);
return NULL;
}
@@ -1440,7 +1450,7 @@ _public_ int sd_journal_open(sd_journal **ret, int flags) {
SD_JOURNAL_SYSTEM_ONLY))
return -EINVAL;
- j = journal_new(flags);
+ j = journal_new(flags, NULL);
if (!j)
return -ENOMEM;
@@ -1470,7 +1480,7 @@ _public_ int sd_journal_open_directory(sd_journal **ret, const char *path, int f
if (flags != 0)
return -EINVAL;
- j = journal_new(flags);
+ j = journal_new(flags, path);
if (!j)
return -ENOMEM;
@@ -1513,6 +1523,7 @@ _public_ void sd_journal_close(sd_journal *j) {
sd_journal_flush_matches(j);
+ free(j->path);
free(j);
}
@@ -1790,7 +1801,10 @@ _public_ int sd_journal_get_fd(sd_journal *j) {
/* Iterate through all dirs again, to add them to the
* inotify */
- r = add_search_paths(j);
+ if (j->path)
+ r = add_root_directory(j, j->path);
+ else
+ r = add_search_paths(j);
if (r < 0)
return r;