Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-systemd
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
le
go-systemd
Commits
1d9051fe
Commit
1d9051fe
authored
8 years ago
by
Iago López Galeiras
Browse files
Options
Downloads
Plain Diff
Merge pull request #160 from jonboulle/master
sdjournal: add ability to rewind JournalReader
parents
7d194297
0f214941
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sdjournal/journal.go
+28
-0
28 additions, 0 deletions
sdjournal/journal.go
sdjournal/read.go
+6
-0
6 additions, 0 deletions
sdjournal/read.go
with
34 additions
and
0 deletions
sdjournal/journal.go
+
28
−
0
View file @
1d9051fe
...
...
@@ -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 *);
...
...
@@ -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
{
...
...
This diff is collapsed.
Click to expand it.
sdjournal/read.go
+
6
−
0
View file @
1d9051fe
...
...
@@ -125,10 +125,16 @@ func (r *JournalReader) Read(b []byte) (int, error) {
return
len
(
msg
),
nil
}
// Close closes the JournalReader's handle to the journal.
func
(
r
*
JournalReader
)
Close
()
error
{
return
r
.
journal
.
Close
()
}
// Rewind attempts to rewind the JournalReader to the first entry.
func
(
r
*
JournalReader
)
Rewind
()
error
{
return
r
.
journal
.
SeekHead
()
}
// Follow synchronously follows the JournalReader, writing each new journal entry to writer. The
// follow will continue until a single time.Time is received on the until channel.
func
(
r
*
JournalReader
)
Follow
(
until
<-
chan
time
.
Time
,
writer
io
.
Writer
)
(
err
error
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment