[AD] linux console fixes

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


The attached patch makes the linux console driver more robust. set_gfx_mode used to get stuck in a infinite loop when there wasn't a console available. Noticed here: http://www.allegro.cc/forums/thread/574023

The change in __al_linux_display_switch_lock is a bit ugly. It can fail silently (something else will fail gracefully later so it's OK for the user). It is a system_driver vtable entry so I'm not sure if we can change the return value from void. That would be good because I could return the ASSERT in __al_linux_leave_console() that this patch removes.
But it should be fine even this way.


--
Milan Mimica
http://sparklet.sf.net
Index: src/linux/vtswitch.c
===================================================================
--- src/linux/vtswitch.c	(revision 5763)
+++ src/linux/vtswitch.c	(working copy)
@@ -198,6 +198,12 @@
  */
 void __al_linux_display_switch_lock(int lock, int foreground)
 {
+	if (lock) {
+		if (__al_linux_use_console() != 0) {
+			return;
+		}
+	}
+	
 	if (foreground) {
 		__al_linux_wait_for_display();
 	}
@@ -208,6 +214,7 @@
 	else {
 		__al_linux_switching_blocked--;
 		poll_console_switch();
+		__al_linux_leave_console();
 	}
 }
 
Index: src/linux/lconsole.c
===================================================================
--- src/linux/lconsole.c	(revision 5763)
+++ src/linux/lconsole.c	(working copy)
@@ -148,7 +148,7 @@
 
       /* tty0 is not really a console, so start counting at 2. */
       fd = -1;
-      for (tty = 1, mask = 2; mask; tty++, mask <<= 1)
+      for (tty = 1, mask = 2; mask; tty++, mask <<= 1) {
 	 if (!(vts.v_state & mask)) {
 	    snprintf (tty_name, sizeof(tty_name), "/dev/tty%d", tty);
 	    tty_name[sizeof(tty_name)-1] = 0;
@@ -157,6 +157,7 @@
 	       break;
 	    }
 	 }
+      }
 
       seteuid (getuid());
 
@@ -274,7 +275,10 @@
    console_users++;
    if (console_users > 1) return 0;
 
-   if (init_console()) return 1;
+   if (init_console()) {
+      console_users--;
+      return 1;
+   }
 
    /* Initialise the console switching system */
    set_display_switch_mode (SWITCH_PAUSE);
@@ -287,8 +291,9 @@
  */
 int __al_linux_leave_console(void)
 {
-   ASSERT (console_users > 0);
-   console_users--;
+   if (console_users > 0) console_users--;
+   else return 1;
+
    if (console_users > 0) return 0;
 
    /* shut down the console switching system */
Index: src/linux/fbcon.c
===================================================================
--- src/linux/fbcon.c	(revision 5763)
+++ src/linux/fbcon.c	(working copy)
@@ -219,7 +219,11 @@
    if (_safe_gfx_mode_change) tries = -1;
    else tries = 0;
 
-   __al_linux_console_graphics();
+   if (__al_linux_console_graphics() != 0) {
+      ioctl(fbfd, FBIOPUT_VSCREENINFO, &orig_mode);
+      close(fbfd);
+      return NULL;
+   }
 
    for (; tries<3; tries++) {
       TRACE(PREFIX_I "...try number %d...\n", tries);


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