Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdjournal: add sd_journal_open_namespace wrapper #421

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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