X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=client.c;h=4c4806f928950919d0d763a02104e5d93f316796;hp=338f05c8b45efe6f80705cbfc1d18fb231424549;hb=47a9983cc65ef57ad25c4ba3e16cabe48fd57b23;hpb=a96be5bc4fda8c0df5370d646defb5ff632ba391 diff --git a/client.c b/client.c index 338f05c8..4c4806f9 100644 --- a/client.c +++ b/client.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 1997-2014 Andre Noll + * Copyright (C) 1997-2014 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -39,24 +39,24 @@ __printf_2_3 void (*para_log)(int, const char*, ...) = stderr_log; #include "afs_completion.h" struct exec_task { - struct task task; + struct task *task; struct btr_node *btrn; char *result_buf; size_t result_size; }; -static void exec_pre_select(struct sched *s, struct task *t) +static void exec_pre_select(struct sched *s, void *context) { - struct exec_task *et = container_of(t, struct exec_task, task); + struct exec_task *et = context; int ret = btr_node_status(et->btrn, 0, BTR_NT_LEAF); if (ret != 0) sched_min_delay(s); } -static int exec_post_select(__a_unused struct sched *s, struct task *t) +static int exec_post_select(__a_unused struct sched *s, void *context) { - struct exec_task *et = container_of(t, struct exec_task, task); + struct exec_task *et = context; struct btr_node *btrn = et->btrn; char *buf; size_t sz; @@ -93,11 +93,6 @@ static int execute_client_command(const char *cmd, char **result) int ret; struct sched command_sched = {.default_timeout = {.tv_sec = 1}}; struct exec_task exec_task = { - .task = { - .pre_select = exec_pre_select, - .post_select = exec_post_select, - .status = "client exec task", - }, .result_buf = para_strdup(""), .result_size = 1, }; @@ -107,11 +102,17 @@ static int execute_client_command(const char *cmd, char **result) goto out; exec_task.btrn = btr_new_node(&(struct btr_node_description) EMBRACE(.name = "exec_collect")); - register_task(&command_sched, &exec_task.task); + exec_task.task = task_register(&(struct task_info) { + .name = "client exec", + .pre_select = exec_pre_select, + .post_select = exec_post_select, + .context = &exec_task, + }, &command_sched); ret = client_connect(ct, &command_sched, NULL, exec_task.btrn); if (ret < 0) goto out; schedule(&command_sched); + sched_shutdown(&command_sched); *result = exec_task.result_buf; btr_remove_node(&exec_task.btrn); ret = 1; @@ -495,6 +496,7 @@ __noreturn static void interactive_session(void) goto out; para_log = i9e_log; ret = schedule(&sched); + sched_shutdown(&sched); i9e_close(); para_log = stderr_log; out: @@ -528,35 +530,29 @@ __noreturn static void print_completions(void) struct supervisor_task { bool stdout_task_started; - struct task task; + struct task *task; }; -static int supervisor_post_select(struct sched *s, struct task *t) +static int supervisor_post_select(struct sched *s, void *context) { - struct supervisor_task *svt = container_of(t, struct supervisor_task, - task); + struct supervisor_task *svt = context; + int ret = task_status(ct->task); - if (ct->task.error < 0) - return ct->task.error; + if (ret < 0) + return ret; if (!svt->stdout_task_started && ct->status == CL_EXECUTING) { stdout_task_register(&sot, s); svt->stdout_task_started = true; return 1; } if (ct->status == CL_SENDING) { - stdin_set_defaults(&sit); - register_task(s, &sit.task); + stdin_task_register(&sit, s); return -E_TASK_STARTED; } return 0; } -static struct supervisor_task supervisor_task = { - .task = { - .post_select = supervisor_post_select, - .status = "supervisor task" - } -}; +static struct supervisor_task supervisor_task; /** * The client program to connect to para_server. @@ -604,18 +600,26 @@ int main(int argc, char *argv[]) goto out; sot.btrn = btr_new_node(&(struct btr_node_description) EMBRACE(.name = "stdout", .parent = ct->btrn[0])); - register_task(&sched, &supervisor_task.task); + supervisor_task.task = task_register(&(struct task_info) { + .name = "supervisor", + .post_select = supervisor_post_select, + .context = &supervisor_task, + }, &sched); + 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; + if (ret >= 0) { + ret = task_status(ct->task); + if (ret < 0) { + switch (ret) { + /* 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; + } } } sched_shutdown(&sched);