/*
* todo
- * - rename defraise to raise_default
- * - xmalloc + memset -> xcalloc
- * - macro for conn iteration
* - skipping_long offset calculation is wrong
* - reset signals TERM and INT (and HUP) in children
*
* - admin-initiated flush
*
* debugging rune:
- * build-lfs/backends/innduct --no-daemon -C ../inn.conf -f `pwd`/fee sit localhost
+ * build-lfs/backends/innduct --connection-timeout=30 --no-daemon -C ../inn.conf -f `pwd`/fee sit localhost
*/
/*
#define PRINTF(f,a) __attribute__((__format__(printf,f,a)))
#define NORET_PRINTF(f,a) __attribute__((__noreturn__,__format__(printf,f,a)))
+#define NEW(ptr) ((ptr)= zxmalloc(sizeof(*(ptr))))
+#define NEW_DECL(type,ptr) type ptr = zxmalloc(sizeof(*(ptr)))
+
#define DUMPV(fmt,pfx,v) fprintf(f, " " #v "=" fmt, pfx v);
+#define FOR_CONN(conn) \
+ for ((conn)=LIST_HEAD(conns); (conn); (conn)=LIST_NEXT((conn)))
+
/*----- doubly linked lists -----*/
#define ISNODE(T) struct node list_node
static void close_defer(void);
static void search_backlog_file(void);
static void preterminate(void);
-static void defraise(int signo);
+static void raise_default(int signo);
static char *debug_report_ipf(InputFile *ipf);
static void inputfile_reading_start(InputFile *ipf);
return status;
}
+static void *zxmalloc(size_t sz) {
+ void *p= xmalloc(sz);
+ memset(p,0,sz);
+ return p;
+}
+
static void xunlink(const char *path, const char *what) {
int r= unlink(path);
if (r) sysdie("can't unlink %s %s", path, what);
CCMD(stop) {
preterminate();
notice("terminating (CTRL%d)",cc->fd);
- defraise(SIGTERM);
+ raise_default(SIGTERM);
abort();
}
}
static void control_stdio(void) {
- ControlConn *cc= xmalloc(sizeof(*cc));
- memset(cc,0,sizeof(*cc));
+ NEW_DECL(ControlConn *,cc);
cc->destroy= control_stdio_destroy;
cc->fd= 0;
static void *control_master_readable(oop_source *lp, int master,
oop_event ev, void *u) {
- ControlConn *cc= xmalloc(sizeof(*cc));
- memset(cc,0,sizeof(*cc));
+ NEW_DECL(ControlConn *,cc);
cc->destroy= control_accepted_destroy;
cc->salen= sizeof(cc->sa);
static void check_idle_conns(void) {
Conn *conn;
- for (conn=LIST_HEAD(conns); conn; conn=LIST_NEXT(conn))
+ FOR_CONN(conn)
conn->since_activity++;
search_again:
- for (conn=LIST_HEAD(conns); conn; conn=LIST_NEXT(conn)) {
+ FOR_CONN(conn) {
if (conn->since_activity <= need_activity_periods) continue;
/* We need to shut this down */
goto x;
}
- conn= xmalloc(sizeof(*conn));
- memset(conn,0,sizeof(*conn));
+ NEW(conn);
LIST_INIT(conn->waiting);
LIST_INIT(conn->priority);
LIST_INIT(conn->sent);
* connections in order. That way if we have too many
* connections, the spare ones will go away eventually.
*/
- for (walk=LIST_HEAD(conns); walk; walk=LIST_NEXT(walk)) {
+ FOR_CONN(walk) {
if (walk->quitting) continue;
inqueue= walk->sent.count + walk->priority.count
+ walk->waiting.count;
static void filemon_start(InputFile *ipf) {
assert(!ipf->filemon);
- ipf->filemon= xmalloc(sizeof(*ipf->filemon));
- memset(ipf->filemon, 0, sizeof(*ipf->filemon));
+ NEW(ipf->filemon);
filemon_method_startfile(ipf, ipf->filemon);
}
static int signal_self_pipe[2];
static sig_atomic_t terminate_sig_flag;
-static void defraise(int signo) {
+static void raise_default(int signo) {
struct sigaction sa;
memset(&sa,0,sizeof(sa));
sa.sa_handler= SIG_DFL;
if (terminate_sig_flag) {
preterminate();
notice("terminating (%s)", strsignal(terminate_sig_flag));
- defraise(terminate_sig_flag);
+ raise_default(terminate_sig_flag);
abort();
}
return OOP_CONTINUE;
postfork_inputfile(flushing_input_file);
Conn *conn;
- for (conn=LIST_HEAD(conns); conn; conn=LIST_NEXT(conn))
+ FOR_CONN(conn)
conn_closefd(conn,"(in child) ");
postfork_stdio(defer, "defer file ", path_defer);
}
static void every(int interval, int fixed_rate, void (*f)(void)) {
- Every *e= xmalloc(sizeof(*e));
+ NEW_DECL(Every *,e);
e->interval.tv_sec= interval;
e->interval.tv_usec= 0;
e->fixed_rate= fixed_rate;
fprintf(f,"conns count=%d\n", conns.count);
Conn *conn;
- for (conn=LIST_HEAD(conns); conn; conn=LIST_NEXT(conn)) {
+ FOR_CONN(conn) {
fprintf(f,"C%d",conn->fd);
DUMPV("%p",conn->,rd); DUMPV("%d",conn->,max_queue);