summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2077339)
raw | patch | inline | side by side (parent: 2077339)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 30 Apr 2014 21:49:25 +0000 (23:49 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Wed, 30 Apr 2014 21:49:25 +0000 (23:49 +0200) |
src/tools/sysdb/command.c | patch | blob | history | |
src/tools/sysdb/command.h | patch | blob | history | |
src/tools/sysdb/main.c | patch | blob | history |
index c79259e401c0786bb80336601208b058180e23e9..77f3c8346498c430be10fcbafcf1ab9a06ee5cc2 100644 (file)
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);
}
sdb_strbuf_destroy(recv_buf);
- return 0;
+ return status;
} /* sdb_command_print_reply */
char *
/* 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;
}
index febf64f144a3c6f54ecee86d077531d14b414f76..bd9833828167de802c063c28e0878efdf06e3bf1 100644 (file)
*
* 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 991e1ffb6d8e744252309646f4741e67abfe901d..8455a6c7000e4856483b8650ce02a932c0fa98a2 100644 (file)
--- a/src/tools/sysdb/main.c
+++ b/src/tools/sysdb/main.c
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",
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;
}