From owner-freebsd-bugs@FreeBSD.ORG Tue Jun 26 10:00:09 2007 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8CE2D16A468 for ; Tue, 26 Jun 2007 10:00:09 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [69.147.83.40]) by mx1.freebsd.org (Postfix) with ESMTP id 6556313C46A for ; Tue, 26 Jun 2007 10:00:09 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id l5QA09ov019583 for ; Tue, 26 Jun 2007 10:00:09 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id l5QA09Dk019578; Tue, 26 Jun 2007 10:00:09 GMT (envelope-from gnats) Resent-Date: Tue, 26 Jun 2007 10:00:09 GMT Resent-Message-Id: <200706261000.l5QA09Dk019578@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Ed Schouten Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id CAE1016A400 for ; Tue, 26 Jun 2007 09:51:21 +0000 (UTC) (envelope-from ed@hoeg.nl) Received: from palm.hoeg.nl (mx0.hoeg.nl [83.98.131.211]) by mx1.freebsd.org (Postfix) with ESMTP id 60B8913C43E for ; Tue, 26 Jun 2007 09:51:21 +0000 (UTC) (envelope-from ed@hoeg.nl) Received: by palm.hoeg.nl (Postfix, from userid 1000) id 39BBF1CC28; Tue, 26 Jun 2007 11:51:20 +0200 (CEST) Message-Id: <20070626095120.39BBF1CC28@palm.hoeg.nl> Date: Tue, 26 Jun 2007 11:51:20 +0200 (CEST) From: Ed Schouten To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: kern/114033: [patch] COMPAT_43TTY: log all deprecated ioctl's X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Ed Schouten List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 Jun 2007 10:00:09 -0000 >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@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 | | 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 #include #include +#include #include 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: