From: Sebastian Harl Date: Thu, 1 May 2014 13:56:23 +0000 (+0200) Subject: sysdb: When using -c, wait for the server's final response. X-Git-Tag: sysdb-0.1.0~53 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8c58d65dec8e046ec1d8b26eb1a6d913b971e5be;p=sysdb.git sysdb: When using -c, wait for the server's final response. There might be some intermediate log messages, which should be printed but then we need to wait for further replies. --- diff --git a/src/tools/sysdb/command.c b/src/tools/sysdb/command.c index 77f3c83..7cbde41 100644 --- a/src/tools/sysdb/command.c +++ b/src/tools/sysdb/command.c @@ -67,7 +67,7 @@ sdb_command_print_reply(sdb_client_t *client) return -1; if (rcode == CONNECTION_ERROR) - status = 1; + status = CONNECTION_ERROR; if (rcode == UINT32_MAX) printf("ERROR: "); @@ -109,6 +109,12 @@ sdb_command_exec(sdb_input_t *input) /* ignore errors; we'll only hide the command from the caller */ sdb_client_send(input->client, CONNECTION_QUERY, query_len, query); + + /* The server will send back *something*, either error/log messages + * and/or the reply to the query. Here, we don't care about what it + * sends back. We'll wait for the first reply and then return to the + * main loop which will handle any subsequent replies, including + * eventually the reply to the query (if it's not the first reply). */ if (sdb_command_print_reply(input->client) < 0) return NULL; } diff --git a/src/tools/sysdb/main.c b/src/tools/sysdb/main.c index 8455a6c..1174fa9 100644 --- a/src/tools/sysdb/main.c +++ b/src/tools/sysdb/main.c @@ -184,7 +184,6 @@ execute_commands(sdb_client_t *client, sdb_llist_t *commands) while (sdb_llist_iter_has_next(iter)) { sdb_object_t *obj = sdb_llist_iter_get_next(iter); - int err; if (sdb_client_send(client, CONNECTION_QUERY, (uint32_t)strlen(obj->name), obj->name) <= 0) { @@ -193,13 +192,23 @@ execute_commands(sdb_client_t *client, sdb_llist_t *commands) status = 1; break; } - err = sdb_command_print_reply(client); - if (err) { - if (err < 0) + + /* Wait for server replies. We might get any number of log messages + * but eventually see the reply to the query, which is either OK or + * ERROR. */ + while (42) { + status = sdb_command_print_reply(client); + if (status < 0) { sdb_log(SDB_LOG_ERR, "Failed to read reply from server"); - status = 1; - break; + break; + } + + if ((status == CONNECTION_OK) || (status == CONNECTION_ERROR)) + break; } + + if (status) + break; } sdb_llist_iter_destroy(iter);