client: Improve error diagnostics.
authorAndre Noll <maan@systemlinux.org>
Sun, 26 Feb 2012 11:53:43 +0000 (12:53 +0100)
committerAndre Noll <maan@systemlinux.org>
Sat, 5 May 2012 10:54:53 +0000 (12:54 +0200)
If an error occurs in the post_select() method of the client task,
the scheduler removes this task from the task list and then returns
zero to indicate that the task list has become empty.

Currently, client.c looks only at the return value of schedule() and
therefore returns success in this case.  This patch makes client.c
additionally check the task error state of the client task and
prints an error message if it was negative and different from an
EOF condition.

client.c

index 5f511708506a464e1a0e06f679eaa856ac015164..4998222ea7c89df98ad55879a08f9dea1b5f6c6b 100644 (file)
--- a/client.c
+++ b/client.c
@@ -603,14 +603,22 @@ int main(int argc, char *argv[])
                EMBRACE(.name = "stdout", .parent = ct->btrn));
        register_task(&sched, &svt);
        ret = schedule(&sched);
+       if (ret >= 0 && ct->task.error < 0) {
+               switch(ct->task.error) {
+               /* these are not errors */
+               case -E_EOF:
+               case -E_SERVER_EOF:
+               case -E_BTR_EOF:
+                       ret = 0;
+                       break;
+               default: ret = ct->task.error;
+               }
+       }
 out:
+       if (ret < 0)
+               PARA_ERROR_LOG("%s\n", para_strerror(-ret));
        client_close(ct);
        btr_free_node(sit.btrn);
        btr_free_node(sot.btrn);
-       if (ret < 0) {
-               /* can not use PARA_LOG here because ct is NULL */
-               fprintf(stderr, "%s\n", para_strerror(-ret));
-               return EXIT_FAILURE;
-       }
-       return EXIT_SUCCESS;
+       return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;
 }