Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys cleanup & uniform descriptor owner handling:



details:   https://anonhg.NetBSD.org/src/rev/a21e2b13600d
branches:  trunk
changeset: 552213:a21e2b13600d
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Sun Sep 21 19:16:48 2003 +0000

description:
cleanup & uniform descriptor owner handling:
* introduce fsetown(), fgetown(), fownsignal() - this sets/retrieves/signals
  the owner of descriptor, according to appropriate sematics
  of TIOCSPGRP/FIOSETOWN/SIOCSPGRP/TIOCGPGRP/FIOGETOWN/SIOCGPGRP ioctl; use
  these routines instead of custom code where appropriate
* make every place handling TIOCSPGRP/TIOCGPGRP handle also FIOSETOWN/FIOGETOWN
  properly, and remove the translation of FIO[SG]OWN to TIOC[SG]PGRP
  in sys_ioctl() & sys_fcntl()
* also remove the socket-specific hack in sys_ioctl()/sys_fcntl() and
  pass the ioctls down to soo_ioctl() as any other ioctl

change discussed on tech-kern@

diffstat:

 sys/arch/amiga/dev/kbd.c             |  10 ++-
 sys/arch/amiga/dev/ms.c              |   9 ++-
 sys/arch/atari/dev/kbd.c             |  10 ++-
 sys/arch/atari/dev/ms.c              |   9 ++-
 sys/arch/x68k/dev/kbd.c              |  10 ++-
 sys/arch/x68k/dev/ms.c               |  10 ++-
 sys/compat/netbsd32/netbsd32_ioctl.c |  35 +------------
 sys/dev/mm.c                         |   6 +-
 sys/dev/sun/kbd.c                    |  10 ++-
 sys/dev/sun/ms.c                     |  10 ++-
 sys/dev/usb/uhid.c                   |  12 +++-
 sys/dev/wscons/wskbd.c               |  12 +++-
 sys/dev/wscons/wsmouse.c             |  12 +++-
 sys/dev/wscons/wsmux.c               |  12 +++-
 sys/kern/kern_descrip.c              |  98 +++++++++++++++++++++++++++--------
 sys/kern/subr_log.c                  |  33 +++--------
 sys/kern/sys_generic.c               |  45 ++--------------
 sys/kern/sys_pipe.c                  |  47 +++++-----------
 sys/kern/sys_socket.c                |  14 ++--
 sys/kern/tty.c                       |  33 +++++++++++-
 sys/kern/uipc_socket2.c              |  24 ++-----
 sys/net/bpf.c                        |  34 ++---------
 sys/net/if_tun.c                     |  53 ++++++------------
 sys/net/if_tun.h                     |   4 +-
 sys/sys/file.h                       |   6 +-
 25 files changed, 293 insertions(+), 265 deletions(-)

diffs (truncated from 1262 to 300 lines):

