Move socket & pipe specific logic in their ioctl handler.
authormpi <mpi@openbsd.org>
Tue, 10 Jul 2018 08:58:50 +0000 (08:58 +0000)
committermpi <mpi@openbsd.org>
Tue, 10 Jul 2018 08:58:50 +0000 (08:58 +0000)
ok visa@, tb@

sys/kern/kern_descrip.c
sys/kern/sys_generic.c
sys/kern/sys_pipe.c
sys/kern/sys_socket.c

index c45cb20..831d801 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_descrip.c,v 1.176 2018/07/07 16:14:40 visa Exp $ */
+/*     $OpenBSD: kern_descrip.c,v 1.177 2018/07/10 08:58:50 mpi Exp $  */
 /*     $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $       */
 
 /*
@@ -484,14 +484,6 @@ restart:
                break;
 
        case F_GETOWN:
-               if (fp->f_type == DTYPE_SOCKET) {
-                       *retval = ((struct socket *)fp->f_data)->so_pgid;
-                       break;
-               }
-               if (fp->f_type == DTYPE_PIPE) {
-                       *retval = ((struct pipe *)fp->f_data)->pipe_pgid;
-                       break;
-               }
                tmp = 0;
                error = (*fp->f_ops->fo_ioctl)
                        (fp, TIOCGPGRP, (caddr_t)&tmp, p);
@@ -500,21 +492,9 @@ restart:
 
        case F_SETOWN:
                tmp = (long)SCARG(uap, arg);
-               if (fp->f_type == DTYPE_SOCKET) {
-                       struct socket *so = fp->f_data;
-
-                       so->so_pgid = tmp;
-                       so->so_siguid = p->p_ucred->cr_ruid;
-                       so->so_sigeuid = p->p_ucred->cr_uid;
-                       break;
-               }
-               if (fp->f_type == DTYPE_PIPE) {
-                       struct pipe *mpipe = fp->f_data;
-
-                       mpipe->pipe_pgid = tmp;
-                       break;
-               }
-               if (tmp <= 0) {
+               if (fp->f_type == DTYPE_SOCKET || fp->f_type == DTYPE_PIPE) {
+                       /* nothing */
+               } else if (tmp <= 0) {
                        tmp = -tmp;
                } else {
                        struct process *pr1 = prfind(tmp);
index f8c1635..9af308c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: sys_generic.c,v 1.119 2018/05/08 08:53:41 mpi Exp $   */
+/*     $OpenBSD: sys_generic.c,v 1.120 2018/07/10 08:58:50 mpi Exp $   */
 /*     $NetBSD: sys_generic.c,v 1.24 1996/03/29 00:25:32 cgd Exp $     */
 
 /*
@@ -389,7 +389,7 @@ sys_ioctl(struct proc *p, void *v, register_t *retval)
                syscallarg(void *) data;
        } */ *uap = v;
        struct file *fp;
-       struct filedesc *fdp;
+       struct filedesc *fdp = p->p_fd;
        u_long com = SCARG(uap, com);
        int error = 0;
        u_int size;
@@ -398,7 +398,6 @@ sys_ioctl(struct proc *p, void *v, register_t *retval)
 #define STK_PARAMS     128
        long long stkbuf[STK_PARAMS / sizeof(long long)];
 
-       fdp = p->p_fd;
        if ((fp = fd_getfile_mode(fdp, SCARG(uap, fd), FREAD|FWRITE)) == NULL)
                return (EBADF);
 
@@ -478,16 +477,10 @@ sys_ioctl(struct proc *p, void *v, register_t *retval)
 
        case FIOSETOWN:
                tmp = *(int *)data;
-               if (fp->f_type == DTYPE_SOCKET) {
-                       struct socket *so = fp->f_data;
 
-                       so->so_pgid = tmp;
-                       so->so_siguid = p->p_ucred->cr_ruid;
-                       so->so_sigeuid = p->p_ucred->cr_uid;
-                       error = 0;
-                       break;
-               }
-               if (tmp <= 0) {
+               if (fp->f_type == DTYPE_SOCKET || fp->f_type == DTYPE_PIPE) {
+                       /* nothing */
+               } else if (tmp <= 0) {
                        tmp = -tmp;
                } else {
                        struct process *pr = prfind(tmp);
@@ -502,11 +495,6 @@ sys_ioctl(struct proc *p, void *v, register_t *retval)
                break;
 
        case FIOGETOWN:
-               if (fp->f_type == DTYPE_SOCKET) {
-                       error = 0;
-                       *(int *)data = ((struct socket *)fp->f_data)->so_pgid;
-                       break;
-               }
                error = (*fp->f_ops->fo_ioctl)(fp, TIOCGPGRP, data, p);
                *(int *)data = -*(int *)data;
                break;
index b1a6c51..f3cf0fa 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: sys_pipe.c,v 1.81 2018/06/18 09:15:05 mpi Exp $       */
+/*     $OpenBSD: sys_pipe.c,v 1.82 2018/07/10 08:58:50 mpi Exp $       */
 
 /*
  * Copyright (c) 1996 John S. Dyson
@@ -665,6 +665,8 @@ pipe_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p)
                *(int *)data = mpipe->pipe_buffer.cnt;
                return (0);
 
+       case TIOCSPGRP:
+               /* FALLTHROUGH */
        case SIOCSPGRP:
                mpipe->pipe_pgid = *(int *)data;
                return (0);
@@ -673,6 +675,10 @@ pipe_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p)
                *(int *)data = mpipe->pipe_pgid;
                return (0);
 
+       case TIOCGPGRP:
+               *(int *)data = -mpipe->pipe_pgid;
+               break;
+
        }
        return (ENOTTY);
 }
index 8bf77eb..01e0ced 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: sys_socket.c,v 1.38 2018/06/06 06:55:22 mpi Exp $     */
+/*     $OpenBSD: sys_socket.c,v 1.39 2018/07/10 08:58:50 mpi Exp $     */
 /*     $NetBSD: sys_socket.c,v 1.13 1995/08/12 23:59:09 mycroft Exp $  */
 
 /*
@@ -109,12 +109,18 @@ soo_ioctl(struct file *fp, u_long cmd, caddr_t data, struct proc *p)
                *(int *)data = so->so_rcv.sb_datacc;
                break;
 
+       case TIOCSPGRP:
+               /* FALLTHROUGH */
        case SIOCSPGRP:
                so->so_pgid = *(int *)data;
                so->so_siguid = p->p_ucred->cr_ruid;
                so->so_sigeuid = p->p_ucred->cr_uid;
                break;
 
+       case TIOCGPGRP:
+               *(int *)data = -so->so_pgid;
+               break;
+
        case SIOCGPGRP:
                *(int *)data = so->so_pgid;
                break;