summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThadeu Lima de Souza Cascardo <cascardo@cascardo.eti.br>2016-03-18 10:22:16 -0300
committerGabriel F. T. Gomes <gabriel@gftg.com.br>2016-04-03 17:13:59 -0300
commit6742a53bd88c11e2f8c3231fdaf0f86ba133646d (patch)
tree2eabd3fd24ea605261db15b74ccc8fa50eacbd66
parent8894d9439bd99b0c722065f754cc47097913296b (diff)
Improve exit status for rnetclient.
When error happens, exit earlier and do proper cleanup, exiting with an error. Reviewed-by: Gabriel F. T. Gomes <gabriel@gftg.com.br>
-rw-r--r--rnetclient.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/rnetclient.c b/rnetclient.c
index 0ba06a8..41e57b3 100644
--- a/rnetclient.c
+++ b/rnetclient.c
@@ -441,7 +441,7 @@ static void handle_response_error(struct rnet_message *message)
int main(int argc, char **argv)
{
int c;
- int r;
+ int r = 0;
struct rnet_decfile *decfile;
struct rnet_message *message = NULL;
struct rnetclient_args rnet_args;
@@ -478,20 +478,26 @@ int main(int argc, char **argv)
if (r) {
fprintf(stderr, "error connecting to server: %s\n",
r == EAI_SYSTEM ? strerror(errno) : gai_strerror(r));
- exit(1);
+ r = 1;
+ goto out_connect;
}
gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t)(intptr_t) c);
r = handshake(c);
if (r < 0) {
- exit(1);
+ r = 1;
+ goto out_handshake;
}
- if ((r = gnutls_handshake(session)) < 0)
+ if ((r = gnutls_handshake(session)) < 0) {
fprintf(stderr, "error in handshake: %s\n",
gnutls_strerror(r));
+ r = 1;
+ goto out_handshake;
+ }
r = rnet_encode(decfile, &message);
if (r < 0) {
fprintf(stderr, "error encoding message, file not supported?\n");
+ r = 1;
goto out;
}
@@ -502,6 +508,7 @@ int main(int argc, char **argv)
r = rnet_recv(session, &message);
if (r || !message || message->len == 0) {
fprintf(stderr, "error when receiving response\n");
+ r = 1;
goto out;
}
switch (message->buffer[0]) {
@@ -534,6 +541,7 @@ int main(int argc, char **argv)
r = rnet_recv(session, &message);
if (r || !message || message->len == 0) {
fprintf(stderr, "error when receiving response\n");
+ r = 1;
goto out;
}
switch (message->buffer[0]) {
@@ -550,9 +558,11 @@ int main(int argc, char **argv)
out:
gnutls_bye(session, GNUTLS_SHUT_RDWR);
+out_handshake:
close(c);
- rnet_decfile_close(decfile);
+out_connect:
gnutls_global_deinit();
+ rnet_decfile_close(decfile);
- return 0;
+ return r;
}