sd-journal.c revision 0ac38b707212e9aa40e25d65ffbae648cc9116f5
/*-*- 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 "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;
f->current_offset = new_offset;
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;
f->current_offset = new_offset;
return 1;
}
return 0;
}
JournalCursor *c;
Object *o;
int r;
assert(j);
return 0;
r = journal_file_move_to_object(j->current_file, j->current_file->current_offset, OBJECT_ENTRY, &o);
if (r < 0)
return r;
if (!c)
return -ENOMEM;
c->version = 1;
*cursor = c;
*size = sizeof(JournalCursor);
return 1;
}
return -EINVAL;
}
sd_journal *j;
char *fn;
const char *p;
int r = 0;
const char search_paths[] =
if (!j)
return -ENOMEM;
if (!j->files)
goto fail;
NULSTR_FOREACH(p, search_paths) {
DIR *d;
d = opendir(p);
if (!d) {
r = -errno;
continue;
}
for (;;) {
int k;
JournalFile *f;
if (k != 0) {
if (r == 0)
r = -k;
break;
}
if (!de)
break;
continue;
if (!fn) {
r = -ENOMEM;
closedir(d);
goto fail;
}
if (k < 0) {
if (r == 0)
r = -k;
} else {
if (k < 0) {
closedir(d);
r = k;
goto fail;
}
}
}
}
*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);
}