Xenomai-Solo: bug in vxWorks taskSpawn with twice the same name
Hi
Thanks a lot to Philippe for fixing the previous bug so quickly! Never got fixed a bug as fast by WindRIver despite having paid quite a lot of money for it!
Now my testsuite passes almost all tests but crashes, when it spawns twice a task with the same name. E.g. I get the following output:
Quoted 8 lines
testTask done t1
0x901a0f4t20x901a2b4Xenomai/SOLO: duplicate task name: Test assert passed at task1 line 24 assert passed at task1 line 24 assert passed at task1 line 26 assert passed at task1 line 26Command terminated by signal 11
Attached my simple test case.
Best regards
Signature · 1 line
NIklaus Giger
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#define assert(cond) \
if (!cond) printf("assert failed at %s line %d\n", __FUNCTION__, __LINE__); \
else printf("assert passed at %s line %d\n", __FUNCTION__, __LINE__);
#if defined(__SOLO__) || defined(_WRS_VXWORKS_MAJOR) // #include <vxWorks.h>
#include <semLib.h>
#include <taskLib.h>
#include <tickLib.h>
#include <kernelLib.h>
void testTask(long a1, long a2, long a3, long a4, long a5,
long a6, long a7, long a8, long a9, long a10);
bool finished;
extern "C" void task1(long int, long int, long int, long int, long int, long int, long int, long int, long int, long int)
{
assert(1);
taskDelay(30);
assert(2);
finished = true;}
#endif
/**
* Main functions
*/
#if defined(PLAT_VXWORKS) || defined(_WRS_VXWORKS_MAJOR)
extern "C" int tSysMain(const char* arg)
{
const char* argv[2];
argv[0] = "undefined";
argv[1] = arg;
int argc = sizeof(argv) / sizeof(char*);#else
int main(int argc, char *const argv[])
{
#endif
#ifdef __SOLO__
kernelInit(testTask, argc, argv);
while(!finished) { sleep(1); }
exit(0);
}void testTask(long a1, long a2, long a3, long a4, long a5,
long a6, long a7, long a8, long a9, long a10)
{
int argc=0; char *const argv[]={0};
#endif
int t1 =taskSpawn("Test", // name of new task (stored at pStackBase)
90, // priority of new task
0, // task option word
20*1024, // size (bytes) of stack needed plus name task1, // entry point of new task
0, // first argument
0,0,0,0,0,0,0,0,0); // unused parameters
int t2 =taskSpawn("Test", // name of new task (stored at pStackBase)
90, // priority of new task
0, // task option word
20*1024, // size (bytes) of stack needed plus name task1, // entry point of new task
0, // first argument
0,0,0,0,0,0,0,0,0); // unused parameters
printf("%s done t1 0x%x t2 0x%x\n", __FUNCTION__, t1, t2); while (!finished) sleep(1);
#ifdef __SOLO__
finished = true;
return;
#else
return 0;
#endif
}
// ___________________________________________________________________________
Quoted 6 lines · Niklaus Giger
Hi
Thanks a lot to Philippe for fixing the previous bug so quickly! Never got fixed a bug as fast by WindRIver despite having paid quite a lot of money for it!
inertia = success / competition
Quoted 9 lines
Now my testsuite passes almost all tests but crashes, when it spawns twice a task with the same name. E.g. I get the following output:
Quoted 7 lines
testTask done t1
0x901a0f4t20x901a2b4Xenomai/SOLO: duplicate task name: Test assert passed at task1 line 24 assert passed at task1 line 24 assert passed at task1 line 26 assert passed at task1 line 26
Quoted 4 lines
Quoted 1 line
Command terminated by signal 11
Attached my simple test case.
I eventually found out that this problem was triggered by the registry support, in case duplicate names where found. This patch should fix the issue:
base/registry.c +20 -3
@@ -116,11 +116,28 @@ done:return ret; } -int registry_add_file (struct fsobj *fsobj,struct registry_operations *ops, -int mode,const char *fmt, ...) +int registry_init_file (struct fsobj *fsobj,struct registry_operations *ops) { -char path[PATH_MAX ], *basename, *dir;pthread_mutexattr_t mattr; + +if (__no_registry_arg) +return 0 ; + + fsobj->path =NULL ; + fsobj->ops = ops; +holder_init (&fsobj->link); + +pthread_mutexattr_init (&mattr); +pthread_mutexattr_setprotocol (&mattr,PTHREAD_PRIO_INHERIT ); +pthread_mutex_init (&fsobj->lock, &mattr); +pthread_mutexattr_destroy (&mattr); + +return 0 ; +} + +int registry_add_file (struct fsobj *fsobj,int mode,const char *fmt, ...) +{ +char path[PATH_MAX ], *basename, *dir;struct hashobj *hobj;struct regfs_dir *d;va_list ap;
@@ -139,16 +156,9 @@ int registry_add_file(struct fsobj *fsobj, struct
registry_operations *ops,
fsobj->path = xnstrdup(path); fsobj->basename = fsobj->path + (basename - path) + 1;
- fsobj->ops = ops;
fsobj->mode = mode & O_ACCMODE; clock_gettime(CLOCK_REALTIME, &fsobj->ctime); fsobj->mtime = fsobj->ctime;
- holder_init(&fsobj->link);
-
- pthread_mutexattr_init(&mattr);
- pthread_mutexattr_setprotocol(&mattr, PTHREAD_PRIO_INHERIT);
- pthread_mutex_init(&fsobj->lock, &mattr);
- pthread_mutexattr_destroy(&mattr);
pthread_mutex_lock(®fs_lock);
@@ -161,7 +171,9 @@ int registry_add_file(struct fsobj *fsobj, struct registry_operations *ops,
hobj = hash_search(®fs_dirtable, dir);
if (hobj == NULL) {
fail:
+ hash_remove(®fs_objtable, &fsobj->hobj);
xnfree(path);
+ fsobj->path = NULL;
ret = -ENOENT;
goto done;
}
@@ -184,6 +196,10 @@ void registry_remove_file(struct fsobj *fsobj)
return;
pthread_mutex_lock(®fs_lock);
+
+ if (fsobj->path == NULL)
+ goto out; /* Not registered. */
+
hash_remove(®fs_objtable, &fsobj->hobj);
pthread_mutex_lock(&fsobj->lock);
@@ -194,7 +210,7 @@ void registry_remove_file(struct fsobj *fsobj)
xnfree(fsobj->path); pthread_mutex_unlock(&fsobj->lock); pthread_mutex_destroy(&fsobj->lock);
-
+out:
pthread_mutex_unlock(®fs_lock);
}
include/xenomai/registry.h +10 -2
@@ -57,8 +57,10 @@ extern "C" {int registry_add_dir (const char *fmt, ...); +int registry_init_file (struct fsobj *fsobj, +struct registry_operations *ops); +int registry_add_file (struct fsobj *fsobj, -struct registry_operations *ops,int mode,const char *fmt, ...);
@@ -89,8 +91,14 @@ int registry_add_dir(const char *fmt, ...) }static inline +int registry_init_file (struct fsobj *fsobj, +struct registry_operations *ops) +{ +return 0 ; +} + +static inline int registry_add_file (struct fsobj *fsobj, -struct registry_operations *ops,int mode,const char *fmt, ...) {
vxworks/taskLib.c +7 -6
@@ -234,17 +234,18 @@ static void *task_trampoline(void *arg) goto done; } + ret =registry_init_file (&task->fsobj, ®istry_ops); +if (hash_enter (&wind_task_table, task->name, &task->obj)) {warning ("duplicate task name: %s" , task->name);/* Make sure we won't un-hash the previous one. */ strcpy (task->name,"(dup)" ); - }else { - ret =registry_add_file (&task->fsobj, ®istry_ops,O_RDONLY , + }else if (ret ==0 ) + ret =registry_add_file (&task->fsobj,O_RDONLY ,"/vxworks/tasks/%s" , task->name); -if (ret) -warning ("failed to export task %s to registry" , - task->name); - } +if (ret) +warning ("failed to export task %s to registry" , + task->name);pthread_setcancelstate (PTHREAD_CANCEL_ENABLE ,NULL );pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS ,NULL );
Signature · 1 line
Philippe.