Fix to virtual terminal UTF-8 mode handling
PATCH 1/1 Fix to virtual terminal UTF-8 mode handling
This patch fixes a bug in the virtual terminal driver, whereby the UTF-8 mode is reset to "off" following a console reset, such as might be delivered by mingetty, screen, vim, etc...
Rather than resetting to hardcoded "0", it gets reset on or off, as determined by a new sysctl located in /proc/tty/vt/default_utf8_mode. This patch is best accompanied with an addition of the following line to the system's init scripts:
echo 1 >/proc/tty/vt/default_utf8_mode
Following this, all resets to the console will leave it with UTF-8 mode on.
The default behaviour of this sysctl is as before, without the patch. Namely, UTF-8 mode is switched off on reset. [I.e applying this patch does not affect default behaviour].
--- linux-2.6.11/drivers/char/vt.c 2005-05-04 02:01:08.000000000
+0100 +++ linux-2.6.11-utfswitch/drivers/char/vt.c 2005-05-07
22:41:58.000000000 +0100 @@ -93,6 +93,7 @@
#include <linux/pm.h>
#include <linux/font.h>
#include <linux/bitops.h>
+#include <linux/proc_fs.h>
#include <asm/io.h>
#include <asm/system.h>
@@ -162,6 +163,15 @@
static int blankinterval = 10*60*HZ;
static int vesa_off_interval;
+/*
+ * When resetting a console, do we start in UTF-8 mode or not?
+ * 0 = no, 1 = yes
+ */
+static int default_utf8_mode = 0;
+
+struct proc_dir_entry *proc_vt_dir;
+struct proc_dir_entry *proc_default_utf8_mode;
+
static DECLARE_WORK(console_work, console_callback, NULL);
/*
@@ -1472,7 +1482,7 @@
charset = 0;
need_wrap = 0;
report_mouse = 0;
- utf = 0; + utf = default_utf8_mode; utf_count = 0;
disp_ctrl = 0;
@@ -2530,6 +2540,63 @@
reset_terminal(currcons, do_clear);
}
+static int proc_write_default_utf8_mode(struct file *file, const char *buffer,
+ unsigned long count, void *data)
+{
+ char temp[16];
+ int len;
+
+ if (count > sizeof(temp)-1)
+ len = sizeof(temp)-1;
+ else
+ len = count;
+
+ if (copy_from_user(temp, buffer, len))
+ return -EFAULT;
+
+ temp[len] = 0;
+
+ /* No effect if empty or >1 character long */
+ if (temp[0] == 0 || (temp[1] != '\n' && temp[1] != 0)) {
+ return len;
+ }
+
+ /* No effect if outside the range 0<=x<=1 */
+ if (temp[0] < '0' || temp[0] > '1') {
+ return len;
+ }
+
+ default_utf8_mode = (temp[0] - '0');
+
+ return len;
+}
+
+static int proc_read_default_utf8_mode(char *page, char **start, off_t off,
+ int count, int *eof, void *data)
+{
+ return sprintf(page, "default_utf8_mode = %d\n",default_utf8_mode); +}
+
+static int init_proc(void)
+{
+ proc_vt_dir = proc_mkdir("tty/vt", NULL);
+
+ if (!proc_vt_dir)
+ return -ENOMEM;
+
+ proc_default_utf8_mode = create_proc_entry("default_utf8_mode",
0644, proc_vt_dir); +
+ if (!proc_default_utf8_mode)
+ return -ENOMEM;
+
+ proc_default_utf8_mode->owner = THIS_MODULE;
+ proc_default_utf8_mode->data = &default_utf8_mode;
+ proc_default_utf8_mode->write_proc =proc_write_default_utf8_mode;
+ proc_default_utf8_mode->read_proc = proc_read_default_utf8_mode;
+
+ return 0;
+}
+
/*
* This routine initializes console interrupts, and does nothing
* else. If you want the screen to clear, call tty_write with
@@ -2612,6 +2679,8 @@
int __init vty_init(void)
{
+ int ret;
+
vcs_init();
console_driver = alloc_tty_driver(MAX_NR_CONSOLES);
@@ -2638,6 +2707,11 @@
#ifdef CONFIG_MDA_CONSOLE
mda_console_init();
#endif
+
+ ret = init_proc();
+ if (ret)
+ return ret;
+
return 0;
}
Signature · 5 lines
Paul "LeoNerd" Evans [email protected] ICQ# 4135350 | Registered Linux# 179460 http://www.leonerd.org.uk/
Apologies, my mail client annoyingly wrapped the patch; here it is fixed.
drivers/char/vt.c +75 -1
@@ -93,6 +93,7 @@#include <linux/pm.h> #include <linux/font.h> #include <linux/bitops.h> +#include <linux/proc_fs.h> #include <asm/io.h> #include <asm/system.h>
@@ -162,6 +163,15 @@static int blankinterval =10 *60 *HZ ;static int vesa_off_interval; +/* +* When resetting a console, do we start in UTF-8 mode or not? +* 0 = no, 1 = yes +*/ +static int default_utf8_mode =0 ; + +struct proc_dir_entry *proc_vt_dir; +struct proc_dir_entry *proc_default_utf8_mode; + static DECLARE_WORK(console_work, console_callback, NULL);/*
@@ -1472,7 +1482,7 @@ charset =0 ; need_wrap =0 ; report_mouse =0 ; - utf =0 ; + utf = default_utf8_mode; utf_count =0 ; disp_ctrl =0 ;
@@ -2530,6 +2540,63 @@reset_terminal (currcons, do_clear); } +static int proc_write_default_utf8_mode (struct file *file,const char *buffer, +unsigned long count,void *data) +{ +char temp[16 ]; +int len; + +if (count >sizeof (temp)-1 ) + len =sizeof (temp)-1 ; +else + len = count; + +if (copy_from_user (temp, buffer, len)) +return -EFAULT ; + + temp[len] =0 ; + +/* No effect if empty or >1 character long */ +if (temp[0 ] ==0 || (temp[1 ] !='\n' && temp[1 ] !=0 )) { +return len; + } + +/* No effect if outside the range 0<=x<=1 */ +if (temp[0 ] <'0' || temp[0 ] >'1' ) { +return len; + } + + default_utf8_mode = (temp[0 ] -'0' ); + +return len; +} + +static int proc_read_default_utf8_mode (char *page,char **start,off_t off, +int count,int *eof,void *data) +{ +return sprintf (page,"default_utf8_mode = %d\n" , default_utf8_mode); +} + +static int init_proc (void ) +{ + proc_vt_dir =proc_mkdir ("tty/vt" ,NULL ); + +if (!proc_vt_dir) +return -ENOMEM ; + + proc_default_utf8_mode =create_proc_entry ("default_utf8_mode" ,0644 , proc_vt_dir); + +if (!proc_default_utf8_mode) +return -ENOMEM ; + + proc_default_utf8_mode->owner =THIS_MODULE ; + proc_default_utf8_mode->data = &default_utf8_mode; + proc_default_utf8_mode->write_proc = proc_write_default_utf8_mode; + proc_default_utf8_mode->read_proc = proc_read_default_utf8_mode; + +return 0 ; +} +/* * This routine initializes console interrupts, and does nothing * else. If you want the screen to clear, call tty_write with
@@ -2612,6 +2679,8 @@int __init vty_init (void ) { +int ret; +vcs_init (); console_driver =alloc_tty_driver (MAX_NR_CONSOLES );
@@ -2638,6 +2707,11 @@#ifdef CONFIG_MDA_CONSOLE mda_console_init ();#endif + + ret =init_proc (); +if (ret) +return ret; +return 0 ; }
Signature · 5 lines
Paul "LeoNerd" Evans [email protected] ICQ# 4135350 | Registered Linux# 179460 http://www.leonerd.org.uk/
Quoted 4 lines · Paul LeoNerd Evans
This patch fixes a bug in the virtual terminal driver, whereby the UTF-8 mode is reset to "off" following a console reset, such as might be delivered by mingetty, screen, vim, etc...
Is it a bug? What did earlier kernels do? 2.4.x?
Quoted 5 lines
Rather than resetting to hardcoded "0", it gets reset on or off, as determined by a new sysctl located in
/proc/tty/vt/default_utf8_mode. This patch is best accompanied with an addition of the following line to the system's init scripts:
Quoted 8 lines
echo 1 >/proc/tty/vt/default_utf8_mode
Following this, all resets to the console will leave it with UTF-8 mode on.
The default behaviour of this sysctl is as before, without the patch. Namely, UTF-8 mode is switched off on reset. [I.e applying this patch does not affect default behaviour].
Presumably userspace knows what mode the user wants the terminal to be using. Shouldn't userspace be resetting that mode after a reset?
Quoted 7 lines · Andrew Morton
Quoted 4 lines · Paul LeoNerd Evans
This patch fixes a bug in the virtual terminal driver, whereby the UTF-8 mode is reset to "off" following a console reset, such as might be delivered by mingetty, screen, vim, etc...
Is it a bug? What did earlier kernels do? 2.4.x?
I'd be inclined to think that this is more of a terminfo issue. If you want your terminal to reset into UTF-8, use a terminfo entry with the appropriate command string instead of the current one - this would be the 'rs1' capability:
rs1=\Ec\E]R
That's reset console to default, reset palette.
Quoted 2 lines
Presumably userspace knows what mode the user wants the terminal to be using. Shouldn't userspace be resetting that mode after a reset?
There's no standard way to represent this in userspace. But yeah.
Signature · 2 lines
Daniel Jacobowitz CodeSourcery, LLC
Quoted 8 lines · On Tue, 17 May 2005 23:10:30 -0400 Daniel Jacobowitz <[email protected]> wrote:
I'd be inclined to think that this is more of a terminfo issue. If you want your terminal to reset into UTF-8, use a terminfo entry with the appropriate command string instead of the current one - this would be the 'rs1' capability:
rs1=\Ec\E]R
That's reset console to default, reset palette.
Unfortunately, that doesn't work. Doing it that way means that any program running on a host whose terminfo is so configured, would force UTF-8 mode on, when it issues a reset to a Linux console, regardless of which machine that is on (e.g. telnet, ssh,...). Furthermore, it would do so regardless of whether we want UTF-8 mode, or not. Again with my patch it is a user configurable matter whether they want UTF-8 or not. This terminfo entry forces it to happen.
That said, I am planning a whole bunch of other changes to terminfo; my repeated wrestling with xterm recently on the regard of modified cursor keys (e.g. Ctrl+left) has lead me to conclude the whole system needs a bit of an overhaul... But that's somewhat off-topic to the kernel.. :)
Signature · 5 lines
Paul "LeoNerd" Evans [email protected] ICQ# 4135350 | Registered Linux# 179460 http://www.leonerd.org.uk/
Quoted 7 lines · On Tue, 17 May 2005 19:58:48 -0700 Andrew Morton <[email protected]> wrote:
Quoted 4 lines · Paul LeoNerd Evans
This patch fixes a bug in the virtual terminal driver, whereby the
UTF-8 mode is reset to "off" following a console reset, such as might be delivered by mingetty, screen, vim, etc...Is it a bug? What did earlier kernels do? 2.4.x?
I haven't checked earlier 2.4 kernels, but I know the 2.6 ones have done this for quite some time; a good year or so at least.
Quoted 2 lines
Presumably userspace knows what mode the user wants the terminal to be using. Shouldn't userspace be resetting that mode after a reset?
Well, that does require changes to a lot of the programs that talk to the console, moreover, they now need to be sensitive to whether it is in UTF-8 mode, where previously they did not. E.g. consider mingetty...
Also, as I understand it, there is one keyboard map, and one console font for the entire virtual console system - either they are UTF-8, or not. It doesn't really make sense to be switching these about.
Moreover, this code also affects dynamic creation of new virtual consoles. E.g. when debian's "oh no, I can't start the X server" ncurses dialog appears, without my patch it prints UTF-8 characters on a new console, tty8, on a console that isn't set to display them, and mass breakage results. Now, it all happens cleanly, because the new console is already in UTF-8 mode.
Were this to be pushed to userland, every program that outputs data would need to detect the UTF-8 mode of the console, and set it appropriately. Moreover, they would need to perform this logic only on a Linux virtual console; such things as XTerm or Gnome-terminal do it automatically.
Signature · 5 lines
Paul "LeoNerd" Evans [email protected] ICQ# 4135350 | Registered Linux# 179460 http://www.leonerd.org.uk/