diff -r 353bdc6c96a3 -r a21e2b13600d sys/arch/amiga/dev/kbd.c
--- a/sys/arch/amiga/dev/kbd.c  Sun Sep 21 19:01:05 2003 +0000
+++ b/sys/arch/amiga/dev/kbd.c  Sun Sep 21 19:16:48 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kbd.c,v 1.45 2003/08/07 16:26:42 agc Exp $ */
+/*     $NetBSD: kbd.c,v 1.46 2003/09/21 19:16:48 jdolecek Exp $ */
 
 /*
  * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kbd.c,v 1.45 2003/08/07 16:26:42 agc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kbd.c,v 1.46 2003/09/21 19:16:48 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -491,6 +491,12 @@
                        k->k_events.ev_async = *(int *)data != 0;
                        return 0;
 
+               case FIOSETOWN:
+                       if (-*(int *)data != k->k_events.ev_io->p_pgid
+                           && *(int *)data != k->k_events.ev_io->p_pid)
+                               return EPERM;
+                       return 0;
+
                case TIOCSPGRP:
                        if (*(int *)data != k->k_events.ev_io->p_pgid)
                                return EPERM;
diff -r 353bdc6c96a3 -r a21e2b13600d sys/arch/amiga/dev/ms.c
--- a/sys/arch/amiga/dev/ms.c   Sun Sep 21 19:01:05 2003 +0000
+++ b/sys/arch/amiga/dev/ms.c   Sun Sep 21 19:16:48 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ms.c,v 1.26 2003/08/07 16:26:42 agc Exp $ */
+/*     $NetBSD: ms.c,v 1.27 2003/09/21 19:16:49 jdolecek Exp $ */
 
 /*
  * based on:
@@ -45,7 +45,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.26 2003/08/07 16:26:42 agc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.27 2003/09/21 19:16:49 jdolecek Exp $");
 
 /*
  * Mouse driver.
@@ -419,6 +419,11 @@
        case FIOASYNC:
                ms->ms_events.ev_async = *(int *)data != 0;
                return(0);
+       case FIOSETOWN:
+               if (-*(int *)data != ms->ms_events.ev_io->p_pgid
+                   && *(int *)data != ms->ms_events.ev_io->p_pid)
+                       return(EPERM);
+               return(0);
        case TIOCSPGRP:
                if (*(int *)data != ms->ms_events.ev_io->p_pgid)
                        return(EPERM);
diff -r 353bdc6c96a3 -r a21e2b13600d sys/arch/atari/dev/kbd.c
--- a/sys/arch/atari/dev/kbd.c  Sun Sep 21 19:01:05 2003 +0000
+++ b/sys/arch/atari/dev/kbd.c  Sun Sep 21 19:16:48 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kbd.c,v 1.26 2003/08/07 16:27:01 agc Exp $     */
+/*     $NetBSD: kbd.c,v 1.27 2003/09/21 19:16:52 jdolecek Exp $        */
 
 /*
  * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kbd.c,v 1.26 2003/08/07 16:27:01 agc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kbd.c,v 1.27 2003/09/21 19:16:52 jdolecek Exp $");
 
 #include "mouse.h"
 #include "ite.h"
@@ -367,6 +367,12 @@
                        k->k_events.ev_async = *(int *)data != 0;
                                return 0;
 
+               case FIOSETOWN:
+                       if (-*(int *)data != k->k_events.ev_io->p_pgid
+                           && *(int *)data != k->k_events.ev_io->p_pid)
+                               return EPERM;
+                       return 0;
+
                case TIOCSPGRP:
                        if (*(int *)data != k->k_events.ev_io->p_pgid)
                                return EPERM;
diff -r 353bdc6c96a3 -r a21e2b13600d sys/arch/atari/dev/ms.c
--- a/sys/arch/atari/dev/ms.c   Sun Sep 21 19:01:05 2003 +0000
+++ b/sys/arch/atari/dev/ms.c   Sun Sep 21 19:16:48 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ms.c,v 1.14 2003/08/07 16:27:02 agc Exp $      */
+/*     $NetBSD: ms.c,v 1.15 2003/09/21 19:16:52 jdolecek Exp $ */
 
 /*
  * Copyright (c) 1995 Leo Weppelman.
@@ -52,7 +52,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.14 2003/08/07 16:27:02 agc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.15 2003/09/21 19:16:52 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -398,6 +398,11 @@
        case FIOASYNC:
                ms->ms_events.ev_async = *(int *)data != 0;
                return(0);
+       case FIOSETOWN:
+               if (-*(int *)data != ms->ms_events.ev_io->p_pgid
+                   && *(int *)data != ms->ms_events.ev_io->p_pid)
+                       return(EPERM);
+               return(0);
        case TIOCSPGRP:
                if (*(int *)data != ms->ms_events.ev_io->p_pgid)
                        return(EPERM);
diff -r 353bdc6c96a3 -r a21e2b13600d sys/arch/x68k/dev/kbd.c
--- a/sys/arch/x68k/dev/kbd.c   Sun Sep 21 19:01:05 2003 +0000
+++ b/sys/arch/x68k/dev/kbd.c   Sun Sep 21 19:16:48 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kbd.c,v 1.18 2003/08/07 16:30:24 agc Exp $     */
+/*     $NetBSD: kbd.c,v 1.19 2003/09/21 19:16:53 jdolecek Exp $        */
 
 /*
  * Copyright (c) 1982, 1986, 1990 The Regents of the University of California.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kbd.c,v 1.18 2003/08/07 16:30:24 agc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kbd.c,v 1.19 2003/09/21 19:16:53 jdolecek Exp $");
 
 #include "ite.h"
 #include "bell.h"
@@ -280,6 +280,12 @@
                k->sc_events.ev_async = *(int *)data != 0;
                return (0);
 
+       case FIOSETOWN:
+               if (-*(int *)data != k->k_events.ev_io->p_pgid
+                   && *(int *)data != k->k_events.ev_io->p_pid)
+                       return (EPERM);
+               return 0;
+
        case TIOCSPGRP:
                if (*(int *)data != k->sc_events.ev_io->p_pgid)
                        return (EPERM);
diff -r 353bdc6c96a3 -r a21e2b13600d sys/arch/x68k/dev/ms.c
--- a/sys/arch/x68k/dev/ms.c    Sun Sep 21 19:01:05 2003 +0000
+++ b/sys/arch/x68k/dev/ms.c    Sun Sep 21 19:16:48 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ms.c,v 1.18 2003/08/07 16:30:25 agc Exp $ */
+/*     $NetBSD: ms.c,v 1.19 2003/09/21 19:16:53 jdolecek Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.18 2003/08/07 16:30:25 agc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ms.c,v 1.19 2003/09/21 19:16:53 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -305,6 +305,12 @@
                ms->ms_events.ev_async = *(int *)data != 0;
                return (0);
 
+       case FIOSETOWN:
+               if (-*(int *)data != ms->ms_events.ev_io->p_pgid
+                   && *(int *)data != ms->ms_events.ev_io->p_pid)
+                       return (EPERM);
+               return(0);
+
        case TIOCSPGRP:
                if (*(int *)data != ms->ms_events.ev_io->p_pgid)
                        return (EPERM);
diff -r 353bdc6c96a3 -r a21e2b13600d sys/compat/netbsd32/netbsd32_ioctl.c
--- a/sys/compat/netbsd32/netbsd32_ioctl.c      Sun Sep 21 19:01:05 2003 +0000
+++ b/sys/compat/netbsd32/netbsd32_ioctl.c      Sun Sep 21 19:16:48 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: netbsd32_ioctl.c,v 1.20 2003/06/29 22:29:38 fvdl Exp $ */
+/*     $NetBSD: netbsd32_ioctl.c,v 1.21 2003/09/21 19:16:54 jdolecek Exp $     */
 
 /*
  * Copyright (c) 1998, 2001 Matthew R. Green
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: netbsd32_ioctl.c,v 1.20 2003/06/29 22:29:38 fvdl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: netbsd32_ioctl.c,v 1.21 2003/09/21 19:16:54 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -452,37 +452,6 @@
                error = (*fp->f_ops->fo_ioctl)(fp, FIOASYNC, (caddr_t)&tmp, p);
                break;
 
-       case FIOSETOWN:
-               tmp = *(int *)data32;
-               if (fp->f_type == DTYPE_SOCKET) {
-                       ((struct socket *)fp->f_data)->so_pgid = tmp;
-                       error = 0;
-                       break;
-               }
-               if (tmp <= 0) {
-                       tmp = -tmp;
-               } else {
-                       struct proc *p1 = pfind(tmp);
-                       if (p1 == 0) {
-                               error = ESRCH;
-                               break;
-                       }
-                       tmp = p1->p_pgrp->pg_id;
-               }
-               error = (*fp->f_ops->fo_ioctl)
-                       (fp, TIOCSPGRP, (caddr_t)&tmp, p);
-               break;
-
-       case FIOGETOWN:
-               if (fp->f_type == DTYPE_SOCKET) {
-                       error = 0;
-                       *(int *)data32 = ((struct socket *)fp->f_data)->so_pgid;
-                       break;
-               }
-               error = (*fp->f_ops->fo_ioctl)(fp, TIOCGPGRP, data32, p);
-               *(int *)data32 = -*(int *)data32;
-               break;
-
        case DIOCGPART32:
                IOCTL_STRUCT_CONV_TO(DIOCGPART, partinfo);
 #if 0  /* not implemented by anything */
