potash_precord po_precord_create(int type) { potash_precord pr; pr=g_new(struct _potash_precord,1); pr->buffer=0; pr->buffer_offset=0; pr->buffer_len=0; record_write(pr,PRECORD_RECORD_REGULAR); record_write(pr,type); /* XXX write local context */ record_write(pr,PRECORD_HEADBODY); return pr; }
enum RECORD_RESULT record_flush(struct record_t *record) { if (NULL == record) { fprintf (stderr, "Invalid record in record_flush\n"); return RECORD_ERROR; } if (debug) fprintf (stderr, "record_flush: %s\n", record->filename); // flush if (record->buf && record->cur > 0) { record_write(record, record->buf, record->cur); record->cur = 0; } return RECORD_SUCCESS; }
void vs_ring_write(msg_level_t level, const char *format, va_list ap) { int n; rtapi_msg_t logmsg; #if defined(RTAPI) && defined(BUILD_SYS_USER_DSO) static pid_t rtapi_pid; if (rtapi_pid == 0) rtapi_pid = getpid(); #endif if (global_data) { // one-time initialisation if (!rtapi_message_buffer.header) { ringbuffer_init(&global_data->rtapi_messages, &rtapi_message_buffer); } logmsg.hdr.origin = MSG_ORIGIN; #if defined(RTAPI) && defined(BUILD_SYS_KBUILD) logmsg.hdr.pid = 0; #endif #if defined(RTAPI) && defined(BUILD_SYS_USER_DSO) logmsg.hdr.pid = rtapi_pid; #endif #if defined(ULAPI) logmsg.hdr.pid = getpid(); #endif logmsg.hdr.level = level; logmsg.hdr.encoding = MSG_ASCII; strncpy(logmsg.hdr.tag, logtag, sizeof(logmsg.hdr.tag)); // do format outside critical section n = vsnprintf(logmsg.buf, RTPRINTBUFFERLEN, format, ap); if (rtapi_message_buffer.header->use_wmutex && rtapi_mutex_try(&rtapi_message_buffer.header->wmutex)) { global_data->error_ring_locked++; return; } // use copying writer to shorten criticial section record_write(&rtapi_message_buffer, (void *) &logmsg, sizeof(rtapi_msgheader_t) + n + 1); // trailing zero if (rtapi_message_buffer.header->use_wmutex) rtapi_mutex_give(&rtapi_message_buffer.header->wmutex); } }
void log_write(struct bbs_msgbuf *msg) { int index = -1; // print BBSLOG_POST logs as BBSLOG_USER index = msg->mtype == BBSLOG_POST ? BBSLOG_USER : msg->mtype; // log range if (index < 1 || index > LOG_RECORDS_SIZE) return; struct record_t *record = log_records + (index - 1); char ch = msg->mtext[0]; msg->mtext[0] = 0; // print header char header[256]; if (msg->mtype == BBSLOG_POST) { print_post_header(msg, header, 256); } else { struct tm *n; n = localtime(&msg->msgtime); snprintf(header, 256, "[%02u/%02u %02u:%02u:%02u %5lu %lu] %s %c%s", /* mon/day */ n->tm_mon + 1, n->tm_mday, /* h:m:s */ n->tm_hour, n->tm_min, n->tm_sec, (long int) msg->pid, msg->mtype, msg->userid, ch, &msg->mtext[1]); } int header_len = strlen(header); // write to buffer if (RECORD_FULL == record_append(record, header, header_len)) { // or flush and then write to disk record_flush(record); record_write(record, header, header_len); } }
int vos_sort_merge(struct Stmt *sort, struct LL *lsfile, struct Record **_all_rows, unsigned long all_n_row) { int s = 0; unsigned long n_row = 0; struct File *F = 0; struct MNode *root = 0; struct MNode *loser = 0; struct MNode *loser2 = 0; struct Record *rows = 0; struct Record *R = 0; struct Record *all_rows = (*_all_rows); s = stmtsort_init_output(sort); if (s) return s; /* in case of only one file to merge */ if (! lsfile->next) { s = single_merge(lsfile->str, sort->out->filename); return s; } s = file_open(&F, sort->out->filename, FOPEN_WO); if (s) goto err; s = merge_init(&root, lsfile, sort->out->fields); if (s) goto err; R = all_rows; all_rows = R->row_next; R->row_next = 0; R->row_last = 0; while (root) { loser2 = 0; loser = mnode_get_loser(&root, &loser2); if (loser2) { do { record_add_row(&rows, loser->row); n_row++; if (n_row >= all_n_row || ! all_rows) { s = record_write(rows, F, sort->out->fields); if (s) goto err; all_rows = rows; all_rows->row_last = 0; rows = 0; n_row = 0; } loser->row = R; R = all_rows; all_rows = R->row_next; R->row_next = 0; R->row_last = 0; s = record_read2(loser->row, loser->file, sort->out->fields); if (s) break; s = record_cmp(loser2->row, loser->row); } while (s > 0 || (s == 0 && loser2->level > loser->level)); } else { do { record_add_row(&rows, loser->row); n_row++; if (n_row >= all_n_row || ! all_rows) { s = record_write(rows, F, sort->out->fields); if (s) goto err; all_rows = rows; all_rows->row_last = 0; rows = 0; n_row = 0; } loser->row = R; R = all_rows; all_rows = R->row_next; R->row_next = 0; R->row_last = 0; s = record_read2(loser->row, loser->file, sort->out->fields); } while (s == 0); } if (s == E_FILE_END) mnode_destroy(&loser); else root = mnode_insert(root, loser); } R->row_next = all_rows; if (n_row) { s = record_write(rows, F, sort->out->fields); if (s) goto err; rows->row_last->row_next = R; (*_all_rows) = rows; } else { (*_all_rows) = R; } file_write(F); s = 0; err: mnode_destroy(&root); file_close(&F); return s; }