Example #1
0
// SeekMonotonicUsec seeks to the entry with the specified monotonic timestamp,
// i.e. CLOCK_MONOTONIC. Since monotonic time restarts on every reboot a boot ID needs
// to be specified as well.
func (j *Journal) SeekMonotonicUsec(boot_id string, usec uint64) error {
	// get the boot_id first
	cs := C.CString(boot_id)
	defer C.free(unsafe.Pointer(cs))
	var cboot_id C.sd_id128_t
	r := C.sd_id128_from_string(cs, &cboot_id)
	if r < 0 {
		return fmt.Errorf("failed to retrieve 128bit ID from string '%s': %d", boot_id, r)
	}

	j.mu.Lock()
	r = C.sd_journal_seek_monotonic_usec(j.cjournal, cboot_id, C.uint64_t(usec))
	j.mu.Unlock()

	if r < 0 {
		return fmt.Errorf("failed to seek to monotonic_clock(%s, %d): %d", boot_id, usec, r)
	}
	return nil
}
Example #2
0
// GetCatalogForMessageID works similar to GetCatalog(), but the entry is looked
// up by the specified message ID (no open journal context is necessary for
// this), and no field substitution is performed.
func GetCatalogForMessageID(messageId string) (string, error) {
	cmessageId := C.CString(messageId)
	defer C.free(unsafe.Pointer(cmessageId))

	var mid C.sd_id128_t
	r := C.sd_id128_from_string(cmessageId, &mid)
	if r < 0 {
		return "", fmt.Errorf("failed to get sd_id128_t from provided MESSAGE_ID '%s': %d", messageId, r)
	}

	var ccatalog *C.char
	r = C.sd_journal_get_catalog_for_message_id(mid, (**C.char)(&ccatalog))
	defer C.free(unsafe.Pointer(ccatalog))

	if r < 0 {
		return "", fmt.Errorf("failed to retrieve catalog entry for MESSAGE_ID '%s': %d", messageId, r)
	}

	catalog := C.GoString(ccatalog)
	return catalog, nil
}