kern/114033: [patch] COMPAT_43TTY: log all deprecated ioctl's

Ed Schouten ed at fxq.nl
Tue Jun 26 10:00:09 UTC 2007


>Number:         114033
>Category:       kern
>Synopsis:       [patch] COMPAT_43TTY: log all deprecated ioctl's
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jun 26 10:00:08 GMT 2007
>Closed-Date:
>Last-Modified:
>Originator:     Ed Schouten
>Release:        FreeBSD 6.2-STABLE i386
>Organization:
>Environment:
System: FreeBSD palm.hoeg.nl 6.2-STABLE FreeBSD 6.2-STABLE #0: Fri Apr 20 13:44:49 CEST 2007 root at palm.hoeg.nl:/usr/obj/usr/src/sys/PALM i386
>Description:
The last few months I've been sending patches for a lot of Ports to make
them use the termios interface. Almost all patches have been processed,
which means that most machines can live without COMPAT_43TTY nowadays.

We shouldn't remove COMPAT_43TTY yet, because that would go by
unnoticed, which may cause regressions for certain users. That's why we
should add a subtle message to the dmesg, notifying the user that their
application uses outdated ioctl's.

The following testcase was used to generate warnings:

| #include <sgtty.h>
| 
| int
| main(int argc, char *argv[])
| {
|         struct sgttyb a;
|         ioctl(0, TIOCGETP, a);
| }
>How-To-Repeat:
>Fix:
The following patch makes ttcompat() print a warning (up to 10 times)
that the application in question uses ioctl's that are handled by
COMPAT_43TTY.

In order to make the printing of the message accurate (don't print the
message when an unknown ioctl occurs), I had to do some small
refactoring. ttcompat() now first checks whether the ioctl is valid to
determine whether the message should be printed.

--- src/sys/kern/tty.c	2007-06-11 23:05:41.000000000 +0200
+++ src/sys/kern/tty.c	2007-06-26 11:38:15.000000000 +0200
@@ -1262,7 +1262,7 @@
 		return (tt_break(tp, 0));
 	default:
 #if defined(COMPAT_43TTY)
-		return (ttcompat(tp, cmd, data, flag));
+		return (ttcompat(tp, cmd, data, flag, td));
 #else
 		return (ENOIOCTL);
 #endif
--- src/sys/kern/tty_compat.c	2006-01-10 10:19:09.000000000 +0100
+++ src/sys/kern/tty_compat.c	2007-06-26 11:38:15.000000000 +0200
@@ -43,6 +43,7 @@
 #include <sys/ioctl_compat.h>
 #include <sys/tty.h>
 #include <sys/kernel.h>
+#include <sys/proc.h>
 #include <sys/sysctl.h>
 
 static int ttcompatgetflags(struct tty *tp);
@@ -169,9 +170,12 @@
 	return 0;
 }
 
+static int ttcompat_warnings = 0;
+#define NUM_TTCOMPAT_WARNINGS 10
+
 /*ARGSUSED*/
 int
-ttcompat(struct tty *tp, u_long com, caddr_t data, int flag)
+ttcompat(struct tty *tp, u_long com, caddr_t data, int flag, struct thread *td)
 {
 	switch (com) {
 	case TIOCSETP:
@@ -180,6 +184,31 @@
 	case TIOCSLTC:
 	case TIOCLBIS:
 	case TIOCLBIC:
+	case TIOCLSET:
+	case TIOCGETP:
+	case TIOCGETC:
+	case TIOCGLTC:
+	case TIOCLGET:
+	case OTIOCGETD:
+	case OTIOCSETD:
+	case OTIOCCONS:
+		if (ttcompat_warnings++ < NUM_TTCOMPAT_WARNINGS) {
+			/* Warn the user that their app uses an outdated ioctl */
+			printf("Warning: pid %d used deprecated COMPAT_43TTY interface.\n",
+			    td->td_proc->p_pid);
+		}
+		break;
+	default:
+		return (ENOIOCTL);
+	}
+
+	switch (com) {
+	case TIOCSETP:
+	case TIOCSETN:
+	case TIOCSETC:
+	case TIOCSLTC:
+	case TIOCLBIS:
+	case TIOCLBIC:
 	case TIOCLSET: {
 		struct termios term;
 		int error;
@@ -252,7 +281,7 @@
 		return (ttioctl(tp, TIOCCONS, data, flag));
 
 	default:
-		return (ENOIOCTL);
+		panic("Invalid ioctl should have been caught");
 	}
 	return (0);
 }
--- src/sys/sys/tty.h	2006-01-04 10:59:06.000000000 +0100
+++ src/sys/sys/tty.h	2007-06-26 11:38:27.000000000 +0200
@@ -333,7 +333,7 @@
 int	 q_to_b(struct clist *q, char *cp, int cc);
 void	 termioschars(struct termios *t);
 int	 tputchar(int c, struct tty *tp);
-int	 ttcompat(struct tty *tp, u_long com, caddr_t data, int flag);
+int	 ttcompat(struct tty *tp, u_long com, caddr_t data, int flag, struct thread *td);
 int	 ttioctl(struct tty *tp, u_long com, void *data, int flag);
 int	 ttread(struct tty *tp, struct uio *uio, int flag);
 void	 ttrstrt(void *tp);
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list