Skip to content

Commit 2665651

Browse files
author
Igor Tsiglyar
committed
sdjournal: add sd_journal_open_namespace wrapper
wrap sd_journal_open_namespace C call to enable reading journal records in non-default namespace fixes #413
1 parent d5623bf commit 2665651

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

sdjournal/journal.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ package sdjournal
3939
// }
4040
//
4141
// int
42+
// my_sd_journal_open_namespace(void *f, sd_journal **ret, const char *namespace, int flags)
43+
// {
44+
// int (*sd_journal_open_namespace)(sd_journal **, const char *, int);
45+
//
46+
// sd_journal_open_namespace = f;
47+
// return sd_journal_open_namespace(ret, namespace, flags);
48+
// }
49+
//
50+
// int
4251
// my_sd_journal_open_directory(void *f, sd_journal **ret, const char *path, int flags)
4352
// {
4453
// int (*sd_journal_open_directory)(sd_journal **, const char *, int);
@@ -438,6 +447,27 @@ func NewJournal() (j *Journal, err error) {
438447
return j, nil
439448
}
440449

450+
// NewJournal returns a new Journal instance pointing to the local journal in a given namespace
451+
func NewJournalInNamespace(namespace string) (j *Journal, err error) {
452+
j = &Journal{}
453+
454+
sd_journal_open_namespace, err := getFunction("sd_journal_open_namespace")
455+
if err != nil {
456+
return nil, err
457+
}
458+
459+
n := C.CString(namespace)
460+
defer C.free(unsafe.Pointer(n))
461+
462+
r := C.my_sd_journal_open_namespace(sd_journal_open_namespace, &j.cjournal, n, C.SD_JOURNAL_LOCAL_ONLY)
463+
464+
if r < 0 {
465+
return nil, fmt.Errorf("failed to open journal in namespace %q: %s", namespace, syscall.Errno(-r).Error())
466+
}
467+
468+
return j, nil
469+
}
470+
441471
// NewJournalFromDir returns a new Journal instance pointing to a journal residing
442472
// in a given directory.
443473
func NewJournalFromDir(path string) (j *Journal, err error) {

0 commit comments

Comments
 (0)