char * fmdump_nvl2str(nvlist_t *nvl) { fmd_scheme_t *sp; char c, *name, *s = NULL; ssize_t len; if (nvlist_lookup_string(nvl, FM_FMRI_SCHEME, &name) != 0) { fmdump_warn("fmri does not contain required '%s' nvpair\n", FM_FMRI_SCHEME); return (NULL); } if ((sp = fmd_scheme_lookup("/usr/lib/fm/fmd/schemes", name)) == NULL || sp->sch_dlp == NULL || sp->sch_err != 0) { const char *msg = sp->sch_err == ELIBACC ? dlerror() : strerror(sp->sch_err); fmdump_warn("cannot init '%s' scheme library to " "format fmri: %s\n", name, msg ? msg : "unknown error"); return (NULL); } if ((len = sp->sch_ops.sop_nvl2str(nvl, &c, sizeof (c))) == -1 || (s = malloc(len + 1)) == NULL || sp->sch_ops.sop_nvl2str(nvl, s, len + 1) == -1) { fmdump_warn("cannot format fmri using scheme '%s'", name); free(s); return (NULL); } return (s); }
char * fmdump_year(char *buf, size_t len, const fmd_log_record_t *rp) { #ifdef _ILP32 if (rp->rec_sec > LONG_MAX) { fmdump_warn("record time is too large for 32-bit utility\n"); (void) snprintf(buf, len, "0x%llx", rp->rec_sec); } else { #endif time_t tod = (time_t)rp->rec_sec; (void) strftime(buf, len, "%b %d %Y %T", localtime(&tod)); #ifdef _ILP32 } #endif return (buf); }
char * fmdump_date(char *buf, size_t len, const fmd_log_record_t *rp) { if (rp->rec_sec > LONG_MAX) { fmdump_warn("record time is too large for 32-bit utility\n"); (void) snprintf(buf, len, "0x%llx", rp->rec_sec); } else { time_t tod = (time_t)rp->rec_sec; time_t now = time(NULL); if (tod > now+60 || tod < now - 6L*30L*24L*60L*60L) { /* 6 months ago */ (void) strftime(buf, len, "%b %d %Y %T", localtime(&tod)); } else { size_t sz; sz = strftime(buf, len, "%b %d %T", localtime(&tod)); (void) snprintf(buf + sz, len - sz, ".%4.4llu", rp->rec_nsec / (NANOSEC / 10000)); } } return (buf); }