Skip to content

Commit 059599b

Browse files
committed
Clarify documentation's notion of "current"
As per e.g. https://www.freedesktop.org/software/systemd/man/sd_journal_get_realtime_usec.html: > Note that these functions will not work before sd_journal_next(3) (or related call) has been called at least once, in order to position the read pointer at a valid entry. The prior wording of the documentation was ambiguous regarding its usage of "current". This change attempts to clarify that it's "current" in terms of "the state of the read pointer, adjusted by the Next/Previous family of functions" vs. "current" in terms of chronology.
1 parent d219646 commit 059599b

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

sdjournal/journal.go

+37-16
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,8 @@ func (j *Journal) getData(field string) (unsafe.Pointer, C.int, error) {
641641
}
642642

643643
// GetData gets the data object associated with a specific field from the
644-
// current journal entry.
644+
// the journal entry referenced by the last completed Next/Previous function
645+
// call. To call GetData, you must have first called one of these functions.
645646
func (j *Journal) GetData(field string) (string, error) {
646647
d, l, err := j.getData(field)
647648
if err != nil {
@@ -652,7 +653,9 @@ func (j *Journal) GetData(field string) (string, error) {
652653
}
653654

654655
// GetDataValue gets the data object associated with a specific field from the
655-
// current journal entry, returning only the value of the object.
656+
// journal entry referenced by the last completed Next/Previous function call,
657+
// returning only the value of the object. To call GetDataValue, you must first
658+
// have called one of the Next/Previous functions.
656659
func (j *Journal) GetDataValue(field string) (string, error) {
657660
val, err := j.GetData(field)
658661
if err != nil {
@@ -663,7 +666,8 @@ func (j *Journal) GetDataValue(field string) (string, error) {
663666
}
664667

665668
// GetDataBytes gets the data object associated with a specific field from the
666-
// current journal entry.
669+
// journal entry referenced by the last completed Next/Previous function call.
670+
// To call GetDataBytes, you must first have called one of these functions.
667671
func (j *Journal) GetDataBytes(field string) ([]byte, error) {
668672
d, l, err := j.getData(field)
669673
if err != nil {
@@ -674,7 +678,9 @@ func (j *Journal) GetDataBytes(field string) ([]byte, error) {
674678
}
675679

676680
// GetDataValueBytes gets the data object associated with a specific field from the
677-
// current journal entry, returning only the value of the object.
681+
// journal entry referenced by the last completed Next/Previous function call,
682+
// returning only the value of the object. To call GetDataValueBytes, you must first
683+
// have called one of the Next/Previous functions.
678684
func (j *Journal) GetDataValueBytes(field string) ([]byte, error) {
679685
val, err := j.GetDataBytes(field)
680686
if err != nil {
@@ -684,9 +690,10 @@ func (j *Journal) GetDataValueBytes(field string) ([]byte, error) {
684690
return bytes.SplitN(val, []byte("="), 2)[1], nil
685691
}
686692

687-
// GetEntry returns a full representation of a journal entry with
688-
// all key-value pairs of data as well as address fields (cursor, realtime
689-
// timestamp and monotonic timestamp)
693+
// GetEntry returns a full representation of the journal entry referenced by the
694+
// last completed Next/Previous function call, with all key-value pairs of data
695+
// as well as address fields (cursor, realtime timestamp and monotonic timestamp).
696+
// To call GetEntry, you must first have called one of the Next/Previous functions.
690697
func (j *Journal) GetEntry() (*JournalEntry, error) {
691698
sd_journal_get_realtime_usec, err := getFunction("sd_journal_get_realtime_usec")
692699
if err != nil {
@@ -795,8 +802,10 @@ func (j *Journal) SetDataThreshold(threshold uint64) error {
795802
return nil
796803
}
797804

798-
// GetRealtimeUsec gets the realtime (wallclock) timestamp of the current
799-
// journal entry.
805+
// GetRealtimeUsec gets the realtime (wallclock) timestamp of the journal
806+
// entry referenced by the last completed Next/Previous function call. To
807+
// call GetRealtimeUsec, you must first have called one of the Next/Previous
808+
// functions.
800809
func (j *Journal) GetRealtimeUsec() (uint64, error) {
801810
var usec C.uint64_t
802811

@@ -816,7 +825,10 @@ func (j *Journal) GetRealtimeUsec() (uint64, error) {
816825
return uint64(usec), nil
817826
}
818827

819-
// GetMonotonicUsec gets the monotonic timestamp of the current journal entry.
828+
// GetMonotonicUsec gets the monotonic timestamp of the journal entry
829+
// referenced by the last completed Next/Previous function call. To call
830+
// GetMonotonicUsec, you must first have called one of the Next/Previous
831+
// functions.
820832
func (j *Journal) GetMonotonicUsec() (uint64, error) {
821833
var usec C.uint64_t
822834
var boot_id C.sd_id128_t
@@ -837,7 +849,9 @@ func (j *Journal) GetMonotonicUsec() (uint64, error) {
837849
return uint64(usec), nil
838850
}
839851

840-
// GetCursor gets the cursor of the current journal entry.
852+
// GetCursor gets the cursor of the last journal entry reeferenced by the
853+
// last completed Next/Previous function call. To call GetCursor, you must
854+
// first have called one of the Next/Previous functions.
841855
func (j *Journal) GetCursor() (string, error) {
842856
sd_journal_get_cursor, err := getFunction("sd_journal_get_cursor")
843857
if err != nil {
@@ -885,7 +899,8 @@ func (j *Journal) TestCursor(cursor string) error {
885899
}
886900

887901
// SeekHead seeks to the beginning of the journal, i.e. the oldest available
888-
// entry.
902+
// entry. This call must be followed by a call to Next before any call to
903+
// Get* will return data about the first element.
889904
func (j *Journal) SeekHead() error {
890905
sd_journal_seek_head, err := getFunction("sd_journal_seek_head")
891906
if err != nil {
@@ -904,7 +919,8 @@ func (j *Journal) SeekHead() error {
904919
}
905920

906921
// SeekTail may be used to seek to the end of the journal, i.e. the most recent
907-
// available entry.
922+
// available entry. This call must be followed by a call to Next before any
923+
// call to Get* will return data about the last element.
908924
func (j *Journal) SeekTail() error {
909925
sd_journal_seek_tail, err := getFunction("sd_journal_seek_tail")
910926
if err != nil {
@@ -923,7 +939,8 @@ func (j *Journal) SeekTail() error {
923939
}
924940

925941
// SeekRealtimeUsec seeks to the entry with the specified realtime (wallclock)
926-
// timestamp, i.e. CLOCK_REALTIME.
942+
// timestamp, i.e. CLOCK_REALTIME. This call must be followed by a call to
943+
// Next/Previous before any call to Get* will return data about the sought entry.
927944
func (j *Journal) SeekRealtimeUsec(usec uint64) error {
928945
sd_journal_seek_realtime_usec, err := getFunction("sd_journal_seek_realtime_usec")
929946
if err != nil {
@@ -941,7 +958,9 @@ func (j *Journal) SeekRealtimeUsec(usec uint64) error {
941958
return nil
942959
}
943960

944-
// SeekCursor seeks to a concrete journal cursor.
961+
// SeekCursor seeks to a concrete journal cursor. This call must be
962+
// followed by a call to Next/Previous before any call to Get* will return
963+
// data about the sought entry.
945964
func (j *Journal) SeekCursor(cursor string) error {
946965
sd_journal_seek_cursor, err := getFunction("sd_journal_seek_cursor")
947966
if err != nil {
@@ -1066,7 +1085,9 @@ func (j *Journal) GetUniqueValues(field string) ([]string, error) {
10661085
return result, nil
10671086
}
10681087

1069-
// GetCatalog retrieves a message catalog entry for the current journal entry.
1088+
// GetCatalog retrieves a message catalog entry for the journal entry referenced
1089+
// by the last completed Next/Previous function call. To call GetCatalog, you
1090+
// must first have called one of these functions.
10701091
func (j *Journal) GetCatalog() (string, error) {
10711092
sd_journal_get_catalog, err := getFunction("sd_journal_get_catalog")
10721093
if err != nil {

0 commit comments

Comments
 (0)