I've removed all occurences of WithRoot and checks of euid!=0 I've had
to add --mode-check to XENOMAI_CFLAGS and XENOMAI_LDFLAGS.  The method
to create a periodic thread is a little different.

The attached patch shows all the changes I did to get it working.

regards,

Mark.



Alec Ari <[email protected]> wrote:

        What's the problem exactly? Maybe I can help?
        Alec
diff --git a/src/Makefile b/src/Makefile
index f0df90a6b..49d84e5ef 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -188,7 +188,7 @@ INCLUDE += -I$(INCLUDEPY)
 
 # Compilation options. Perhaps some of these should come from Makefile.inc? 
(CXXFLAGS now does)
 INTEGER_OVERFLOW_FLAGS := -fwrapv
-OPT := -Os $(INTEGER_OVERFLOW_FLAGS)
+OPT := -fPIC -O0 $(INTEGER_OVERFLOW_FLAGS)
 DEBUG := $(DEBUG) -g -Wall
 CFLAGS := $(INCLUDE) $(OPT) $(DEBUG) $(EXTRA_DEBUG) -DULAPI -std=gnu99 
-fgnu89-inline
 CXXFLAGS := $(INCLUDE) $(CXXFLAGS)   $(EXTRA_DEBUG) -DULAPI $(DEBUG) $(OPT) 
-Woverloaded-virtual
diff --git a/src/configure.in b/src/configure.in
index 538d3b732..e1feead89 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -166,7 +166,7 @@ RTPREFIX=""
 KERNELDIR=""
 RTFLAGS=""
 
