Bug#392237: tleds: no leds in X with kernel 2.6.18 [PATCH]
The last patch, implementing usage of X in tleds as started task, had a problem: if a user logged off gdm then tleds would get a SIGPIPE. That has to do with xbase-clients' handling of I/O errors and that is corrected in the attached patch. But this is only for the sake of completion, because using X has 3 big problems: 1. You are now dependent on xbase-clients and Xlib.h 2. The NumLock LED doesn't work 3. If no one is logged on the X there are no LEDs working: you have to be logged on for the interface to work. diff -Naur tleds-1.05beta10-orig/Makefile tleds-1.05beta10/Makefile --- tleds-1.05beta10-orig/Makefile 2006-10-10 15:20:26.0 -0500 +++ tleds-1.05beta10/Makefile 2007-01-09 10:18:42.0 -0600 @@ -22,8 +22,8 @@ # in the source code. tleds: tleds.c Makefile # Making tleds - gcc -DNO_X_SUPPORT $(GCCOPTS) -o tleds_20 tleds.c - gcc -DNO_X_SUPPORT -DKERNEL2_1 $(GCCOPTS) -o tleds_21 tleds.c + gcc $(GCCOPTS) -o tleds_20 tleds.c -I /usr/X11R6/include/ -L /usr/X11R6/lib/ -lX11 + gcc -DKERNEL2_1 $(GCCOPTS) -o tleds_21 tleds.c -I /usr/X11R6/include/ -L /usr/X11R6/lib/ -lX11 help: # make help - this. diff -Naur tleds-1.05beta10-orig/tleds.c tleds-1.05beta10/tleds.c --- tleds-1.05beta10-orig/tleds.c 2006-10-10 15:20:26.0 -0500 +++ tleds-1.05beta10/tleds.c2007-01-11 10:17:44.0 -0600 @@ -43,6 +43,11 @@ * E. Hull (1999-08-20, 1999-05-14) for cleaner shutdown, security fixes to * the PID handling, use of daemon for backgrounding, and the -n option. */ +/* Modified extensively by HVW (2006-01-08) to eliminate the NO_X_SUPPORT + * and use X to flash the LEDs if the -x option is given. + * This because in kernel > 2.6.17 LEDs would not work in X without the X api-use. + * The displays are attempted to be opened and are used, all by the daemon. */ + #define VERSION"1.05beta10" #define MYNAME "tleds" @@ -56,13 +61,6 @@ #define KERNEL2_0 1 #endif -/* If you don't want X stuff. */ -#ifdef NO_X_SUPPORT -#define REMOVE_X_CODE 1 -#else -#define REMOVE_X_CODE 0 -#endif - #include #include #include @@ -71,12 +69,7 @@ #include #include #include -#if (! REMOVE_X_CODE) #include -#else -#define LedModeOff 0 -#define LedModeOn 1 -#endif #include #include #include @@ -88,6 +81,9 @@ #include /* needed by getfd and friends to support console deallocating */ #include +#include +#include +#include #ifndef TRUE #define TRUE 1 @@ -97,6 +93,7 @@ #define KEYBOARDDEVICE "/dev/console" #define CURRENTTTY "/dev/tty0" #define MAXVT 64 +#define MAXDISPLAYS2 #define NETDEVFILENAME "/proc/net/dev" #define TERMINATESTR "Program (and child) terminated.\n" #define DEEPSLEEP 10 @@ -128,6 +125,16 @@ ulong detach_vt_leds(int tty, int wantDetach); char *find_device_line(char *buffer, char *netDeviceName); inline int find_max_VT(); + +void opendisplays(); +void closedisplays(); +void changekeyboardcontrol( unsigned long, XKeyboardControl* ); +void xsync(Bool); +Bool was_at_least_five_secs_ago(); +static int sync_handler(Display *display); +static int CKC_handler(Display *display); +void do_print_it (char *vsname, ...); + pid_t get_old_pid(); pid_t get_own_pid(char *fileName); int get_sleeptime(int isDefinedByUser, char *interfaceName); @@ -159,24 +166,26 @@ int getfd(); /* Global and static variables */ +jmp_buf sync_buf; +jmp_buf CKC_buf; + static const char devFileName[] = NETDEVFILENAME; static char pidFileName[30] = ""; /* 30 should be enough */ static char rootPidFileName[30] = ""; -#if (! REMOVE_X_CODE) -static Display *myDisplay = NULL; +static Display *myDisplay[MAXDISPLAYS]; +FILE *stream; +static int handling_display = -1; +static int (*old_xioerror_handler)(Display *) = NULL; -#else -static char *myDisplay = NULL; - -#endif static int keyboardDevice = 0; +static long int last_time; static char ttyLEDs[MAXVT] = {}; static ushort previousActive = (ushort) (MAXVT + 1); static int remindVTcoef = 0; static int opt_b = FALSE, opt_d = FALSE, opt_h = FALSE, opt_k = FALSE, opt_q -= FALSE, opt_v = FALSE, opt_V = FALSE, opt_c = FALSE, opt_n = FALSE; += FALSE, opt_v = FALSE, opt_V = FALSE, opt_c = FALSE, opt_n = FALSE, opt_x = FALSE; static int inled = NUMLOCKLED, outled = SCROLLLOCKLED; /* The code */ @@ -184,7 +193,7 @@ { char *interfaceName; char buffer[MAXLEN]; -ulong ledVal; +//ulong ledVal; char *tmpPointer; char **list; pid_t pid; @@ -192,6 +201,13 @@ int wasInDeepSleep; struct timeval sleeptimeval; +struct timeval t0; +int n; + +int i; +for (i=0; i] \n", name); printf("Example: %s -d 300 ppp0\n", name); -printf("Options:\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", +printf("Options:\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", "\t-b\tDon't go to the background.", "\t-c\tFix the CapsLE
Bug#392237: tleds: no leds in X with kernel 2.6.18 [PATCH][SOLVED]
A better way to resolve the problem (when a user is not in a VT there are no LEDs displayed from tleds, in kernels >= 2.6.18) was suggested by Bauke Jan Douma: use the HID input event interface. It is documented here: http://www.frogmouth.net/hid-doco/linux-hid.html That I have now done that by adding an '-e' option. In that case /dev/input is searched for input devices that support LEDs and the right kind of LEDs and if so write to those devices with plain write instead of using the ioctl interface. The patch is attached. It solves the problem: although I found few users who reported the problem. Now the latest kernel (2.6.19.2) causes no problems displaying LEDs in X. Hugo diff -Naur tleds-1.05beta10-orig/tleds.c tleds-1.05beta10/tleds.c --- tleds-1.05beta10-orig/tleds.c 2006-10-10 15:20:26.0 -0500 +++ tleds-1.05beta10/tleds.c2007-01-15 08:45:12.0 -0600 @@ -43,6 +43,13 @@ * E. Hull (1999-08-20, 1999-05-14) for cleaner shutdown, security fixes to * the PID handling, use of daemon for backgrounding, and the -n option. */ +/* Added the -e option to use the HID interface instead of the conioctl + * interface. This incase the LEDs don't function in X. Only as root. + * 01/14/07 - began changes: writes but no LEds + + */ + + #define VERSION"1.05beta10" #define MYNAME "tleds" @@ -89,6 +96,18 @@ /* needed by getfd and friends to support console deallocating */ #include +#include +#include +#include +#include +#include +#include +#include +#define BASICDIR "/dev/input" +#define NOINPUTDEVICES 20 +#define MAX_STR_LEN 256 +#define test_bit(bit, array)(array[bit/8] & (1<<(bit%8))) + #ifndef TRUE #define TRUE 1 #define FALSE 0 @@ -158,6 +177,20 @@ /* from kbd-0.99, needed to support console deallocating */ int getfd(); +int device_has_leds(char *device); +int device_has_ncs_locks(char *device); +void my_write(int * fd_array, char ** start_array, const void *buf, size_t count); +void my_fflush(int * fd_array, char ** start_array, const void *buf, size_t count); +void close_it(int * fd_array, char ** start_array); +void free_it(int * fd_array, char ** start_array); +int find_devices(void); +int open_the_devices(void); +void hid_led(int what, LedMode mode, ActionMode doAction); +void do_log_it(char *vsname, ...); + +char ** start_array; +int * fd_array; + /* Global and static variables */ static const char devFileName[] = NETDEVFILENAME; static char pidFileName[30] = ""; /* 30 should be enough */ @@ -176,7 +209,8 @@ static ushort previousActive = (ushort) (MAXVT + 1); static int remindVTcoef = 0; static int opt_b = FALSE, opt_d = FALSE, opt_h = FALSE, opt_k = FALSE, opt_q -= FALSE, opt_v = FALSE, opt_V = FALSE, opt_c = FALSE, opt_n = FALSE; += FALSE, opt_v = FALSE, opt_V = FALSE, opt_c = FALSE, opt_n = FALSE, +opt_e = FALSE; static int inled = NUMLOCKLED, outled = SCROLLLOCKLED; /* The code */ @@ -190,8 +224,12 @@ pid_t pid; int sleeptime; int wasInDeepSleep; + +int num_devs; + struct timeval sleeptimeval; + interfaceName = NULL; sleeptime = 0; check_kernel_version();/* May die here */ @@ -236,8 +274,10 @@ "Maybe later there will be. Kill me (-k) if ya want."); } +do_log_it("Before daemon %d %s\n",__LINE__,__FILE__); if (!opt_b) { if (-1 == daemon(0, (geteuid() != 0))) { + do_log_it("Daemon failure! %d %s\n",__LINE__,__FILE__); perror("tleds: daemon"); return 1; } @@ -250,11 +290,13 @@ (opt_b ? "fore" : "back"), (long) pid); } +do_log_it("Running in %sground. Pid: %ld\n",(opt_b ? "fore" : "back"),(long) pid); if (atexit(my_exit)) { perror("tleds: atexit() failed"); return 1; } if (!opt_b) { + do_log_it("parent_wants_me_dead! %d %s\n",__LINE__,__FILE__); signal(SIGUSR1, parent_wants_me_dead); } signal(SIGHUP, SIG_IGN); @@ -265,9 +307,27 @@ signal(SIGUSR2, SIG_IGN); signal(SIGPIPE, my_signal_handler); if (!geteuid()) { /* We are running as EUID root - CONSOLE */ - if (-1 == (keyboardDevice = open(KEYBOARDDEVICE, O_RDONLY))) { + if ( opt_e ) { + num_devs=find_devices(); + printf("%d keyboards found\n",num_devs); + do_log_it("%d keyboards found\n",num_devs); + if (num_devs == 0) { + do_log_it("exit %d %s\n",__LINE__,__FILE__); + exit(1); + } + if ( open_the_devices() == 1 ) { + printf("Open error\n"); + do_log_it("Open error\n"); + if ( num_devs > 0 ) + free_it(fd_array, start_array); + do_log_it("exit %d %s\n",__LINE__,__FILE__); + exit(1); + } + } + else if (-1 == (keyboardDevice = open
Bug#392237: tleds: no leds in X with kernel 2.6.18 [PATCH]
On 1/9/07, Julien Danjou <[EMAIL PROTECTED]> wrote: At 1168289040 time_t, hugo vanwoerkom wrote: Hi Hugo, > I changed the tleds code to get LED display of net traffic in X. > > I added an option '-x' that would if used, open the available X > displays and flask the LEDs. > > Bug#50842 now into its seventh year, prevents the NumLock LED from > working, so under X the LEDs work as if the -n option is specified. > > The diff file is attached. I tried your patch. I'm not yet very familiar with tled, but at first glance, I just installed tleds 1.05beta10-10 and my LEDs are blinking :) And your patch does not change anything for me (with -x it does not work). I'm running xorg 7.1 with on kernel 2.6.18-3-k7. What are you using ? Hi Julien, This is a strange one all right. I am using 2.6.18 from kernel.org or 2.6.19.1-ck2 or 2.6.17.14-ck1. To summarize again: the issue is running tleds as a Debian started task and having the LEDs blink when in a VT text console *and* also when in X. Going back to last October 2006 I noticed that when I ran a kernel >= 2.6.18 the LEDs blinked in VT text consoles but *not* when in X. I posted various times to LDU and I must say that nobody can verify this. E.g. http://lists.debian.org/debian-user/2006/10/msg01036.html http://lists.debian.org/debian-user/2007/01/msg00773.html http://lists.debian.org/debian-user/2007/01/msg00774.html Yet, I have tried the kernel you use on Sid, with xorg 7.1 and the LEDs definitely do *not* blink in X and *do* blink in a VT. So now the tleds change. Tleds goes back a while. In its present Debian version it essentially has 2 modes of operating: as root and as non-root. As root it opens /dev/console and uses ioctl's to set the LEDs based on traffic. As non-root it can run in X and use the xbase-clients API to set the LEDs. To get this to work you have to recompile without the -DNO_X_SUPPORT option. But the above does away with the Debian started task of course. So I added a -x option that will use the X API when it finds displays openable, based on the MAXDISPLAYS define. Yet, the problem only seems to occur on my box. I have the latest Sid installed, but run xorg 7.1 to support 2 simultaneous users (I have 2 Nvidia cards/Xservers/mice/keyboards/monitors). But is all just Sid. As I indicated in the addendum to 392237 bug#50842 prevents both the NumLock LED *and* the ScrollLock LED from operating in X: that bug is now more than 7 years old and means that 'xset led' will *only* turn on the ScrollLock LED. So in X tleds works as if the -n option is used: that is a Debian change to operate only the latter LED. I'll CC this to 392237 just for the record. If I can do anything else let me know. I appreciate you attention. Hugo -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Bug#392237: tleds: no leds in X with kernel 2.6.18 [PATCH]
At 1168289040 time_t, hugo vanwoerkom wrote: Hi Hugo, > I changed the tleds code to get LED display of net traffic in X. > > I added an option '-x' that would if used, open the available X > displays and flask the LEDs. > > Bug#50842 now into its seventh year, prevents the NumLock LED from > working, so under X the LEDs work as if the -n option is specified. > > The diff file is attached. I tried your patch. I'm not yet very familiar with tled, but at first glance, I just installed tleds 1.05beta10-10 and my LEDs are blinking :) And your patch does not change anything for me (with -x it does not work). I'm running xorg 7.1 with on kernel 2.6.18-3-k7. What are you using ? Cheers, -- Julien Danjou .''`. Debian Developer : :' : http://julien.danjou.info `. `' http://people.debian.org/~acid `- 9A0D 5FD9 EB42 22F6 8974 C95C A462 B51E C2FE E5CD signature.asc Description: Digital signature
Bug#392237: tleds: no leds in X with kernel 2.6.18 [PATCH]
I changed the tleds code to get LED display of net traffic in X. I added an option '-x' that would if used, open the available X displays and flask the LEDs. Bug#50842 now into its seventh year, prevents the NumLock LED from working, so under X the LEDs work as if the -n option is specified. The diff file is attached. Hugo diff -Naur tleds-1.05beta10-orig/Makefile tleds-1.05beta10/Makefile --- tleds-1.05beta10-orig/Makefile 2006-10-10 15:20:26.0 -0500 +++ tleds-1.05beta10/Makefile 2007-01-08 13:27:21.0 -0600 @@ -22,8 +22,8 @@ # in the source code. tleds: tleds.c Makefile # Making tleds - gcc -DNO_X_SUPPORT $(GCCOPTS) -o tleds_20 tleds.c - gcc -DNO_X_SUPPORT -DKERNEL2_1 $(GCCOPTS) -o tleds_21 tleds.c + gcc $(GCCOPTS) -o tleds_20 tleds.c -I /usr/X11R6/include/ -L /usr/X11R6/lib/ -lX11 + gcc -DKERNEL2_1 $(GCCOPTS) -o tleds_21 tleds.c -I /usr/X11R6/include/ -L /usr/X11R6/lib/ -lX11 help: # make help - this. diff -Naur tleds-1.05beta10-orig/tleds.c tleds-1.05beta10/tleds.c --- tleds-1.05beta10-orig/tleds.c 2006-10-10 15:20:26.0 -0500 +++ tleds-1.05beta10/tleds.c2007-01-08 13:45:26.0 -0600 @@ -43,6 +43,11 @@ * E. Hull (1999-08-20, 1999-05-14) for cleaner shutdown, security fixes to * the PID handling, use of daemon for backgrounding, and the -n option. */ +/* Modified extensively by HVW (2006-01-08) to eliminate the NO_X_SUPPORT + * and use X to flash the LEDs if the -x option is given. + * This because in kernel > 2.6.17 LEDs would not work in X without the X api-use. + * The displays are attempted to be opened and are used, all by the daemon. */ + #define VERSION"1.05beta10" #define MYNAME "tleds" @@ -56,13 +61,6 @@ #define KERNEL2_0 1 #endif -/* If you don't want X stuff. */ -#ifdef NO_X_SUPPORT -#define REMOVE_X_CODE 1 -#else -#define REMOVE_X_CODE 0 -#endif - #include #include #include @@ -71,12 +69,7 @@ #include #include #include -#if (! REMOVE_X_CODE) #include -#else -#define LedModeOff 0 -#define LedModeOn 1 -#endif #include #include #include @@ -97,6 +90,7 @@ #define KEYBOARDDEVICE "/dev/console" #define CURRENTTTY "/dev/tty0" #define MAXVT 64 +#define MAXDISPLAYS2 #define NETDEVFILENAME "/proc/net/dev" #define TERMINATESTR "Program (and child) terminated.\n" #define DEEPSLEEP 10 @@ -128,6 +122,13 @@ ulong detach_vt_leds(int tty, int wantDetach); char *find_device_line(char *buffer, char *netDeviceName); inline int find_max_VT(); + +void opendisplays(); +void closedisplays(); +void changekeyboardcontrol( unsigned long, XKeyboardControl* ); +void xsync(Bool); +Bool was_at_least_five_secs_ago(); + pid_t get_old_pid(); pid_t get_own_pid(char *fileName); int get_sleeptime(int isDefinedByUser, char *interfaceName); @@ -163,20 +164,17 @@ static char pidFileName[30] = ""; /* 30 should be enough */ static char rootPidFileName[30] = ""; -#if (! REMOVE_X_CODE) -static Display *myDisplay = NULL; - -#else -static char *myDisplay = NULL; +static Display *myDisplay[MAXDISPLAYS]; +FILE *stream; -#endif static int keyboardDevice = 0; +static long int last_time; static char ttyLEDs[MAXVT] = {}; static ushort previousActive = (ushort) (MAXVT + 1); static int remindVTcoef = 0; static int opt_b = FALSE, opt_d = FALSE, opt_h = FALSE, opt_k = FALSE, opt_q -= FALSE, opt_v = FALSE, opt_V = FALSE, opt_c = FALSE, opt_n = FALSE; += FALSE, opt_v = FALSE, opt_V = FALSE, opt_c = FALSE, opt_n = FALSE, opt_x = FALSE; static int inled = NUMLOCKLED, outled = SCROLLLOCKLED; /* The code */ @@ -184,7 +182,7 @@ { char *interfaceName; char buffer[MAXLEN]; -ulong ledVal; +//ulong ledVal; char *tmpPointer; char **list; pid_t pid; @@ -192,6 +190,10 @@ int wasInDeepSleep; struct timeval sleeptimeval; +int i; +for (i=0; i] \n", name); printf("Example: %s -d 300 ppp0\n", name); -printf("Options:\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", +printf("Options:\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n", "\t-b\tDon't go to the background.", "\t-c\tFix the CapsLED in VTs. Only for EUID root.", "\t-d N\tSet update delay.", "\t\tN must be between 1 and 1 (milliseconds)", "\t-h\tHelp. (this)", "\t-k\tKill (old) (x)tleds running.", + "\t-n\tUse only ScrollLock LED.", + "\t-x\tAlso use X to flash LEDs.", "\t-q\tBe quiet.", "\t-v\tPrint version information.", "\t\t(`cat /proc/net/dev` to see your interfaces.)"); @@ -971,6 +951,112 @@ } /* End (almost) verbatim copy of kbd-0.99's getfd.c */ + + +void opendisplays(void) +{ +//XSetErrorHandler(X_error_handler); // but these don't do anything for XOpen +//XSetIOErrorHandler(X_IO_error_handler); // ... + +in
Bug#392237: tleds: no leds in X with kernel 2.6.18
On Tue, Nov 14, 2006 at 10:24:39AM -0600, hugo vanwoerkom wrote: > If kernel 2.6.18 ships with Etch and this tleds version ships with it > also then there will be no leds shown in X, as opposed to 2.6.17 where > they do show. > > I have entered this bug on Oct. 10th 2006 but the maintainer does not > answer. I saw that bug, I have simply no idea for now where it comes from neither time to take a look on it. Help welcomed. Cheers, -- Julien Danjou .''`. Debian Developer : :' : http://julien.danjou.info `. `' http://people.debian.org/~acid `- 9A0D 5FD9 EB42 22F6 8974 C95C A462 B51E C2FE E5CD signature.asc Description: Digital signature
Bug#392237: tleds: no leds in X with kernel 2.6.18
If kernel 2.6.18 ships with Etch and this tleds version ships with it also then there will be no leds shown in X, as opposed to 2.6.17 where they do show. I have entered this bug on Oct. 10th 2006 but the maintainer does not answer. Be forewarned! Hugo Vanwoerkom -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]