Deleted Added
full compact
kern_descrip.c (37951) kern_descrip.c (41086)
1/*
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94
1/*
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94
39 * $Id: kern_descrip.c,v 1.54 1998/07/15 06:10:16 bde Exp $
39 * $Id: kern_descrip.c,v 1.55 1998/07/29 17:38:13 bde Exp $
40 */
41
42#include "opt_compat.h"
43#include "opt_devfs.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/sysproto.h>

--- 18 unchanged lines hidden (view full) ---

66#include <vm/vm_extern.h>
67
68#ifdef DEVFS
69#include <sys/devfsext.h>
70#endif /*DEVFS*/
71
72static MALLOC_DEFINE(M_FILEDESC, "file desc", "Open file descriptor table");
73MALLOC_DEFINE(M_FILE, "file", "Open file structure");
40 */
41
42#include "opt_compat.h"
43#include "opt_devfs.h"
44
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/sysproto.h>

--- 18 unchanged lines hidden (view full) ---

66#include <vm/vm_extern.h>
67
68#ifdef DEVFS
69#include <sys/devfsext.h>
70#endif /*DEVFS*/
71
72static MALLOC_DEFINE(M_FILEDESC, "file desc", "Open file descriptor table");
73MALLOC_DEFINE(M_FILE, "file", "Open file structure");
74static MALLOC_DEFINE(M_SIGIO, "sigio", "sigio structures");
74
75
76static d_open_t fdopen;
77#define NUMFDESC 64
78
79#define CDEV_MAJOR 22
80static struct cdevsw fildesc_cdevsw =
81 { fdopen, noclose, noread, nowrite,

--- 170 unchanged lines hidden (view full) ---

252 if (!error)
253 return (0);
254 fp->f_flag &= ~FNONBLOCK;
255 tmp = 0;
256 (void) (*fp->f_ops->fo_ioctl)(fp, FIONBIO, (caddr_t)&tmp, p);
257 return (error);
258
259 case F_GETOWN:
75
76
77static d_open_t fdopen;
78#define NUMFDESC 64
79
80#define CDEV_MAJOR 22
81static struct cdevsw fildesc_cdevsw =
82 { fdopen, noclose, noread, nowrite,

--- 170 unchanged lines hidden (view full) ---

253 if (!error)
254 return (0);
255 fp->f_flag &= ~FNONBLOCK;
256 tmp = 0;
257 (void) (*fp->f_ops->fo_ioctl)(fp, FIONBIO, (caddr_t)&tmp, p);
258 return (error);
259
260 case F_GETOWN:
260 if (fp->f_type == DTYPE_SOCKET) {
261 p->p_retval[0] = ((struct socket *)fp->f_data)->so_pgid;
262 return (0);
263 }
264 error = (*fp->f_ops->fo_ioctl)
261 error = (*fp->f_ops->fo_ioctl)
265 (fp, TIOCGPGRP, (caddr_t)p->p_retval, p);
266 p->p_retval[0] = - p->p_retval[0];
262 (fp, FIOGETOWN, (caddr_t)p->p_retval, p);
267 return (error);
268
269 case F_SETOWN:
263 return (error);
264
265 case F_SETOWN:
270 if (fp->f_type == DTYPE_SOCKET) {
271 ((struct socket *)fp->f_data)->so_pgid = uap->arg;
272 return (0);
273 }
274 if (uap->arg <= 0) {
275 uap->arg = -uap->arg;
276 } else {
277 struct proc *p1 = pfind(uap->arg);
278 if (p1 == 0)
279 return (ESRCH);
280 uap->arg = p1->p_pgrp->pg_id;
281 }
282 return ((*fp->f_ops->fo_ioctl)
266 return ((*fp->f_ops->fo_ioctl)
283 (fp, TIOCSPGRP, (caddr_t)&uap->arg, p));
267 (fp, FIOSETOWN, (caddr_t)&uap->arg, p));
284
285 case F_SETLKW:
286 flg |= F_WAIT;
287 /* Fall into F_SETLK */
288
289 case F_SETLK:
290 if (fp->f_type != DTYPE_VNODE)
291 return (EBADF);

--- 69 unchanged lines hidden (view full) ---

361 fp->f_count++;
362 if (new > fdp->fd_lastfile)
363 fdp->fd_lastfile = new;
364 *retval = new;
365 return (0);
366}
367
368/*
268
269 case F_SETLKW:
270 flg |= F_WAIT;
271 /* Fall into F_SETLK */
272
273 case F_SETLK:
274 if (fp->f_type != DTYPE_VNODE)
275 return (EBADF);

--- 69 unchanged lines hidden (view full) ---

345 fp->f_count++;
346 if (new > fdp->fd_lastfile)
347 fdp->fd_lastfile = new;
348 *retval = new;
349 return (0);
350}
351
352/*
353 * If sigio is on the list associated with a process or process group,
354 * disable signalling from the device, remove sigio from the list and
355 * free sigio.
356 */
357void
358funsetown(sigio)
359 struct sigio *sigio;
360{
361 int s;
362
363 if (sigio == NULL)
364 return;
365 s = splhigh();
366 *(sigio->sio_myref) = NULL;
367 splx(s);
368 if (sigio->sio_pgid < 0) {
369 SLIST_REMOVE(&sigio->sio_pgrp->pg_sigiolst, sigio,
370 sigio, sio_pgsigio);
371 } else /* if ((*sigiop)->sio_pgid > 0) */ {
372 SLIST_REMOVE(&sigio->sio_proc->p_sigiolst, sigio,
373 sigio, sio_pgsigio);
374 }
375 crfree(sigio->sio_ucred);
376 FREE(sigio, M_SIGIO);
377}
378
379/* Free a list of sigio structures. */
380void
381funsetownlst(sigiolst)
382 struct sigiolst *sigiolst;
383{
384 struct sigio *sigio;
385
386 while ((sigio = sigiolst->slh_first) != NULL)
387 funsetown(sigio);
388}
389
390/*
391 * This is common code for FIOSETOWN ioctl called by fcntl(fd, F_SETOWN, arg).
392 *
393 * After permission checking, add a sigio structure to the sigio list for
394 * the process or process group.
395 */
396int
397fsetown(pgid, sigiop)
398 pid_t pgid;
399 struct sigio **sigiop;
400{
401 struct proc *proc = NULL;
402 struct pgrp *pgrp = NULL;
403 struct sigio *sigio;
404 int s;
405
406 if (pgid == 0) {
407 funsetown(*sigiop);
408 return (0);
409 } else if (pgid > 0) {
410 proc = pfind(pgid);
411 if (proc == NULL)
412 return (ESRCH);
413 /*
414 * Policy - Don't allow a process to FSETOWN a process
415 * in another session.
416 *
417 * Remove this test to allow maximum flexibility or
418 * restrict FSETOWN to the current process or process
419 * group for maximum safety.
420 */
421 else if (proc->p_session != curproc->p_session)
422 return (EPERM);
423 } else /* if (pgid < 0) */ {
424 pgrp = pgfind(-pgid);
425 if (pgrp == NULL)
426 return (ESRCH);
427 /*
428 * Policy - Don't allow a process to FSETOWN a process
429 * in another session.
430 *
431 * Remove this test to allow maximum flexibility or
432 * restrict FSETOWN to the current process or process
433 * group for maximum safety.
434 */
435 else if (pgrp->pg_session != curproc->p_session)
436 return (EPERM);
437 }
438 funsetown(*sigiop);
439 MALLOC(sigio, struct sigio *, sizeof(struct sigio), M_SIGIO,
440 M_WAITOK);
441 if (pgid > 0) {
442 SLIST_INSERT_HEAD(&proc->p_sigiolst, sigio, sio_pgsigio);
443 sigio->sio_proc = proc;
444 } else {
445 SLIST_INSERT_HEAD(&pgrp->pg_sigiolst, sigio, sio_pgsigio);
446 sigio->sio_pgrp = pgrp;
447 }
448 sigio->sio_pgid = pgid;
449 crhold(curproc->p_ucred);
450 sigio->sio_ucred = curproc->p_ucred;
451 /* It would be convenient if p_ruid was in ucred. */
452 sigio->sio_ruid = curproc->p_cred->p_ruid;
453 sigio->sio_myref = sigiop;
454 s = splhigh();
455 *sigiop = sigio;
456 splx(s);
457 return (0);
458}
459
460/*
461 * This is common code for FIOGETOWN ioctl called by fcntl(fd, F_GETOWN, arg).
462 */
463pid_t
464fgetown(sigio)
465 struct sigio *sigio;
466{
467 return (sigio != NULL ? sigio->sio_pgid : 0);
468}
469
470/*
369 * Close a file descriptor.
370 */
371#ifndef _SYS_SYSPROTO_H_
372struct close_args {
373 int fd;
374};
375#endif
376/* ARGSUSED */

--- 832 unchanged lines hidden ---
471 * Close a file descriptor.
472 */
473#ifndef _SYS_SYSPROTO_H_
474struct close_args {
475 int fd;
476};
477#endif
478/* ARGSUSED */

--- 832 unchanged lines hidden ---