1 /*
2 * bug.c
3 *
4 * (C)2003-2011 by Marc Huber <Marc.Huber@web.de>
5 * All rights reserved.
6 *
7 * $Id: bug.c,v 1.10 2011/07/18 17:49:23 marc Exp $
8 *
9 */
10
11 #include "headers.h"
12
invalid_handler(struct context * ctx,int cur,char * which)13 static void invalid_handler(struct context *ctx, int cur, char *which)
14 {
15 logmsg("invalid %s handler called, trying to recover", which);
16 if (cur == ctx->cfn) {
17 logmsg("cleaning up control connection for fd %d", cur);
18 cleanup_control(ctx, ctx->cfn);
19 } else if (cur == ctx->dfn) {
20 logmsg("cleaning up data connection for fd %d", cur);
21 cleanup_data(ctx, ctx->dfn);
22 } else if (cur == ctx->ffn) {
23 logmsg("cleaning up file context for fd %d", cur);
24 cleanup_file(ctx, ctx->ffn);
25 } else {
26 logmsg("unregistering unknown fd %d", cur);
27 io_close(ctx->io, ctx->ffn);
28 }
29 cleanup(ctx_spawnd, 0);
30 die_when_idle = -1;
31 logmsg("Whatever just happened very much looks like a bug.");
32 logmsg("The daemon will stop accepting new connections from spawnd.");
33 }
34
invalid_i(struct context * ctx,int cur)35 static void invalid_i(struct context *ctx, int cur)
36 {
37 invalid_handler(ctx, cur, "input");
38 }
39
invalid_o(struct context * ctx,int cur)40 static void invalid_o(struct context *ctx, int cur)
41 {
42 invalid_handler(ctx, cur, "output");
43 }
44
invalid_e(struct context * ctx,int cur)45 static void invalid_e(struct context *ctx, int cur)
46 {
47 invalid_handler(ctx, cur, "error");
48 }
49
invalid_h(struct context * ctx,int cur)50 static void invalid_h(struct context *ctx, int cur)
51 {
52 invalid_handler(ctx, cur, "hangup");
53 }
54
setup_invalid_callbacks(io_context_t * io)55 void setup_invalid_callbacks(io_context_t * io)
56 {
57 io_set_cb_inv_i(io, (void *) invalid_i);
58 io_set_cb_inv_o(io, (void *) invalid_o);
59 io_set_cb_inv_e(io, (void *) invalid_e);
60 io_set_cb_inv_h(io, (void *) invalid_h);
61 }
62