Module: xenomai-3
Branch: next
Commit: cf10e9c017ec54883901c72dc767b8024428e217
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=cf10e9c017ec54883901c72dc767b8024428e217

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Dec 28 12:08:32 2015 +0100

copperplate/threadobj: mercury: fix stat call (CPU number)

---

 lib/copperplate/threadobj.c |   27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/lib/copperplate/threadobj.c b/lib/copperplate/threadobj.c
index 44266f4..2d37d46 100644
--- a/lib/copperplate/threadobj.c
+++ b/lib/copperplate/threadobj.c
@@ -22,6 +22,8 @@
 #include <errno.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 #include <unistd.h>
 #include <time.h>
 #include <fcntl.h>
@@ -851,14 +853,33 @@ static void disable_rr_corespec(struct threadobj *thobj) 
/* thobj->lock held */
 int threadobj_stat(struct threadobj *thobj,
                   struct threadobj_stat *stat) /* thobj->lock held */
 {
+       char procstat[64], buf[BUFSIZ], *p;
        struct timespec now, delta;
+       FILE *fp;
+       int n;
 
        __threadobj_check_locked(thobj);
 
-       stat->cpu = sched_getcpu();
-       if (stat->cpu < 0)
-               stat->cpu = 0;  /* assume uniprocessor on ENOSYS */
+       snprintf(procstat, sizeof(procstat), "/proc/%d/stat", thobj->pid);
+       fp = fopen(procstat, "r");
+       if (fp == NULL)
+               return -EINVAL;
+
+       p = fgets(buf, sizeof(buf), fp);
+       fclose(fp);
+
+       if (p == NULL)
+               return -EIO;
+
+       p += strlen(buf);
+       for (n = 0; n < 14; n++) {
+               while (*--p != ' ') {
+                       if (p <= buf)
+                               return -EINVAL;
+               }
+       }
 
+       stat->cpu = atoi(++p);
        stat->status = threadobj_get_status(thobj);
 
        if (thobj->run_state & (__THREAD_S_TIMEDWAIT|__THREAD_S_DELAYED)) {


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to