gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Latest GM2 binaries try to open /dev/tty (which is not always avaiab


From: Gaius Mulley
Subject: Re: Latest GM2 binaries try to open /dev/tty (which is not always avaiable!)
Date: Tue, 16 May 2023 13:42:55 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

Rudolf Schubert <rudolf@muc.de> writes:

> Hi Gaius,
>
> I recently noticed that my cgi 'stops before it really starts'.
> In the web server's error log I find this line:
>
> unable to open /dev/tty: No such device or address
>
> So I made an strace and near program start I find this line:
>
> openat(AT_FDCWD, "/dev/tty", O_RDONLY)  = 3
>
> I did not change my code so this behaviour must have been introduced by
> some change in other places. Is there an 'urgent' reason for this change?

Hi Rudolf,

many thanks for the email.  I'm not yet sure of why a recent change
opens /dev/tty, however I did apply a bool/int patch to KeyBoardLEDs.cc
which is suspicious...  I've revisited that code (and also
TimerHandler.mod) and changed these modules to no longer open /dev/tty
(for LED switching diagnostics).

Anyway here is a patch - which I'll apply if the bootstrap is
successful.  I'm curious if the patch fixes the bug you've reported.
I'm slightly optimistic that the patch might also fix regression test
timeouts which have been reported by other users (but alas I don't see
on my testing infrastructure)

regards,
Gaius

diff --git a/gcc/m2/gm2-libs-coroutines/TimerHandler.mod 
b/gcc/m2/gm2-libs-coroutines/TimerHandler.mod
index d3dee319ca1..1285873486d 100644
--- a/gcc/m2/gm2-libs-coroutines/TimerHandler.mod
+++ b/gcc/m2/gm2-libs-coroutines/TimerHandler.mod
@@ -41,8 +41,9 @@ CONST
    MaxQuantum     =     4 ;   (* Maximum ticks a process may consume    *)
                               (* before being rescheduled.              *)
    BaseTicks      = 1000000 ; (* Max resolution of clock ticks per sec  *)
-   TimerStackSize = 100000H ; (* Reasonable sized stack for a process  *)
-   Debugging      =  FALSE ;  (* Do you want lots of debugging info?   *)
+   TimerStackSize = 100000H ; (* Reasonable sized stack for a process   *)
+   Debugging      =  FALSE ;  (* Do you want lots of debugging info?    *)
+   EnableLED      =  FALSE ;  (* Should the scroll LED be pulsed?       *)
 
 TYPE
    EVENT = POINTER TO RECORD
@@ -328,21 +329,23 @@ BEGIN
       (* Now compenstate for lost ticks *)
       StartClock (TimerIntNo, CurrentCount + (BaseTicks DIV TicksPerSecond)) ;
 
-      (* your code needs to go here *)
-      INC (TotalTicks) ;                                     (* (iii) *)    (* 
remove for student *)
-      (* now pulse scroll LED *)                                            (* 
remove for student *)
-      IF (TotalTicks MOD TicksPerSecond) = 0                                (* 
remove for student *)
-      THEN                                                                  (* 
remove for student *)
-         ScrollLED := NOT ScrollLED ;                                       (* 
remove for student *)
-         (* r := printf("<scroll %d>", TotalTicks); *)
-         SwitchScroll(ScrollLED)                             (* (iv)  *)    (* 
remove for student *)
-      END ;                                                                 (* 
remove for student *)
-      IF (TotalTicks MOD MaxQuantum) = 0                                    (* 
remove for student *)
-      THEN                                                                  (* 
remove for student *)
-         RotateRunQueue                                      (* (ii)  *)    (* 
remove for student *)
-      END ;                                                                 (* 
remove for student *)
-
-      CheckActiveQueue                                       (* (i)   *)    (* 
remove for student *)
+      INC (TotalTicks) ;                                     (* (iii) *)
+      IF EnableLED
+      THEN
+         (* now pulse scroll LED *)
+         IF (TotalTicks MOD TicksPerSecond) = 0
+         THEN
+            ScrollLED := NOT ScrollLED ;
+            (* r := printf("<scroll %d>", TotalTicks); *)
+            SwitchScroll(ScrollLED)                          (* (iv)  *)
+         END
+      END ;
+      IF (TotalTicks MOD MaxQuantum) = 0
+      THEN
+         RotateRunQueue                                      (* (ii)  *)
+      END ;
+
+      CheckActiveQueue                                       (* (i)   *)
    END
 END Timer ;
 
diff --git a/libgm2/libm2cor/KeyBoardLEDs.cc b/libgm2/libm2cor/KeyBoardLEDs.cc
index 8d2b50bf99e..32f4c0ce711 100644
--- a/libgm2/libm2cor/KeyBoardLEDs.cc
+++ b/libgm2/libm2cor/KeyBoardLEDs.cc
@@ -46,10 +46,27 @@ static int fd;
 static bool initialized = false;
 
 
+void
+initialize_module (void)
+{
+  if (! initialized)
+    {
+      initialized = true;
+      fd = open ("/dev/tty", O_RDONLY);
+      if (fd == -1)
+       {
+         perror ("unable to open /dev/tty");
+         exit (1);
+       }
+    }
+}
+
 extern "C" void
 EXPORT(SwitchScroll) (int scrolllock)
 {
   unsigned char leds;
+
+  initialize_module ();
   int r = ioctl (fd, KDGETLED, &leds);
   if (scrolllock)
     leds = leds | LED_SCR;
@@ -62,6 +79,8 @@ extern "C" void
 EXPORT(SwitchNum) (int numlock)
 {
   unsigned char leds;
+
+  initialize_module ();
   int r = ioctl (fd, KDGETLED, &leds);
   if (numlock)
     leds = leds | LED_NUM;
@@ -74,6 +93,8 @@ extern "C" void
 EXPORT(SwitchCaps) (int capslock)
 {
   unsigned char leds;
+
+  initialize_module ();
   int r = ioctl (fd, KDGETLED, &leds);
   if (capslock)
     leds = leds | LED_CAP;
@@ -93,16 +114,6 @@ EXPORT(SwitchLeds) (int numlock, int capslock, int 
scrolllock)
 extern "C" void
 M2EXPORT(init) (int, char **, char **)
 {
-  if (! initialized)
-    {
-      initialized = true;
-      fd = open ("/dev/tty", O_RDONLY);
-      if (fd == -1)
-       {
-         perror ("unable to open /dev/tty");
-         exit (1);
-       }
-    }
 }
 
 #else

reply via email to

[Prev in Thread] Current Thread [Next in Thread]