Bug#504721: Possible reason for serial console misdetection
On Tuesday 02 December 2008, Frans Pop wrote:
> Someone who can actually write in C please check the code and let me
> know if anything can be removed or is missing. I may well have added
> unneeded includes for example and I have no idea what the original
> sprintf statements were supposed to do.
main can probably be safely reduced to:
+int main(int argc, char ** argv)
+{
+ union {
+ struct vt_stat vt;
+ struct serial_struct sr;
+ char paranoia[sizeof(struct serial_struct) * 3];
+ } u;
+
+ if (ioctl(0, TIOCGSERIAL, &u.sr) == 0) {
+ /* this is a serial console */
+ printf("serial\n");
+ } else if (ioctl(0, VT_GETSTATE, &u.vt) == 0) {
+ /* this is linux virtual tty */
+ printf("virtual\n");
+ }
+
+ return 0;
+}
Reply to: