Skip to content

Commit

Permalink
sdjournal: add sd_journal_open_namespace wrapper
Browse files Browse the repository at this point in the history
wrap sd_journal_open_namespace C call to enable reading
journal records in non-default namespace

fixes #413
  • Loading branch information
Igor Tsiglyar committed Jun 5, 2023
1 parent d843340 commit 00cf474
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions sdjournal/journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ package sdjournal
// }
//
// int
// my_sd_journal_open_namespace(void *f, sd_journal **ret, const char *namespace, int flags)
// {
// int (*sd_journal_open_namespace)(sd_journal **, const char *, int);
//
// sd_journal_open_namespace = f;
// return sd_journal_open_namespace(ret, namespace, flags);
// }
//
// int
// my_sd_journal_open_directory(void *f, sd_journal **ret, const char *path, int flags)
// {
// int (*sd_journal_open_directory)(sd_journal **, const char *, int);
Expand Down Expand Up @@ -438,6 +447,27 @@ func NewJournal() (j *Journal, err error) {
return j, nil
}

// NewJournal returns a new Journal instance pointing to the local journal in a given namespace
func NewJournalInNamespace(namespace string) (j *Journal, err error) {
j = &Journal{}

sd_journal_open_namespace, err := getFunction("sd_journal_open_namespace")
if err != nil {
return nil, err
}

n := C.CString(namespace)
defer C.free(unsafe.Pointer(n))

r := C.my_sd_journal_open_namespace(sd_journal_open_namespace, &j.cjournal, n, C.SD_JOURNAL_LOCAL_ONLY)

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

return j, nil
}

// NewJournalFromDir returns a new Journal instance pointing to a journal residing
// in a given directory.
func NewJournalFromDir(path string) (j *Journal, err error) {
Expand Down

0 comments on commit 00cf474

Please sign in to comment.