@@ -155,6 +155,24 @@ package sdjournal
155155// }
156156//
157157// int
158+ // my_sd_journal_get_cursor(void *f, sd_journal *j, char **cursor)
159+ // {
160+ // int (*sd_journal_get_cursor)(sd_journal *, char **);
161+ //
162+ // sd_journal_get_cursor = f;
163+ // return sd_journal_get_cursor(j, cursor);
164+ // }
165+ //
166+ // int
167+ // my_sd_journal_test_cursor(void *f, sd_journal *j, const char *cursor)
168+ // {
169+ // int (*sd_journal_test_cursor)(sd_journal *, const char *);
170+ //
171+ // sd_journal_test_cursor = f;
172+ // return sd_journal_test_cursor(j, cursor);
173+ // }
174+ //
175+ // int
158176// my_sd_journal_get_realtime_usec(void *f, sd_journal *j, uint64_t *usec)
159177// {
160178// int (*sd_journal_get_realtime_usec)(sd_journal *, uint64_t *);
@@ -181,6 +199,16 @@ package sdjournal
181199// return sd_journal_seek_tail(j);
182200// }
183201//
202+ //
203+ // int
204+ // my_sd_journal_seek_cursor(void *f, sd_journal *j, const char *cursor)
205+ // {
206+ // int (*sd_journal_seek_cursor)(sd_journal *, const char *);
207+ //
208+ // sd_journal_seek_cursor = f;
209+ // return sd_journal_seek_cursor(j, cursor);
210+ // }
211+ //
184212// int
185213// my_sd_journal_seek_realtime_usec(void *f, sd_journal *j, uint64_t usec)
186214// {
@@ -597,6 +625,50 @@ func (j *Journal) GetRealtimeUsec() (uint64, error) {
597625 return uint64 (usec ), nil
598626}
599627
628+ // GetCursor gets the cursor of the current journal entry.
629+ func (j * Journal ) GetCursor () (string , error ) {
630+ var d * C.char
631+
632+ sd_journal_get_cursor , err := j .getFunction ("sd_journal_get_cursor" )
633+ if err != nil {
634+ return "" , err
635+ }
636+
637+ j .mu .Lock ()
638+ r := C .my_sd_journal_get_cursor (sd_journal_get_cursor , j .cjournal , & d )
639+ j .mu .Unlock ()
640+
641+ if r < 0 {
642+ return "" , fmt .Errorf ("failed to get cursor: %d" , syscall .Errno (- r ))
643+ }
644+
645+ cursor := C .GoString (d )
646+
647+ return cursor , nil
648+ }
649+
650+ // TestCursor checks whether the current position in the journal matches the
651+ // specified cursor
652+ func (j * Journal ) TestCursor (cursor string ) error {
653+ sd_journal_test_cursor , err := j .getFunction ("sd_journal_test_cursor" )
654+ if err != nil {
655+ return err
656+ }
657+
658+ c := C .CString (cursor )
659+ defer C .free (unsafe .Pointer (c ))
660+
661+ j .mu .Lock ()
662+ r := C .my_sd_journal_test_cursor (sd_journal_test_cursor , j .cjournal , c )
663+ j .mu .Unlock ()
664+
665+ if r < 0 {
666+ return fmt .Errorf ("failed to test to cursor %q: %d" , cursor , syscall .Errno (- r ))
667+ }
668+
669+ return nil
670+ }
671+
600672// SeekHead seeks to the beginning of the journal, i.e. the oldest available
601673// entry.
602674func (j * Journal ) SeekHead () error {
@@ -654,6 +726,27 @@ func (j *Journal) SeekRealtimeUsec(usec uint64) error {
654726 return nil
655727}
656728
729+ // SeekCursor seeks to a concrete journal cursor.
730+ func (j * Journal ) SeekCursor (cursor string ) error {
731+ sd_journal_seek_cursor , err := j .getFunction ("sd_journal_seek_cursor" )
732+ if err != nil {
733+ return err
734+ }
735+
736+ c := C .CString (cursor )
737+ defer C .free (unsafe .Pointer (c ))
738+
739+ j .mu .Lock ()
740+ r := C .my_sd_journal_seek_cursor (sd_journal_seek_cursor , j .cjournal , c )
741+ j .mu .Unlock ()
742+
743+ if r < 0 {
744+ return fmt .Errorf ("failed to seek to cursor %q: %d" , cursor , syscall .Errno (- r ))
745+ }
746+
747+ return nil
748+ }
749+
657750// Wait will synchronously wait until the journal gets changed. The maximum time
658751// this call sleeps may be controlled with the timeout parameter. If
659752// sdjournal.IndefiniteWait is passed as the timeout parameter, Wait will
0 commit comments