Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions sdjournal/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func NewJournal() (j *Journal, err error) {
r := C.my_sd_journal_open(sd_journal_open, &j.cjournal, C.SD_JOURNAL_LOCAL_ONLY)

if r < 0 {
return nil, fmt.Errorf("failed to open journal: %d", syscall.Errno(-r))
return nil, fmt.Errorf("failed to open journal: %s", syscall.Errno(-r).Error())
}

return j, nil
Expand All @@ -435,7 +435,7 @@ func NewJournalFromDir(path string) (j *Journal, err error) {

r := C.my_sd_journal_open_directory(sd_journal_open_directory, &j.cjournal, p, 0)
if r < 0 {
return nil, fmt.Errorf("failed to open journal in directory %q: %d", path, syscall.Errno(-r))
return nil, fmt.Errorf("failed to open journal in directory %q: %s", path, syscall.Errno(-r).Error())
}

return j, nil
Expand All @@ -461,7 +461,7 @@ func NewJournalFromFiles(paths ...string) (j *Journal, err error) {

r := C.my_sd_journal_open_files(sd_journal_open_files, &j.cjournal, &cPaths[0], 0)
if r < 0 {
return nil, fmt.Errorf("failed to open journals in paths %q: %d", paths, syscall.Errno(-r))
return nil, fmt.Errorf("failed to open journals in paths %q: %s", paths, syscall.Errno(-r).Error())
}

return j, nil
Expand Down Expand Up @@ -496,7 +496,7 @@ func (j *Journal) AddMatch(match string) error {
j.mu.Unlock()

if r < 0 {
return fmt.Errorf("failed to add match: %d", syscall.Errno(-r))
return fmt.Errorf("failed to add match: %s", syscall.Errno(-r).Error())
}

return nil
Expand All @@ -514,7 +514,7 @@ func (j *Journal) AddDisjunction() error {
j.mu.Unlock()

if r < 0 {
return fmt.Errorf("failed to add a disjunction in the match list: %d", syscall.Errno(-r))
return fmt.Errorf("failed to add a disjunction in the match list: %s", syscall.Errno(-r).Error())
}

return nil
Expand All @@ -532,7 +532,7 @@ func (j *Journal) AddConjunction() error {
j.mu.Unlock()

if r < 0 {
return fmt.Errorf("failed to add a conjunction in the match list: %d", syscall.Errno(-r))
return fmt.Errorf("failed to add a conjunction in the match list: %s", syscall.Errno(-r).Error())
}

return nil
Expand Down Expand Up @@ -562,7 +562,7 @@ func (j *Journal) Next() (uint64, error) {
j.mu.Unlock()

if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
return 0, fmt.Errorf("failed to iterate journal: %s", syscall.Errno(-r).Error())
}

return uint64(r), nil
Expand All @@ -581,7 +581,7 @@ func (j *Journal) NextSkip(skip uint64) (uint64, error) {
j.mu.Unlock()

if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
return 0, fmt.Errorf("failed to iterate journal: %s", syscall.Errno(-r).Error())
}

return uint64(r), nil
Expand All @@ -599,7 +599,7 @@ func (j *Journal) Previous() (uint64, error) {
j.mu.Unlock()

if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
return 0, fmt.Errorf("failed to iterate journal: %s", syscall.Errno(-r).Error())
}

return uint64(r), nil
Expand All @@ -618,7 +618,7 @@ func (j *Journal) PreviousSkip(skip uint64) (uint64, error) {
j.mu.Unlock()

if r < 0 {
return 0, fmt.Errorf("failed to iterate journal: %d", syscall.Errno(-r))
return 0, fmt.Errorf("failed to iterate journal: %s", syscall.Errno(-r).Error())
}

return uint64(r), nil
Expand All @@ -641,7 +641,7 @@ func (j *Journal) getData(field string) (unsafe.Pointer, C.int, error) {
j.mu.Unlock()

if r < 0 {
return nil, 0, fmt.Errorf("failed to read message: %d", syscall.Errno(-r))
return nil, 0, fmt.Errorf("failed to read message: %s", syscall.Errno(-r).Error())
}

return d, C.int(l), nil
Expand Down Expand Up @@ -736,7 +736,7 @@ func (j *Journal) GetEntry() (*JournalEntry, error) {
var realtimeUsec C.uint64_t
r = C.my_sd_journal_get_realtime_usec(sd_journal_get_realtime_usec, j.cjournal, &realtimeUsec)
if r < 0 {
return nil, fmt.Errorf("failed to get realtime timestamp: %d", syscall.Errno(-r))
return nil, fmt.Errorf("failed to get realtime timestamp: %s", syscall.Errno(-r).Error())
}

entry.RealtimeTimestamp = uint64(realtimeUsec)
Expand All @@ -746,7 +746,7 @@ func (j *Journal) GetEntry() (*JournalEntry, error) {

r = C.my_sd_journal_get_monotonic_usec(sd_journal_get_monotonic_usec, j.cjournal, &monotonicUsec, &boot_id)
if r < 0 {
return nil, fmt.Errorf("failed to get monotonic timestamp: %d", syscall.Errno(-r))
return nil, fmt.Errorf("failed to get monotonic timestamp: %s", syscall.Errno(-r).Error())
}

entry.MonotonicTimestamp = uint64(monotonicUsec)
Expand All @@ -757,7 +757,7 @@ func (j *Journal) GetEntry() (*JournalEntry, error) {
r = C.my_sd_journal_get_cursor(sd_journal_get_cursor, j.cjournal, &c)
defer C.free(unsafe.Pointer(c))
if r < 0 {
return nil, fmt.Errorf("failed to get cursor: %d", syscall.Errno(-r))
return nil, fmt.Errorf("failed to get cursor: %s", syscall.Errno(-r).Error())
}

entry.Cursor = C.GoString(c)
Expand All @@ -773,7 +773,7 @@ func (j *Journal) GetEntry() (*JournalEntry, error) {
}

if r < 0 {
return nil, fmt.Errorf("failed to read message field: %d", syscall.Errno(-r))
return nil, fmt.Errorf("failed to read message field: %s", syscall.Errno(-r).Error())
}

msg := C.GoStringN((*C.char)(d), C.int(l))
Expand Down Expand Up @@ -803,7 +803,7 @@ func (j *Journal) SetDataThreshold(threshold uint64) error {
j.mu.Unlock()

if r < 0 {
return fmt.Errorf("failed to set data threshold: %d", syscall.Errno(-r))
return fmt.Errorf("failed to set data threshold: %s", syscall.Errno(-r).Error())
}

return nil
Expand All @@ -826,7 +826,7 @@ func (j *Journal) GetRealtimeUsec() (uint64, error) {
j.mu.Unlock()

if r < 0 {
return 0, fmt.Errorf("failed to get realtime timestamp: %d", syscall.Errno(-r))
return 0, fmt.Errorf("failed to get realtime timestamp: %s", syscall.Errno(-r).Error())
}

return uint64(usec), nil
Expand All @@ -850,7 +850,7 @@ func (j *Journal) GetMonotonicUsec() (uint64, error) {
j.mu.Unlock()

if r < 0 {
return 0, fmt.Errorf("failed to get monotonic timestamp: %d", syscall.Errno(-r))
return 0, fmt.Errorf("failed to get monotonic timestamp: %s", syscall.Errno(-r).Error())
}

return uint64(usec), nil
Expand All @@ -875,7 +875,7 @@ func (j *Journal) GetCursor() (string, error) {
defer C.free(unsafe.Pointer(d))

if r < 0 {
return "", fmt.Errorf("failed to get cursor: %d", syscall.Errno(-r))
return "", fmt.Errorf("failed to get cursor: %s", syscall.Errno(-r).Error())
}

cursor := C.GoString(d)
Expand All @@ -899,7 +899,7 @@ func (j *Journal) TestCursor(cursor string) error {
j.mu.Unlock()

if r < 0 {
return fmt.Errorf("failed to test to cursor %q: %d", cursor, syscall.Errno(-r))
return fmt.Errorf("failed to test to cursor %q: %s", cursor, syscall.Errno(-r).Error())
} else if r == 0 {
return ErrNoTestCursor
}
Expand All @@ -921,7 +921,7 @@ func (j *Journal) SeekHead() error {
j.mu.Unlock()

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

return nil
Expand All @@ -941,7 +941,7 @@ func (j *Journal) SeekTail() error {
j.mu.Unlock()

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

return nil
Expand All @@ -961,7 +961,7 @@ func (j *Journal) SeekRealtimeUsec(usec uint64) error {
j.mu.Unlock()

if r < 0 {
return fmt.Errorf("failed to seek to %d: %d", usec, syscall.Errno(-r))
return fmt.Errorf("failed to seek to %d: %s", usec, syscall.Errno(-r).Error())
}

return nil
Expand All @@ -984,7 +984,7 @@ func (j *Journal) SeekCursor(cursor string) error {
j.mu.Unlock()

if r < 0 {
return fmt.Errorf("failed to seek to cursor %q: %d", cursor, syscall.Errno(-r))
return fmt.Errorf("failed to seek to cursor %q: %s", cursor, syscall.Errno(-r).Error())
}

return nil
Expand Down Expand Up @@ -1031,7 +1031,7 @@ func (j *Journal) GetUsage() (uint64, error) {
j.mu.Unlock()

if r < 0 {
return 0, fmt.Errorf("failed to get journal disk space usage: %d", syscall.Errno(-r))
return 0, fmt.Errorf("failed to get journal disk space usage: %s", syscall.Errno(-r).Error())
}

return uint64(out), nil
Expand Down Expand Up @@ -1065,7 +1065,7 @@ func (j *Journal) GetUniqueValues(field string) ([]string, error) {
r := C.my_sd_journal_query_unique(sd_journal_query_unique, j.cjournal, f)

if r < 0 {
return nil, fmt.Errorf("failed to query journal: %d", syscall.Errno(-r))
return nil, fmt.Errorf("failed to query journal: %s", syscall.Errno(-r).Error())
}

// Implements the SD_JOURNAL_FOREACH_UNIQUE macro from sd-journal.h
Expand All @@ -1079,7 +1079,7 @@ func (j *Journal) GetUniqueValues(field string) ([]string, error) {
}

if r < 0 {
return nil, fmt.Errorf("failed to read message field: %d", syscall.Errno(-r))
return nil, fmt.Errorf("failed to read message field: %s", syscall.Errno(-r).Error())
}

msg := C.GoStringN((*C.char)(d), C.int(l))
Expand Down Expand Up @@ -1111,7 +1111,7 @@ func (j *Journal) GetCatalog() (string, error) {
defer C.free(unsafe.Pointer(c))

if r < 0 {
return "", fmt.Errorf("failed to retrieve catalog entry for current journal entry: %d", syscall.Errno(-r))
return "", fmt.Errorf("failed to retrieve catalog entry for current journal entry: %s", syscall.Errno(-r).Error())
}

catalog := C.GoString(c)
Expand Down