* todo
* - inotify not working ?
* - some per-conn info thing for control
- * - option for realsockdir
- * - option for no inotify
* - manpage: document control master stuff
*
* debugging rune:
static const char *sitename, *remote_host;
static const char *feedfile, *realsockdir="/tmp/innduct.control";
static int quiet_multiple=0;
-static int become_daemon=1;
+static int become_daemon=1, try_filemon=1;
static int try_stream=1;
static int port=119;
static const char *inndconffile;
static int sm_period_counter;
/* initialisation to 0 is good */
-static int until_connect, until_backlog_nextscan, until_backup_filepoll;
+static int until_connect, until_backlog_nextscan;
static double accept_proportion;
static int nocheck, nocheck_reported;
CCMD(period) { period(); }
CCMD(setintarg) { *(int*)c->xdata= atoi(arg); }
CCMD(setint) { *(int*)c->xdata= c->xval; }
+CCMD(setint_period) { *(int*)c->xdata= c->xval; period(); }
static const ControlCommand control_commands[]= {
{ "h", ccmd_help },
{ "p", ccmd_period },
{ "pretend flush", ccmd_setintarg, &simulate_flush },
- { "poke sm", ccmd_setint, &sm_period_counter, 1 },
- { "poke conn", ccmd_setint, &until_connect, 0 },
- { "poke blscan", ccmd_setint, &until_backlog_nextscan, 0 },
+
+#define POKES(cmd,func) \
+ { cmd "sm", func, &sm_period_counter, 1 }, \
+ { cmd "conn", func, &until_connect, 0 }, \
+ { cmd "blscan", func, &until_backlog_nextscan, 0 },
+POKES("prod ", ccmd_setint_period)
+POKES("next ", ccmd_setint)
+
{ "wedge blscan", ccmd_setint, &until_backlog_nextscan, -1 },
{ 0 }
};
uid_t self= geteuid();
if (!S_ISDIR(stab.st_mode) ||
stab.st_uid != self ||
- stab.st_mode & 0077) {
+ stab.st_mode & 0007) {
warn("no control socket, because real socket directory"
" is somehow wrong (ISDIR=%d, uid=%lu (exp.%lu), mode %lo)",
!!S_ISDIR(stab.st_mode),
return OOP_CONTINUE;
}
+ int conn_busy=
+ conn->waiting.count ||
+ conn->priority.count ||
+ conn->sent.count ||
+ conn->xmitu;
+
if (conn->quitting) {
if (code!=205 && code!=503) {
connfail(conn, "peer gave unexpected response to QUIT: %s", sani);
} else {
- notice("C%d idle connection closed", conn->fd);
- assert(!conn->waiting.count);
- assert(!conn->priority.count);
- assert(!conn->sent.count);
- assert(!conn->xmitu);
+ notice("C%d idle connection closed by us", conn->fd);
+ assert(!conn_busy);
LIST_REMOVE(conns,conn);
conn_dispose(conn);
}
conn->since_activity= 0;
Article *art;
-#define GET_ARTICLE(musthavesent) \
- art= article_reply_check(conn, data, code_streaming, musthavesent, sani); \
- if (art) ; else return OOP_CONTINUE /* reply_check has failed the conn */
+#define GET_ARTICLE(musthavesent) do{ \
+ art= article_reply_check(conn, data, code_streaming, musthavesent, sani); \
+ if (!art) return OOP_CONTINUE; /* reply_check has failed the conn */ \
+ }while(0)
-#define ARTICLE_DEALTWITH(streaming,musthavesent,how) \
- code_streaming= (streaming); \
- GET_ARTICLE(musthavesent); \
- article_done(conn, art, RC_##how); break;
+#define ARTICLE_DEALTWITH(streaming,musthavesent,how) do{ \
+ code_streaming= (streaming); \
+ GET_ARTICLE(musthavesent); \
+ article_done(conn, art, RC_##how); \
+ goto dealtwith; \
+ }while(0)
-#define PEERBADMSG(m) connfail(conn, m ": %s", sani); return OOP_CONTINUE
+#define PEERBADMSG(m) do { \
+ connfail(conn, m ": %s", sani); return OOP_CONTINUE; \
+ }while(0)
int code_streaming= 0;
switch (code) {
case 400: PEERBADMSG("peer stopped accepting articles");
- case 503: PEERBADMSG("peer timed us out");
default: PEERBADMSG("peer sent unexpected message");
+ case 503:
+ if (conn_busy) PEERBADMSG("peer timed us out");
+ notice("C%d idle connection closed by peer", conn->fd);
+ LIST_REMOVE(conns,conn);
+ conn_dispose(conn);
+ return OOP_CONTINUE;
+
case 435: ARTICLE_DEALTWITH(0,0,unwanted); /* IHAVE says they have it */
case 438: ARTICLE_DEALTWITH(1,0,unwanted); /* CHECK/TAKETHIS: they have it */
break;
}
+dealtwith:
conn_maybe_write(conn);
check_assign_articles();
die("inotify read %d bytes wanted struct of %d", r, (int)sizeof(iev));
}
InputFile *ipf= filemon_inotify_wd2ipf[iev.wd];
- debug("filemon inotify readable read %d wd=%p", iev.wd, ipf);
+ debug("filemon inotify readable read %p wd=%d", ipf, iev.wd);
filemon_callback(ipf);
}
return OOP_CONTINUE;
{'q',"quiet-multiple", 0, &quiet_multiple, op_setint, 1 },
{0,"no-daemon", 0, &become_daemon, op_setint, 0 },
{0,"no-streaming", 0, &try_stream, op_setint, 0 },
+{0,"no-filemon", 0, &try_filemon, op_setint, 0 },
{'C',"inndconf", "F", &inndconffile, op_string },
{'P',"port", "PORT", &port, op_integer },
+{0,"ctrl-sock-dir", 0, &realsockdir, op_string },
{0,"help", 0, 0, help },
{0,"max-connections", "N", &max_connections, op_integer },
control_init();
- if (!filemon_method_init()) {
- warn("filemon: no file monitoring available, polling");
- every(filepoll_seconds,0,filepoll);
+ int filemon_ok= 0;
+ if (!try_filemon) {
+ notice("filemon: suppressed by command line option, polling");
+ } else {
+ filemon_ok= filemon_method_init();
+ if (!filemon_ok)
+ warn("filemon: no file monitoring available, polling");
}
+ if (!filemon_ok)
+ every(filepoll_seconds,0,filepoll);
every(period_seconds,1,period);