func (j *Journal) getData(field string) (unsafe.Pointer, C.int, error) { sd_journal_get_data, err := getFunction("sd_journal_get_data") if err != nil { return nil, 0, err } f := C.CString(field) defer C.free(unsafe.Pointer(f)) var d unsafe.Pointer var l C.size_t j.mu.Lock() r := C.my_sd_journal_get_data(sd_journal_get_data, j.cjournal, f, &d, &l) j.mu.Unlock() if r < 0 { return nil, 0, fmt.Errorf("failed to read message: %d", syscall.Errno(-r)) } return d, C.int(l), nil }
// GetData gets the data object associated with a specific field from the // current journal entry. func (j *Journal) GetData(field string) (string, error) { sd_journal_get_data, err := j.getFunction("sd_journal_get_data") if err != nil { return "", err } f := C.CString(field) defer C.free(unsafe.Pointer(f)) var d unsafe.Pointer var l C.size_t j.mu.Lock() r := C.my_sd_journal_get_data(sd_journal_get_data, j.cjournal, f, &d, &l) j.mu.Unlock() if r < 0 { return "", fmt.Errorf("failed to read message: %d", syscall.Errno(-r)) } msg := C.GoStringN((*C.char)(d), C.int(l)) return msg, nil }