chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
journal/compress: fix calls to decompress_blob
[elogind.git]
/
src
/
journal
/
sd-journal.c
diff --git
a/src/journal/sd-journal.c
b/src/journal/sd-journal.c
index 3740a9a84035c1c5926371a3c503f27936d415dc..8dd82ec2ac30c985e8a07f9f8edcbe4118c05093 100644
(file)
--- a/
src/journal/sd-journal.c
+++ b/
src/journal/sd-journal.c
@@
-51,6
+51,8
@@
#define DEFAULT_DATA_THRESHOLD (64*1024)
#define DEFAULT_DATA_THRESHOLD (64*1024)
+static void remove_file_real(sd_journal *j, JournalFile *f);
+
static bool journal_pid_changed(sd_journal *j) {
assert(j);
static bool journal_pid_changed(sd_journal *j) {
assert(j);
@@
-885,6
+887,7
@@
static int real_journal_next(sd_journal *j, direction_t direction) {
r = next_beyond_location(j, f, direction, &o, &p);
if (r < 0) {
log_debug("Can't iterate through %s, ignoring: %s", f->path, strerror(-r));
r = next_beyond_location(j, f, direction, &o, &p);
if (r < 0) {
log_debug("Can't iterate through %s, ignoring: %s", f->path, strerror(-r));
+ remove_file_real(j, f);
continue;
} else if (r == 0)
continue;
continue;
} else if (r == 0)
continue;
@@
-1270,7
+1273,7
@@
static bool file_type_wanted(int flags, const char *filename) {
if (flags & SD_JOURNAL_CURRENT_USER) {
char prefix[5 + DECIMAL_STR_MAX(uid_t) + 1];
if (flags & SD_JOURNAL_CURRENT_USER) {
char prefix[5 + DECIMAL_STR_MAX(uid_t) + 1];
- assert_se(snprintf(prefix, sizeof(prefix), "user-
%lu", (unsigned long)
getuid())
+ assert_se(snprintf(prefix, sizeof(prefix), "user-
"UID_FMT,
getuid())
< (int) sizeof(prefix));
if (file_has_type_prefix(prefix, filename))
< (int) sizeof(prefix));
if (file_has_type_prefix(prefix, filename))
@@
-1339,7
+1342,7
@@
static int add_file(sd_journal *j, const char *prefix, const char *filename) {
}
static int remove_file(sd_journal *j, const char *prefix, const char *filename) {
}
static int remove_file(sd_journal *j, const char *prefix, const char *filename) {
- char *path;
+
_cleanup_free_
char *path;
JournalFile *f;
assert(j);
JournalFile *f;
assert(j);
@@
-1351,10
+1354,17
@@
static int remove_file(sd_journal *j, const char *prefix, const char *filename)
return -ENOMEM;
f = hashmap_get(j->files, path);
return -ENOMEM;
f = hashmap_get(j->files, path);
- free(path);
if (!f)
return 0;
if (!f)
return 0;
+ remove_file_real(j, f);
+ return 0;
+}
+
+static void remove_file_real(sd_journal *j, JournalFile *f) {
+ assert(j);
+ assert(f);
+
hashmap_remove(j->files, f->path);
log_debug("File %s removed.", f->path);
hashmap_remove(j->files, f->path);
log_debug("File %s removed.", f->path);
@@
-1372,8
+1382,6
@@
static int remove_file(sd_journal *j, const char *prefix, const char *filename)
journal_file_close(f);
j->current_invalidate_counter ++;
journal_file_close(f);
j->current_invalidate_counter ++;
-
- return 0;
}
static int add_directory(sd_journal *j, const char *prefix, const char *dirname) {
}
static int add_directory(sd_journal *j, const char *prefix, const char *dirname) {
@@
-1447,8
+1455,7
@@
static int add_directory(sd_journal *j, const char *prefix, const char *dirname)
de = readdir(d);
if (!de && errno != 0) {
r = -errno;
de = readdir(d);
if (!de && errno != 0) {
r = -errno;
- log_debug("Failed to read directory %s: %s",
- m->path, strerror(errno));
+ log_debug("Failed to read directory %s: %m", m->path);
return r;
}
if (!de)
return r;
}
if (!de)
@@
-1538,8
+1545,7
@@
static int add_root_directory(sd_journal *j, const char *p) {
de = readdir(d);
if (!de && errno != 0) {
r = -errno;
de = readdir(d);
if (!de && errno != 0) {
r = -errno;
- log_debug("Failed to read directory %s: %s",
- m->path, strerror(errno));
+ log_debug("Failed to read directory %s: %m", m->path);
return r;
}
if (!de)
return r;
}
if (!de)
@@
-1842,8
+1848,7
@@
_public_ void sd_journal_close(sd_journal *j) {
hashmap_free(j->directories_by_path);
hashmap_free(j->directories_by_wd);
hashmap_free(j->directories_by_path);
hashmap_free(j->directories_by_wd);
- if (j->inotify_fd >= 0)
- close_nointr_nofail(j->inotify_fd);
+ safe_close(j->inotify_fd);
if (j->mmap) {
log_debug("mmap cache statistics: %u hit, %u miss", mmap_cache_get_hit(j->mmap), mmap_cache_get_missed(j->mmap));
if (j->mmap) {
log_debug("mmap cache statistics: %u hit, %u miss", mmap_cache_get_hit(j->mmap), mmap_cache_get_missed(j->mmap));
@@
-1978,6
+1983,7
@@
_public_ int sd_journal_get_data(sd_journal *j, const char *field, const void **
uint64_t p, l;
le64_t le_hash;
size_t t;
uint64_t p, l;
le64_t le_hash;
size_t t;
+ int compression;
p = le64toh(o->entry.items[i].object_offset);
le_hash = o->entry.items[i].hash;
p = le64toh(o->entry.items[i].object_offset);
le_hash = o->entry.items[i].hash;
@@
-1990,28
+1996,26
@@
_public_ int sd_journal_get_data(sd_journal *j, const char *field, const void **
l = le64toh(o->object.size) - offsetof(Object, data.payload);
l = le64toh(o->object.size) - offsetof(Object, data.payload);
- if (o->object.flags & OBJECT_COMPRESSED) {
+ compression = o->object.flags & OBJECT_COMPRESSION_MASK;
+ if (compression &&
+ decompress_startswith(compression,
+ o->data.payload, l,
+ &f->compress_buffer, &f->compress_buffer_size,
+ field, field_length, '=')) {
-#ifdef HAVE_XZ
- if (uncompress_startswith(o->data.payload, l,
- &f->compress_buffer, &f->compress_buffer_size,
- field, field_length, '=')) {
+ uint64_t rsize;
- uint64_t rsize;
-
-
if (!uncompress_blob(o->data.payload, l
,
- &f->compress_buffer, &f->compress_buffer_size, &rsize,
-
j->data_threshold)
)
-
return -EBADMSG
;
+ r = decompress_blob(compression,
+ o->data.payload, l,
+
&f->compress_buffer, &f->compress_buffer_size, &rsize
,
+ j->data_threshold);
+
if (r < 0
)
+
return r
;
-
*data = f->compress_buffer;
-
*size = (size_t) rsize;
+ *data = f->compress_buffer;
+ *size = (size_t) rsize;
- return 0;
- }
-#else
- return -EPROTONOSUPPORT;
-#endif
+ return 0;
} else if (l >= field_length+1 &&
memcmp(o->data.payload, field, field_length) == 0 &&
} else if (l >= field_length+1 &&
memcmp(o->data.payload, field, field_length) == 0 &&
@@
-2039,6
+2043,7
@@
_public_ int sd_journal_get_data(sd_journal *j, const char *field, const void **
static int return_data(sd_journal *j, JournalFile *f, Object *o, const void **data, size_t *size) {
size_t t;
uint64_t l;
static int return_data(sd_journal *j, JournalFile *f, Object *o, const void **data, size_t *size) {
size_t t;
uint64_t l;
+ int compression, r;
l = le64toh(o->object.size) - offsetof(Object, data.payload);
t = (size_t) l;
l = le64toh(o->object.size) - offsetof(Object, data.payload);
t = (size_t) l;
@@
-2047,18
+2052,18
@@
static int return_data(sd_journal *j, JournalFile *f, Object *o, const void **da
if ((uint64_t) t != l)
return -E2BIG;
if ((uint64_t) t != l)
return -E2BIG;
- if (o->object.flags & OBJECT_COMPRESSED) {
-#ifdef HAVE_XZ
+ compression = o->object.flags & OBJECT_COMPRESSION_MASK;
+ if (compression) {
uint64_t rsize;
uint64_t rsize;
- if (!uncompress_blob(o->data.payload, l, &f->compress_buffer, &f->compress_buffer_size, &rsize, j->data_threshold))
- return -EBADMSG;
+ r = decompress_blob(compression,
+ o->data.payload, l, &f->compress_buffer,
+ &f->compress_buffer_size, &rsize, j->data_threshold);
+ if (r < 0)
+ return r;
*data = f->compress_buffer;
*size = (size_t) rsize;
*data = f->compress_buffer;
*size = (size_t) rsize;
-#else
- return -EPROTONOSUPPORT;
-#endif
} else {
*data = o->data.payload;
*size = t;
} else {
*data = o->data.payload;
*size = t;
@@
-2293,8
+2298,6
@@
_public_ int sd_journal_process(sd_journal *j) {
l -= step;
}
}
l -= step;
}
}
-
- return determine_change(j);
}
_public_ int sd_journal_wait(sd_journal *j, uint64_t timeout_usec) {
}
_public_ int sd_journal_wait(sd_journal *j, uint64_t timeout_usec) {