diff -r 353bdc6c96a3 -r a21e2b13600d sys/dev/mm.c
--- a/sys/dev/mm.c      Sun Sep 21 19:01:05 2003 +0000
+++ b/sys/dev/mm.c      Sun Sep 21 19:16:48 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mm.c,v 1.4 2003/06/29 22:30:01 fvdl Exp $      */
+/*     $NetBSD: mm.c,v 1.5 2003/09/21 19:16:55 jdolecek Exp $  */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: mm.c,v 1.4 2003/06/29 22:30:01 fvdl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mm.c,v 1.5 2003/09/21 19:16:55 jdolecek Exp $");
 
 /*
  * Memory special file
@@ -71,6 +71,8 @@
                switch (cmd) {
                case FIONBIO:   /* We never block anyway */
                        return 0;
+               case FIOSETOWN:
+               case FIOGETOWN:
                case TIOCGPGRP:
                case TIOCSPGRP:
                        return ENOTTY;
diff -r 353bdc6c96a3 -r a21e2b13600d sys/dev/sun/kbd.c
--- a/sys/dev/sun/kbd.c Sun Sep 21 19:01:05 2003 +0000
+++ b/sys/dev/sun/kbd.c Sun Sep 21 19:16:48 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kbd.c,v 1.38 2003/08/07 16:31:24 agc Exp $     */
+/*     $NetBSD: kbd.c,v 1.39 2003/09/21 19:16:56 jdolecek Exp $        */
 
 /*
  * Copyright (c) 1992, 1993
@@ -47,7 +47,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kbd.c,v 1.38 2003/08/07 16:31:24 agc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kbd.c,v 1.39 2003/09/21 19:16:56 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -352,6 +352,12 @@
                k->k_events.ev_async = (*(int *)data != 0);
                break;
 
+       case FIOSETOWN:
+               if (-*(int *)data != k->k_events.ev_io->p_pgid
+                   && *(int *)data != k->k_events.ev_io->p_pid)
+                       error = EPERM;
+               break;
+
        case TIOCSPGRP:
                if (*(int *)data != k->k_events.ev_io->p_pgid)
                        error = EPERM;
diff -r 353bdc6c96a3 -r a21e2b13600d sys/dev/sun/ms.c
--- a/sys/dev/sun/ms.c  Sun Sep 21 19:01:05 2003 +0000



Home | Main Index | Thread Index | Old Index