diff options
author | Gaius Mulley <gaiusmod2@gmail.com> | 2023-05-16 15:51:53 +0100 |
---|---|---|
committer | Gaius Mulley <gaiusmod2@gmail.com> | 2023-05-16 15:51:53 +0100 |
commit | cf4dcfa6727b89362494bd49e2a28ebd10d767ce (patch) | |
tree | a2b1162ce4f3c6ea6e6f97c47a3c277505ce0f76 /libgm2 | |
parent | 057e537e2a6f0fead3ebb503c8dcc08c9c6491ec (diff) | |
download | gcc-cf4dcfa6727b89362494bd49e2a28ebd10d767ce.zip gcc-cf4dcfa6727b89362494bd49e2a28ebd10d767ce.tar.gz gcc-cf4dcfa6727b89362494bd49e2a28ebd10d767ce.tar.bz2 |
PR modula2/108344 disable default opening of /dev/tty
This patch changes removes the static initialisation code for KeyBoardLEDs.cc.
The module is only initialised if one of the exported functions is called.
This is useful as the module will access /dev/tty which might not be
available. TimerHandler.mod has also been changed to disable the scroll
lock LED as a sign of life.
gcc/m2/ChangeLog:
PR modula2/108344
* gm2-libs-coroutines/TimerHandler.mod (EnableLED): New constant.
(Timer): Test EnableLED before switching on the scroll LED.
libgm2/ChangeLog:
PR modula2/108344
* libm2cor/KeyBoardLEDs.cc (initialize_module): New function.
(SwitchScroll): Call initialize_module.
(SwitchNum): Call initialize_module.
(SwitchCaps): Call initialize_module.
(SwitchLEDs): Call initialize_module.
(M2EXPORT): Remove initialization code.
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Diffstat (limited to 'libgm2')
-rw-r--r-- | libgm2/libm2cor/KeyBoardLEDs.cc | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/libgm2/libm2cor/KeyBoardLEDs.cc b/libgm2/libm2cor/KeyBoardLEDs.cc index 8d2b50b..32f4c0c 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 |