-NONDISTRIBUTABLE=false
+NONDISTRIBUTABLE=true
 AC_ARG_ENABLE(non-distributable,
     AS_HELP_STRING(
         [--enable-non-distributable],
@@ -276,8 +276,9 @@ if test "$RTS" = uspace || test -z "$RTS" -a "$RTAI_CONFIG" 
= "none" ; then
   else
     USPACE_XENOMAI=+xenomai
     CONFIG_USPACE_XENOMAI=y
-    XENOMAI_CFLAGS=`$XENOMAI_CONFIG --skin posix --cflags`
-    XENOMAI_LDFLAGS=`$XENOMAI_CONFIG --skin posix --ldflags`
+    XENOMAI_CFLAGS=`$XENOMAI_CONFIG --auto-init-solib --skin posix --cflags 
--mode-check`
+    XENOMAI_LDFLAGS=`$XENOMAI_CONFIG --auto-init-solib --skin posix --ldflags 
--mode-check`
+    XENOMAI_LDFLAGS="$XENOMAI_LDFLAGS -lanalogy"
     AC_DEFINE([USPACE_XENOMAI], [], [Define if uspace realtime should 
optionally support Xenomai])
   fi
   AC_SUBST([CONFIG_USPACE_XENOMAI])
diff --git a/src/emc/usr_intf/axis/scripts/axis.py 
b/src/emc/usr_intf/axis/scripts/axis.py
index 74e18c22c..8161330bd 100755
--- a/src/emc/usr_intf/axis/scripts/axis.py
+++ b/src/emc/usr_intf/axis/scripts/axis.py
@@ -1711,7 +1711,7 @@ def get_jog_speed_map(a):
     return get_jog_speed(a)
 
 def get_max_jog_speed(a):
-    max_linear_speed = vars.max_speed.get()
+    max_linear_speed = vars.maxvel_speed.get()
     max_linear_speed = to_internal_linear_unit(max_linear_speed)
     if vars.metric.get(): max_linear_speed = max_linear_speed * 25.4
 
diff --git a/src/hal/utils/scope.c b/src/hal/utils/scope.c
index da5f552b5..14426046f 100644
--- a/src/hal/utils/scope.c
+++ b/src/hal/utils/scope.c
@@ -767,7 +767,7 @@ static void main_window_closed(GtkWidget * widget, gpointer 
* gdata)
 }
 
 static void set_focus(GtkWindow *window, GtkWidget *widget, gpointer *data) {
-    gtk_window_set_urgency_hint(window, FALSE);
+    // gtk_window_set_urgency_hint(window, FALSE);
 }
 
 static void quit(int sig)
diff --git a/src/rtapi/Submakefile b/src/rtapi/Submakefile
index c4f145d69..26113a202 100644
--- a/src/rtapi/Submakefile
+++ b/src/rtapi/Submakefile
@@ -16,10 +16,10 @@ USERSRCS += $(RTAPI_APP_SRCS)
 
 $(call TOOBJSDEPS, rtapi/rtapi_pci.cc): EXTRAFLAGS += $(LIBUDEV_CFLAGS) -O0
 $(call TOOBJSDEPS, $(RTAPI_APP_SRCS)): EXTRAFLAGS += -DSIM \
-       -UULAPI -DRTAPI -pthread $(RTAPI_APP_CFLAGS)
+       -UULAPI -DRTAPI $(RTAPI_APP_CFLAGS)
 ../bin/rtapi_app: $(call TOOBJS, $(RTAPI_APP_SRCS))
        $(ECHO) Linking $(notdir $@)
-       $(Q)$(CXX) -rdynamic $(LDFLAGS) -o $@ $^ $(LIBDL) -pthread -lrt 
$(LIBUDEV_LIBS)
+       $(Q)$(CXX) -rdynamic $(LDFLAGS) -o $@ $^ $(XENOMAI_LDFLAGS) $(LIBDL) 
$(LIBUDEV_LIBS)
 TARGETS += ../bin/rtapi_app
 endif
 
diff --git a/src/rtapi/uspace_common.h b/src/rtapi/uspace_common.h
index 82f1c5bfb..0bd484021 100644
--- a/src/rtapi/uspace_common.h
+++ b/src/rtapi/uspace_common.h
@@ -33,10 +33,6 @@ static int msg_level = RTAPI_MSG_ERR;        /* message 
printing level */
 
 #include "config.h"
 
-#ifdef RTAPI
-#include "rtapi_uspace.hh"
-#endif
-
 typedef struct {
   int magic;                   /* to check for valid handle */
   int key;                     /* key to shared memory area */
@@ -54,9 +50,6 @@ static rtapi_shmem_handle shmem_array[MAX_SHM] = {{0},};
 
 int rtapi_shmem_new(int key, int module_id, unsigned long int size)
 {
-#ifdef RTAPI
-  WITH_ROOT;
-#endif
   rtapi_shmem_handle *shmem;
   int i;
 
@@ -351,7 +344,7 @@ static int detect_rtai() {
 static int detect_xenomai() {
     struct utsname u;
     uname(&u);
-    return strcasestr (u.release, "-xenomai") != 0;
+    return strcasestr (u.release, "-ipipe+") != 0;
 }
 #else
 static int detect_xenomai() {
diff --git a/src/rtapi/uspace_rtapi_app.cc b/src/rtapi/uspace_rtapi_app.cc
index 30cd371c6..f7607c0c3 100644
--- a/src/rtapi/uspace_rtapi_app.cc
+++ b/src/rtapi/uspace_rtapi_app.cc
@@ -529,6 +529,9 @@ int main(int argc, char **argv) {
     } 
     vector<string> args;
     for(int i=1; i<argc; i++) { args.push_back(string(argv[i])); }
+    seteuid(euid);
+    ruid=0;
+    euid=0;
 
 become_master:
     int fd = socket(PF_UNIX, SOCK_STREAM, 0);
@@ -775,12 +778,12 @@ static int harden_rt()
 
 static RtapiApp *makeApp()
 {
-    if(euid != 0 || harden_rt() < 0)
+    if(0 && (euid != 0 || harden_rt() < 0))
     {
         rtapi_print_msg(RTAPI_MSG_ERR, "Note: Using POSIX non-realtime\n");
         return new Posix(SCHED_OTHER);
     }
-    WithRoot r;
+    // WithRoot r;
     void *dll = nullptr;
     if(detect_xenomai()) {
         dll = dlopen(EMC2_HOME "/lib/libuspace-xenomai.so.0", RTLD_NOW);
@@ -1188,8 +1191,9 @@ void rtapi_timespec_advance(struct timespec &result, 
const struct timespec &src,
 }
 
 int rtapi_open_as_root(const char *filename, int mode) {
-    WITH_ROOT;
+    setfsuid(geteuid());
     int r = open(filename, mode);
+    setfsuid(getuid());
     if(r < 0) return -errno;
     return r;
 }
@@ -1202,10 +1206,7 @@ int rtapi_spawn_as_root(pid_t *pid, const char *path,
     WITH_ROOT;
     setreuid(euid, euid);
     priv_info("before posix_spawn");
-    int r = posix_spawn(pid, path, file_actions, attrp, argv, envp);
-    setresuid(ruid, ruid, (pid_t)-1);
-    priv_info("after posix_spawnp");
-    return r;
+    return posix_spawn(pid, path, file_actions, attrp, argv, envp);
 }
 
 int rtapi_spawnp_as_root(pid_t *pid, const char *path,
@@ -1216,10 +1217,7 @@ int rtapi_spawnp_as_root(pid_t *pid, const char *path,
     WITH_ROOT;
     setreuid(euid, euid);
     priv_info("before posix_spawnp");
-    int r = posix_spawnp(pid, path, file_actions, attrp, argv, envp);
-    setresuid(ruid, ruid, (pid_t)-1);
-    priv_info("after posix_spawnp");
-    return r;
+    return posix_spawnp(pid, path, file_actions, attrp, argv, envp);
 }
 
 int rtapi_do_as_root(int (*fn)(void *), void *arg) {
diff --git a/src/rtapi/uspace_xenomai.cc b/src/rtapi/uspace_xenomai.cc
index 35151d611..a047f8059 100644
--- a/src/rtapi/uspace_xenomai.cc
+++ b/src/rtapi/uspace_xenomai.cc
@@ -2,19 +2,27 @@
 #include "rtapi.h"
 #include "rtapi_uspace.hh"
 #include <posix/pthread.h>
+#include <time.h>
 #include <atomic>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <signal.h>
 #ifdef HAVE_SYS_IO_H
 #include <sys/io.h>
 #endif
+#include <sys/syscall.h>
 
-namespace
+#define gettid() syscall(__NR_gettid)
+#define sigev_notify_thread_id _sigev_un._tid
+
+#include "uspace_xenomai.hh"
+
+namespace uspace_xenomai
 {
-struct RtaiTask : rtapi_task {
-    RtaiTask() : rtapi_task{}, cancel{}, thr{} {}
-    std::atomic<int> cancel;
-    pthread_t thr;
-};
 
+pthread_once_t key_once;
+pthread_key_t key;
 
 struct XenomaiApp : RtapiApp {
     XenomaiApp() : RtapiApp(SCHED_FIFO) {
@@ -75,15 +83,24 @@ struct XenomaiApp : RtapiApp {
         auto task = reinterpret_cast<RtaiTask*>(arg);
         pthread_setspecific(key, arg);
 
-        struct timespec now;
-        clock_gettime(CLOCK_MONOTONIC, &now);
+        struct sigevent ev;
+        ev.sigev_notify=SIGEV_THREAD_ID;
+       ev.sigev_signo=SIGALRM;
+        ev.sigev_notify_thread_id=gettid();
+        if(timer_create(CLOCK_MONOTONIC, &ev, &task->timer)) {
+               rtapi_print("Cannot create timer for task %d\n", task->id);
+               return nullptr;
+        }
 
-        // originally, I used pthread_make_periodic_np here, and
-        // pthread_wait_np in wait(), but in about 1 run in 50 this led to
-        // "xenomai: watchdog triggered" and rtapi_app was killed.
-        //
-        // encountered on: 3.18.20-xenomai-2.6.5 with a 2-thread SMP system
-        rtapi_timespec_advance(task->nextstart, now, task->period);
+       struct itimerspec its;
+       its.it_value.tv_sec=0;
+       its.it_value.tv_nsec=task->period;
+       its.it_interval.tv_sec=0;
+       its.it_interval.tv_nsec=task->period;
+       if(timer_settime(task->timer, 0, &its, NULL)) {
+               rtapi_print("Cannot set timer for task %d\n", task->id);
+               return nullptr;
+       }
 
         (task->taskcode) (task->arg);
 
@@ -100,24 +117,19 @@ struct XenomaiApp : RtapiApp {
     }
 
     void wait() {
-        int task_id = task_self();
-        auto task = ::rtapi_get_task<RtaiTask>(task_id);
-        if(task->cancel) {
+        auto task = ::rtapi_get_task<RtaiTask>(task_self());
+
+        int sigs;
+        sigset_t sigset;
+        sigemptyset(&sigset);
+        sigaddset(&sigset, SIGALRM);
+        if(sigwait(&sigset, &sigs)<0)
+            rtapi_print("sigwait failed for task %d\n", task->id);
+
+       if(timer_getoverrun(task->timer))
+               unexpected_realtime_delay(task);
+        if(task->cancel)
             pthread_exit(nullptr);
-        }
-        rtapi_timespec_advance(task->nextstart, task->nextstart, task->period);
-        struct timespec now;
-        clock_gettime(CLOCK_MONOTONIC, &now);
-        if(rtapi_timespec_less(task->nextstart, now))
-        {
-            if(policy == SCHED_FIFO)
-                unexpected_realtime_delay(task);
-        }
-        else
-        {
-            int res = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, 
&task->nextstart, nullptr);
-            if(res < 0) perror("clock_nanosleep");
-        }
     }
 
     unsigned char do_inb(unsigned int port) {
@@ -143,8 +155,6 @@ struct XenomaiApp : RtapiApp {
         return task->id;
     }
 
-    static pthread_once_t key_once;
-    static pthread_key_t key;
     static void init_key(void) {
         pthread_key_create(&key, NULL);
     }
@@ -161,13 +171,11 @@ struct XenomaiApp : RtapiApp {
     }
 };
 
-pthread_once_t XenomaiApp::key_once;
-pthread_key_t XenomaiApp::key;
 }
 
 extern "C" RtapiApp *make();
 
 RtapiApp *make() {
     rtapi_print_msg(RTAPI_MSG_ERR, "Note: Using XENOMAI (posix-skin) 
realtime\n");
-    return new XenomaiApp;
+    return new uspace_xenomai::XenomaiApp;
 }
diff --git a/src/rtapi/uspace_xenomai.hh b/src/rtapi/uspace_xenomai.hh
new file mode 100644
index 000000000..40db40b16
--- /dev/null
+++ b/src/rtapi/uspace_xenomai.hh
@@ -0,0 +1,10 @@
+namespace uspace_xenomai {
+struct RtaiTask : rtapi_task {
+    RtaiTask() : rtapi_task{}, cancel{}, thr{} {}
+    std::atomic<int> cancel;
+    pthread_t thr;
+    timer_t timer;
+};
+
+extern pthread_key_t key;
+}
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to