From 9406f29b89f6727c3db5485d109466701393b4d4 Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Fri, 17 Jul 2009 13:33:36 +0200 Subject: local: add LOCAL_RET_* return values for UNIX sockets callbacks This patch adds the LOCAL_RET_* return values. The return value LOCAL_RET_STOLEN which allows to leave a client socket open while waiting for an operation to finish. Signed-off-by: Pablo Neira Ayuso --- src/local.c | 7 ++++--- src/run.c | 22 +++++++++++++--------- src/stats-mode.c | 2 +- src/sync-ftfw.c | 5 +---- src/sync-mode.c | 2 +- 5 files changed, 20 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/local.c b/src/local.c index 4739e56..feff608 100644 --- a/src/local.c +++ b/src/local.c @@ -72,7 +72,7 @@ void local_server_destroy(struct local_server *server) } int do_local_server_step(struct local_server *server, void *data, - void (*process)(int fd, void *data)) + int (*process)(int fd, void *data)) { int rfd; struct sockaddr_un local; @@ -82,8 +82,9 @@ int do_local_server_step(struct local_server *server, void *data, if (rfd == -1) return -1; - process(rfd, data); - close(rfd); + /* This descriptor will be closed later, we ignore OK and errors */ + if (process(rfd, data) != LOCAL_RET_STOLEN) + close(rfd); return 0; } diff --git a/src/run.c b/src/run.c index 95d51a2..87b6fb2 100644 --- a/src/run.c +++ b/src/run.c @@ -182,18 +182,18 @@ static void dump_stats_runtime(int fd) send(fd, buf, size, 0); } -void local_handler(int fd, void *data) +static int local_handler(int fd, void *data) { - int ret; + int ret = LOCAL_RET_OK; int type; ret = read(fd, &type, sizeof(type)); if (ret == -1) { STATE(stats).local_read_failed++; - return; + return LOCAL_RET_OK; } if (ret == 0) - return; + return LOCAL_RET_OK; switch(type) { case FLUSH_MASTER: @@ -207,22 +207,26 @@ void local_handler(int fd, void *data) nl_flush_conntrack_table(STATE(flush)); exit(EXIT_SUCCESS); } - return; + break; case RESYNC_MASTER: STATE(stats).nl_kernel_table_resync++; dlog(LOG_NOTICE, "resync with master table"); nl_dump_conntrack_table(STATE(dump)); - return; + break; case STATS_RUNTIME: dump_stats_runtime(fd); - return; + break; case STATS_PROCESS: fork_process_dump(fd); - return; + break; } - if (!STATE(mode)->local(fd, type, data)) + ret = STATE(mode)->local(fd, type, data); + if (ret == LOCAL_RET_ERROR) { STATE(stats).local_unknown_request++; + return LOCAL_RET_ERROR; + } + return ret; } static void do_overrun_resync_alarm(struct alarm_block *a, void *data) diff --git a/src/stats-mode.c b/src/stats-mode.c index b84c7a1..5cfb638 100644 --- a/src/stats-mode.c +++ b/src/stats-mode.c @@ -55,7 +55,7 @@ static void kill_stats(void) /* handler for requests coming via UNIX socket */ static int local_handler_stats(int fd, int type, void *data) { - int ret = 1; + int ret = LOCAL_RET_OK; switch(type) { case DUMP_INTERNAL: diff --git a/src/sync-ftfw.c b/src/sync-ftfw.c index bf9f4f7..0d31e17 100644 --- a/src/sync-ftfw.c +++ b/src/sync-ftfw.c @@ -215,7 +215,7 @@ static void ftfw_local_queue(int fd) static int ftfw_local(int fd, int type, void *data) { - int ret = 1; + int ret = LOCAL_RET_OK; switch(type) { case REQUEST_DUMP: @@ -229,9 +229,6 @@ static int ftfw_local(int fd, int type, void *data) case STATS_RSQUEUE: ftfw_local_queue(fd); break; - default: - ret = 0; - break; } return ret; diff --git a/src/sync-mode.c b/src/sync-mode.c index 4d6956e..b0e2b02 100644 --- a/src/sync-mode.c +++ b/src/sync-mode.c @@ -403,7 +403,7 @@ static void dump_stats_sync_extended(int fd) /* handler for requests coming via UNIX socket */ static int local_handler_sync(int fd, int type, void *data) { - int ret = 1; + int ret = LOCAL_RET_OK; switch(type) { case DUMP_INTERNAL: -- cgit v1.2.3