From: Sebastian Harl Date: Wed, 30 Apr 2014 21:49:25 +0000 (+0200) Subject: sysdb: When using -c, exit non-zero if any command failed. X-Git-Tag: sysdb-0.1.0~55 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=2b9b5d989993f6f9fe925da883757e92a8f00b9b;p=sysdb.git sysdb: When using -c, exit non-zero if any command failed. --- diff --git a/src/tools/sysdb/command.c b/src/tools/sysdb/command.c index c79259e..77f3c83 100644 --- a/src/tools/sysdb/command.c +++ b/src/tools/sysdb/command.c @@ -52,17 +52,23 @@ sdb_command_print_reply(sdb_client_t *client) sdb_strbuf_t *recv_buf; const char *result; uint32_t rcode = 0; + int status = 0; recv_buf = sdb_strbuf_create(1024); if (! recv_buf) return -1; - if (sdb_client_recv(client, &rcode, recv_buf) < 0) + if (sdb_client_recv(client, &rcode, recv_buf) < 0) { rcode = UINT32_MAX; + status = -1; + } if (sdb_client_eof(client)) return -1; + if (rcode == CONNECTION_ERROR) + status = 1; + if (rcode == UINT32_MAX) printf("ERROR: "); result = sdb_strbuf_string(recv_buf); @@ -74,7 +80,7 @@ sdb_command_print_reply(sdb_client_t *client) } sdb_strbuf_destroy(recv_buf); - return 0; + return status; } /* sdb_command_print_reply */ char * @@ -103,7 +109,7 @@ 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); - if (sdb_command_print_reply(input->client)) + if (sdb_command_print_reply(input->client) < 0) return NULL; } diff --git a/src/tools/sysdb/command.h b/src/tools/sysdb/command.h index febf64f..bd98338 100644 --- a/src/tools/sysdb/command.h +++ b/src/tools/sysdb/command.h @@ -36,7 +36,8 @@ * * Returns: * - 0 on success - * - a negative value else + * - a negative value if no reply could be read from the server + * - a positive value if the server returned an error */ int sdb_command_print_reply(sdb_client_t *client); diff --git a/src/tools/sysdb/main.c b/src/tools/sysdb/main.c index 991e1ff..8455a6c 100644 --- a/src/tools/sysdb/main.c +++ b/src/tools/sysdb/main.c @@ -184,6 +184,8 @@ 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) { sdb_log(SDB_LOG_ERR, "Failed to send command '%s' to server", @@ -191,8 +193,10 @@ execute_commands(sdb_client_t *client, sdb_llist_t *commands) status = 1; break; } - if (sdb_command_print_reply(client)) { - sdb_log(SDB_LOG_ERR, "Failed to read reply from server"); + err = sdb_command_print_reply(client); + if (err) { + if (err < 0) + sdb_log(SDB_LOG_ERR, "Failed to read reply from server"); status = 1; break; }