Re: [AD] [LNX] Mode-X and threads and mouse

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On 2001-11-30, Eric Botcazou <ebotcazou@xxxxxxxxxx> wrote:
> 
> It looks like threads created with the POSIX pthread_create() call don't
> inherit I/O privileges from their parent process. Yet quoted from the iopl()
> man page: "Permissions are inherited by fork and exec."
> 
> If you comment out line 180 in src/linux/lsystem.c and put an 'iopl(3)' call
> line 70 in src/unix/uptimer.c, all works nicely (that's of course not a
> recommended fix ;-)

I can't think of anything better, so here's a proposed patch.
Index: src/unix/uptimer.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/unix/uptimer.c,v
retrieving revision 1.3
diff -u -r1.3 uptimer.c
--- src/unix/uptimer.c	2001/12/01 12:30:07	1.3
+++ src/unix/uptimer.c	2001/12/02 00:08:25
@@ -19,6 +19,15 @@
 #include "allegro.h"
 #include "allegro/internal/aintern.h"
 
+/* See hack later.  */
+#ifdef ALLEGRO_LINUX
+#include <unistd.h>
+#ifdef HAVE_SYS_IO_H
+#include <sys/io.h>
+#endif
+#include "allegro/platform/aintlnx.h"
+#endif
+
 
 
 #ifdef HAVE_LIBPTHREAD
@@ -68,6 +77,25 @@
 
 
 
+/* privileges_hack_for_linux:
+ *  One of the jobs of the timer thread is to update the mouse pointer
+ *  on screen.  When using the Mode-X driver under Linux console, this
+ *  involves selecting different planes (in modexgfx.s), which require
+ *  special priviledges.  This function gets those priviledges.
+ */
+static void privileges_hack_for_linux(void)
+{
+#ifdef ALLEGRO_LINUX
+   if ((system_driver == &system_linux) && (__al_linux_have_ioperms)) {
+      seteuid(0);
+      iopl(3);
+      seteuid(getuid());
+   }
+#endif
+}
+
+
+
 /* ptimer_thread_func:
  *  The timer thread.
  */
@@ -79,6 +107,8 @@
    long interval = 0x8000;
 
    block_all_signals();
+
+   privileges_hack_for_linux();
 
    gettimeofday(&old_time, 0);
 



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/