dovecot-2.0: ipc: Fixes when sending commands to an empty group.
dovecot at dovecot.org
dovecot at dovecot.org
Mon May 23 15:05:21 EEST 2011
details: http://hg.dovecot.org/dovecot-2.0/rev/6bb200302acd
changeset: 12824:6bb200302acd
user: Timo Sirainen <tss at iki.fi>
date: Mon May 23 15:04:36 2011 +0300
description:
ipc: Fixes when sending commands to an empty group.
diffstat:
src/ipc/client.c | 32 ++++++++++++++++++++------------
src/ipc/ipc-group.c | 5 +++--
src/ipc/ipc-group.h | 5 +++--
3 files changed, 26 insertions(+), 16 deletions(-)
diffs (115 lines):
diff -r 79f9dce5d5fd -r 6bb200302acd src/ipc/client.c
--- a/src/ipc/client.c Mon May 23 14:54:02 2011 +0300
+++ b/src/ipc/client.c Mon May 23 15:04:36 2011 +0300
@@ -48,8 +48,7 @@
t_strdup_printf("%c%s\n", chr, line));
} T_END;
- if (status != IPC_CMD_STATUS_REPLY) {
- i_assert(client->io == NULL);
+ if (status != IPC_CMD_STATUS_REPLY && client->io == NULL) {
client->io = io_add(client->fd, IO_READ, client_input, client);
client_input(client);
}
@@ -61,6 +60,7 @@
struct ipc_connection *conn;
char *line, *id, *data;
unsigned int id_num;
+ bool ret;
while ((line = i_stream_read_next_line(client->input)) != NULL) {
/* <ipc name> *|<id> <command> */
@@ -78,31 +78,39 @@
*data++ = '\0';
group = ipc_group_lookup_name(line);
- if (group == NULL) {
- o_stream_send_str(client->output,
- t_strdup_printf("-Unknown IPC group: %s\n", line));
- continue;
- }
+ ret = FALSE;
if (strcmp(id, "*") == 0) {
/* send to everyone */
- ipc_group_cmd(group, data, client_cmd_input, client);
+ if (group == NULL) {
+ client_cmd_input(IPC_CMD_STATUS_OK,
+ NULL, client);
+ } else {
+ ret = ipc_group_cmd(group, data,
+ client_cmd_input, client);
+ }
} else if (str_to_uint(id, &id_num) < 0) {
o_stream_send_str(client->output,
t_strdup_printf("-Invalid IPC connection id: %s\n", id));
continue;
+ } else if (group == NULL) {
+ o_stream_send_str(client->output,
+ t_strdup_printf("-Unknown IPC group: %s\n", line));
} else if ((conn = ipc_connection_lookup_id(group, id_num)) == NULL) {
o_stream_send_str(client->output,
t_strdup_printf("-Unknown IPC connection id: %u\n", id_num));
continue;
} else {
ipc_connection_cmd(conn, data, client_cmd_input, client);
+ ret = TRUE;
}
- /* we'll handle commands one at a time. stop reading input
- until this command is finished. */
- io_remove(&client->io);
- break;
+ if (ret) {
+ /* we'll handle commands one at a time. stop reading
+ input until this command is finished. */
+ io_remove(&client->io);
+ break;
+ }
}
if (client->input->eof || client->input->stream_errno != 0)
client_destroy(&client);
diff -r 79f9dce5d5fd -r 6bb200302acd src/ipc/ipc-group.c
--- a/src/ipc/ipc-group.c Mon May 23 14:54:02 2011 +0300
+++ b/src/ipc/ipc-group.c Mon May 23 15:04:36 2011 +0300
@@ -113,7 +113,7 @@
}
-void ipc_group_cmd(struct ipc_group *group, const char *cmd,
+bool ipc_group_cmd(struct ipc_group *group, const char *cmd,
ipc_cmd_callback_t *callback, void *context)
{
struct ipc_connection *conn, *next;
@@ -121,7 +121,7 @@
if (group->connections == NULL) {
callback(IPC_CMD_STATUS_OK, NULL, context);
- return;
+ return FALSE;
}
group_cmd = i_new(struct ipc_group_cmd, 1);
@@ -135,6 +135,7 @@
ipc_connection_cmd(conn, cmd,
ipc_group_cmd_callback, group_cmd);
}
+ return TRUE;
}
void ipc_groups_init(void)
diff -r 79f9dce5d5fd -r 6bb200302acd src/ipc/ipc-group.h
--- a/src/ipc/ipc-group.h Mon May 23 14:54:02 2011 +0300
+++ b/src/ipc/ipc-group.h Mon May 23 15:04:36 2011 +0300
@@ -33,8 +33,9 @@
int ipc_group_update_name(struct ipc_group *group, const char *name);
/* Send a command to all connections in a group. All connections are expected
- to answer something. All replies are */
-void ipc_group_cmd(struct ipc_group *group, const char *cmd,
+ to answer something. If there are no connections, callback() is called
+ immediately and FALSE is returned. */
+bool ipc_group_cmd(struct ipc_group *group, const char *cmd,
ipc_cmd_callback_t *callback, void *context);
void ipc_groups_init(void);
More information about the dovecot-cvs
mailing list