X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=client.c;h=7f0e3211241a77dad0d6dbe5774f6671e49823f8;hb=e009fa7ff09186e0ebd748661d46338b5eb8d016;hp=5f511708506a464e1a0e06f679eaa856ac015164;hpb=39ec52d7bfec591dcad0d41bcdbdf6d980bf5913;p=paraslash.git diff --git a/client.c b/client.c index 5f511708..7f0e3211 100644 --- a/client.c +++ b/client.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1997-2012 Andre Noll + * Copyright (C) 1997-2013 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -54,7 +54,7 @@ static void exec_pre_select(struct sched *s, struct task *t) sched_min_delay(s); } -static void exec_post_select(__a_unused struct sched *s, struct task *t) +static int exec_post_select(__a_unused struct sched *s, struct task *t) { struct exec_task *et = container_of(t, struct exec_task, task); struct btr_node *btrn = et->btrn; @@ -63,10 +63,8 @@ static void exec_post_select(__a_unused struct sched *s, struct task *t) int ret; ret = btr_node_status(btrn, 0, BTR_NT_LEAF); - if (ret <= 0) { - t->error = ret; - return; - } + if (ret <= 0) + return ret; sz = btr_next_buffer(btrn, &buf); if (sz <= 1) goto out; @@ -76,6 +74,7 @@ static void exec_post_select(__a_unused struct sched *s, struct task *t) et->result_buf[et->result_size - 1] = '\0'; out: btr_consume(btrn, sz); + return 0; } static int make_client_argv(const char *line) @@ -96,7 +95,8 @@ static int execute_client_command(const char *cmd, char **result) struct exec_task exec_task = { .task = { .pre_select = exec_pre_select, - .post_select = exec_post_select, + .new_post_select = exec_post_select, + .post_select = NULL, .status = "client exec task", }, .result_buf = para_strdup(""), @@ -114,11 +114,11 @@ static int execute_client_command(const char *cmd, char **result) goto out; schedule(&command_sched); *result = exec_task.result_buf; - btr_remove_node(exec_task.btrn); + btr_remove_node(&exec_task.btrn); client_disconnect(ct); ret = 1; out: - btr_free_node(exec_task.btrn); + btr_remove_node(&exec_task.btrn); if (ret < 0) free(exec_task.result_buf); return ret; @@ -307,7 +307,7 @@ static void setatt_completer(struct i9e_completion_info *ci, free(orig); } sl[2 * num_atts] = NULL; - ret = i9e_extract_completions(ci->word, sl, &cr->matches); + i9e_extract_completions(ci->word, sl, &cr->matches); out: free(buf); free_argv(sl); @@ -603,14 +603,23 @@ 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_SERVER_CMD_SUCCESS: + case -E_EOF: + case -E_SERVER_EOF: + case -E_BTR_EOF: + ret = 0; + break; + default: ret = -E_SERVER_CMD_FAILURE; + } + } 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; + btr_remove_node(&sit.btrn); + btr_remove_node(&sot.btrn); + return ret < 0? EXIT_FAILURE : EXIT_SUCCESS; }