From aa9d24a6608f02455eefd1440cad28c7e86913fa Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Mon, 30 Dec 2013 23:26:00 +0000 Subject: [PATCH] task_register() conversion: server command task --- server.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/server.c b/server.c index fa19ce42..ab7c3c1b 100644 --- a/server.c +++ b/server.c @@ -110,7 +110,7 @@ struct server_command_task { /** Argument vector passed to para_server's main function. */ char **argv; /** The command task structure for scheduling. */ - struct task task; + struct task *task; }; static int want_colors(void) @@ -329,13 +329,13 @@ static void init_signal_task(void) static void command_pre_select(struct sched *s, struct task *t) { - struct server_command_task *sct = container_of(t, struct server_command_task, task); + struct server_command_task *sct = task_context(t); para_fd_set(sct->listen_fd, &s->rfds, &s->max_fileno); } static int command_post_select(struct sched *s, struct task *t) { - struct server_command_task *sct = container_of(t, struct server_command_task, task); + struct server_command_task *sct = task_context(t); int new_fd, ret, i; char *peer_name; @@ -399,8 +399,6 @@ static void init_server_command_task(int argc, char **argv) *sct = &server_command_task_struct; PARA_NOTICE_LOG("initializing tcp command socket\n"); - sct->task.pre_select = command_pre_select; - sct->task.post_select = command_post_select; sct->argc = argc; sct->argv = argv; ret = para_listen_simple(IPPROTO_TCP, conf.port_arg); @@ -411,8 +409,12 @@ static void init_server_command_task(int argc, char **argv) if (ret < 0) goto err; add_close_on_fork_list(sct->listen_fd); /* child doesn't need the listener */ - sprintf(sct->task.status, "server command task"); - register_task(&sched, &sct->task); + sct->task = task_register(&(struct task_info) { + .name = "server command", + .pre_select = command_pre_select, + .post_select = command_post_select, + .context = sct, + }, &sched); return; err: PARA_EMERG_LOG("%s\n", para_strerror(-ret)); @@ -573,6 +575,7 @@ int main(int argc, char *argv[]) server_init(argc, argv); mutex_lock(mmd_mutex); ret = schedule(&sched); + sched_shutdown(&sched); if (ret < 0) { PARA_EMERG_LOG("%s\n", para_strerror(-ret)); exit(EXIT_FAILURE); -- 2.39.5