Skip to content

Commit

Permalink
sdjournal: add SeekHead method
Browse files Browse the repository at this point in the history
Simple wrapper around `sd_journal_seek_head`
  • Loading branch information
jonboulle committed May 20, 2016
1 parent 7d19429 commit 48fe794
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions sdjournal/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ package sdjournal
// }
//
// int
// my_sd_journal_seek_head(void *f, sd_journal *j)
// {
// int (*sd_journal_seek_head)(sd_journal *);
//
// sd_journal_seek_head = f;
// return sd_journal_seek_head(j);
// }
//
// int
// my_sd_journal_seek_tail(void *f, sd_journal *j)
// {
// int (*sd_journal_seek_tail)(sd_journal *);
Expand Down Expand Up @@ -587,6 +596,25 @@ func (j *Journal) GetRealtimeUsec() (uint64, error) {
return uint64(usec), nil
}

// SeekHead seeks to the beginning of the journal, i.e. the oldest available
// entry.
func (j *Journal) SeekHead() error {
sd_journal_seek_head, err := j.getFunction("sd_journal_seek_head")
if err != nil {
return err
}

j.mu.Lock()
r := C.my_sd_journal_seek_head(sd_journal_seek_head, j.cjournal)
j.mu.Unlock()

if r < 0 {
return fmt.Errorf("failed to seek to head of journal: %d", syscall.Errno(-r))
}

return nil
}

// SeekTail may be used to seek to the end of the journal, i.e. the most recent
// available entry.
func (j *Journal) SeekTail() error {
Expand Down

0 comments on commit 48fe794

Please sign in to comment.