sd-journal.c revision 161e54f8719c4a11440d762276cbccbeb1736f8c
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2011 Lennart Poettering
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
#include "sd-journal.h"
#include "journal-def.h"
#include "journal-file.h"
#include "hashmap.h"
#include "list.h"
struct Match {
char *data;
};
struct sd_journal {
};
Match *m;
char *e;
assert(j);
if (!m)
return -ENOMEM;
if (!m->data) {
free(m);
return -ENOMEM;
}
*(e++) = '=';
return 0;
}
void sd_journal_flush_matches(sd_journal *j) {
assert(j);
while (j->matches) {
free(m);
}
}
uint64_t a, b;
/* If this is from the same seqnum source, compare
* seqnums */
/* If the boot id matches compare monotonic time */
} else {
/* Otherwise compare UTC time */
}
return
a < b ? -1 :
a > b ? +1 : 0;
}
int sd_journal_next(sd_journal *j) {
Iterator i;
int r;
uint64_t new_offset = 0;
assert(j);
HASHMAP_FOREACH(f, j->files, i) {
Object *o;
uint64_t p;
if (f->current_offset > 0) {
if (r < 0)
return r;
} else
o = NULL;
r = journal_file_next_entry(f, o, &o, &p);
if (r < 0)
return r;
else if (r == 0)
continue;
new_current = f;
new_entry = o;
new_offset = p;
}
}
if (new_current) {
j->current_file = new_current;
j->current_file->current_field = 0;
return 1;
}
return 0;
}
int sd_journal_previous(sd_journal *j) {
Iterator i;
int r;
uint64_t new_offset = 0;
assert(j);
HASHMAP_FOREACH(f, j->files, i) {
Object *o;
uint64_t p;
if (f->current_offset > 0) {
if (r < 0)
return r;
} else
o = NULL;
r = journal_file_prev_entry(f, o, &o, &p);
if (r < 0)
return r;
else if (r == 0)
continue;
new_current = f;
new_entry = o;
new_offset = p;
}
}
if (new_current) {
j->current_file = new_current;
j->current_file->current_field = 0;
return 1;
}
return 0;
}
Object *o;
int r;
assert(j);
return -EADDRNOTAVAIL;
r = journal_file_move_to_object(j->current_file, j->current_file->current_offset, OBJECT_ENTRY, &o);
if (r < 0)
return r;
"s=%s;i=%llx;b=%s;m=%llx;t=%llx;x=%llx;p=%s",
return -ENOMEM;
return 1;
}
return -EINVAL;
}
char *fn;
int r;
JournalFile *f;
assert(j);
if (dir)
else
if (!fn)
return -ENOMEM;
if (r < 0) {
return 0;
return r;
}
if (r < 0) {
return r;
}
return 0;
}
char *fn;
int r;
DIR *d;
assert(j);
if (!fn)
return -ENOMEM;
if (!d) {
return 0;
return -errno;
}
for (;;) {
if (r != 0 || !de)
break;
continue;
if (r < 0)
}
closedir(d);
return 0;
}
sd_journal *j;
const char *p;
const char search_paths[] =
int r;
if (!j)
return -ENOMEM;
if (!j->files) {
r = -ENOMEM;
goto fail;
}
/* We ignore most errors here, since the idea is to only open
* what's actually accessible, and ignore the rest. */
NULSTR_FOREACH(p, search_paths) {
DIR *d;
d = opendir(p);
if (!d) {
log_debug("Failed to open %s: %m", p);
continue;
}
for (;;) {
if (r != 0 || !de)
break;
if (r < 0)
if (r < 0)
}
}
closedir(d);
}
*ret = j;
return 0;
fail:
sd_journal_close(j);
return r;
};
void sd_journal_close(sd_journal *j) {
assert(j);
if (j->files) {
JournalFile *f;
while ((f = hashmap_steal_first(j->files)))
hashmap_free(j->files);
}
free(j);
}
Object *o;
JournalFile *f;
int r;
assert(j);
f = j->current_file;
if (!f)
return 0;
if (f->current_offset <= 0)
return 0;
if (r < 0)
return r;
return 1;
}
Object *o;
JournalFile *f;
int r;
assert(j);
f = j->current_file;
if (!f)
return 0;
if (f->current_offset <= 0)
return 0;
r = sd_id128_get_machine(&id);
if (r < 0)
return r;
if (r < 0)
return r;
return 0;
return 1;
}
JournalFile *f;
uint64_t i, n;
int r;
Object *o;
assert(j);
return -EINVAL;
f = j->current_file;
if (!f)
return 0;
if (f->current_offset <= 0)
return 0;
if (r < 0)
return r;
n = journal_file_entry_n_items(o);
for (i = 0; i < n; i++) {
uint64_t p, l;
size_t t;
r = journal_file_move_to_object(f, p, OBJECT_DATA, &o);
if (r < 0)
return r;
if (l >= field_length+1 &&
t = (size_t) l;
if ((uint64_t) t != l)
return -E2BIG;
*size = t;
return 1;
}
if (r < 0)
return r;
}
return 0;
}
JournalFile *f;
uint64_t p, l, n;
size_t t;
int r;
Object *o;
assert(j);
f = j->current_file;
if (!f)
return 0;
if (f->current_offset <= 0)
return 0;
if (r < 0)
return r;
n = journal_file_entry_n_items(o);
if (f->current_field >= n)
return 0;
r = journal_file_move_to_object(f, p, OBJECT_DATA, &o);
if (r < 0)
return r;
t = (size_t) l;
/* We can't read objects larger than 4G on a 32bit machine */
if ((uint64_t) t != l)
return -E2BIG;
*size = t;
f->current_field ++;
return 1;
}