Submit #3063 » intermediary_patch.patch
| usr.bin/kcollect/kcollect.c | ||
|---|---|---|
|
#define DISPLAY_TIME_ONLY "%H:%M:%S"
|
||
|
#define DISPLAY_FULL_DATE "%F %H:%M:%S"
|
||
|
#define HDR_FMT "HEADER0"
|
||
|
#define HDR_TITLE "HEADER1"
|
||
|
static void format_output(uintmax_t value,char fmt,uintmax_t scale, char* ret);
|
||
|
static void dump_text(kcollect_t *ary, size_t count,
|
||
| ... | ... | |
|
int OutputWidth = 1024;
|
||
|
int OutputHeight = 1024;
|
||
|
int SmoothOpt;
|
||
|
int LoadedFromDB = 0;
|
||
|
int
|
||
|
main(int ac, char **av)
|
||
| ... | ... | |
|
* Timestamp
|
||
|
*/
|
||
|
t = ary[i].realtime.tv_sec;
|
||
|
if (UseGMT)
|
||
|
if (UseGMT && !LoadedFromDB)
|
||
|
tmv = gmtime(&t);
|
||
|
else
|
||
|
tmv = localtime(&t);
|
||
| ... | ... | |
|
time_t t;
|
||
|
uint i;
|
||
|
|
||
|
char h0[] = "HEADER 0";
|
||
|
char h1[] = "HEADER 1";
|
||
|
for (i = 0; i < (count); ++i) {
|
||
|
/* first 2 INFO records are special and get 0|1 */
|
||
|
t = (i < 2)? i : ary[i].realtime.tv_sec;
|
||
|
tmv = gmtime(&t);
|
||
|
strftime(buf, sizeof(buf), DISPLAY_FULL_DATE, tmv);
|
||
|
/* store the first 2 records with their own key */
|
||
|
key.dptr = (t < 2)?((t == 0)? h0:h1): buf;
|
||
|
key.dsize = (t < 2)?sizeof("HEADER 0"):sizeof(buf);
|
||
|
|
||
|
if( i < 2) {
|
||
|
if(i == 0)
|
||
|
key.dptr = strdup(HDR_FMT);
|
||
|
else
|
||
|
key.dptr = strdup(HDR_TITLE);
|
||
|
key.dsize = sizeof(HDR_FMT);
|
||
|
}
|
||
|
else {
|
||
|
t = ary[i].realtime.tv_sec;
|
||
|
if(LoadedFromDB)
|
||
|
tmv = localtime(&t);
|
||
|
else
|
||
|
tmv = gmtime(&t);
|
||
|
strftime(buf, sizeof(buf), DISPLAY_FULL_DATE, tmv);
|
||
|
|
||
|
key.dptr = buf;
|
||
|
key.dsize = sizeof(buf);
|
||
|
}
|
||
|
value.dptr = ary[i].data;
|
||
|
value.dsize = sizeof(uint64_t) * KCOLLECT_ENTRIES;
|
||
|
if (dbm_store(db,key,value,DBM_INSERT) == -1) {
|
||
| ... | ... | |
|
while (key.dptr && c < recCounter) {
|
||
|
value = dbm_fetch(db, key);
|
||
|
if (value.dptr != NULL) {
|
||
|
if(!strcmp(key.dptr,"HEADER 0")) {
|
||
|
if(!strcmp(key.dptr,HDR_FMT)) {
|
||
|
sc = 0;
|
||
|
headersFound |= 1;
|
||
|
}
|
||
|
else if(!strcmp(key.dptr,"HEADER 1")) {
|
||
|
else if(!strcmp(key.dptr,HDR_TITLE)) {
|
||
|
sc = 1;
|
||
|
headersFound |= 2;
|
||
|
}
|
||
| ... | ... | |
|
fprintf(stderr, "We could not retrieve all necessary headers, might be the database file is corrupted? (%i)\n", headersFound);
|
||
|
exit(EXIT_FAILURE);
|
||
|
}
|
||
|
LoadedFromDB = 1;
|
||
|
}
|
||
|
static void
|
||