// NewJournalFromDir returns a new Journal instance pointing to a journal residing // in a given directory. The supplied path may be relative or absolute; if // relative, it will be converted to an absolute path before being opened. func NewJournalFromDir(path string) (j *Journal, err error) { j = &Journal{} sd_journal_open_directory, err := getFunction("sd_journal_open_directory") if err != nil { return nil, err } p := C.CString(path) defer C.free(unsafe.Pointer(p)) 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 j, nil }
// NewJournalFromDir returns a new Journal instance pointing to a journal residing // in a given directory. The supplied path may be relative or absolute; if // relative, it will be converted to an absolute path before being opened. func NewJournalFromDir(path string) (j *Journal, err error) { h, err := dlopen.GetHandle(libsystemdNames) if err != nil { return nil, err } defer func() { if err == nil { return } err2 := h.Close() if err2 != nil { err = fmt.Errorf(`%q and "error closing handle: %v"`, err, err2) } }() path, err = filepath.Abs(path) if err != nil { return nil, err } j = &Journal{lib: h} sd_journal_open_directory, err := j.getFunction("sd_journal_open_directory") if err != nil { return nil, err } p := C.CString(path) defer C.free(unsafe.Pointer(p)) 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 j, nil }