@@ -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// {
@@ -596,6 +624,50 @@ func (j *Journal) GetRealtimeUsec() (uint64, error) {
596624 return uint64 (usec ), nil
597625}
598626
627+ // GetCursor gets the cursor of the current journal entry.
628+ func (j * Journal ) GetCursor () (string , error ) {
629+ var d * C.char
630+
631+ sd_journal_get_cursor , err := j .getFunction ("sd_journal_get_cursor" )
632+ if err != nil {
633+ return "" , err
634+ }
635+
636+ j .mu .Lock ()
637+ r := C .my_sd_journal_get_cursor (sd_journal_get_cursor , j .cjournal , & d )
638+ j .mu .Unlock ()
639+
640+ if r < 0 {
641+ return "" , fmt .Errorf ("failed to get cursor: %d" , syscall .Errno (- r ))
642+ }
643+
644+ cursor := C .GoString (d )
645+
646+ return cursor , nil
647+ }
648+
649+ // TestCursor checks whether the current position in the journal matches the
650+ // specified cursor
651+ func (j * Journal ) TestCursor (cursor string ) error {
652+ sd_journal_test_cursor , err := j .getFunction ("sd_journal_test_cursor" )
653+ if err != nil {
654+ return err
655+ }
656+
657+ c := C .CString (cursor )
658+ defer C .free (unsafe .Pointer (c ))
659+
660+ j .mu .Lock ()
661+ r := C .my_sd_journal_test_cursor (sd_journal_test_cursor , j .cjournal , c )
662+ j .mu .Unlock ()
663+
664+ if r < 0 {
665+ return fmt .Errorf ("failed to test to cursor %q: %d" , cursor , syscall .Errno (- r ))
666+ }
667+
668+ return nil
669+ }
670+
599671// SeekHead seeks to the beginning of the journal, i.e. the oldest available
600672// entry.
601673func (j * Journal ) SeekHead () error {
@@ -653,6 +725,27 @@ func (j *Journal) SeekRealtimeUsec(usec uint64) error {
653725 return nil
654726}
655727
728+ // SeekCursor seeks to a concrete journal cursor.
729+ func (j * Journal ) SeekCursor (cursor string ) error {
730+ sd_journal_seek_cursor , err := j .getFunction ("sd_journal_seek_cursor" )
731+ if err != nil {
732+ return err
733+ }
734+
735+ c := C .CString (cursor )
736+ defer C .free (unsafe .Pointer (c ))
737+
738+ j .mu .Lock ()
739+ r := C .my_sd_journal_seek_cursor (sd_journal_seek_cursor , j .cjournal , c )
740+ j .mu .Unlock ()
741+
742+ if r < 0 {
743+ return fmt .Errorf ("failed to seek to cursor %q: %d" , cursor , syscall .Errno (- r ))
744+ }
745+
746+ return nil
747+ }
748+
656749// Wait will synchronously wait until the journal gets changed. The maximum time
657750// this call sleeps may be controlled with the timeout parameter. If
658751// sdjournal.IndefiniteWait is passed as the timeout parameter, Wait will
0 commit comments