Subject: Re: Console Magic redux
To: None <cgd@sibyte.com, eeh@netbsd.org>
From: None <eeh@netbsd.org>
List: tech-kern
Date: 11/14/2000 17:35:38
Wow!  Someone actually read this!

	eeh@netbsd.org writes:
	> int
	> cn_isconsole(dev_t dev);
	> 
	> This routine takes a dev_t and returns non-zero if that is the console device.
	> It can be overridden in MD header files if needed.

	Where exactly would this be used?

This is used by cn_check_magic().

	typically code for drivers which are capable of being the console also
	keep a flag around to note that fact.  I'd think that accessing a
	global (via a macro) to test this fairly often would be a lose --
	esp. if the alternative is checking a flag in a flags word defined in
	the softc, that may be needed for other work anyway.

It defaults to comparing the `dev' to the value of `cn_tab->cn_dev' but
you can override it to do anything you want.

	> void
	> cn_check_magic(dev_t dev, int k, cnm_state_t);
	> 
	> It uses cn_isconsole() to determine if this device is the console or on part
	> of the console input stream.  If so, it checks the key sequence (k) to see if
	> it matches the the magic sequence.  If there is a match, it calls cn_trap().

	I guess i'm not sure why this needs to be invoked for anything but the
	console device, to begin with.

It uses cn_isconsole() to determine if it is the console device.
The driver could determine that beforehand but that seems like
a bit of a waste.

	> kern.cnmagic sysctl variable will be added.  This takes a
	> string.  cn_set_magic() will be used to convert kern.cnmagic to an internal
	> representation.

	is there any reason to skimp on letters, in the user-visible name
	here?  to me, it unnecessarily obscures the usage of the variable.

O.K.  Name suggestions?

	If i understand what you're proposing properly, it's kind of annoying
	for users who want to use BREAK to have to set it using ESC C-A...  i
	mean, that's probably the most common value desired (since it's the
	current default), and it seems a shame to make it ... quite so weird.

The encoding was quite arbitrary.  Since we could use any of 
the 255 byte values as well as some values that are not part
of the character stream, something needs to be escaped.  This
seemed to be the simplest method.  Things get much nastier when
you're using a keyboard, because the values tested are keycodes
not ASCII.  For instance, `L1-A' becomes "\01\115".

I had originally planned to be able to set the magic sequence
to a regular expression so you can define it for a set of different
devices all at the same time.  However, this quickly became complex
so I decided to go with a simpler solution for the time being.  

I'm not particularly married to this implementation, but trying
to use regular expressions to match binary input streams is...
interesting.


Eduardo