+/*========== dumping state ==========*/
+
+static void dump_article_list(FILE *f, const ControlCommand *c,
+ const ArticleList *al) {
+ fprintf(f, " count=%d\n", al->count);
+ if (!c->xval) return;
+
+ int i; Article *art;
+ for (i=0, art=LIST_HEAD(*al); art; i++, art=LIST_NEXT(art)) {
+ fprintf(f," #%05d %-11s", i, artstate_names[art->state]);
+ DUMPV("%p", art->,ipf);
+ DUMPV("%d", art->,missing);
+ DUMPV("%lu", (unsigned long)art->,offset);
+ DUMPV("%d", art->,blanklen);
+ DUMPV("%d", art->,midlen);
+ fprintf(f, " %s %s\n", TokenToText(art->token), art->messageid);
+ }
+}
+
+static void dump_input_file(FILE *f, const ControlCommand *c,
+ InputFile *ipf, const char *wh) {
+ char *dipf= debug_report_ipf(ipf);
+ fprintf(f,"input %s %s", wh, dipf);
+ free(dipf);
+
+ if (ipf) {
+ DUMPV("%d", ipf->,readcount_ok);
+ DUMPV("%d", ipf->,readcount_blank);
+ DUMPV("%d", ipf->,readcount_err);
+ DUMPV("%d", ipf->,count_nooffer_missing);
+ }
+ fprintf(f,"\n");
+ if (ipf) {
+ ArtState state; const char *const *statename;
+ for (state=0, statename=artstate_names; *statename; state++,statename++) {
+#define RC_DUMP_FMT(x) " " #x "=%d"
+#define RC_DUMP_VAL(x) ,ipf->counts[state][RC_##x]
+ fprintf(f,"input %s counts %-11s"
+ RESULT_COUNTS(RC_DUMP_FMT,RC_DUMP_FMT) "\n",
+ wh, *statename
+ RESULT_COUNTS(RC_DUMP_VAL,RC_DUMP_VAL));
+ }
+ fprintf(f,"input %s queue", wh);
+ dump_article_list(f,c,&ipf->queue);
+ }
+}
+
+CCMD(dump) {
+ int i;
+ fprintf(cc->out, "dumping state to %s\n", path_dump);
+ FILE *f= fopen(path_dump, "w");
+ if (!f) { fprintf(cc->out, "failed: open: %s\n", strerror(errno)); return; }
+
+ fprintf(f,"general");
+ DUMPV("%s", sms_names,[sms]);
+ DUMPV("%d", ,until_flush);
+ DUMPV("%ld", (long),self_pid);
+ DUMPV("%p", , defer);
+ DUMPV("%d", , until_connect);
+ DUMPV("%d", , until_backlog_nextscan);
+ DUMPV("%d", , simulate_flush);
+ fprintf(f,"\nnocheck");
+ DUMPV("%#.10f", , accept_proportion);
+ DUMPV("%d", , nocheck);
+ DUMPV("%d", , nocheck_reported);
+ fprintf(f,"\n");
+
+ fprintf(f,"special");
+ DUMPV("%ld", (long),connecting_child);
+ DUMPV("%d", , connecting_fdpass_sock);
+ DUMPV("%d", , control_master);
+ fprintf(f,"\n");
+
+ fprintf(f,"filemon ");
+ filemon_method_dump_info(f);
+
+ dump_input_file(f,c, main_input_file, "main" );
+ dump_input_file(f,c, flushing_input_file, "flushing");
+ dump_input_file(f,c, backlog_input_file, "backlog" );
+
+ fprintf(f,"conns count=%d\n", conns.count);
+
+ Conn *conn;
+ FOR_CONN(conn) {
+
+ fprintf(f,"C%d",conn->fd);
+ DUMPV("%p",conn->,rd); DUMPV("%d",conn->,max_queue);
+ DUMPV("%d",conn->,stream); DUMPV("%d",conn->,quitting);
+ DUMPV("%d",conn->,since_activity);
+ fprintf(f,"\n");
+
+ fprintf(f,"C%d waiting", conn->fd); dump_article_list(f,c,&conn->waiting);
+ fprintf(f,"C%d priority",conn->fd); dump_article_list(f,c,&conn->priority);
+ fprintf(f,"C%d sent", conn->fd); dump_article_list(f,c,&conn->sent);
+
+ fprintf(f,"C%d xmit xmitu=%d\n", conn->fd, conn->xmitu);
+ for (i=0; i<conn->xmitu; i++) {
+ const struct iovec *iv= &conn->xmit[i];
+ const XmitDetails *xd= &conn->xmitd[i];
+ char *dinfo;
+ switch (xd->kind) {
+ case xk_Const: dinfo= xasprintf("Const"); break;
+ case xk_Artdata: dinfo= xasprintf("A%p", xd->info.sm_art); break;
+ default:
+ abort();
+ }
+ fprintf(f," #%03d %-11s l=%d %s\n", i, dinfo, iv->iov_len,
+ sanitise(iv->iov_base, iv->iov_len));
+ free(dinfo);
+ }
+ }
+
+ fprintf(f,"paths");
+ DUMPV("%s", , feedfile);
+ DUMPV("%s", , path_control);
+ DUMPV("%s", , path_lock);
+ DUMPV("%s", , path_flushing);
+ DUMPV("%s", , path_defer);
+ DUMPV("%s", , path_dump);
+ DUMPV("%s", , globpat_backlog);
+ fprintf(f,"\n");
+
+ if (!!ferror(f) + !!fclose(f)) {
+ fprintf(cc->out, "failed: write: %s\n", strerror(errno));
+ return;
+ }
+}
+