sched: Dont use fixed-size buffer for task names.
authorAndre Noll <maan@systemlinux.org>
Thu, 2 Jan 2014 01:16:33 +0000 (01:16 +0000)
committerAndre Noll <maan@systemlinux.org>
Sun, 25 May 2014 13:39:01 +0000 (15:39 +0200)
This is not more complicated than the strncpy(), and it allows for
arbitrary long task names.

sched.c

diff --git a/sched.c b/sched.c
index b92774f..0a1cff2 100644 (file)
--- a/sched.c
+++ b/sched.c
@@ -20,7 +20,7 @@
 
 struct task {
        /** The task name supplied when the task was registered(). */
-       char name[255];
+       char *name;
        /** Copied from the task_info struct during task_register(). */
        void (*pre_select)(struct sched *s, struct task *t);
        /** Copied from the task_info struct during task_register(). */
@@ -64,6 +64,7 @@ static void unlink_and_free_task(struct task *t)
 {
        PARA_INFO_LOG("freeing task %s\n", t->name);
        list_del(&t->node);
+       free(t->name);
        free(t);
 }
 
@@ -239,8 +240,7 @@ struct task *task_register(struct task_info *info, struct sched *s)
        if (!s->task_list.next)
                INIT_LIST_HEAD(&s->task_list);
 
-       snprintf(t->name, sizeof(t->name) - 1, "%s", info->name);
-       t->name[sizeof(t->name) - 1] = '\0';
+       t->name = para_strdup(info->name);
        t->notification = 0;
        t->status = 0;
        t->dead = false;