client: Switch to the alternative post select method.
authorAndre Noll <maan@systemlinux.org>
Sun, 31 Mar 2013 16:46:08 +0000 (16:46 +0000)
committerAndre Noll <maan@systemlinux.org>
Tue, 30 Apr 2013 12:12:46 +0000 (14:12 +0200)
client_common.c

index 7bdb473..3e20eaf 100644 (file)
@@ -326,7 +326,7 @@ static int send_sb_command(struct client_task *ct)
  *
  * \sa struct sched, struct task.
  */
-static void client_post_select(struct sched *s, struct task *t)
+static int client_post_select(struct sched *s, struct task *t)
 {
        struct client_task *ct = container_of(t, struct client_task, task);
        struct btr_node *btrn = ct->btrn;
@@ -338,7 +338,7 @@ static void client_post_select(struct sched *s, struct task *t)
        if (ret < 0)
                goto out;
        if (ct->scc.fd < 0)
-               return;
+               return 0;
        switch (ct->status) {
        case CL_CONNECTED: /* receive welcome message */
                ret = client_recv_buffer(ct, &s->rfds, buf, sizeof(buf), &n);
@@ -346,10 +346,10 @@ static void client_post_select(struct sched *s, struct task *t)
                        goto out;
                ct->features = parse_features(buf);
                ct->status = CL_RECEIVED_WELCOME;
-               return;
+               return 0;
        case CL_RECEIVED_WELCOME: /* send auth command */
                if (!FD_ISSET(ct->scc.fd, &s->wfds))
-                       return;
+                       return 0;
                if (has_feature("sideband", ct)) {
                        ct->use_sideband = true;
                        sprintf(buf, AUTH_REQUEST_MSG "%s sideband", ct->user);
@@ -360,7 +360,7 @@ static void client_post_select(struct sched *s, struct task *t)
                if (ret < 0)
                        goto out;
                ct->status = CL_SENT_AUTH;
-               return;
+               return 0;
        case CL_SENT_AUTH:
                /*
                 * Receive challenge and session keys, decrypt the challenge and
@@ -406,7 +406,7 @@ static void client_post_select(struct sched *s, struct task *t)
                hash_to_asc(ct->challenge_hash, buf);
                PARA_INFO_LOG("--> %s\n", buf);
                ct->status = CL_RECEIVED_CHALLENGE;
-               return;
+               return 0;
                }
        case CL_RECEIVED_CHALLENGE:
                if (ct->use_sideband) {
@@ -447,20 +447,20 @@ static void client_post_select(struct sched *s, struct task *t)
                if (!strstr(buf, PROCEED_MSG))
                        goto out;
                ct->status = CL_RECEIVED_PROCEED;
-               return;
+               return 0;
                }
        case CL_RECEIVED_PROCEED: /* concat args and send command */
                {
                int i;
                char *command = NULL;
                if (!FD_ISSET(ct->scc.fd, &s->wfds))
-                       return;
+                       return 0;
                if (ct->use_sideband) {
                        ret = send_sb_command(ct);
                        if (ret <= 0)
                                goto out;
                        ct->status = CL_SENT_COMMAND;
-                       return;
+                       return 0;
                }
                for (i = 0; i < ct->conf.inputs_num; i++) {
                        char *tmp = command;
@@ -475,7 +475,7 @@ static void client_post_select(struct sched *s, struct task *t)
                if (ret < 0)
                        goto out;
                ct->status = CL_SENT_COMMAND;
-               return;
+               return 0;
                }
        case CL_SENT_COMMAND:
                {
@@ -501,7 +501,7 @@ static void client_post_select(struct sched *s, struct task *t)
                        if (strstr(buf2, AWAITING_DATA_MSG)) {
                                free(buf2);
                                ct->status = CL_SENDING;
-                               return;
+                               return 0;
                        }
                        ct->status = CL_RECEIVING;
                        btr_add_output(buf2, n, btrn);
@@ -517,15 +517,15 @@ static void client_post_select(struct sched *s, struct task *t)
                if (ret < 0)
                        goto out;
                if (ret == 0)
-                       return;
+                       return 0;
                if (!FD_ISSET(ct->scc.fd, &s->wfds))
-                       return;
+                       return 0;
                sz = btr_next_buffer(btrn, &buf2);
                ret = sc_send_bin_buffer(&ct->scc, buf2, sz);
                if (ret < 0)
                        goto out;
                btr_consume(btrn, sz);
-               return;
+               return 0;
                }
        case CL_RECEIVING:
                {
@@ -534,13 +534,13 @@ static void client_post_select(struct sched *s, struct task *t)
                if (ret < 0)
                        goto out;
                if (ret == 0)
-                       return;
+                       return 0;
                /*
                 * The FD_ISSET() is not strictly necessary, but is allows us
                 * to skip the malloc below if there is nothing to read anyway.
                 */
                if (!FD_ISSET(ct->scc.fd, &s->rfds))
-                       return;
+                       return 0;
                if (ct->use_sideband) {
                        struct sb_buffer sbb;
                        ret = recv_sb(ct, &s->rfds, &sbb);
@@ -559,13 +559,13 @@ static void client_post_select(struct sched *s, struct task *t)
                }
        }
 out:
-       t->error = ret;
        if (ret < 0) {
                if (!ct->use_sideband && ret != -E_SERVER_EOF &&
                                ret != -E_BTR_EOF && ret != -E_EOF)
-                       PARA_ERROR_LOG("%s\n", para_strerror(-t->error));
+                       PARA_ERROR_LOG("%s\n", para_strerror(-ret));
                btr_remove_node(&ct->btrn);
        }
+       return ret;
 }
 
 /**
@@ -601,7 +601,8 @@ int client_connect(struct client_task *ct, struct sched *s,
        ct->btrn = btr_new_node(&(struct btr_node_description)
                EMBRACE(.name = "client", .parent = parent, .child = child));
        ct->task.pre_select = client_pre_select;
-       ct->task.post_select = client_post_select;
+       ct->task.new_post_select = client_post_select;
+       ct->task.post_select = NULL;
        ct->task.error = 0;
        sprintf(ct->task.status, "client");
        register_task(s, &ct->task);