From 5ac46f4a009be3bdcce4d951fbd0eed1cac71377 Mon Sep 17 00:00:00 2001 From: niklas Date: Sun, 3 Mar 1996 17:19:36 +0000 Subject: [PATCH] From NetBSD: 960217 merge --- sys/kern/exec_aout.c | 4 +- sys/kern/exec_elf.c | 18 +- sys/kern/exec_script.c | 7 +- sys/kern/init_main.c | 24 +- sys/kern/kern_acct.c | 7 +- sys/kern/kern_clock.c | 14 +- sys/kern/kern_descrip.c | 42 +++- sys/kern/kern_exec.c | 42 ++-- sys/kern/kern_exit.c | 39 ++-- sys/kern/kern_fork.c | 14 +- sys/kern/kern_ktrace.c | 17 +- sys/kern/kern_lkm.c | 126 ++++++----- sys/kern/kern_malloc.c | 10 +- sys/kern/kern_physio.c | 7 +- sys/kern/kern_proc.c | 13 +- sys/kern/kern_prot.c | 36 ++- sys/kern/kern_resource.c | 14 +- sys/kern/kern_sig.c | 32 ++- sys/kern/kern_synch.c | 28 ++- sys/kern/kern_sysctl.c | 48 ++-- sys/kern/kern_time.c | 25 ++- sys/kern/kern_xxx.c | 7 +- sys/kern/subr_autoconf.c | 8 +- sys/kern/subr_log.c | 20 +- sys/kern/subr_prof.c | 12 +- sys/kern/subr_rmap.c | 15 +- sys/kern/sys_generic.c | 45 +++- sys/kern/sys_process.c | 12 +- sys/kern/sysv_msg.c | 21 +- sys/kern/sysv_sem.c | 26 ++- sys/kern/sysv_shm.c | 52 +++-- sys/kern/tty.c | 90 ++++---- sys/kern/tty_compat.c | 472 --------------------------------------- sys/kern/tty_conf.c | 7 +- sys/kern/tty_subr.c | 20 +- sys/kern/tty_tb.c | 195 +++++++++------- sys/kern/tty_tty.c | 11 +- sys/kern/uipc_domain.c | 5 +- sys/kern/uipc_mbuf.c | 17 +- sys/kern/uipc_proto.c | 12 +- sys/kern/uipc_socket.c | 81 ++++--- sys/kern/uipc_socket2.c | 25 ++- sys/kern/uipc_syscalls.c | 177 ++++++++------- sys/kern/uipc_usrreq.c | 14 +- sys/kern/vfs_cache.c | 9 +- sys/kern/vfs_cluster.c | 9 +- sys/kern/vfs_lockf.c | 19 +- sys/kern/vfs_lookup.c | 14 +- sys/kern/vfs_vnops.c | 40 +++- 49 files changed, 955 insertions(+), 1047 deletions(-) delete mode 100644 sys/kern/tty_compat.c diff --git a/sys/kern/exec_aout.c b/sys/kern/exec_aout.c index 7b84aafde96..3a13bd0711c 100644 --- a/sys/kern/exec_aout.c +++ b/sys/kern/exec_aout.c @@ -1,4 +1,5 @@ -/* $NetBSD: exec_aout.c,v 1.13 1994/08/01 18:49:49 pk Exp $ */ +/* $OpenBSD: exec_aout.c,v 1.2 1996/03/03 17:19:36 niklas Exp $ */ +/* $NetBSD: exec_aout.c,v 1.14 1996/02/04 02:15:01 christos Exp $ */ /* * Copyright (c) 1993, 1994 Christopher G. Demetriou @@ -87,7 +88,6 @@ exec_aout_makecmds(p, epp) if (error) kill_vmcmds(&epp->ep_vmcmds); -bad: return error; } diff --git a/sys/kern/exec_elf.c b/sys/kern/exec_elf.c index e065eef5152..a32eaabe1b5 100644 --- a/sys/kern/exec_elf.c +++ b/sys/kern/exec_elf.c @@ -1,4 +1,5 @@ -/* $NetBSD: exec_elf.c,v 1.4 1996/01/16 23:07:18 fvdl Exp $ */ +/* $OpenBSD: exec_elf.c,v 1.3 1996/03/03 17:19:37 niklas Exp $ */ +/* $NetBSD: exec_elf.c,v 1.6 1996/02/09 18:59:18 christos Exp $ */ /* * Copyright (c) 1994 Christos Zoulas @@ -55,7 +56,8 @@ #include #endif -int (*elf_probe_funcs[])() = { +int (*elf_probe_funcs[]) __P((struct proc *, struct exec_package *, + char *, u_long *)) = { #ifdef COMPAT_SVR4 svr4_elf_probe, #endif @@ -64,6 +66,10 @@ int (*elf_probe_funcs[])() = { #endif }; +int elf_check_header __P((Elf32_Ehdr *, int)); +int elf_load_file __P((struct proc *, char *, struct exec_vmcmd_set *, + u_long *, struct elf_args *, u_long *)); + static int elf_read_from __P((struct proc *, struct vnode *, u_long, caddr_t, int)); static void elf_load_psection __P((struct exec_vmcmd_set *, @@ -492,6 +498,14 @@ exec_elf_makecmds(p, epp) } } + /* + * If no position to load the interpreter was set by a probe + * function, pick the same address that a non-fixed mmap(0, ..) + * would (i.e. something safely out of the way). + */ + if (pos == ELF32_NO_ADDR) + pos = round_page(epp->ep_daddr + MAXDSIZ); + /* * Check if we found a dynamically linked binary and arrange to load * it's interpreter diff --git a/sys/kern/exec_script.c b/sys/kern/exec_script.c index dfd1a405f00..fea8f4cf23d 100644 --- a/sys/kern/exec_script.c +++ b/sys/kern/exec_script.c @@ -1,4 +1,5 @@ -/* $NetBSD: exec_script.c,v 1.12 1995/04/10 18:27:59 mycroft Exp $ */ +/* $OpenBSD: exec_script.c,v 1.2 1996/03/03 17:19:38 niklas Exp $ */ +/* $NetBSD: exec_script.c,v 1.13 1996/02/04 02:15:06 christos Exp $ */ /* * Copyright (c) 1993, 1994 Christopher G. Demetriou @@ -105,6 +106,7 @@ exec_script_makecmds(p, epp) shellname = NULL; shellarg = NULL; + shellarglen = 0; /* strip spaces before the shell name */ for (cp = hdrstr + EXEC_SCRIPT_MAGICLEN; *cp == ' ' || *cp == '\t'; @@ -134,7 +136,6 @@ exec_script_makecmds(p, epp) * behaviour. */ shellarg = cp; - shellarglen = 0; for ( /* cp = cp */ ; *cp != '\0'; cp++) shellarglen++; *cp++ = '\0'; @@ -263,7 +264,9 @@ check_shell: /* XXX oldpnbuf not set for "goto fail" path */ epp->ep_ndp->ni_cnd.cn_pnbuf = oldpnbuf; +#ifdef FDSCRIPTS fail: +#endif /* note that we've clobbered the header */ epp->ep_flags |= EXEC_DESTR; diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index f439beda980..64a05f5d3e7 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -1,4 +1,5 @@ -/* $NetBSD: init_main.c,v 1.80 1996/01/07 22:03:47 thorpej Exp $ */ +/* $OpenBSD: init_main.c,v 1.4 1996/03/03 17:19:39 niklas Exp $ */ +/* $NetBSD: init_main.c,v 1.82 1996/02/09 18:59:21 christos Exp $ */ /* * Copyright (c) 1995 Christopher G. Demetriou. All rights reserved. @@ -62,6 +63,18 @@ #include #include #include +#include +#ifdef SYSVSHM +#include +#endif +#ifdef SYSVSEM +#include +#endif +#ifdef SYSVMSG +#include +#endif +#include +#include #include #include @@ -71,6 +84,10 @@ #include #include +#include + +#include +#include char copyright[] = "Copyright (c) 1982, 1986, 1989, 1991, 1993\n\tThe Regents of the University of California. All rights reserved.\n\n"; @@ -96,6 +113,7 @@ struct timeval runtime; static void start_init __P((struct proc *)); static void start_pagedaemon __P((struct proc *)); +void main __P((void *)); #ifdef cpu_set_init_frame void *initframep; /* XXX should go away */ @@ -131,7 +149,7 @@ struct emul emul_netbsd = { * hard work is done in the lower-level initialization routines including * startup(), which does memory initialization and autoconfiguration. */ -int +void main(framep) void *framep; /* XXX should go away */ { @@ -380,7 +398,7 @@ start_init(p) int options, i, error; register_t retval[2]; char flags[4], *flagsp; - char **pathp, *path, *ucp, **uap, *arg0, *arg1; + char **pathp, *path, *ucp, **uap, *arg0, *arg1 = NULL; /* * Now in process 1. diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c index 3a999f0806b..c371c085046 100644 --- a/sys/kern/kern_acct.c +++ b/sys/kern/kern_acct.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_acct.c,v 1.41 1995/10/07 06:28:07 mycroft Exp $ */ +/* $OpenBSD: kern_acct.c,v 1.2 1996/03/03 17:19:40 niklas Exp $ */ +/* $NetBSD: kern_acct.c,v 1.42 1996/02/04 02:15:12 christos Exp $ */ /*- * Copyright (c) 1994 Christopher G. Demetriou @@ -107,7 +108,7 @@ sys_acct(p, v, retval) int error; /* Make sure that the caller is root. */ - if (error = suser(p->p_ucred, &p->p_acflag)) + if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) return (error); /* @@ -117,7 +118,7 @@ sys_acct(p, v, retval) if (SCARG(uap, path) != NULL) { NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, SCARG(uap, path), p); - if (error = vn_open(&nd, FWRITE, 0)) + if ((error = vn_open(&nd, FWRITE, 0)) != 0) return (error); VOP_UNLOCK(nd.ni_vp); if (nd.ni_vp->v_type != VREG) { diff --git a/sys/kern/kern_clock.c b/sys/kern/kern_clock.c index 5fb3ad112f2..5d689ad163f 100644 --- a/sys/kern/kern_clock.c +++ b/sys/kern/kern_clock.c @@ -1,3 +1,4 @@ +/* $OpenBSD: kern_clock.c,v 1.7 1996/03/03 17:19:41 niklas Exp $ */ /* $NetBSD: kern_clock.c,v 1.23 1995/12/28 19:16:41 thorpej Exp $ */ /*- @@ -64,6 +65,10 @@ #include #include #include +#include +#include +#include +#include #include #include @@ -915,6 +920,7 @@ statclock(frame) /* * Return information about system clocks. */ +int sysctl_clockrate(where, sizep) register char *where; size_t *sizep; @@ -934,10 +940,16 @@ sysctl_clockrate(where, sizep) #ifdef DDB #include +#include #include #include +#include -void db_show_callout(long addr, int haddr, int count, char *modif) +void db_show_callout(addr, haddr, count, modif) + db_expr_t addr; + int haddr; + db_expr_t count; + char *modif; { register struct callout *p1; register int cum; diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 2aac60d9e02..58d5766e496 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_descrip.c,v 1.37 1995/10/07 06:28:09 mycroft Exp $ */ +/* $OpenBSD: kern_descrip.c,v 1.3 1996/03/03 17:19:42 niklas Exp $ */ +/* $NetBSD: kern_descrip.c,v 1.39 1996/02/09 18:59:26 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1991, 1993 @@ -60,13 +61,21 @@ #include #include +#include + +#include + /* * Descriptor management. */ struct filelist filehead; /* head of list of open files */ int nfiles; /* actual number of open files */ -static __inline +static __inline void fd_used __P((struct filedesc *, int)); +static __inline void fd_unused __P((struct filedesc *, int)); +int finishdup __P((struct filedesc *, int, int, register_t *)); + +static __inline void fd_used(fdp, fd) register struct filedesc *fdp; register int fd; @@ -76,7 +85,7 @@ fd_used(fdp, fd) fdp->fd_lastfile = fd; } -static __inline +static __inline void fd_unused(fdp, fd) register struct filedesc *fdp; register int fd; @@ -104,6 +113,7 @@ fd_unused(fdp, fd) * Duplicate a file descriptor. */ /* ARGSUSED */ +int sys_dup(p, v, retval) struct proc *p; void *v; @@ -119,7 +129,7 @@ sys_dup(p, v, retval) if ((u_int)old >= fdp->fd_nfiles || fdp->fd_ofiles[old] == NULL) return (EBADF); - if (error = fdalloc(p, 0, &new)) + if ((error = fdalloc(p, 0, &new)) != 0) return (error); return (finishdup(fdp, old, new, retval)); } @@ -128,6 +138,7 @@ sys_dup(p, v, retval) * Duplicate a file descriptor to a particular value. */ /* ARGSUSED */ +int sys_dup2(p, v, retval) struct proc *p; void *v; @@ -150,7 +161,7 @@ sys_dup2(p, v, retval) return (0); } if (new >= fdp->fd_nfiles) { - if (error = fdalloc(p, new, &i)) + if ((error = fdalloc(p, new, &i)) != 0) return (error); if (new != i) panic("dup2: fdalloc"); @@ -164,6 +175,7 @@ sys_dup2(p, v, retval) * The file control system call. */ /* ARGSUSED */ +int sys_fcntl(p, v, retval) struct proc *p; void *v; @@ -192,7 +204,7 @@ sys_fcntl(p, v, retval) if ((u_int)newmin >= p->p_rlimit[RLIMIT_NOFILE].rlim_cur || (u_int)newmin >= maxfiles) return (EINVAL); - if (error = fdalloc(p, newmin, &i)) + if ((error = fdalloc(p, newmin, &i)) != 0) return (error); return (finishdup(fdp, fd, i, retval)); @@ -302,7 +314,8 @@ sys_fcntl(p, v, retval) return (error); if (fl.l_whence == SEEK_CUR) fl.l_start += fp->f_offset; - if (error = VOP_ADVLOCK(vp, (caddr_t)p, F_GETLK, &fl, F_POSIX)) + error = VOP_ADVLOCK(vp, (caddr_t)p, F_GETLK, &fl, F_POSIX); + if (error) return (error); return (copyout((caddr_t)&fl, (caddr_t)SCARG(uap, arg), sizeof (fl))); @@ -359,6 +372,7 @@ fdrelease(p, fd) * Close a file descriptor. */ /* ARGSUSED */ +int sys_close(p, v, retval) struct proc *p; void *v; @@ -379,6 +393,7 @@ sys_close(p, v, retval) * Return status information about a file descriptor. */ /* ARGSUSED */ +int sys_fstat(p, v, retval) struct proc *p; void *v; @@ -421,6 +436,7 @@ sys_fstat(p, v, retval) * Return pathconf information about a file descriptor. */ /* ARGSUSED */ +int sys_fpathconf(p, v, retval) struct proc *p; void *v; @@ -461,6 +477,7 @@ sys_fpathconf(p, v, retval) */ int fdexpand; +int fdalloc(p, want, result) struct proc *p; int want; @@ -527,6 +544,7 @@ fdalloc(p, want, result) * Check to see whether n user file descriptors * are available to the process p. */ +int fdavail(p, n) struct proc *p; register int n; @@ -549,6 +567,7 @@ fdavail(p, n) * Create a new open file structure and allocate * a file decriptor for the process that refers to it. */ +int falloc(p, resultfp, resultfd) register struct proc *p; struct file **resultfp; @@ -557,7 +576,7 @@ falloc(p, resultfp, resultfd) register struct file *fp, *fq; int error, i; - if (error = fdalloc(p, 0, &i)) + if ((error = fdalloc(p, 0, &i)) != 0) return (error); if (nfiles >= maxfiles) { tablefull("file"); @@ -572,7 +591,7 @@ falloc(p, resultfp, resultfd) nfiles++; MALLOC(fp, struct file *, sizeof(struct file), M_FILE, M_WAITOK); bzero(fp, sizeof(struct file)); - if (fq = p->p_fd->fd_ofiles[0]) { + if ((fq = p->p_fd->fd_ofiles[0]) != NULL) { LIST_INSERT_AFTER(fq, fp, f_list); } else { LIST_INSERT_HEAD(&filehead, fp, f_list); @@ -591,11 +610,10 @@ falloc(p, resultfp, resultfd) /* * Free a file descriptor. */ +void ffree(fp) register struct file *fp; { - register struct file *fq; - LIST_REMOVE(fp, f_list); crfree(fp->f_cred); #ifdef DIAGNOSTIC @@ -738,6 +756,7 @@ fdfree(p) * Note: p may be NULL when closing a file * that was being passed in a message. */ +int closef(fp, p) register struct file *fp; register struct proc *p; @@ -791,6 +810,7 @@ closef(fp, p) * the entire file (l_whence = SEEK_SET, l_start = 0, l_len = 0). */ /* ARGSUSED */ +int sys_flock(p, v, retval) struct proc *p; void *v; diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 8c902c2a829..26db4b37d20 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_exec.c,v 1.73 1995/12/09 04:11:00 mycroft Exp $ */ +/* $OpenBSD: kern_exec.c,v 1.3 1996/03/03 17:19:43 niklas Exp $ */ +/* $NetBSD: kern_exec.c,v 1.75 1996/02/09 18:59:28 christos Exp $ */ /*- * Copyright (C) 1993, 1994 Christopher G. Demetriou @@ -50,6 +51,9 @@ #include #include #include +#ifdef SYSVSHM +#include +#endif #include @@ -90,7 +94,6 @@ check_exec(p, epp) { int error, i; struct vnode *vp; - char *cp, *ep, *name; struct nameidata *ndp; int resid; @@ -98,7 +101,7 @@ check_exec(p, epp) ndp->ni_cnd.cn_nameiop = LOOKUP; ndp->ni_cnd.cn_flags = FOLLOW | LOCKLEAF | SAVENAME; /* first get the vnode */ - if (error = namei(ndp)) + if ((error = namei(ndp)) != 0) return error; epp->ep_vp = vp = ndp->ni_vp; @@ -109,7 +112,7 @@ check_exec(p, epp) } /* get attributes */ - if (error = VOP_GETATTR(vp, epp->ep_vap, p->p_ucred, p)) + if ((error = VOP_GETATTR(vp, epp->ep_vap, p->p_ucred, p)) != 0) goto bad1; /* Check mount point */ @@ -121,7 +124,7 @@ check_exec(p, epp) epp->ep_vap->va_mode &= ~(VSUID | VSGID); /* check access. for root we have to see if any exec bit on */ - if (error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p)) + if ((error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p)) != 0) goto bad1; if ((epp->ep_vap->va_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) == 0) { error = EACCES; @@ -129,12 +132,13 @@ check_exec(p, epp) } /* try to open it */ - if (error = VOP_OPEN(vp, FREAD, p->p_ucred, p)) + if ((error = VOP_OPEN(vp, FREAD, p->p_ucred, p)) != 0) goto bad1; /* now we have the file, get the exec header */ - if (error = vn_rdwr(UIO_READ, vp, epp->ep_hdr, epp->ep_hdrlen, 0, - UIO_SYSSPACE, IO_NODELOCKED, p->p_ucred, &resid, p)) + error = vn_rdwr(UIO_READ, vp, epp->ep_hdr, epp->ep_hdrlen, 0, + UIO_SYSSPACE, IO_NODELOCKED, p->p_ucred, &resid, p); + if (error) goto bad2; epp->ep_hdrvalid = epp->ep_hdrlen - resid; @@ -200,6 +204,7 @@ bad1: * exec system call */ /* ARGSUSED */ +int sys_execve(p, v, retval) register struct proc *p; void *v; @@ -257,7 +262,7 @@ sys_execve(p, v, retval) pack.ep_flags = 0; /* see if we can run it. */ - if (error = check_exec(p, &pack)) + if ((error = check_exec(p, &pack)) != 0) goto freehdr; /* XXX -- THE FOLLOWING SECTION NEEDS MAJOR CLEANUP */ @@ -280,7 +285,7 @@ sys_execve(p, v, retval) cp = *tmpfap; while (*cp) *dp++ = *cp++; - *dp++; + dp++; FREE(*tmpfap, M_EXEC); tmpfap++; argc++; @@ -300,11 +305,11 @@ sys_execve(p, v, retval) while (1) { len = argp + ARG_MAX - dp; - if (error = copyin(cpp, &sp, sizeof(sp))) + if ((error = copyin(cpp, &sp, sizeof(sp))) != 0) goto bad; if (!sp) break; - if (error = copyinstr(sp, dp, len, &len)) { + if ((error = copyinstr(sp, dp, len, &len)) != 0) { if (error == ENAMETOOLONG) error = E2BIG; goto bad; @@ -315,14 +320,15 @@ sys_execve(p, v, retval) } envc = 0; - if (cpp = SCARG(uap, envp)) { /* environment need not be there */ + /* environment need not be there */ + if ((cpp = SCARG(uap, envp)) != NULL ) { while (1) { len = argp + ARG_MAX - dp; - if (error = copyin(cpp, &sp, sizeof(sp))) + if ((error = copyin(cpp, &sp, sizeof(sp))) != 0) goto bad; if (!sp) break; - if (error = copyinstr(sp, dp, len, &len)) { + if ((error = copyinstr(sp, dp, len, &len)) != 0) { if (error == ENAMETOOLONG) error = E2BIG; goto bad; @@ -436,10 +442,8 @@ sys_execve(p, v, retval) * MNT_NOEXEC and P_TRACED have already been used to disable s[ug]id. */ p->p_flag &= ~P_SUGID; - if (((attr.va_mode & VSUID) != 0 && - p->p_ucred->cr_uid != attr.va_uid) - || (attr.va_mode & VSGID) != 0 && - p->p_ucred->cr_gid != attr.va_gid) { + if (((attr.va_mode & VSUID) != 0 && p->p_ucred->cr_uid != attr.va_uid) + || ((attr.va_mode & VSGID) != 0 && p->p_ucred->cr_gid != attr.va_gid)){ p->p_ucred = crcopy(cred); #ifdef KTRACE /* diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index c696ac37c62..3c6a54e5d9f 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_exit.c,v 1.35 1995/12/24 11:23:33 mycroft Exp $ */ +/* $OpenBSD: kern_exit.c,v 1.5 1996/03/03 17:19:44 niklas Exp $ */ +/* $NetBSD: kern_exit.c,v 1.38 1996/02/09 18:59:29 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1991, 1993 @@ -59,6 +60,15 @@ #include #include #include +#include +#include +#ifdef SYSVSHM +#include +#endif +#ifdef SYSVSEM +#include +#endif +#include #include #include @@ -68,9 +78,6 @@ #include #include -void cpu_exit __P((struct proc *)); /* XXX MOVE ME */ -void exit1 __P((struct proc *, int)); - /* * exit -- * Death of process. @@ -114,11 +121,15 @@ exit1(p, rv) MALLOC(p->p_ru, struct rusage *, sizeof(struct rusage), M_ZOMBIE, M_WAITOK); /* - * If parent is waiting for us to exit or exec, - * P_PPWAIT is set; we will wakeup the parent below. + * If parent is waiting for us to exit or exec, P_PPWAIT is set; we + * wake up the parent early to avoid deadlock. */ - p->p_flag &= ~(P_TRACED | P_PPWAIT); p->p_flag |= P_WEXIT; + p->p_flag &= ~P_TRACED; + if (p->p_flag & P_PPWAIT) { + p->p_flag &= ~P_PPWAIT; + wakeup((caddr_t)p->p_pptr); + } p->p_sigignore = ~0; p->p_siglist = 0; untimeout(realitexpire, (caddr_t)p); @@ -205,7 +216,7 @@ exit1(p, rv) q = p->p_children.lh_first; if (q) /* only need this if any child is S_ZOMB */ - wakeup((caddr_t) initproc); + wakeup((caddr_t)initproc); for (; q != 0; q = nq) { nq = q->p_sibling.le_next; proc_reparent(q, initproc); @@ -253,7 +264,8 @@ exit1(p, rv) * Other substructures are freed from wait(). */ curproc = NULL; - limfree(p->p_limit); + if (--p->p_limit->p_refcnt == 0) + FREE(p->p_limit, M_SUBPROC); /* * Finally, call machine-dependent code to release the remaining @@ -306,9 +318,10 @@ loop: if (SCARG(uap, status)) { status = p->p_xstat; /* convert to int */ - if (error = copyout((caddr_t)&status, - (caddr_t)SCARG(uap, status), - sizeof(status))) + error = copyout((caddr_t)&status, + (caddr_t)SCARG(uap, status), + sizeof(status)); + if (error) return (error); } if (SCARG(uap, rusage) && @@ -389,7 +402,7 @@ loop: retval[0] = 0; return (0); } - if (error = tsleep((caddr_t)q, PWAIT | PCATCH, "wait", 0)) + if ((error = tsleep((caddr_t)q, PWAIT | PCATCH, "wait", 0)) != 0) return (error); goto loop; } diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index 589de5b0aec..8a836d44487 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_fork.c,v 1.27 1995/12/10 08:26:02 mycroft Exp $ */ +/* $OpenBSD: kern_fork.c,v 1.5 1996/03/03 17:19:45 niklas Exp $ */ +/* $NetBSD: kern_fork.c,v 1.29 1996/02/09 18:59:34 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1991, 1993 @@ -46,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -53,17 +55,19 @@ #include #include -#include - -#include #include +#include + int nprocs = 1; /* process 0 */ #define ISFORK 0 #define ISVFORK 1 #define ISRFORK 2 +int fork1 __P((struct proc *, int, int, register_t *)); + +/*ARGSUSED*/ int sys_fork(p, v, retval) struct proc *p; @@ -73,6 +77,7 @@ sys_fork(p, v, retval) return (fork1(p, ISFORK, 0, retval)); } +/*ARGSUSED*/ int sys_vfork(p, v, retval) struct proc *p; @@ -105,7 +110,6 @@ fork1(p1, forktype, rforkflags, retval) register struct proc *p2; register uid_t uid; struct proc *newproc; - struct proc **hash; int count; static int nextpid, pidchecked = 0; int dupfd = 1, cleanfd = 0; diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index a506e9635ed..ab28fda5075 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_ktrace.c,v 1.21 1995/10/22 00:35:06 christos Exp $ */ +/* $OpenBSD: kern_ktrace.c,v 1.3 1996/03/03 17:19:46 niklas Exp $ */ +/* $NetBSD: kern_ktrace.c,v 1.23 1996/02/09 18:59:36 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -50,6 +51,13 @@ #include #include +struct ktr_header *ktrgetheader __P((int)); +int ktrops __P((struct proc *, struct proc *, int, int, struct vnode *)); +int ktrsetchildren __P((struct proc *, struct proc *, int, int, + struct vnode *)); +void ktrwrite __P((struct vnode *, struct ktr_header *)); +int ktrcanset __P((struct proc *, struct proc *)); + struct ktr_header * ktrgetheader(type) int type; @@ -266,7 +274,7 @@ sys_ktrace(curp, v, retval) register struct vnode *vp = NULL; register struct proc *p; struct pgrp *pg; - int facs = SCARG(uap, facs) & ~KTRFAC_ROOT; + int facs = SCARG(uap, facs) & ~((unsigned) KTRFAC_ROOT); int ops = KTROP(SCARG(uap, ops)); int descend = SCARG(uap, ops) & KTRFLAG_DESCEND; int ret = 0; @@ -280,7 +288,7 @@ sys_ktrace(curp, v, retval) */ NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, SCARG(uap, fname), curp); - if (error = vn_open(&nd, FREAD|FWRITE, 0)) { + if ((error = vn_open(&nd, FREAD|FWRITE, 0)) != 0) { curp->p_traceflag &= ~KTRFAC_ACTIVE; return (error); } @@ -401,6 +409,7 @@ ktrops(curp, p, ops, facs, vp) return (1); } +int ktrsetchildren(curp, top, ops, facs, vp) struct proc *curp, *top; int ops, facs; @@ -432,6 +441,7 @@ ktrsetchildren(curp, top, ops, facs, vp) /*NOTREACHED*/ } +void ktrwrite(vp, kth) struct vnode *vp; register struct ktr_header *kth; @@ -486,6 +496,7 @@ ktrwrite(vp, kth) * * TODO: check groups. use caller effective gid. */ +int ktrcanset(callp, targetp) struct proc *callp, *targetp; { diff --git a/sys/kern/kern_lkm.c b/sys/kern/kern_lkm.c index b04ae281ece..54a616e2ff3 100644 --- a/sys/kern/kern_lkm.c +++ b/sys/kern/kern_lkm.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_lkm.c,v 1.26 1995/10/10 00:23:20 thorpej Exp $ */ +/* $OpenBSD: kern_lkm.c,v 1.2 1996/03/03 17:19:47 niklas Exp $ */ +/* $NetBSD: kern_lkm.c,v 1.28 1996/02/09 18:59:38 christos Exp $ */ /* * Copyright (c) 1994 Christopher G. Demetriou @@ -44,7 +45,6 @@ #include #include #include -#include #include #include #include @@ -53,6 +53,10 @@ #include #include #include +#include + +#include + #include #include @@ -60,6 +64,7 @@ #include #include + #define PAGESIZE 1024 /* kmem_alloc() allocation quantum */ #define LKM_ALLOC 0x01 @@ -81,6 +86,18 @@ static int lkm_state = LKMS_IDLE; static struct lkm_table lkmods[MAXLKMS]; /* table of loaded modules */ static struct lkm_table *curp; /* global for in-progress ops */ +static void lkmunreserve __P((void)); +static int _lkm_syscall __P((struct lkm_table *, int)); +static int _lkm_vfs __P((struct lkm_table *, int)); +static int _lkm_dev __P((struct lkm_table *, int)); +#ifdef STREAMS +static int _lkm_strmod __P((struct lkm_table *, int)); +#endif +static int _lkm_exec __P((struct lkm_table *, int)); + +int lkmexists __P((struct lkm_table *)); +int lkmdispatch __P((struct lkm_table *, int)); + /*ARGSUSED*/ int lkmopen(dev, flag, devtype, p) @@ -107,7 +124,8 @@ lkmopen(dev, flag, devtype, p) * Sleep pending unlock; we use tsleep() to allow * an alarm out of the open. */ - if (error = tsleep((caddr_t)&lkm_v, TTIPRI|PCATCH, "lkmopn", 0)) + error = tsleep((caddr_t)&lkm_v, TTIPRI|PCATCH, "lkmopn", 0); + if (error) return (error); /* leave LKM_WANT set -- no problem */ } lkm_v |= LKM_ALLOC; @@ -120,7 +138,7 @@ lkmopen(dev, flag, devtype, p) * a coerced close of the lkm device (close on premature exit of modload) * or explicitly by modload as a result of a link failure. */ -static int +static void lkmunreserve() { @@ -171,19 +189,19 @@ lkmclose(dev, flag, mode, p) /*ARGSUSED*/ int -lkmioctl(dev, cmd, data, flag) +lkmioctl(dev, cmd, data, flag, p) dev_t dev; u_long cmd; caddr_t data; int flag; + struct proc *p; { - int err = 0; + int error = 0; int i; struct lmc_resrv *resrvp; struct lmc_loadbuf *loadbufp; struct lmc_unload *unloadp; struct lmc_stat *statp; - int (*funcp)(); char istr[MAXLKMNAME]; switch(cmd) { @@ -203,7 +221,7 @@ lkmioctl(dev, cmd, data, flag) if (!lkmods[i].used) break; if (i == MAXLKMS) { - err = ENOMEM; /* no slots available */ + error = ENOMEM; /* no slots available */ break; } curp = &lkmods[i]; @@ -243,12 +261,14 @@ lkmioctl(dev, cmd, data, flag) || i < 0 || i > MODIOBUF || i > curp->size - curp->offset) { - err = ENOMEM; + error = ENOMEM; break; } /* copy in buffer full of data */ - if (err = copyin((caddr_t)loadbufp->data, (caddr_t)curp->area + curp->offset, i)) + error = copyin(loadbufp->data, + (caddr_t)curp->area + curp->offset, i); + if (error) break; if ((curp->offset + i) < curp->size) { @@ -302,10 +322,12 @@ lkmioctl(dev, cmd, data, flag) return ENXIO; } - curp->entry = (int (*)()) (*((long *) (data))); + curp->entry = (int (*) __P((struct lkm_table *, int, int))) + (*((long *) (data))); /* call entry(load)... (assigns "private" portion) */ - if (err = (*(curp->entry))(curp, LKM_E_LOAD, LKM_VERSION)) { + error = (*(curp->entry))(curp, LKM_E_LOAD, LKM_VERSION); + if (error) { /* * Module may refuse loading or may have a * version mismatch... @@ -337,8 +359,9 @@ lkmioctl(dev, cmd, data, flag) * Copy name and lookup id from all loaded * modules. May fail. */ - if (err = copyinstr(unloadp->name, istr, MAXLKMNAME-1, - (size_t *)0)) + error = copyinstr(unloadp->name, istr, MAXLKMNAME-1, + NULL); + if (error) break; /* @@ -357,20 +380,20 @@ lkmioctl(dev, cmd, data, flag) * Range check the value; on failure, return EINVAL */ if (i < 0 || i >= MAXLKMS) { - err = EINVAL; + error = EINVAL; break; } curp = &lkmods[i]; if (!curp->used) { - err = ENOENT; + error = ENOENT; break; } /* call entry(unload) */ if ((*(curp->entry))(curp, LKM_E_UNLOAD, LKM_VERSION)) { - err = EBUSY; + error = EBUSY; break; } @@ -402,7 +425,7 @@ lkmioctl(dev, cmd, data, flag) } if (i == MAXLKMS) { /* Not found */ - err = ENOENT; + error = ENOENT; break; } } @@ -411,14 +434,14 @@ lkmioctl(dev, cmd, data, flag) * Range check the value; on failure, return EINVAL */ if (i < 0 || i >= MAXLKMS) { - err = EINVAL; + error = EINVAL; break; } curp = &lkmods[i]; if (!curp->used) { /* Not found */ - err = ENOENT; + error = ENOENT; break; } @@ -440,11 +463,11 @@ lkmioctl(dev, cmd, data, flag) break; default: /* bad ioctl()... */ - err = ENOTTY; + error = ENOTTY; break; } - return (err); + return (error); } /* @@ -528,7 +551,7 @@ _lkm_syscall(lkmtp, cmd) { struct lkm_syscall *args = lkmtp->private.lkm_syscall; int i; - int err = 0; + int error = 0; switch(cmd) { case LKM_E_LOAD: @@ -545,12 +568,12 @@ _lkm_syscall(lkmtp, cmd) break; /* found it! */ /* out of allocable slots? */ if (i == SYS_MAXSYSCALL) { - err = ENFILE; + error = ENFILE; break; } } else { /* assign */ if (i < 0 || i >= SYS_MAXSYSCALL) { - err = EINVAL; + error = EINVAL; break; } } @@ -579,7 +602,7 @@ _lkm_syscall(lkmtp, cmd) break; } - return (err); + return (error); } /* @@ -593,7 +616,7 @@ _lkm_vfs(lkmtp, cmd) { struct lkm_vfs *args = lkmtp->private.lkm_vfs; int i; - int err = 0; + int error = 0; switch(cmd) { case LKM_E_LOAD: @@ -605,7 +628,8 @@ _lkm_vfs(lkmtp, cmd) for (i = 0; i < nvfssw; i++) if (vfssw[i] != (struct vfsops *)0 && strncmp(vfssw[i]->vfs_name, - args->lkm_vfsops->vfs_name, MFSNAMELEN) == 0) + args->lkm_vfsops->vfs_name, + MFSNAMELEN) == 0) return (EEXIST); /* pick the last available empty slot */ @@ -613,7 +637,7 @@ _lkm_vfs(lkmtp, cmd) if (vfssw[i] == (struct vfsops *)0) break; if (i == -1) { /* or if none, punt */ - err = EINVAL; + error = EINVAL; break; } @@ -647,7 +671,7 @@ _lkm_vfs(lkmtp, cmd) break; } - return (err); + return (error); } /* @@ -661,7 +685,7 @@ _lkm_dev(lkmtp, cmd) { struct lkm_dev *args = lkmtp->private.lkm_dev; int i; - int err = 0; + int error = 0; extern int nblkdev, nchrdev; /* from conf.c */ switch(cmd) { @@ -681,12 +705,12 @@ _lkm_dev(lkmtp, cmd) break; /* found it! */ /* out of allocable slots? */ if (i == nblkdev) { - err = ENFILE; + error = ENFILE; break; } } else { /* assign */ if (i < 0 || i >= nblkdev) { - err = EINVAL; + error = EINVAL; break; } } @@ -711,12 +735,12 @@ _lkm_dev(lkmtp, cmd) break; /* found it! */ /* out of allocable slots? */ if (i == nchrdev) { - err = ENFILE; + error = ENFILE; break; } } else { /* assign */ if (i < 0 || i >= nchrdev) { - err = EINVAL; + error = EINVAL; break; } } @@ -733,7 +757,7 @@ _lkm_dev(lkmtp, cmd) break; default: - err = ENODEV; + error = ENODEV; break; } break; @@ -754,7 +778,7 @@ _lkm_dev(lkmtp, cmd) break; default: - err = ENODEV; + error = ENODEV; break; } break; @@ -763,7 +787,7 @@ _lkm_dev(lkmtp, cmd) break; } - return (err); + return (error); } #ifdef STREAMS @@ -778,7 +802,7 @@ _lkm_strmod(lkmtp, cmd) { struct lkm_strmod *args = lkmtp->private.lkm_strmod; int i; - int err = 0; + int error = 0; switch(cmd) { case LKM_E_LOAD: @@ -794,7 +818,7 @@ _lkm_strmod(lkmtp, cmd) break; } - return (err); + return (error); } #endif /* STREAMS */ @@ -809,7 +833,7 @@ _lkm_exec(lkmtp, cmd) { struct lkm_exec *args = lkmtp->private.lkm_exec; int i; - int err = 0; + int error = 0; switch(cmd) { case LKM_E_LOAD: @@ -826,12 +850,12 @@ _lkm_exec(lkmtp, cmd) break; /* found it! */ /* out of allocable slots? */ if (i == nexecs) { - err = ENFILE; + error = ENFILE; break; } } else { /* assign */ if (i < 0 || i >= nexecs) { - err = EINVAL; + error = EINVAL; break; } } @@ -866,7 +890,7 @@ _lkm_exec(lkmtp, cmd) break; } - return (err); + return (error); } /* @@ -880,19 +904,19 @@ lkmdispatch(lkmtp, cmd) struct lkm_table *lkmtp; int cmd; { - int err = 0; /* default = success */ + int error = 0; /* default = success */ switch(lkmtp->private.lkm_any->lkm_type) { case LM_SYSCALL: - err = _lkm_syscall(lkmtp, cmd); + error = _lkm_syscall(lkmtp, cmd); break; case LM_VFS: - err = _lkm_vfs(lkmtp, cmd); + error = _lkm_vfs(lkmtp, cmd); break; case LM_DEV: - err = _lkm_dev(lkmtp, cmd); + error = _lkm_dev(lkmtp, cmd); break; #ifdef STREAMS @@ -905,16 +929,16 @@ lkmdispatch(lkmtp, cmd) #endif /* STREAMS */ case LM_EXEC: - err = _lkm_exec(lkmtp, cmd); + error = _lkm_exec(lkmtp, cmd); break; case LM_MISC: /* ignore content -- no "misc-specific" procedure */ break; default: - err = ENXIO; /* unknown type */ + error = ENXIO; /* unknown type */ break; } - return (err); + return (error); } diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c index f7985a03150..4b54f438045 100644 --- a/sys/kern/kern_malloc.c +++ b/sys/kern/kern_malloc.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_malloc.c,v 1.11 1995/05/01 22:39:11 cgd Exp $ */ +/* $OpenBSD: kern_malloc.c,v 1.2 1996/03/03 17:19:49 niklas Exp $ */ +/* $NetBSD: kern_malloc.c,v 1.13 1996/02/09 18:59:39 christos Exp $ */ /* * Copyright (c) 1987, 1991, 1993 @@ -40,6 +41,7 @@ #include #include #include +#include #include #include @@ -65,7 +67,7 @@ long addrmask[] = { 0, * The WEIRD_ADDR is used as known text to copy into free objects so * that modifications after frees can be detected. */ -#define WEIRD_ADDR 0xdeadbeef +#define WEIRD_ADDR ((unsigned) 0xdeadbeef) #define MAX_COPY 32 /* @@ -224,7 +226,8 @@ malloc(size, type, flags) continue; printf("%s %d of object %p size %d %s %s (%p != %p)\n", "Data modified on freelist: word", lp - (int32_t *)va, - va, size, "previous type", savedtype, *lp, WEIRD_ADDR); + va, size, "previous type", savedtype, (void *)*lp, + (void *) WEIRD_ADDR); break; } @@ -359,6 +362,7 @@ free(addr, type) /* * Initialize the kernel memory allocator */ +void kmeminit() { register long indx; diff --git a/sys/kern/kern_physio.c b/sys/kern/kern_physio.c index 3c8dccec428..4e02351d3f0 100644 --- a/sys/kern/kern_physio.c +++ b/sys/kern/kern_physio.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_physio.c,v 1.25 1995/10/10 02:51:45 mycroft Exp $ */ +/* $OpenBSD: kern_physio.c,v 1.2 1996/03/03 17:19:50 niklas Exp $ */ +/* $NetBSD: kern_physio.c,v 1.26 1996/02/04 02:15:51 christos Exp $ */ /*- * Copyright (c) 1994 Christopher G. Demetriou @@ -47,6 +48,8 @@ #include #include +#include + /* * The routines implemented in this file are described in: * Leffler, et al.: The Design and Implementation of the 4.3BSD @@ -96,7 +99,7 @@ physio(strategy, bp, dev, flags, minphys, uio) return (EFAULT); /* Make sure we have a buffer, creating one if necessary. */ - if (nobuf = (bp == NULL)) + if ((nobuf = (bp == NULL)) != 0) bp = getphysbuf(); /* [raise the processor priority level to splbio;] */ diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 85514b0bbe8..0e55acd5de9 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_proc.c,v 1.12 1995/03/19 23:44:49 mycroft Exp $ */ +/* $OpenBSD: kern_proc.c,v 1.2 1996/03/03 17:19:51 niklas Exp $ */ +/* $NetBSD: kern_proc.c,v 1.14 1996/02/09 18:59:41 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1991, 1993 @@ -74,6 +75,11 @@ u_long pgrphash; struct proclist allproc; struct proclist zombproc; +static void orphanpg __P((struct pgrp *)); +#ifdef DEBUG +void pgrpdump __P((void)); +#endif + /* * Initialize global process hashing structures. */ @@ -280,8 +286,6 @@ pgdelete(pgrp) FREE(pgrp, M_PGRP); } -static void orphanpg(); - /* * Adjust pgrp jobc counters when specified process changes process group. * We count the number of processes in each process group that "qualify" @@ -351,6 +355,7 @@ orphanpg(pg) } #ifdef DEBUG +void pgrpdump() { register struct pgrp *pgrp; @@ -358,7 +363,7 @@ pgrpdump() register i; for (i = 0; i <= pgrphash; i++) { - if (pgrp = pgrphashtbl[i].lh_first) { + if ((pgrp = pgrphashtbl[i].lh_first) != NULL) { printf("\tindx %d\n", i); for (; pgrp != 0; pgrp = pgrp->pg_hash.le_next) { printf("\tpgrp %p, pgid %d, sess %p, sesscnt %d, mem %p\n", diff --git a/sys/kern/kern_prot.c b/sys/kern/kern_prot.c index bf23a99c4b0..f957ecbccb3 100644 --- a/sys/kern/kern_prot.c +++ b/sys/kern/kern_prot.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_prot.c,v 1.31 1995/10/10 01:26:53 mycroft Exp $ */ +/* $OpenBSD: kern_prot.c,v 1.2 1996/03/03 17:19:52 niklas Exp $ */ +/* $NetBSD: kern_prot.c,v 1.33 1996/02/09 18:59:42 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1990, 1991, 1993 @@ -57,6 +58,7 @@ #include /* ARGSUSED */ +int sys_getpid(p, v, retval) struct proc *p; void *v; @@ -72,6 +74,7 @@ sys_getpid(p, v, retval) } /* ARGSUSED */ +int sys_getppid(p, v, retval) struct proc *p; void *v; @@ -83,6 +86,7 @@ sys_getppid(p, v, retval) } /* Get process group ID; note that POSIX getpgrp takes no parameter */ +int sys_getpgrp(p, v, retval) struct proc *p; void *v; @@ -94,6 +98,7 @@ sys_getpgrp(p, v, retval) } /* ARGSUSED */ +int sys_getuid(p, v, retval) struct proc *p; void *v; @@ -109,6 +114,7 @@ sys_getuid(p, v, retval) } /* ARGSUSED */ +int sys_geteuid(p, v, retval) struct proc *p; void *v; @@ -120,6 +126,7 @@ sys_geteuid(p, v, retval) } /* ARGSUSED */ +int sys_getgid(p, v, retval) struct proc *p; void *v; @@ -139,6 +146,7 @@ sys_getgid(p, v, retval) * correctly in a library function. */ /* ARGSUSED */ +int sys_getegid(p, v, retval) struct proc *p; void *v; @@ -149,6 +157,7 @@ sys_getegid(p, v, retval) return (0); } +int sys_getgroups(p, v, retval) struct proc *p; void *v; @@ -169,14 +178,16 @@ sys_getgroups(p, v, retval) if (ngrp < pc->pc_ucred->cr_ngroups) return (EINVAL); ngrp = pc->pc_ucred->cr_ngroups; - if (error = copyout((caddr_t)pc->pc_ucred->cr_groups, - (caddr_t)SCARG(uap, gidset), ngrp * sizeof(gid_t))) + error = copyout((caddr_t)pc->pc_ucred->cr_groups, + (caddr_t)SCARG(uap, gidset), ngrp * sizeof(gid_t)); + if (error) return (error); *retval = ngrp; return (0); } /* ARGSUSED */ +int sys_setsid(p, v, retval) register struct proc *p; void *v; @@ -206,6 +217,7 @@ sys_setsid(p, v, retval) * pid must not be session leader (EPERM) */ /* ARGSUSED */ +int sys_setpgid(curp, v, retval) struct proc *curp; void *v; @@ -244,6 +256,7 @@ sys_setpgid(curp, v, retval) } /* ARGSUSED */ +int sys_setuid(p, v, retval) struct proc *p; void *v; @@ -280,6 +293,7 @@ sys_setuid(p, v, retval) } /* ARGSUSED */ +int sys_seteuid(p, v, retval) struct proc *p; void *v; @@ -311,6 +325,7 @@ sys_seteuid(p, v, retval) } /* ARGSUSED */ +int sys_setgid(p, v, retval) struct proc *p; void *v; @@ -339,6 +354,7 @@ sys_setgid(p, v, retval) } /* ARGSUSED */ +int sys_setegid(p, v, retval) struct proc *p; void *v; @@ -366,6 +382,7 @@ sys_setegid(p, v, retval) } /* ARGSUSED */ +int sys_setgroups(p, v, retval) struct proc *p; void *v; @@ -379,14 +396,15 @@ sys_setgroups(p, v, retval) register u_int ngrp; int error; - if (error = suser(pc->pc_ucred, &p->p_acflag)) + if ((error = suser(pc->pc_ucred, &p->p_acflag)) != 0) return (error); ngrp = SCARG(uap, gidsetsize); if (ngrp > NGROUPS) return (EINVAL); pc->pc_ucred = crcopy(pc->pc_ucred); - if (error = copyin((caddr_t)SCARG(uap, gidset), - (caddr_t)pc->pc_ucred->cr_groups, ngrp * sizeof(gid_t))) + error = copyin((caddr_t)SCARG(uap, gidset), + (caddr_t)pc->pc_ucred->cr_groups, ngrp * sizeof(gid_t)); + if (error) return (error); pc->pc_ucred->cr_ngroups = ngrp; p->p_flag |= P_SUGID; @@ -396,6 +414,7 @@ sys_setgroups(p, v, retval) /* * Check if gid is a member of the group set. */ +int groupmember(gid, cred) gid_t gid; register struct ucred *cred; @@ -416,6 +435,7 @@ groupmember(gid, cred) * indicating use of super-powers. * Returns 0 or error. */ +int suser(cred, acflag) struct ucred *cred; u_short *acflag; @@ -495,6 +515,7 @@ crdup(cr) * Get login name, if available. */ /* ARGSUSED */ +int sys_getlogin(p, v, retval) struct proc *p; void *v; @@ -515,6 +536,7 @@ sys_getlogin(p, v, retval) * Set login name. */ /* ARGSUSED */ +int sys_setlogin(p, v, retval) struct proc *p; void *v; @@ -525,7 +547,7 @@ sys_setlogin(p, v, retval) } */ *uap = v; int error; - if (error = suser(p->p_ucred, &p->p_acflag)) + if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) return (error); error = copyinstr((caddr_t) SCARG(uap, namebuf), (caddr_t) p->p_pgrp->pg_session->s_login, diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index 7f4e56a16ae..27e8045f7cb 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_resource.c,v 1.32 1995/12/09 04:09:34 mycroft Exp $ */ +/* $OpenBSD: kern_resource.c,v 1.3 1996/03/03 17:19:53 niklas Exp $ */ +/* $NetBSD: kern_resource.c,v 1.34 1996/02/09 18:59:44 christos Exp $ */ /*- * Copyright (c) 1982, 1986, 1991, 1993 @@ -53,9 +54,7 @@ #include -int donice __P((struct proc *curp, struct proc *chgp, int n)); -int dosetrlimit __P((struct proc *p, u_int which, struct rlimit *limp)); - +void limfree __P((struct plimit *)); /* * Resource controls and accounting. */ @@ -214,8 +213,9 @@ sys_setrlimit(p, v, retval) struct rlimit alim; int error; - if (error = copyin((caddr_t)SCARG(uap, rlp), (caddr_t)&alim, - sizeof (struct rlimit))) + error = copyin((caddr_t)SCARG(uap, rlp), (caddr_t)&alim, + sizeof (struct rlimit)); + if (error) return (error); return (dosetrlimit(p, SCARG(uap, which), &alim)); } @@ -235,7 +235,7 @@ dosetrlimit(p, which, limp) alimp = &p->p_rlimit[which]; if (limp->rlim_cur > alimp->rlim_max || limp->rlim_max > alimp->rlim_max) - if (error = suser(p->p_ucred, &p->p_acflag)) + if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) return (error); if (limp->rlim_cur > limp->rlim_max) limp->rlim_cur = limp->rlim_max; diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index ca2ab83a721..17ecd41a5da 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_sig.c,v 1.51 1996/01/04 22:23:14 jtc Exp $ */ +/* $OpenBSD: kern_sig.c,v 1.3 1996/03/03 17:19:54 niklas Exp $ */ +/* $NetBSD: kern_sig.c,v 1.53 1996/02/09 18:59:47 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1991, 1993 @@ -59,6 +60,8 @@ #include #include #include +#include +#include #include #include @@ -69,6 +72,7 @@ #include /* for coredump */ void stop __P((struct proc *p)); +void killproc __P((struct proc *, char *)); /* * Can process p, with pcred pc, send the signal signum to process q? @@ -82,6 +86,7 @@ void stop __P((struct proc *p)); ((signum) == SIGCONT && (q)->p_session == (p)->p_session)) /* ARGSUSED */ +int sys_sigaction(p, v, retval) struct proc *p; void *v; @@ -121,19 +126,22 @@ sys_sigaction(p, v, retval) if ((sa->sa_mask & bit) == 0) sa->sa_flags |= SA_NODEFER; sa->sa_mask &= ~bit; - if (error = copyout((caddr_t)sa, (caddr_t)SCARG(uap, osa), - sizeof (vec))) + error = copyout((caddr_t)sa, (caddr_t)SCARG(uap, osa), + sizeof (vec)); + if (error) return (error); } if (SCARG(uap, nsa)) { - if (error = copyin((caddr_t)SCARG(uap, nsa), (caddr_t)sa, - sizeof (vec))) + error = copyin((caddr_t)SCARG(uap, nsa), (caddr_t)sa, + sizeof (vec)); + if (error) return (error); setsigvec(p, signum, sa); } return (0); } +void setsigvec(p, signum, sa) register struct proc *p; int signum; @@ -257,6 +265,7 @@ execsigs(p) * and return old mask as return value; * the library stub does the rest. */ +int sys_sigprocmask(p, v, retval) register struct proc *p; void *v; @@ -293,6 +302,7 @@ sys_sigprocmask(p, v, retval) } /* ARGSUSED */ +int sys_sigpending(p, v, retval) struct proc *p; void *v; @@ -337,6 +347,7 @@ sys_sigsuspend(p, v, retval) } /* ARGSUSED */ +int sys_sigaltstack(p, v, retval) struct proc *p; void *v; @@ -358,8 +369,8 @@ sys_sigaltstack(p, v, retval) return (error); if (SCARG(uap, nss) == 0) return (0); - if (error = copyin((caddr_t)SCARG(uap, nss), (caddr_t)&ss, - sizeof (ss))) + error = copyin((caddr_t)SCARG(uap, nss), (caddr_t)&ss, sizeof (ss)); + if (error) return (error); if (ss.ss_flags & SS_DISABLE) { if (psp->ps_sigstk.ss_flags & SS_ONSTACK) @@ -420,6 +431,7 @@ sys_kill(cp, v, retval) * Common code for kill process group/broadcast kill. * cp is calling process. */ +int killpg1(cp, signum, pgid, all) register struct proc *cp; int signum, pgid, all; @@ -991,6 +1003,7 @@ postsig(signum) /* * Kill the current process for stated reason. */ +void killproc(p, why) struct proc *p; char *why; @@ -1009,7 +1022,7 @@ killproc(p, why) * If dumping core, save the signal number for the debugger. Calls exit and * does not return. */ -int +void sigexit(p, signum) register struct proc *p; int signum; @@ -1050,7 +1063,8 @@ coredump(p) return (EFAULT); sprintf(name, "%s.core", p->p_comm); NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, name, p); - if (error = vn_open(&nd, O_CREAT | FWRITE, S_IRUSR | S_IWUSR)) + error = vn_open(&nd, O_CREAT | FWRITE, S_IRUSR | S_IWUSR); + if (error) return (error); vp = nd.ni_vp; diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 26dee13037d..b60c2e4f6f3 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_synch.c,v 1.33 1995/06/08 23:51:03 mycroft Exp $ */ +/* $OpenBSD: kern_synch.c,v 1.2 1996/03/03 17:19:55 niklas Exp $ */ +/* $NetBSD: kern_synch.c,v 1.35 1996/02/09 18:59:50 christos Exp $ */ /*- * Copyright (c) 1982, 1986, 1990, 1991, 1993 @@ -47,16 +48,22 @@ #include #include #include -#include +#include #ifdef KTRACE #include #endif +#include #include u_char curpriority; /* usrpri of curproc */ int lbolt; /* once a second sleep address */ +void roundrobin __P((void *)); +void schedcpu __P((void *)); +void updatepri __P((struct proc *)); +void endtsleep __P((void *)); + /* * Force switch among equal priority processes every 100ms. */ @@ -335,7 +342,7 @@ tsleep(ident, priority, wmesg, timo) */ if (catch) { p->p_flag |= P_SINTR; - if (sig = CURSIG(p)) { + if ((sig = CURSIG(p)) != 0) { if (p->p_wchan) unsleep(p); p->p_stat = SRUN; @@ -369,7 +376,7 @@ resume: } } else if (timo) untimeout(endtsleep, (void *)p); - if (catch && (sig != 0 || (sig = CURSIG(p)))) { + if (catch && (sig != 0 || (sig = CURSIG(p)) != 0)) { #ifdef KTRACE if (KTRPOINT(p, KTR_CSW)) ktrcsw(p->p_tracep, 0, 0); @@ -513,9 +520,9 @@ wakeup(ident) s = splhigh(); qp = &slpque[LOOKUP(ident)]; restart: - for (q = &qp->sq_head; p = *q; ) { + for (q = &qp->sq_head; (p = *q) != NULL; ) { #ifdef DIAGNOSTIC - if (p->p_back || p->p_stat != SSLEEP && p->p_stat != SSTOP) + if (p->p_back || (p->p_stat != SSLEEP && p->p_stat != SSTOP)) panic("wakeup"); #endif if (p->p_wchan == ident) { @@ -683,11 +690,16 @@ resetpriority(p) } #ifdef DDB +#include + +#include +#include + void db_show_all_procs(addr, haddr, count, modif) - long addr; + db_expr_t addr; int haddr; - int count; + db_expr_t count; char *modif; { int map = modif[0] == 'm'; diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 7849091829c..79a2fc09975 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_sysctl.c,v 1.12 1995/10/07 06:28:27 mycroft Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.2 1996/03/03 17:19:56 niklas Exp $ */ +/* $NetBSD: kern_sysctl.c,v 1.14 1996/02/09 18:59:52 christos Exp $ */ /*- * Copyright (c) 1982, 1986, 1989, 1993 @@ -60,16 +61,6 @@ #include #include -sysctlfn kern_sysctl; -sysctlfn hw_sysctl; -#ifdef DEBUG -sysctlfn debug_sysctl; -#endif -extern sysctlfn vm_sysctl; -extern sysctlfn fs_sysctl; -extern sysctlfn net_sysctl; -extern sysctlfn cpu_sysctl; - /* * Locking and stats */ @@ -94,7 +85,7 @@ sys___sysctl(p, v, retval) syscallarg(size_t) newlen; } */ *uap = v; int error, dolock = 1; - size_t savelen, oldlen = 0; + size_t savelen = 0, oldlen = 0; sysctlfn *fn; int name[CTL_MAXNAME]; @@ -106,8 +97,9 @@ sys___sysctl(p, v, retval) */ if (SCARG(uap, namelen) > CTL_MAXNAME || SCARG(uap, namelen) < 2) return (EINVAL); - if (error = - copyin(SCARG(uap, name), &name, SCARG(uap, namelen) * sizeof(int))) + error = copyin(SCARG(uap, name), &name, + SCARG(uap, namelen) * sizeof(int)); + if (error) return (error); switch (name[0]) { @@ -162,7 +154,7 @@ sys___sysctl(p, v, retval) &oldlen, SCARG(uap, new), SCARG(uap, newlen), p); if (SCARG(uap, old) != NULL) { if (dolock) - vsunlock(SCARG(uap, old), savelen, B_WRITE); + vsunlock(SCARG(uap, old), savelen); memlock.sl_lock = 0; if (memlock.sl_want) { memlock.sl_want = 0; @@ -194,6 +186,7 @@ int securelevel; /* * kernel related system variables. */ +int kern_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) int *name; u_int namelen; @@ -294,6 +287,7 @@ kern_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) /* * hardware related system variables. */ +int hw_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) int *name; u_int namelen; @@ -379,6 +373,7 @@ debug_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) * Validate parameters and get old / set new parameters * for an integer-valued sysctl function. */ +int sysctl_int(oldp, oldlenp, newp, newlen, valp) void *oldp; size_t *oldlenp; @@ -403,6 +398,7 @@ sysctl_int(oldp, oldlenp, newp, newlen, valp) /* * As above, but read-only. */ +int sysctl_rdint(oldp, oldlenp, newp, val) void *oldp; size_t *oldlenp; @@ -425,6 +421,7 @@ sysctl_rdint(oldp, oldlenp, newp, val) * Validate parameters and get old / set new parameters * for a string-valued sysctl function. */ +int sysctl_string(oldp, oldlenp, newp, newlen, str, maxlen) void *oldp; size_t *oldlenp; @@ -454,6 +451,7 @@ sysctl_string(oldp, oldlenp, newp, newlen, str, maxlen) /* * As above, but read-only. */ +int sysctl_rdstring(oldp, oldlenp, newp, str) void *oldp; size_t *oldlenp; @@ -477,6 +475,7 @@ sysctl_rdstring(oldp, oldlenp, newp, str) * Validate parameters and get old / set new parameters * for a structure oriented sysctl function. */ +int sysctl_struct(oldp, oldlenp, newp, newlen, sp, len) void *oldp; size_t *oldlenp; @@ -504,6 +503,7 @@ sysctl_struct(oldp, oldlenp, newp, newlen, sp, len) * Validate parameters and get old parameters * for a structure oriented sysctl function. */ +int sysctl_rdstruct(oldp, oldlenp, newp, sp, len) void *oldp; size_t *oldlenp; @@ -525,6 +525,7 @@ sysctl_rdstruct(oldp, oldlenp, newp, sp, len) /* * Get file structures. */ +int sysctl_file(where, sizep) char *where; size_t *sizep; @@ -549,7 +550,8 @@ sysctl_file(where, sizep) *sizep = 0; return (0); } - if (error = copyout((caddr_t)&filehead, where, sizeof(filehead))) + error = copyout((caddr_t)&filehead, where, sizeof(filehead)); + if (error) return (error); buflen -= sizeof(filehead); where += sizeof(filehead); @@ -562,7 +564,8 @@ sysctl_file(where, sizep) *sizep = where - start; return (ENOMEM); } - if (error = copyout((caddr_t)fp, where, sizeof (struct file))) + error = copyout((caddr_t)fp, where, sizeof (struct file)); + if (error) return (error); buflen -= sizeof(struct file); where += sizeof(struct file); @@ -576,6 +579,7 @@ sysctl_file(where, sizep) */ #define KERN_PROCSLOP (5 * sizeof (struct kinfo_proc)) +int sysctl_doproc(name, namelen, where, sizep) int *name; u_int namelen; @@ -638,11 +642,13 @@ again: } if (buflen >= sizeof(struct kinfo_proc)) { fill_eproc(p, &eproc); - if (error = copyout((caddr_t)p, &dp->kp_proc, - sizeof(struct proc))) + error = copyout((caddr_t)p, &dp->kp_proc, + sizeof(struct proc)); + if (error) return (error); - if (error = copyout((caddr_t)&eproc, &dp->kp_eproc, - sizeof(eproc))) + error = copyout((caddr_t)&eproc, &dp->kp_eproc, + sizeof(eproc)); + if (error) return (error); dp++; buflen -= sizeof(struct kinfo_proc); diff --git a/sys/kern/kern_time.c b/sys/kern/kern_time.c index 3a5a555a477..365e00195c4 100644 --- a/sys/kern/kern_time.c +++ b/sys/kern/kern_time.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_time.c,v 1.16 1995/10/07 06:28:28 mycroft Exp $ */ +/* $OpenBSD: kern_time.c,v 1.2 1996/03/03 17:19:57 niklas Exp $ */ +/* $NetBSD: kern_time.c,v 1.19 1996/02/13 21:10:43 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -41,10 +42,15 @@ #include #include #include +#include #include #include +#if defined(NFSCLIENT) || defined(NFSSERVER) +#include +#endif + #include /* @@ -73,8 +79,9 @@ sys_gettimeofday(p, v, retval) if (SCARG(uap, tp)) { microtime(&atv); - if (error = copyout((caddr_t)&atv, (caddr_t)SCARG(uap, tp), - sizeof (atv))) + error = copyout((caddr_t)&atv, (caddr_t)SCARG(uap, tp), + sizeof (atv)); + if (error) return (error); } if (SCARG(uap, tzp)) @@ -98,7 +105,7 @@ sys_settimeofday(p, v, retval) struct timezone atz; int error, s; - if (error = suser(p->p_ucred, &p->p_acflag)) + if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) return (error); /* Verify all parameters before changing time. */ if (SCARG(uap, tv) && (error = copyin((caddr_t)SCARG(uap, tv), @@ -145,10 +152,12 @@ sys_adjtime(p, v, retval) register long ndelta, ntickdelta, odelta; int s, error; - if (error = suser(p->p_ucred, &p->p_acflag)) + if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) return (error); - if (error = copyin((caddr_t)SCARG(uap, delta), (caddr_t)&atv, - sizeof(struct timeval))) + + error = copyin((caddr_t)SCARG(uap, delta), (caddr_t)&atv, + sizeof(struct timeval)); + if (error) return (error); /* @@ -250,7 +259,7 @@ sys_getitimer(p, v, retval) int sys_setitimer(p, v, retval) struct proc *p; - void *v; + register void *v; register_t *retval; { register struct sys_setitimer_args /* { diff --git a/sys/kern/kern_xxx.c b/sys/kern/kern_xxx.c index 990fc036b50..7bfb70d5a06 100644 --- a/sys/kern/kern_xxx.c +++ b/sys/kern/kern_xxx.c @@ -1,4 +1,5 @@ -/* $NetBSD: kern_xxx.c,v 1.29 1995/10/07 06:28:30 mycroft Exp $ */ +/* $OpenBSD: kern_xxx.c,v 1.2 1996/03/03 17:19:58 niklas Exp $ */ +/* $NetBSD: kern_xxx.c,v 1.31 1996/02/09 18:59:54 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -42,7 +43,7 @@ #include #include #include - +#include #include #include @@ -58,7 +59,7 @@ sys_reboot(p, v, retval) } */ *uap = v; int error; - if (error = suser(p->p_ucred, &p->p_acflag)) + if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) return (error); boot(SCARG(uap, opt)); return (0); diff --git a/sys/kern/subr_autoconf.c b/sys/kern/subr_autoconf.c index 95886153e45..c983e682cf6 100644 --- a/sys/kern/subr_autoconf.c +++ b/sys/kern/subr_autoconf.c @@ -1,4 +1,5 @@ -/* $NetBSD: subr_autoconf.c,v 1.16 1994/11/04 06:40:11 mycroft Exp $ */ +/* $OpenBSD: subr_autoconf.c,v 1.2 1996/03/03 17:19:59 niklas Exp $ */ +/* $NetBSD: subr_autoconf.c,v 1.17 1996/02/04 02:16:35 christos Exp $ */ /* * Copyright (c) 1992, 1993 @@ -49,7 +50,7 @@ #include #include #include -#include +#include #include /* @@ -74,6 +75,9 @@ struct matchinfo { int indirect, pri; }; +static char *number __P((char *, int)); +static void mapply __P((struct matchinfo *, struct cfdata *)); + /* * Apply the matching function and choose the best. This is used * a few times and we want to keep the code small. diff --git a/sys/kern/subr_log.c b/sys/kern/subr_log.c index ce7345fedee..d676732a928 100644 --- a/sys/kern/subr_log.c +++ b/sys/kern/subr_log.c @@ -1,4 +1,5 @@ -/* $NetBSD: subr_log.c,v 1.8 1994/10/30 21:47:47 cgd Exp $ */ +/* $OpenBSD: subr_log.c,v 1.2 1996/03/03 17:20:00 niklas Exp $ */ +/* $NetBSD: subr_log.c,v 1.10 1996/02/09 18:59:58 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1993 @@ -46,6 +47,10 @@ #include #include #include +#include +#include + +#include #define LOG_RDPRI (PZERO + 1) @@ -93,7 +98,8 @@ logopen(dev, flags, mode, p) int logclose(dev, flag, mode, p) dev_t dev; - int flag; + int flag, mode; + struct proc *p; { log_open = 0; @@ -120,8 +126,9 @@ logread(dev, uio, flag) return (EWOULDBLOCK); } logsoftc.sc_state |= LOG_RDWAIT; - if (error = tsleep((caddr_t)mbp, LOG_RDPRI | PCATCH, - "klog", 0)) { + error = tsleep((caddr_t)mbp, LOG_RDPRI | PCATCH, + "klog", 0); + if (error) { splx(s); return (error); } @@ -181,7 +188,7 @@ logwakeup() if (logsoftc.sc_state & LOG_ASYNC) { if (logsoftc.sc_pgid < 0) gsignal(-logsoftc.sc_pgid, SIGIO); - else if (p = pfind(logsoftc.sc_pgid)) + else if ((p = pfind(logsoftc.sc_pgid)) != NULL) psignal(p, SIGIO); } if (logsoftc.sc_state & LOG_RDWAIT) { @@ -192,11 +199,12 @@ logwakeup() /*ARGSUSED*/ int -logioctl(dev, com, data, flag) +logioctl(dev, com, data, flag, p) dev_t dev; u_long com; caddr_t data; int flag; + struct proc *p; { long l; int s; diff --git a/sys/kern/subr_prof.c b/sys/kern/subr_prof.c index 85c07cbe64d..6b86246954c 100644 --- a/sys/kern/subr_prof.c +++ b/sys/kern/subr_prof.c @@ -1,4 +1,5 @@ -/* $NetBSD: subr_prof.c,v 1.8 1995/11/22 23:07:26 cgd Exp $ */ +/* $OpenBSD: subr_prof.c,v 1.3 1996/03/03 17:20:01 niklas Exp $ */ +/* $NetBSD: subr_prof.c,v 1.10 1996/02/09 19:00:06 christos Exp $ */ /*- * Copyright (c) 1982, 1986, 1993 @@ -40,7 +41,7 @@ #include #include #include - +#include #include #include @@ -57,6 +58,8 @@ struct gmonparam _gmonparam = { GMON_PROF_OFF }; extern char etext[]; + +void kmstartup() { char *cp; @@ -146,6 +149,7 @@ sysctl_doprof(name, namelen, oldp, oldlenp, newp, newlen, p) * 1.0 is represented as 0x10000. A scale factor of 0 turns off profiling. */ /* ARGSUSED */ +int sys_profil(p, v, retval) struct proc *p; void *v; @@ -153,8 +157,8 @@ sys_profil(p, v, retval) { register struct sys_profil_args /* { syscallarg(caddr_t) samples; - syscallarg(size_t) size; - syscallarg(u_long) offset; + syscallarg(u_int) size; + syscallarg(u_int) offset; syscallarg(u_int) scale; } */ *uap = v; register struct uprof *upp; diff --git a/sys/kern/subr_rmap.c b/sys/kern/subr_rmap.c index 6de5f356836..d2c070c031a 100644 --- a/sys/kern/subr_rmap.c +++ b/sys/kern/subr_rmap.c @@ -1,4 +1,5 @@ -/* $NetBSD: subr_rmap.c,v 1.9 1994/06/29 06:33:02 cgd Exp $ */ +/* $OpenBSD: subr_rmap.c,v 1.2 1996/03/03 17:20:02 niklas Exp $ */ +/* $NetBSD: subr_rmap.c,v 1.10 1996/02/04 02:16:49 christos Exp $ */ /* * Copyright (C) 1992, 1994 Wolfgang Solfrank. @@ -33,6 +34,7 @@ #include #include +#include /* * Resource allocation map handling. @@ -206,14 +208,15 @@ rmfree(mp, size, addr) */ if (fp->m_size > size) { /* range to free is smaller, so drop that */ - printf("rmfree: map '%s' loses space (%d)\n", mp->m_name, - size); + printf("rmfree: map '%s' loses space (%d)\n", + mp->m_name, size); return; } else { /* drop the smallest slot in the list */ - printf("rmfree: map '%s' loses space (%d)\n", mp->m_name, - fp->m_size); - ovbcopy(fp + 1,fp,(char *)(mp->m_limit - 1) - (char *)fp); + printf("rmfree: map '%s' loses space (%d)\n", + mp->m_name, fp->m_size); + ovbcopy(fp + 1, fp, + (char *)(mp->m_limit - 1) - (char *)fp); mp->m_limit[-1].m_addr = 0; /* now retry */ } diff --git a/sys/kern/sys_generic.c b/sys/kern/sys_generic.c index ef5a13d076e..a4af284533d 100644 --- a/sys/kern/sys_generic.c +++ b/sys/kern/sys_generic.c @@ -1,4 +1,5 @@ -/* $NetBSD: sys_generic.c,v 1.21 1995/10/07 06:28:34 mycroft Exp $ */ +/* $OpenBSD: sys_generic.c,v 1.2 1996/03/03 17:20:03 niklas Exp $ */ +/* $NetBSD: sys_generic.c,v 1.23 1996/02/09 19:00:09 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -47,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -58,10 +60,14 @@ #include #include +int selscan __P((struct proc *, fd_set *, fd_set *, int, register_t *)); +int seltrue __P((dev_t, int, struct proc *)); + /* * Read system call. */ /* ARGSUSED */ +int sys_read(p, v, retval) struct proc *p; void *v; @@ -103,7 +109,8 @@ sys_read(p, v, retval) ktriov = aiov; #endif cnt = SCARG(uap, nbyte); - if (error = (*fp->f_ops->fo_read)(fp, &auio, fp->f_cred)) + error = (*fp->f_ops->fo_read)(fp, &auio, fp->f_cred); + if (error) if (auio.uio_resid != cnt && (error == ERESTART || error == EINTR || error == EWOULDBLOCK)) error = 0; @@ -120,6 +127,7 @@ sys_read(p, v, retval) /* * Scatter read system call. */ +int sys_readv(p, v, retval) struct proc *p; void *v; @@ -162,14 +170,18 @@ sys_readv(p, v, retval) auio.uio_rw = UIO_READ; auio.uio_segflg = UIO_USERSPACE; auio.uio_procp = p; - if (error = copyin((caddr_t)SCARG(uap, iovp), (caddr_t)iov, iovlen)) + error = copyin((caddr_t)SCARG(uap, iovp), (caddr_t)iov, iovlen); + if (error) goto done; auio.uio_resid = 0; for (i = 0; i < SCARG(uap, iovcnt); i++) { +#if 0 + /* Cannot happen iov_len is unsigned */ if (iov->iov_len < 0) { error = EINVAL; goto done; } +#endif auio.uio_resid += iov->iov_len; if (auio.uio_resid < 0) { error = EINVAL; @@ -187,7 +199,8 @@ sys_readv(p, v, retval) } #endif cnt = auio.uio_resid; - if (error = (*fp->f_ops->fo_read)(fp, &auio, fp->f_cred)) + error = (*fp->f_ops->fo_read)(fp, &auio, fp->f_cred); + if (error) if (auio.uio_resid != cnt && (error == ERESTART || error == EINTR || error == EWOULDBLOCK)) error = 0; @@ -210,6 +223,7 @@ done: /* * Write system call */ +int sys_write(p, v, retval) struct proc *p; void *v; @@ -251,7 +265,8 @@ sys_write(p, v, retval) ktriov = aiov; #endif cnt = SCARG(uap, nbyte); - if (error = (*fp->f_ops->fo_write)(fp, &auio, fp->f_cred)) { + error = (*fp->f_ops->fo_write)(fp, &auio, fp->f_cred); + if (error) { if (auio.uio_resid != cnt && (error == ERESTART || error == EINTR || error == EWOULDBLOCK)) error = 0; @@ -271,6 +286,7 @@ sys_write(p, v, retval) /* * Gather write system call */ +int sys_writev(p, v, retval) struct proc *p; void *v; @@ -313,14 +329,18 @@ sys_writev(p, v, retval) auio.uio_rw = UIO_WRITE; auio.uio_segflg = UIO_USERSPACE; auio.uio_procp = p; - if (error = copyin((caddr_t)SCARG(uap, iovp), (caddr_t)iov, iovlen)) + error = copyin((caddr_t)SCARG(uap, iovp), (caddr_t)iov, iovlen); + if (error) goto done; auio.uio_resid = 0; for (i = 0; i < SCARG(uap, iovcnt); i++) { +#if 0 + /* Cannot happen iov_len is unsigned */ if (iov->iov_len < 0) { error = EINVAL; goto done; } +#endif auio.uio_resid += iov->iov_len; if (auio.uio_resid < 0) { error = EINVAL; @@ -338,7 +358,8 @@ sys_writev(p, v, retval) } #endif cnt = auio.uio_resid; - if (error = (*fp->f_ops->fo_write)(fp, &auio, fp->f_cred)) { + error = (*fp->f_ops->fo_write)(fp, &auio, fp->f_cred); + if (error) { if (auio.uio_resid != cnt && (error == ERESTART || error == EINTR || error == EWOULDBLOCK)) error = 0; @@ -365,6 +386,7 @@ done: * Ioctl system call */ /* ARGSUSED */ +int sys_ioctl(p, v, retval) struct proc *p; void *v; @@ -437,7 +459,7 @@ sys_ioctl(p, v, retval) switch (com) { case FIONBIO: - if (tmp = *(int *)data) + if ((tmp = *(int *)data) != 0) fp->f_flag |= FNONBLOCK; else fp->f_flag &= ~FNONBLOCK; @@ -445,7 +467,7 @@ sys_ioctl(p, v, retval) break; case FIOASYNC: - if (tmp = *(int *)data) + if ((tmp = *(int *)data) != 0) fp->f_flag |= FASYNC; else fp->f_flag &= ~FASYNC; @@ -503,6 +525,7 @@ int selwait, nselcoll; /* * Select system call. */ +int sys_select(p, v, retval) register struct proc *p; void *v; @@ -568,7 +591,7 @@ retry: s = splhigh(); /* this should be timercmp(&time, &atv, >=) */ if (SCARG(uap, tv) && (time.tv_sec > atv.tv_sec || - time.tv_sec == atv.tv_sec && time.tv_usec >= atv.tv_usec)) { + (time.tv_sec == atv.tv_sec && time.tv_usec >= atv.tv_usec))) { splx(s); goto done; } @@ -603,6 +626,7 @@ done: return (error); } +int selscan(p, ibits, obits, nfd, retval) struct proc *p; fd_set *ibits, *obits; @@ -636,6 +660,7 @@ selscan(p, ibits, obits, nfd, retval) } /*ARGSUSED*/ +int seltrue(dev, flag, p) dev_t dev; int flag; diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index e9a0e748e9b..7ac4adafc82 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -1,4 +1,5 @@ -/* $NetBSD: sys_process.c,v 1.52 1995/10/07 06:28:36 mycroft Exp $ */ +/* $OpenBSD: sys_process.c,v 1.2 1996/03/03 17:20:04 niklas Exp $ */ +/* $NetBSD: sys_process.c,v 1.54 1996/02/09 19:00:14 christos Exp $ */ /*- * Copyright (c) 1994 Christopher G. Demetriou. All rights reserved. @@ -65,6 +66,8 @@ #include +#include + /* Macros to clear/set/test flags. */ #define SET(t, f) (t) |= (f) #define CLR(t, f) (t) &= ~(f) @@ -240,13 +243,14 @@ sys_ptrace(p, v, retval) /* * Arrange for a single-step, if that's requested and possible. */ - if (error = process_sstep(t, SCARG(uap, req) == PT_STEP)) + error = process_sstep(t, SCARG(uap, req) == PT_STEP); + if (error) goto relebad; #endif /* If the address paramter is not (int *)1, set the pc. */ if ((int *)SCARG(uap, addr) != (int *)1) - if (error = process_set_pc(t, SCARG(uap, addr))) + if ((error = process_set_pc(t, SCARG(uap, addr))) != 0) goto relebad; PRELE(t); @@ -356,8 +360,10 @@ sys_ptrace(p, v, retval) #ifdef DIAGNOSTIC panic("ptrace: impossible"); #endif + return 0; } +int trace_req(a1) struct proc *a1; { diff --git a/sys/kern/sysv_msg.c b/sys/kern/sysv_msg.c index c00b676b33a..d68ca5f8685 100644 --- a/sys/kern/sysv_msg.c +++ b/sys/kern/sysv_msg.c @@ -1,4 +1,5 @@ -/* $NetBSD: sysv_msg.c,v 1.17 1995/10/07 06:28:40 mycroft Exp $ */ +/* $OpenBSD: sysv_msg.c,v 1.2 1996/03/03 17:20:05 niklas Exp $ */ +/* $NetBSD: sysv_msg.c,v 1.19 1996/02/09 19:00:18 christos Exp $ */ /* * Implementation of SVID messages @@ -36,11 +37,12 @@ int nfree_msgmaps; /* # of free map entries */ short free_msgmaps; /* head of linked list of free map entries */ struct msg *free_msghdrs; /* list of free msg headers */ -int +static void msg_freehdr __P((struct msg *)); + +void msginit() { register int i; - vm_offset_t whocares1, whocares2; /* * msginfo.msgssz should be a power of two for efficiency reasons. @@ -132,7 +134,7 @@ sys_msgctl(p, v, retval) int cmd = SCARG(uap, cmd); struct msqid_ds *user_msqptr = SCARG(uap, buf); struct ucred *cred = p->p_ucred; - int i, rval, eval; + int rval, eval; struct msqid_ds msqbuf; register struct msqid_ds *msqptr; @@ -173,7 +175,7 @@ sys_msgctl(p, v, retval) case IPC_RMID: { struct msg *msghdr; - if ((eval = ipcperm(cred, &msqptr->msg_perm, IPC_M))) + if ((eval = ipcperm(cred, &msqptr->msg_perm, IPC_M)) != 0) return(eval); /* Free the message headers */ msghdr = msqptr->msg_first; @@ -265,7 +267,7 @@ sys_msgget(p, v, retval) int key = SCARG(uap, key); int msgflg = SCARG(uap, msgflg); struct ucred *cred = p->p_ucred; - register struct msqid_ds *msqptr; + register struct msqid_ds *msqptr = NULL; #ifdef MSG_DEBUG_OK printf("msgget(0x%x, 0%o)\n", key, msgflg); @@ -422,11 +424,11 @@ sys_msgsnd(p, v, retval) int need_more_resources = 0; /* - * check msgsz + * check msgsz [cannot be negative since it is unsigned] * (inside this loop in case msg_qbytes changes while we sleep) */ - if (msgsz < 0 || msgsz > msqptr->msg_qbytes) { + if (msgsz > msqptr->msg_qbytes) { #ifdef MSG_DEBUG_OK printf("msgsz > msqptr->msg_qbytes\n"); #endif @@ -749,12 +751,15 @@ sys_msgrcv(p, v, retval) return(eval); } +#if 0 + /* cannot happen, msgsz is unsigned */ if (msgsz < 0) { #ifdef MSG_DEBUG_OK printf("msgsz < 0\n"); #endif return(EINVAL); } +#endif msghdr = NULL; while (msghdr == NULL) { diff --git a/sys/kern/sysv_sem.c b/sys/kern/sysv_sem.c index d185b1628e2..c4d7c1c5b25 100644 --- a/sys/kern/sysv_sem.c +++ b/sys/kern/sysv_sem.c @@ -1,4 +1,5 @@ -/* $NetBSD: sysv_sem.c,v 1.24 1995/10/07 06:28:42 mycroft Exp $ */ +/* $OpenBSD: sysv_sem.c,v 1.2 1996/03/03 17:20:06 niklas Exp $ */ +/* $NetBSD: sysv_sem.c,v 1.26 1996/02/09 19:00:25 christos Exp $ */ /* * Implementation of SVID semaphores @@ -21,11 +22,15 @@ int semtot = 0; struct proc *semlock_holder = NULL; -int +void semlock __P((struct proc *)); +struct sem_undo *semu_alloc __P((struct proc *)); +int semundo_adjust __P((struct proc *, struct sem_undo **, int, int, int)); +void semundo_clear __P((int, int)); + +void seminit() { register int i; - vm_offset_t whocares1, whocares2; if (sema == NULL) panic("sema is NULL"); @@ -170,6 +175,7 @@ semu_alloc(p) panic("semu_alloc - second attempt failed"); } } + return NULL; } /* @@ -274,7 +280,7 @@ semundo_clear(semid, semnum) int sys___semctl(p, v, retval) struct proc *p; - void *v; + register void *v; register_t *retval; { register struct sys___semctl_args /* { @@ -313,7 +319,7 @@ sys___semctl(p, v, retval) switch (cmd) { case IPC_RMID: - if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_M))) + if ((eval = ipcperm(cred, &semaptr->sem_perm, IPC_M)) != 0) return(eval); semaptr->sem_perm.cuid = cred->cr_uid; semaptr->sem_perm.uid = cred->cr_uid; @@ -565,12 +571,12 @@ sys_semop(p, v, retval) int nsops = SCARG(uap, nsops); struct sembuf sops[MAX_SOPS]; register struct semid_ds *semaptr; - register struct sembuf *sopptr; - register struct sem *semptr; + register struct sembuf *sopptr = NULL; + register struct sem *semptr = NULL; struct sem_undo *suptr = NULL; struct ucred *cred = p->p_ucred; int i, j, eval; - int all_ok, do_wakeup, do_undos; + int do_wakeup, do_undos; #ifdef SEM_DEBUG printf("call to semop(%d, %p, %d)\n", semid, sops, nsops); @@ -641,7 +647,8 @@ sys_semop(p, v, retval) #endif if (sopptr->sem_op < 0) { - if (semptr->semval + sopptr->sem_op < 0) { + if ((int)(semptr->semval + + sopptr->sem_op) < 0) { #ifdef SEM_DEBUG printf("semop: can't do it now\n"); #endif @@ -824,6 +831,7 @@ done: * Go through the undo structures for this process and apply the adjustments to * semaphores. */ +void semexit(p) struct proc *p; { diff --git a/sys/kern/sysv_shm.c b/sys/kern/sysv_shm.c index b59b58959a8..b5955244de2 100644 --- a/sys/kern/sysv_shm.c +++ b/sys/kern/sysv_shm.c @@ -1,4 +1,5 @@ -/* $NetBSD: sysv_shm.c,v 1.34 1995/12/09 04:12:56 mycroft Exp $ */ +/* $OpenBSD: sysv_shm.c,v 1.3 1996/03/03 17:20:08 niklas Exp $ */ +/* $NetBSD: sysv_shm.c,v 1.36 1996/02/09 19:00:29 christos Exp $ */ /* * Copyright (c) 1994 Adam Glass and Charles Hannum. All rights reserved. @@ -50,6 +51,9 @@ #include #include +struct shmid_ds *shm_find_segment_by_shmid __P((int)); +void shmexit __P((struct proc *)); + /* * Provides the following externally accessible functions: * @@ -80,10 +84,13 @@ struct shmmap_state { int shmid; }; -static void shm_deallocate_segment __P((struct shmid_ds *)); static int shm_find_segment_by_key __P((key_t)); -struct shmid_ds *shm_find_segment_by_shmid __P((int)); +static void shm_deallocate_segment __P((struct shmid_ds *)); static int shm_delete_mapping __P((struct proc *, struct shmmap_state *)); +static int shmget_existing __P((struct proc *, struct sys_shmget_args *, + int, int, register_t *)); +static int shmget_allocate_segment __P((struct proc *, struct sys_shmget_args *, + int, register_t *)); static int shm_find_segment_by_key(key) @@ -189,7 +196,7 @@ sys_shmat(p, v, retval) struct sys_shmat_args /* { syscallarg(int) shmid; syscallarg(void *) shmaddr; - syscallarg(int) shmflag; + syscallarg(int) shmflg; } */ *uap = v; int error, i, flags; struct ucred *cred = p->p_ucred; @@ -210,8 +217,9 @@ sys_shmat(p, v, retval) shmseg = shm_find_segment_by_shmid(SCARG(uap, shmid)); if (shmseg == NULL) return EINVAL; - if (error = ipcperm(cred, &shmseg->shm_perm, - (SCARG(uap, shmflg) & SHM_RDONLY) ? IPC_R : IPC_R|IPC_W)) + error = ipcperm(cred, &shmseg->shm_perm, + (SCARG(uap, shmflg) & SHM_RDONLY) ? IPC_R : IPC_R|IPC_W); + if (error) return error; for (i = 0; i < shminfo.shmseg; i++) { if (shmmap_s->shmid == -1) @@ -263,7 +271,7 @@ sys_shmctl(p, v, retval) syscallarg(int) cmd; syscallarg(struct shmid_ds *) buf; } */ *uap = v; - int error, segnum; + int error; struct ucred *cred = p->p_ucred; struct shmid_ds inbuf; struct shmid_ds *shmseg; @@ -273,17 +281,19 @@ sys_shmctl(p, v, retval) return EINVAL; switch (SCARG(uap, cmd)) { case IPC_STAT: - if (error = ipcperm(cred, &shmseg->shm_perm, IPC_R)) + if ((error = ipcperm(cred, &shmseg->shm_perm, IPC_R)) != 0) return error; - if (error = copyout((caddr_t)shmseg, SCARG(uap, buf), - sizeof(inbuf))) + error = copyout((caddr_t)shmseg, SCARG(uap, buf), + sizeof(inbuf)); + if (error) return error; break; case IPC_SET: - if (error = ipcperm(cred, &shmseg->shm_perm, IPC_M)) + if ((error = ipcperm(cred, &shmseg->shm_perm, IPC_M)) != 0) return error; - if (error = copyin(SCARG(uap, buf), (caddr_t)&inbuf, - sizeof(inbuf))) + error = copyin(SCARG(uap, buf), (caddr_t)&inbuf, + sizeof(inbuf)); + if (error) return error; shmseg->shm_perm.uid = inbuf.shm_perm.uid; shmseg->shm_perm.gid = inbuf.shm_perm.gid; @@ -293,7 +303,7 @@ sys_shmctl(p, v, retval) shmseg->shm_ctime = time.tv_sec; break; case IPC_RMID: - if (error = ipcperm(cred, &shmseg->shm_perm, IPC_M)) + if ((error = ipcperm(cred, &shmseg->shm_perm, IPC_M)) != 0) return error; shmseg->shm_perm.key = IPC_PRIVATE; shmseg->shm_perm.mode |= SHMSEG_REMOVED; @@ -316,7 +326,7 @@ shmget_existing(p, uap, mode, segnum, retval) struct sys_shmget_args /* { syscallarg(key_t) key; syscallarg(int) size; - syscallarg(int) shmflag; + syscallarg(int) shmflg; } */ *uap; int mode; int segnum; @@ -334,12 +344,12 @@ shmget_existing(p, uap, mode, segnum, retval) * allocation failed or it was freed). */ shmseg->shm_perm.mode |= SHMSEG_WANTED; - if (error = - tsleep((caddr_t)shmseg, PLOCK | PCATCH, "shmget", 0)) + error = tsleep((caddr_t)shmseg, PLOCK | PCATCH, "shmget", 0); + if (error) return error; return EAGAIN; } - if (error = ipcperm(cred, &shmseg->shm_perm, mode)) + if ((error = ipcperm(cred, &shmseg->shm_perm, mode)) != 0) return error; if (SCARG(uap, size) && SCARG(uap, size) > shmseg->shm_segsz) return EINVAL; @@ -356,7 +366,7 @@ shmget_allocate_segment(p, uap, mode, retval) struct sys_shmget_args /* { syscallarg(key_t) key; syscallarg(int) size; - syscallarg(int) shmflag; + syscallarg(int) shmflg; } */ *uap; int mode; register_t *retval; @@ -439,10 +449,9 @@ sys_shmget(p, v, retval) struct sys_shmget_args /* { syscallarg(key_t) key; syscallarg(int) size; - syscallarg(int) shmflag; + syscallarg(int) shmflg; } */ *uap = v; int segnum, mode, error; - struct shmid_ds *shmseg; mode = SCARG(uap, shmflg) & ACCESSPERMS; if (SCARG(uap, key) != IPC_PRIVATE) { @@ -482,7 +491,6 @@ shmexit(p) struct proc *p; { struct shmmap_state *shmmap_s; - struct shmid_ds *shmseg; int i; shmmap_s = (struct shmmap_state *)p->p_vmspace->vm_shm; diff --git a/sys/kern/tty.c b/sys/kern/tty.c index fee5af84486..60235e20eca 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -1,4 +1,5 @@ -/* $NetBSD: tty.c,v 1.64 1996/01/10 20:52:27 pk Exp $ */ +/* $OpenBSD: tty.c,v 1.3 1996/03/03 17:20:09 niklas Exp $ */ +/* $NetBSD: tty.c,v 1.66 1996/02/09 19:00:38 christos Exp $ */ /*- * Copyright (c) 1982, 1986, 1990, 1991, 1993 @@ -55,14 +56,16 @@ #include #include #include +#include +#include #include -static int proc_compare __P((struct proc *p1, struct proc *p2)); -static int ttnread __P((struct tty *)); -static void ttyblock __P((struct tty *tp)); -static void ttyecho __P((int, struct tty *tp)); -static void ttyrubo __P((struct tty *, int)); +static int ttnread __P((struct tty *)); +static void ttyblock __P((struct tty *)); +static void ttyecho __P((int, struct tty *)); +static void ttyrubo __P((struct tty *, int)); +static int proc_compare __P((struct proc *, struct proc *)); /* Symbolic sleep message strings. */ char ttclos[] = "ttycls"; @@ -149,7 +152,7 @@ char const char_type[] = { /* Macros to clear/set/test flags. */ #define SET(t, f) (t) |= (f) -#define CLR(t, f) (t) &= ~(f) +#define CLR(t, f) (t) &= ~((unsigned)(f)) #define ISSET(t, f) ((t) & (f)) /* @@ -167,8 +170,7 @@ ttyopen(device, tp) if (!ISSET(tp->t_state, TS_ISOPEN)) { SET(tp->t_state, TS_ISOPEN); bzero(&tp->t_winsize, sizeof(tp->t_winsize)); -#if defined(COMPAT_43) || defined(COMPAT_SUNOS) || defined(COMPAT_SVR4) || \ - defined(COMPAT_FREEBSD) +#ifdef COMPAT_OLDTTY tp->t_flags = 0; #endif } @@ -208,7 +210,7 @@ ttyclose(tp) /* Is 'c' a line delimiter ("break" character)? */ #define TTBREAKC(c) \ ((c) == '\n' || ((c) == cc[VEOF] || \ - (c) == cc[VEOL] || (c) == cc[VEOL2]) && (c) != _POSIX_VDISABLE) + (c) == cc[VEOL] || (((c) == cc[VEOL2]) && (c) != _POSIX_VDISABLE))) /* @@ -221,7 +223,7 @@ ttyinput(c, tp) { register int iflag, lflag; register u_char *cc; - int i, err; + int i, error; /* * If input is pending take it first. @@ -244,9 +246,9 @@ ttyinput(c, tp) /* Handle exceptional conditions (break, parity, framing). */ cc = tp->t_cc; iflag = tp->t_iflag; - if (err = (ISSET(c, TTY_ERRORMASK))) { + if ((error = (ISSET(c, TTY_ERRORMASK))) != 0) { CLR(c, TTY_ERRORMASK); - if (ISSET(err, TTY_FE) && !c) { /* Break. */ + if (ISSET(error, TTY_FE) && !c) { /* Break. */ if (ISSET(iflag, IGNBRK)) goto endcase; else if (ISSET(iflag, BRKINT) && @@ -255,8 +257,8 @@ ttyinput(c, tp) c = cc[VINTR]; else if (ISSET(iflag, PARMRK)) goto parmrk; - } else if (ISSET(err, TTY_PE) && - ISSET(iflag, INPCK) || ISSET(err, TTY_FE)) { + } else if ((ISSET(error, TTY_PE) && + ISSET(iflag, INPCK)) || ISSET(error, TTY_FE)) { if (ISSET(iflag, IGNPAR)) goto endcase; else if (ISSET(iflag, PARMRK)) { @@ -643,8 +645,7 @@ ttioctl(tp, cmd, data, flag, p) case TIOCSTAT: case TIOCSTI: case TIOCSWINSZ: -#if defined(COMPAT_43) || defined(COMPAT_SUNOS) || defined(COMPAT_SVR4) || \ - defined(COMPAT_FREEBSD) +#ifdef COMPAT_OLDTTY case TIOCLBIC: case TIOCLBIS: case TIOCLSET: @@ -659,8 +660,9 @@ ttioctl(tp, cmd, data, flag, p) (p->p_sigignore & sigmask(SIGTTOU)) == 0 && (p->p_sigmask & sigmask(SIGTTOU)) == 0) { pgsignal(p->p_pgrp, SIGTTOU, 1); - if (error = ttysleep(tp, - &lbolt, TTOPRI | PCATCH, ttybg, 0)) + error = ttysleep(tp, + &lbolt, TTOPRI | PCATCH, ttybg, 0); + if (error) return (error); } break; @@ -702,7 +704,7 @@ ttioctl(tp, cmd, data, flag, p) (TS_CARR_ON | TS_ISOPEN)) return (EBUSY); #ifndef UCONSOLE - if (error = suser(p->p_ucred, &p->p_acflag)) + if ((error = suser(p->p_ucred, &p->p_acflag)) != 0) return (error); #endif constty = tp; @@ -710,7 +712,7 @@ ttioctl(tp, cmd, data, flag, p) constty = NULL; break; case TIOCDRAIN: /* wait till output drained */ - if (error = ttywait(tp)) + if ((error = ttywait(tp)) != 0) return (error); break; case TIOCGETA: { /* get termios struct */ @@ -752,7 +754,7 @@ ttioctl(tp, cmd, data, flag, p) s = spltty(); if (cmd == TIOCSETAW || cmd == TIOCSETAF) { - if (error = ttywait(tp)) { + if ((error = ttywait(tp)) != 0) { splx(s); return (error); } @@ -862,8 +864,8 @@ ttioctl(tp, cmd, data, flag, p) case TIOCSCTTY: /* become controlling tty */ /* Session ctty vnode pointer set in vnode layer. */ if (!SESS_LEADER(p) || - (p->p_session->s_ttyvp || tp->t_session) && - (tp->t_session != p->p_session)) + ((p->p_session->s_ttyvp || tp->t_session) && + (tp->t_session != p->p_session))) return (EPERM); tp->t_session = p->p_session; tp->t_pgrp = p->p_pgrp; @@ -891,8 +893,7 @@ ttioctl(tp, cmd, data, flag, p) } break; default: -#if defined(COMPAT_43) || defined(COMPAT_SUNOS) || defined(COMPAT_SVR4) || \ - defined(COMPAT_FREEBSD) +#ifdef COMPAT_OLDTTY return (ttcompat(tp, cmd, data, flag, p)); #else return (-1); @@ -916,8 +917,8 @@ ttselect(device, rw, p) switch (rw) { case FREAD: nread = ttnread(tp); - if (nread > 0 || !ISSET(tp->t_cflag, CLOCAL) && - !ISSET(tp->t_state, TS_CARR_ON)) + if (nread > 0 || (!ISSET(tp->t_cflag, CLOCAL) && + !ISSET(tp->t_state, TS_CARR_ON))) goto win; selrecord(p, &tp->t_rsel); break; @@ -966,8 +967,8 @@ ttywait(tp) && tp->t_oproc) { (*tp->t_oproc)(tp); SET(tp->t_state, TS_ASLEEP); - if (error = ttysleep(tp, - &tp->t_outq, TTOPRI | PCATCH, ttyout, 0)) + error = ttysleep(tp, &tp->t_outq, TTOPRI | PCATCH, ttyout, 0); + if (error) break; } splx(s); @@ -1046,9 +1047,9 @@ ttyblock(tp) * Block further input iff: current input > threshold * AND input is available to user program. */ - if (total >= TTYHOG / 2 && - !ISSET(tp->t_state, TS_TBLOCK) && - !ISSET(tp->t_lflag, ICANON) || tp->t_canq.c_cc > 0) { + if ((total >= TTYHOG / 2 && + !ISSET(tp->t_state, TS_TBLOCK) && + !ISSET(tp->t_lflag, ICANON)) || tp->t_canq.c_cc > 0) { if (ISSET(tp->t_iflag, IXOFF) && tp->t_cc[VSTOP] != _POSIX_VDISABLE && putc(tp->t_cc[VSTOP], &tp->t_outq) == 0) { @@ -1212,7 +1213,7 @@ ttread(tp, uio, flag) register struct proc *p = curproc; int s, first, error = 0; struct timeval stime; - int has_stime = 0, last_cc; + int has_stime = 0, last_cc = 0; long slp = 0; loop: lflag = tp->t_lflag; @@ -1233,7 +1234,8 @@ loop: lflag = tp->t_lflag; p->p_flag & P_PPWAIT || p->p_pgrp->pg_jobc == 0) return (EIO); pgsignal(p->p_pgrp, SIGTTIN, 1); - if (error = ttysleep(tp, &lbolt, TTIPRI | PCATCH, ttybg, 0)) + error = ttysleep(tp, &lbolt, TTIPRI | PCATCH, ttybg, 0); + if (error) return (error); goto loop; } @@ -1342,8 +1344,9 @@ read: if (CCEQ(cc[VDSUSP], c) && ISSET(lflag, ISIG)) { pgsignal(tp->t_pgrp, SIGTSTP, 1); if (first) { - if (error = ttysleep(tp, - &lbolt, TTIPRI | PCATCH, ttybg, 0)) + error = ttysleep(tp, &lbolt, + TTIPRI | PCATCH, ttybg, 0); + if (error) break; goto loop; } @@ -1433,7 +1436,7 @@ ttwrite(tp, uio, flag) register struct uio *uio; int flag; { - register u_char *cp; + register u_char *cp = NULL; register int cc, ce; register struct proc *p; int i, hiwat, cnt, error, s; @@ -1475,7 +1478,8 @@ loop: (p->p_sigmask & sigmask(SIGTTOU)) == 0 && p->p_pgrp->pg_jobc) { pgsignal(p->p_pgrp, SIGTTOU, 1); - if (error = ttysleep(tp, &lbolt, TTIPRI | PCATCH, ttybg, 0)) + error = ttysleep(tp, &lbolt, TTIPRI | PCATCH, ttybg, 0); + if (error) goto out; goto loop; } @@ -1768,8 +1772,8 @@ ttyecho(c, tp) (!ISSET(tp->t_lflag, ECHONL) || c != '\n')) || ISSET(tp->t_lflag, EXTPROC)) return; - if (ISSET(tp->t_lflag, ECHOCTL) && - (ISSET(c, TTY_CHARMASK) <= 037 && c != '\t' && c != '\n' || + if (((ISSET(tp->t_lflag, ECHOCTL) && + (ISSET(c, TTY_CHARMASK) <= 037 && c != '\t' && c != '\n')) || ISSET(c, TTY_CHARMASK) == 0177)) { (void)ttyoutput('^', tp); CLR(c, ~TTY_CHARMASK); @@ -1889,7 +1893,7 @@ ttyinfo(tp) #define pgtok(a) (((a) * NBPG) / 1024) /* Print percentage cpu, resident set size. */ - tmp = pick->p_pctcpu * 10000 + FSCALE / 2 >> FSHIFT; + tmp = (pick->p_pctcpu * 10000 + FSCALE / 2) >> FSHIFT; ttyprintf(tp, "%d%% %dk\n", tmp / 100, pick->p_stat == SIDL || pick->p_stat == SZOMB ? 0 : @@ -2016,7 +2020,7 @@ ttysleep(tp, chan, pri, wmesg, timo) short gen; gen = tp->t_gen; - if (error = tsleep(chan, pri, wmesg, timo)) + if ((error = tsleep(chan, pri, wmesg, timo)) != 0) return (error); return (tp->t_gen == gen ? 0 : ERESTART); } diff --git a/sys/kern/tty_compat.c b/sys/kern/tty_compat.c deleted file mode 100644 index 33f691989b7..00000000000 --- a/sys/kern/tty_compat.c +++ /dev/null @@ -1,472 +0,0 @@ -/* $NetBSD: tty_compat.c,v 1.27 1995/12/07 00:53:29 mycroft Exp $ */ - -/*- - * Copyright (c) 1982, 1986, 1991, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)tty_compat.c 8.1 (Berkeley) 6/10/93 - */ - -/* - * mapping routines for old line discipline (yuck) - */ -#if defined(COMPAT_43) || defined(COMPAT_SUNOS) || defined(COMPAT_SVR4) || \ - defined(COMPAT_FREEBSD) - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -int ttydebug = 0; - -static struct speedtab compatspeeds[] = { -#define MAX_SPEED 17 - { 115200, 17 }, - { 57600, 16 }, - { 38400, 15 }, - { 19200, 14 }, - { 9600, 13 }, - { 4800, 12 }, - { 2400, 11 }, - { 1800, 10 }, - { 1200, 9 }, - { 600, 8 }, - { 300, 7 }, - { 200, 6 }, - { 150, 5 }, - { 134, 4 }, - { 110, 3 }, - { 75, 2 }, - { 50, 1 }, - { 0, 0 }, - { -1, -1 }, -}; -static int compatspcodes[] = { - 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, - 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200 -}; - -/* Macros to clear/set/test flags. */ -#define SET(t, f) (t) |= (f) -#define CLR(t, f) (t) &= ~(f) -#define ISSET(t, f) ((t) & (f)) - -/*ARGSUSED*/ -ttcompat(tp, com, data, flag, p) - register struct tty *tp; - u_long com; - caddr_t data; - int flag; - struct proc *p; -{ - - switch (com) { - case TIOCGETP: { - register struct sgttyb *sg = (struct sgttyb *)data; - register u_char *cc = tp->t_cc; - register int speed; - - speed = ttspeedtab(tp->t_ospeed, compatspeeds); - sg->sg_ospeed = (speed == -1) ? MAX_SPEED : speed; - if (tp->t_ispeed == 0) - sg->sg_ispeed = sg->sg_ospeed; - else { - speed = ttspeedtab(tp->t_ispeed, compatspeeds); - sg->sg_ispeed = (speed == -1) ? MAX_SPEED : speed; - } - sg->sg_erase = cc[VERASE]; - sg->sg_kill = cc[VKILL]; - sg->sg_flags = ttcompatgetflags(tp); - break; - } - - case TIOCSETP: - case TIOCSETN: { - register struct sgttyb *sg = (struct sgttyb *)data; - struct termios term; - int speed; - - term = tp->t_termios; - if ((speed = sg->sg_ispeed) > MAX_SPEED || speed < 0) - term.c_ispeed = speed; - else - term.c_ispeed = compatspcodes[speed]; - if ((speed = sg->sg_ospeed) > MAX_SPEED || speed < 0) - term.c_ospeed = speed; - else - term.c_ospeed = compatspcodes[speed]; - term.c_cc[VERASE] = sg->sg_erase; - term.c_cc[VKILL] = sg->sg_kill; - tp->t_flags = (ttcompatgetflags(tp)&0xffff0000) | (sg->sg_flags&0xffff); - ttcompatsetflags(tp, &term); - return (ttioctl(tp, com == TIOCSETP ? TIOCSETAF : TIOCSETA, - (caddr_t)&term, flag, p)); - } - - case TIOCGETC: { - struct tchars *tc = (struct tchars *)data; - register u_char *cc = tp->t_cc; - - tc->t_intrc = cc[VINTR]; - tc->t_quitc = cc[VQUIT]; - tc->t_startc = cc[VSTART]; - tc->t_stopc = cc[VSTOP]; - tc->t_eofc = cc[VEOF]; - tc->t_brkc = cc[VEOL]; - break; - } - case TIOCSETC: { - struct tchars *tc = (struct tchars *)data; - register u_char *cc = tp->t_cc; - - cc[VINTR] = tc->t_intrc; - cc[VQUIT] = tc->t_quitc; - cc[VSTART] = tc->t_startc; - cc[VSTOP] = tc->t_stopc; - cc[VEOF] = tc->t_eofc; - cc[VEOL] = tc->t_brkc; - if (tc->t_brkc == -1) - cc[VEOL2] = _POSIX_VDISABLE; - break; - } - case TIOCSLTC: { - struct ltchars *ltc = (struct ltchars *)data; - register u_char *cc = tp->t_cc; - - cc[VSUSP] = ltc->t_suspc; - cc[VDSUSP] = ltc->t_dsuspc; - cc[VREPRINT] = ltc->t_rprntc; - cc[VDISCARD] = ltc->t_flushc; - cc[VWERASE] = ltc->t_werasc; - cc[VLNEXT] = ltc->t_lnextc; - break; - } - case TIOCGLTC: { - struct ltchars *ltc = (struct ltchars *)data; - register u_char *cc = tp->t_cc; - - ltc->t_suspc = cc[VSUSP]; - ltc->t_dsuspc = cc[VDSUSP]; - ltc->t_rprntc = cc[VREPRINT]; - ltc->t_flushc = cc[VDISCARD]; - ltc->t_werasc = cc[VWERASE]; - ltc->t_lnextc = cc[VLNEXT]; - break; - } - case TIOCLBIS: - case TIOCLBIC: - case TIOCLSET: { - struct termios term; - int flags; - - term = tp->t_termios; - flags = ttcompatgetflags(tp); - switch (com) { - case TIOCLSET: - tp->t_flags = (flags&0xffff) | (*(int *)data<<16); - break; - case TIOCLBIS: - tp->t_flags = flags | (*(int *)data<<16); - break; - case TIOCLBIC: - tp->t_flags = flags & ~(*(int *)data<<16); - break; - } - ttcompatsetlflags(tp, &term); - return (ttioctl(tp, TIOCSETA, (caddr_t)&term, flag, p)); - } - case TIOCLGET: - *(int *)data = ttcompatgetflags(tp)>>16; - if (ttydebug) - printf("CLGET: returning %x\n", *(int *)data); - break; - - case OTIOCGETD: - *(int *)data = tp->t_line ? tp->t_line : 2; - break; - - case OTIOCSETD: { - int ldisczero = 0; - - return (ttioctl(tp, TIOCSETD, - *(int *)data == 2 ? (caddr_t)&ldisczero : data, flag, - p)); - } - - case OTIOCCONS: - *(int *)data = 1; - return (ttioctl(tp, TIOCCONS, data, flag, p)); - - case TIOCHPCL: - SET(tp->t_cflag, HUPCL); - break; - - case TIOCGSID: - if (tp->t_session == NULL) - return ENOTTY; - - if (tp->t_session->s_leader == NULL) - return ENOTTY; - - *(int *) data = tp->t_session->s_leader->p_pid; - break; - - default: - return (-1); - } - return (0); -} - -int -ttcompatgetflags(tp) - register struct tty *tp; -{ - register tcflag_t iflag = tp->t_iflag; - register tcflag_t lflag = tp->t_lflag; - register tcflag_t oflag = tp->t_oflag; - register tcflag_t cflag = tp->t_cflag; - register int flags = 0; - - if (ISSET(iflag, IXOFF)) - SET(flags, TANDEM); - if (ISSET(iflag, ICRNL) || ISSET(oflag, ONLCR)) - SET(flags, CRMOD); - if (ISSET(cflag, PARENB)) { - if (ISSET(iflag, INPCK)) { - if (ISSET(cflag, PARODD)) - SET(flags, ODDP); - else - SET(flags, EVENP); - } else - SET(flags, ANYP); - } - - if (!ISSET(lflag, ICANON)) { - /* fudge */ - if (ISSET(iflag, IXON) || ISSET(lflag, ISIG|IEXTEN) || - ISSET(cflag, PARENB)) - SET(flags, CBREAK); - else - SET(flags, RAW); - } - - if (ISSET(flags, RAW)) - SET(flags, ISSET(tp->t_flags, LITOUT|PASS8)); - else if (ISSET(cflag, CSIZE) == CS8) { - if (!ISSET(oflag, OPOST)) - SET(flags, LITOUT); - if (!ISSET(iflag, ISTRIP)) - SET(flags, PASS8); - } - - if (ISSET(cflag, MDMBUF)) - SET(flags, MDMBUF); - if (!ISSET(cflag, HUPCL)) - SET(flags, NOHANG); - if (ISSET(oflag, OXTABS)) - SET(flags, XTABS); - if (ISSET(lflag, ECHOE)) - SET(flags, CRTERA|CRTBS); - if (ISSET(lflag, ECHOKE)) - SET(flags, CRTKIL|CRTBS); - if (ISSET(lflag, ECHOPRT)) - SET(flags, PRTERA); - if (ISSET(lflag, ECHOCTL)) - SET(flags, CTLECH); - if (!ISSET(iflag, IXANY)) - SET(flags, DECCTQ); - SET(flags, ISSET(lflag, ECHO|TOSTOP|FLUSHO|PENDIN|NOFLSH)); - if (ttydebug) - printf("getflags: %x\n", flags); - return (flags); -} - -ttcompatsetflags(tp, t) - register struct tty *tp; - register struct termios *t; -{ - register int flags = tp->t_flags; - register tcflag_t iflag = t->c_iflag; - register tcflag_t oflag = t->c_oflag; - register tcflag_t lflag = t->c_lflag; - register tcflag_t cflag = t->c_cflag; - - if (ISSET(flags, TANDEM)) - SET(iflag, IXOFF); - else - CLR(iflag, IXOFF); - if (ISSET(flags, ECHO)) - SET(lflag, ECHO); - else - CLR(lflag, ECHO); - if (ISSET(flags, CRMOD)) { - SET(iflag, ICRNL); - SET(oflag, ONLCR); - } else { - CLR(iflag, ICRNL); - CLR(oflag, ONLCR); - } - if (ISSET(flags, XTABS)) - SET(oflag, OXTABS); - else - CLR(oflag, OXTABS); - - - if (ISSET(flags, RAW)) { - iflag &= IXOFF; - CLR(lflag, ISIG|ICANON|IEXTEN); - CLR(cflag, PARENB); - } else { - SET(iflag, BRKINT|IXON|IMAXBEL); - SET(lflag, ISIG|IEXTEN); - if (ISSET(flags, CBREAK)) - CLR(lflag, ICANON); - else - SET(lflag, ICANON); - switch (ISSET(flags, ANYP)) { - case 0: - CLR(cflag, PARENB); - break; - case ANYP: - SET(cflag, PARENB); - CLR(iflag, INPCK); - break; - case EVENP: - SET(cflag, PARENB); - SET(iflag, INPCK); - CLR(cflag, PARODD); - break; - case ODDP: - SET(cflag, PARENB); - SET(iflag, INPCK); - SET(cflag, PARODD); - break; - } - } - - if (ISSET(flags, RAW|LITOUT|PASS8)) { - CLR(cflag, CSIZE); - SET(cflag, CS8); - if (!ISSET(flags, RAW|PASS8)) - SET(iflag, ISTRIP); - else - CLR(iflag, ISTRIP); - if (!ISSET(flags, RAW|LITOUT)) - SET(oflag, OPOST); - else - CLR(oflag, OPOST); - } else { - CLR(cflag, CSIZE); - SET(cflag, CS7); - SET(iflag, ISTRIP); - SET(oflag, OPOST); - } - - t->c_iflag = iflag; - t->c_oflag = oflag; - t->c_lflag = lflag; - t->c_cflag = cflag; -} - -ttcompatsetlflags(tp, t) - register struct tty *tp; - register struct termios *t; -{ - register int flags = tp->t_flags; - register tcflag_t iflag = t->c_iflag; - register tcflag_t oflag = t->c_oflag; - register tcflag_t lflag = t->c_lflag; - register tcflag_t cflag = t->c_cflag; - - /* Nothing we can do with CRTBS. */ - if (ISSET(flags, PRTERA)) - SET(lflag, ECHOPRT); - else - CLR(lflag, ECHOPRT); - if (ISSET(flags, CRTERA)) - SET(lflag, ECHOE); - else - CLR(lflag, ECHOE); - /* Nothing we can do with TILDE. */ - if (ISSET(flags, MDMBUF)) - SET(cflag, MDMBUF); - else - CLR(cflag, MDMBUF); - if (ISSET(flags, NOHANG)) - CLR(cflag, HUPCL); - else - SET(cflag, HUPCL); - if (ISSET(flags, CRTKIL)) - SET(lflag, ECHOKE); - else - CLR(lflag, ECHOKE); - if (ISSET(flags, CTLECH)) - SET(lflag, ECHOCTL); - else - CLR(lflag, ECHOCTL); - if (!ISSET(flags, DECCTQ)) - SET(iflag, IXANY); - else - CLR(iflag, IXANY); - CLR(lflag, TOSTOP|FLUSHO|PENDIN|NOFLSH); - SET(lflag, ISSET(flags, TOSTOP|FLUSHO|PENDIN|NOFLSH)); - - if (ISSET(flags, RAW|LITOUT|PASS8)) { - CLR(cflag, CSIZE); - SET(cflag, CS8); - if (!ISSET(flags, RAW|PASS8)) - SET(iflag, ISTRIP); - else - CLR(iflag, ISTRIP); - if (!ISSET(flags, RAW|LITOUT)) - SET(oflag, OPOST); - else - CLR(oflag, OPOST); - } else { - CLR(cflag, CSIZE); - SET(cflag, CS7); - SET(iflag, ISTRIP); - SET(oflag, OPOST); - } - - t->c_iflag = iflag; - t->c_oflag = oflag; - t->c_lflag = lflag; - t->c_cflag = cflag; -} -#endif /* COMPAT_43 || COMPAT_SUNOS || COMPAT_SVR4 || COMPAT_FREEBSD */ diff --git a/sys/kern/tty_conf.c b/sys/kern/tty_conf.c index 7746a7c47a4..6e3b0ba09f9 100644 --- a/sys/kern/tty_conf.c +++ b/sys/kern/tty_conf.c @@ -1,4 +1,5 @@ -/* $NetBSD: tty_conf.c,v 1.16 1995/10/10 01:27:01 mycroft Exp $ */ +/* $OpenBSD: tty_conf.c,v 1.2 1996/03/03 17:20:11 niklas Exp $ */ +/* $NetBSD: tty_conf.c,v 1.17 1996/02/04 02:17:22 christos Exp $ */ /*- * Copyright (c) 1982, 1986, 1991, 1993 @@ -54,8 +55,7 @@ #define ttyerrinput ((int (*) __P((int c, struct tty *)))enodev) #define ttyerrstart ((int (*) __P((struct tty *)))enodev) -int nullioctl __P((struct tty *tp, u_long cmd, caddr_t data, - int flag, struct proc *p)); +int nullioctl __P((struct tty *, u_long, caddr_t, int, struct proc *)); #include "tb.h" #if NTB > 0 @@ -137,6 +137,7 @@ int nlinesw = sizeof (linesw) / sizeof (linesw[0]); * discipline specific ioctl command. */ /*ARGSUSED*/ +int nullioctl(tp, cmd, data, flags, p) struct tty *tp; u_long cmd; diff --git a/sys/kern/tty_subr.c b/sys/kern/tty_subr.c index 4182093a6e3..fbef87fd854 100644 --- a/sys/kern/tty_subr.c +++ b/sys/kern/tty_subr.c @@ -1,4 +1,5 @@ -/* $NetBSD: tty_subr.c,v 1.11 1994/10/30 21:48:03 cgd Exp $ */ +/* $OpenBSD: tty_subr.c,v 1.2 1996/03/03 17:20:12 niklas Exp $ */ +/* $NetBSD: tty_subr.c,v 1.13 1996/02/09 19:00:43 christos Exp $ */ /* * Copyright (c) 1993, 1994 Theo de Raadt @@ -64,6 +65,14 @@ #define QMEM(n) (n) #endif +void cinit __P((void)); +int ndqb __P((struct clist *, int)); +int putc __P((int, struct clist *)); +#ifdef QBITS +void clrbits __P((u_char *, int, int)); +#endif +int b_to_q __P((u_char *, int, struct clist *)); +u_char *firstc __P((struct clist *, int *)); /* * Initialize clists. @@ -191,6 +200,7 @@ q_to_b(clp, cp, count) * Return count of contiguous characters in clist. * Stop counting if flag&character is non-null. */ +int ndqb(clp, flag) struct clist *clp; int flag; @@ -275,9 +285,7 @@ putc(c, clp) int c; struct clist *clp; { - register u_char *q; register int i; - int r = -1; int s; s = spltty(); @@ -371,9 +379,9 @@ b_to_q(cp, count, clp) int count; struct clist *clp; { - register int i, cc; + register int cc; register u_char *p = cp; - int off, s; + int s; if (count <= 0) return 0; @@ -477,9 +485,7 @@ firstc(clp, c) struct clist *clp; int *c; { - int empty = 0; register u_char *cp; - register int i; cc = clp->c_cc; if (cc == 0) diff --git a/sys/kern/tty_tb.c b/sys/kern/tty_tb.c index 74e8183f900..8616422eceb 100644 --- a/sys/kern/tty_tb.c +++ b/sys/kern/tty_tb.c @@ -1,4 +1,5 @@ -/* $NetBSD: tty_tb.c,v 1.17 1995/05/10 16:53:02 christos Exp $ */ +/* $OpenBSD: tty_tb.c,v 1.2 1996/03/03 17:20:13 niklas Exp $ */ +/* $NetBSD: tty_tb.c,v 1.18 1996/02/04 02:17:36 christos Exp $ */ /*- * Copyright (c) 1982, 1986, 1991, 1993 @@ -43,11 +44,18 @@ */ #include #include +#include #include #include #include #include +union tbpos { + struct hitpos hitpos; + struct gtcopos gtcopos; + struct polpos polpos; +}; + /* * Tablet configuration table. */ @@ -55,7 +63,8 @@ struct tbconf { short tbc_recsize; /* input record size in bytes */ short tbc_uiosize; /* size of data record returned user */ int tbc_sync; /* mask for finding sync byte/bit */ - int (*tbc_decode)();/* decoding routine */ + /* decoding routine */ + void (*tbc_decode) __P((struct tbconf *, char *, union tbpos *)); u_char *tbc_run; /* enter run mode sequence */ u_char *tbc_point; /* enter point mode sequence */ u_char *tbc_stop; /* stop sequence */ @@ -65,22 +74,26 @@ struct tbconf { #define TBF_INPROX 0x2 /* tablet has proximity info */ }; -static int tbdecode(), gtcodecode(), poldecode(); -static int tblresdecode(), tbhresdecode(); +static void gtcodecode __P((struct tbconf *, char *, union tbpos *)); +static void tbolddecode __P((struct tbconf *, char *, union tbpos *)); +static void tblresdecode __P((struct tbconf *, char *, union tbpos *)); +static void tbhresdecode __P((struct tbconf *, char *, union tbpos *)); +static void poldecode __P((struct tbconf *, char *, union tbpos *)); + struct tbconf tbconf[TBTYPE] = { { 0 }, -{ 5, sizeof (struct tbpos), 0200, tbdecode, "6", "4" }, -{ 5, sizeof (struct tbpos), 0200, tbdecode, "\1CN", "\1RT", "\2", "\4" }, +{ 5, sizeof (struct hitpos), 0200, tbolddecode, "6", "4" }, +{ 5, sizeof (struct hitpos), 0200, tbolddecode, "\1CN", "\1RT", "\2", "\4" }, { 8, sizeof (struct gtcopos), 0200, gtcodecode }, {17, sizeof (struct polpos), 0200, poldecode, 0, 0, "\21", "\5\22\2\23", TBF_POL }, -{ 5, sizeof (struct tbpos), 0100, tblresdecode, "\1CN", "\1PT", "\2", "\4", +{ 5, sizeof (struct hitpos), 0100, tblresdecode, "\1CN", "\1PT", "\2", "\4", TBF_INPROX }, -{ 6, sizeof (struct tbpos), 0200, tbhresdecode, "\1CN", "\1PT", "\2", "\4", +{ 6, sizeof (struct hitpos), 0200, tbhresdecode, "\1CN", "\1PT", "\2", "\4", TBF_INPROX }, -{ 5, sizeof (struct tbpos), 0100, tblresdecode, "\1CL\33", "\1PT\33", 0, 0}, -{ 6, sizeof (struct tbpos), 0200, tbhresdecode, "\1CL\33", "\1PT\33", 0, 0}, +{ 5, sizeof (struct hitpos), 0100, tblresdecode, "\1CL\33", "\1PT\33", 0, 0}, +{ 6, sizeof (struct hitpos), 0200, tbhresdecode, "\1CL\33", "\1PT\33", 0, 0}, }; /* @@ -92,17 +105,22 @@ struct tb { char cbuf[TBMAXREC]; /* input buffer */ int tbinbuf; char *tbcp; - union { - struct tbpos tbpos; - struct gtcopos gtcopos; - struct polpos polpos; - } rets; /* processed state */ + union tbpos tbpos; } tb[NTB]; + +int tbopen __P((dev_t, struct tty *)); +void tbclose __P((struct tty *)); +int tbread __P((struct tty *, struct uio *)); +void tbinput __P((int, struct tty *)); +int tbtioctl __P((struct tty *, u_long, caddr_t, int, struct proc *)); +void tbattach __P((int)); + /* * Open as tablet discipline; called on discipline change. */ /*ARGSUSED*/ +int tbopen(dev, tp) dev_t dev; register struct tty *tp; @@ -120,7 +138,7 @@ tbopen(dev, tp) tbp->tbflags = TBTIGER|TBPOINT; /* default */ tbp->tbcp = tbp->cbuf; tbp->tbinbuf = 0; - bzero((caddr_t)&tbp->rets, sizeof (tbp->rets)); + bzero((caddr_t)&tbp->tbpos, sizeof (tbp->tbpos)); tp->t_sc = (caddr_t)tbp; tp->t_flags |= LITOUT; return (0); @@ -129,18 +147,20 @@ tbopen(dev, tp) /* * Line discipline change or last device close. */ +void tbclose(tp) register struct tty *tp; { int modebits = TBPOINT|TBSTOP; - tbtioctl(tp, BIOSMODE, &modebits, 0, curproc); + tbtioctl(tp, BIOSMODE, (caddr_t) &modebits, 0, curproc); } /* * Read from a tablet line. * Characters have been buffered in a buffer and decoded. */ +int tbread(tp, uio) register struct tty *tp; struct uio *uio; @@ -151,9 +171,9 @@ tbread(tp, uio) if ((tp->t_state&TS_CARR_ON) == 0) return (EIO); - ret = uiomove(&tbp->rets, tc->tbc_uiosize, uio); + ret = uiomove((caddr_t) &tbp->tbpos, tc->tbc_uiosize, uio); if (tc->tbc_flags&TBF_POL) - tbp->rets.polpos.p_key = ' '; + tbp->tbpos.polpos.p_key = ' '; return (ret); } @@ -165,6 +185,7 @@ tbread(tp, uio) * This routine could be expanded in-line in the receiver * interrupt routine to make it run as fast as possible. */ +void tbinput(c, tp) register int c; register struct tty *tp; @@ -186,124 +207,129 @@ tbinput(c, tp) * Call decode routine only if a full record has been collected. */ if (++tbp->tbinbuf == tc->tbc_recsize) - (*tc->tbc_decode)(tc, tbp->cbuf, &tbp->rets); + (*tc->tbc_decode)(tc, tbp->cbuf, &tbp->tbpos); } /* * Decode GTCO 8 byte format (high res, tilt, and pressure). */ -static -gtcodecode(tc, cp, tbpos) +static void +gtcodecode(tc, cp, u) struct tbconf *tc; register char *cp; - register struct gtcopos *tbpos; + register union tbpos *u; { - - tbpos->pressure = *cp >> 2; - tbpos->status = (tbpos->pressure > 16) | TBINPROX; /* half way down */ - tbpos->xpos = (*cp++ & 03) << 14; - tbpos->xpos |= *cp++ << 7; - tbpos->xpos |= *cp++; - tbpos->ypos = (*cp++ & 03) << 14; - tbpos->ypos |= *cp++ << 7; - tbpos->ypos |= *cp++; - tbpos->xtilt = *cp++; - tbpos->ytilt = *cp++; - tbpos->scount++; + struct gtcopos *pos = &u->gtcopos; + pos->pressure = *cp >> 2; + pos->status = (pos->pressure > 16) | TBINPROX; /* half way down */ + pos->xpos = (*cp++ & 03) << 14; + pos->xpos |= *cp++ << 7; + pos->xpos |= *cp++; + pos->ypos = (*cp++ & 03) << 14; + pos->ypos |= *cp++ << 7; + pos->ypos |= *cp++; + pos->xtilt = *cp++; + pos->ytilt = *cp++; + pos->scount++; } /* * Decode old Hitachi 5 byte format (low res). */ -static -tbdecode(tc, cp, tbpos) +static void +tbolddecode(tc, cp, u) struct tbconf *tc; register char *cp; - register struct tbpos *tbpos; + register union tbpos *u; { + struct hitpos *pos = &u->hitpos; register char byte; byte = *cp++; - tbpos->status = (byte&0100) ? TBINPROX : 0; + pos->status = (byte&0100) ? TBINPROX : 0; byte &= ~0100; if (byte > 036) - tbpos->status |= 1 << ((byte-040)/2); - tbpos->xpos = *cp++ << 7; - tbpos->xpos |= *cp++; - if (tbpos->xpos < 256) /* tablet wraps around at 256 */ - tbpos->status &= ~TBINPROX; /* make it out of proximity */ - tbpos->ypos = *cp++ << 7; - tbpos->ypos |= *cp++; - tbpos->scount++; + pos->status |= 1 << ((byte-040)/2); + pos->xpos = *cp++ << 7; + pos->xpos |= *cp++; + if (pos->xpos < 256) /* tablet wraps around at 256 */ + pos->status &= ~TBINPROX; /* make it out of proximity */ + pos->ypos = *cp++ << 7; + pos->ypos |= *cp++; + pos->scount++; } /* * Decode new Hitach 5-byte format (low res). */ -static -tblresdecode(tc, cp, tbpos) +static void +tblresdecode(tc, cp, u) struct tbconf *tc; register char *cp; - register struct tbpos *tbpos; + register union tbpos *u; { + struct hitpos *pos = &u->hitpos; *cp &= ~0100; /* mask sync bit */ - tbpos->status = (*cp++ >> 2) | TBINPROX; - if (tc->tbc_flags&TBF_INPROX && tbpos->status&020) - tbpos->status &= ~(020|TBINPROX); - tbpos->xpos = *cp++; - tbpos->xpos |= *cp++ << 6; - tbpos->ypos = *cp++; - tbpos->ypos |= *cp++ << 6; - tbpos->scount++; + pos->status = (*cp++ >> 2) | TBINPROX; + if (tc->tbc_flags&TBF_INPROX && pos->status&020) + pos->status &= ~(020|TBINPROX); + pos->xpos = *cp++; + pos->xpos |= *cp++ << 6; + pos->ypos = *cp++; + pos->ypos |= *cp++ << 6; + pos->scount++; } /* * Decode new Hitach 6-byte format (high res). */ -static -tbhresdecode(tc, cp, tbpos) +static void +tbhresdecode(tc, cp, u) struct tbconf *tc; register char *cp; - register struct tbpos *tbpos; + register union tbpos *u; { + struct hitpos *pos = &u->hitpos; char byte; byte = *cp++; - tbpos->xpos = (byte & 03) << 14; - tbpos->xpos |= *cp++ << 7; - tbpos->xpos |= *cp++; - tbpos->ypos = *cp++ << 14; - tbpos->ypos |= *cp++ << 7; - tbpos->ypos |= *cp++; - tbpos->status = (byte >> 2) | TBINPROX; - if (tc->tbc_flags&TBF_INPROX && tbpos->status&020) - tbpos->status &= ~(020|TBINPROX); - tbpos->scount++; + pos->xpos = (byte & 03) << 14; + pos->xpos |= *cp++ << 7; + pos->xpos |= *cp++; + pos->ypos = *cp++ << 14; + pos->ypos |= *cp++ << 7; + pos->ypos |= *cp++; + pos->status = (byte >> 2) | TBINPROX; + if (tc->tbc_flags&TBF_INPROX && pos->status&020) + pos->status &= ~(020|TBINPROX); + pos->scount++; } /* * Polhemus decode. */ -static -poldecode(tc, cp, polpos) +static void +poldecode(tc, cp, u) struct tbconf *tc; register char *cp; - register struct polpos *polpos; + register union tbpos *u; { - - polpos->p_x = cp[4] | cp[3]<<7 | (cp[9] & 0x03) << 14; - polpos->p_y = cp[6] | cp[5]<<7 | (cp[9] & 0x0c) << 12; - polpos->p_z = cp[8] | cp[7]<<7 | (cp[9] & 0x30) << 10; - polpos->p_azi = cp[11] | cp[10]<<7 | (cp[16] & 0x03) << 14; - polpos->p_pit = cp[13] | cp[12]<<7 | (cp[16] & 0x0c) << 12; - polpos->p_rol = cp[15] | cp[14]<<7 | (cp[16] & 0x30) << 10; - polpos->p_stat = cp[1] | cp[0]<<7; + struct polpos *pos = &u->polpos; + + pos->p_x = cp[4] | cp[3]<<7 | (cp[9] & 0x03) << 14; + pos->p_y = cp[6] | cp[5]<<7 | (cp[9] & 0x0c) << 12; + pos->p_z = cp[8] | cp[7]<<7 | (cp[9] & 0x30) << 10; + pos->p_azi = cp[11] | cp[10]<<7 | (cp[16] & 0x03) << 14; + pos->p_pit = cp[13] | cp[12]<<7 | (cp[16] & 0x0c) << 12; + pos->p_rol = cp[15] | cp[14]<<7 | (cp[16] & 0x30) << 10; + pos->p_stat = cp[1] | cp[0]<<7; if (cp[2] != ' ') - polpos->p_key = cp[2]; + pos->p_key = cp[2]; } /*ARGSUSED*/ +int tbtioctl(tp, cmd, data, flag, p) struct tty *tp; u_long cmd; @@ -368,7 +394,8 @@ tbtioctl(tp, cmd, data, flag, p) return (0); } -void tbattach(dummy) +void +tbattach(dummy) int dummy; { /* stub to handle side effect of new config */ diff --git a/sys/kern/tty_tty.c b/sys/kern/tty_tty.c index d18aa575947..6115a9d5041 100644 --- a/sys/kern/tty_tty.c +++ b/sys/kern/tty_tty.c @@ -1,4 +1,5 @@ -/* $NetBSD: tty_tty.c,v 1.11 1994/10/30 21:48:05 cgd Exp $ */ +/* $OpenBSD: tty_tty.c,v 1.2 1996/03/03 17:20:15 niklas Exp $ */ +/* $NetBSD: tty_tty.c,v 1.12 1996/02/04 02:17:39 christos Exp $ */ /*- * Copyright (c) 1982, 1986, 1991, 1993 @@ -40,16 +41,18 @@ */ #include #include -#include #include #include #include #include #include +#include + #define cttyvp(p) ((p)->p_flag & P_CONTROLT ? (p)->p_session->s_ttyvp : NULL) /*ARGSUSED*/ +int cttyopen(dev, flag, mode, p) dev_t dev; int flag, mode; @@ -80,6 +83,7 @@ cttyopen(dev, flag, mode, p) } /*ARGSUSED*/ +int cttyread(dev, uio, flag) dev_t dev; struct uio *uio; @@ -97,6 +101,7 @@ cttyread(dev, uio, flag) } /*ARGSUSED*/ +int cttywrite(dev, uio, flag) dev_t dev; struct uio *uio; @@ -114,6 +119,7 @@ cttywrite(dev, uio, flag) } /*ARGSUSED*/ +int cttyioctl(dev, cmd, addr, flag, p) dev_t dev; u_long cmd; @@ -138,6 +144,7 @@ cttyioctl(dev, cmd, addr, flag, p) } /*ARGSUSED*/ +int cttyselect(dev, flag, p) dev_t dev; int flag; diff --git a/sys/kern/uipc_domain.c b/sys/kern/uipc_domain.c index 1bc3132cc60..8863103e83e 100644 --- a/sys/kern/uipc_domain.c +++ b/sys/kern/uipc_domain.c @@ -1,4 +1,5 @@ -/* $NetBSD: uipc_domain.c,v 1.12 1994/06/29 06:33:33 cgd Exp $ */ +/* $OpenBSD: uipc_domain.c,v 1.2 1996/03/03 17:20:16 niklas Exp $ */ +/* $NetBSD: uipc_domain.c,v 1.14 1996/02/09 19:00:44 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1993 @@ -195,7 +196,7 @@ pfctlinput(cmd, sa) for (dp = domains; dp; dp = dp->dom_next) for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) if (pr->pr_ctlinput) - (*pr->pr_ctlinput)(cmd, sa, (caddr_t)0); + (*pr->pr_ctlinput)(cmd, sa, NULL); } void diff --git a/sys/kern/uipc_mbuf.c b/sys/kern/uipc_mbuf.c index 3bb0abc1b04..f76c50a51a5 100644 --- a/sys/kern/uipc_mbuf.c +++ b/sys/kern/uipc_mbuf.c @@ -1,4 +1,5 @@ -/* $NetBSD: uipc_mbuf.c,v 1.13 1994/10/30 21:48:06 cgd Exp $ */ +/* $OpenBSD: uipc_mbuf.c,v 1.2 1996/03/03 17:20:17 niklas Exp $ */ +/* $NetBSD: uipc_mbuf.c,v 1.15 1996/02/09 19:00:45 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1988, 1991, 1993 @@ -73,6 +74,7 @@ bad: * Must be called at splimp. */ /* ARGSUSED */ +int m_clalloc(ncl, nowait) register int ncl; int nowait; @@ -135,6 +137,7 @@ m_retryhdr(i, t) return (m); } +void m_reclaim() { register struct domain *dp; @@ -207,7 +210,7 @@ m_freem(m) return; do { MFREE(m, n); - } while (m = n); + } while ((m = n) != NULL); } /* @@ -321,6 +324,7 @@ nospace: * Copy data from an mbuf chain starting "off" bytes from the beginning, * continuing for "len" bytes, into the indicated buffer. */ +void m_copydata(m, off, len, cp) register struct mbuf *m; register int off; @@ -356,6 +360,7 @@ m_copydata(m, off, len, cp) * Both chains must be of the same type (e.g. MT_DATA). * Any m_pkthdr is not updated. */ +void m_cat(m, n) register struct mbuf *m, *n; { @@ -445,7 +450,7 @@ m_adj(mp, req_len) } count -= m->m_len; } - while (m = m->m_next) + while ((m = m->m_next) != NULL) m->m_len = 0; } } @@ -591,7 +596,7 @@ m_devget(buf, totlen, off0, ifp, copy) char *buf; int totlen, off0; struct ifnet *ifp; - void (*copy)(); + void (*copy) __P((const void *, void *, size_t)); { register struct mbuf *m; struct mbuf *top = 0, **mp = ⊤ @@ -644,9 +649,9 @@ m_devget(buf, totlen, off0, ifp, copy) len = m->m_len; } if (copy) - copy(cp, mtod(m, caddr_t), (unsigned)len); + copy(cp, mtod(m, caddr_t), (size_t)len); else - bcopy(cp, mtod(m, caddr_t), (unsigned)len); + bcopy(cp, mtod(m, caddr_t), (size_t)len); cp += len; *mp = m; mp = &m->m_next; diff --git a/sys/kern/uipc_proto.c b/sys/kern/uipc_proto.c index a04c2a96dc1..9fda1823dd7 100644 --- a/sys/kern/uipc_proto.c +++ b/sys/kern/uipc_proto.c @@ -1,4 +1,5 @@ -/* $NetBSD: uipc_proto.c,v 1.5 1994/06/29 06:33:36 cgd Exp $ */ +/* $OpenBSD: uipc_proto.c,v 1.2 1996/03/03 17:20:18 niklas Exp $ */ +/* $NetBSD: uipc_proto.c,v 1.8 1996/02/13 21:10:47 christos Exp $ */ /*- * Copyright (c) 1982, 1986, 1993 @@ -40,13 +41,16 @@ #include #include #include +#include +#include + +#include +#include /* * Definitions of protocols supported in the UNIX domain. */ -int uipc_usrreq(), raw_usrreq(); -void raw_init(), raw_input(), raw_ctlinput(); extern struct domain unixdomain; /* or at least forward */ struct protosw unixsw[] = { @@ -67,8 +71,6 @@ struct protosw unixsw[] = { } }; -int unp_externalize(), unp_dispose(); - struct domain unixdomain = { AF_UNIX, "unix", 0, unp_externalize, unp_dispose, unixsw, &unixsw[sizeof(unixsw)/sizeof(unixsw[0])] }; diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 4566eca3ed7..5375ad7c696 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -1,4 +1,5 @@ -/* $NetBSD: uipc_socket.c,v 1.20 1995/08/12 23:59:11 mycroft Exp $ */ +/* $OpenBSD: uipc_socket.c,v 1.3 1996/03/03 17:20:19 niklas Exp $ */ +/* $NetBSD: uipc_socket.c,v 1.21 1996/02/04 02:17:52 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1988, 1990, 1993 @@ -46,6 +47,7 @@ #include #include #include +#include #include /* @@ -83,8 +85,8 @@ socreate(dom, aso, type, proto) so->so_state = SS_PRIV; so->so_proto = prp; error = - (*prp->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0, - (struct mbuf *)(long)proto, (struct mbuf *)0); + (*prp->pr_usrreq)(so, PRU_ATTACH, NULL, (struct mbuf *)(long)proto, + NULL); if (error) { so->so_state |= SS_NOFDREF; sofree(so); @@ -109,9 +111,7 @@ sobind(so, nam) int s = splsoftnet(); int error; - error = - (*so->so_proto->pr_usrreq)(so, PRU_BIND, - (struct mbuf *)0, nam, (struct mbuf *)0); + error = (*so->so_proto->pr_usrreq)(so, PRU_BIND, NULL, nam, NULL); splx(s); return (error); } @@ -123,9 +123,7 @@ solisten(so, backlog) { int s = splsoftnet(), error; - error = - (*so->so_proto->pr_usrreq)(so, PRU_LISTEN, - (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0); + error = (*so->so_proto->pr_usrreq)(so, PRU_LISTEN, NULL, NULL, NULL); if (error) { splx(s); return (error); @@ -186,17 +184,19 @@ soclose(so) if ((so->so_state & SS_ISDISCONNECTING) && (so->so_state & SS_NBIO)) goto drop; - while (so->so_state & SS_ISCONNECTED) - if (error = tsleep((caddr_t)&so->so_timeo, - PSOCK | PCATCH, netcls, so->so_linger)) + while (so->so_state & SS_ISCONNECTED) { + error = tsleep((caddr_t)&so->so_timeo, + PSOCK | PCATCH, netcls, + so->so_linger); + if (error) break; + } } } drop: if (so->so_pcb) { - int error2 = - (*so->so_proto->pr_usrreq)(so, PRU_DETACH, - (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0); + int error2 = (*so->so_proto->pr_usrreq)(so, PRU_DETACH, NULL, + NULL, NULL); if (error == 0) error = error2; } @@ -217,9 +217,7 @@ soabort(so) struct socket *so; { - return ( - (*so->so_proto->pr_usrreq)(so, PRU_ABORT, - (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0)); + return (*so->so_proto->pr_usrreq)(so, PRU_ABORT, NULL, NULL, NULL); } int @@ -233,8 +231,7 @@ soaccept(so, nam) if ((so->so_state & SS_NOFDREF) == 0) panic("soaccept: !NOFDREF"); so->so_state &= ~SS_NOFDREF; - error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT, - (struct mbuf *)0, nam, (struct mbuf *)0); + error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT, NULL, nam, NULL); splx(s); return (error); } @@ -262,7 +259,7 @@ soconnect(so, nam) error = EISCONN; else error = (*so->so_proto->pr_usrreq)(so, PRU_CONNECT, - (struct mbuf *)0, nam, (struct mbuf *)0); + NULL, nam, NULL); splx(s); return (error); } @@ -275,8 +272,8 @@ soconnect2(so1, so2) int s = splsoftnet(); int error; - error = (*so1->so_proto->pr_usrreq)(so1, PRU_CONNECT2, - (struct mbuf *)0, (struct mbuf *)so2, (struct mbuf *)0); + error = (*so1->so_proto->pr_usrreq)(so1, PRU_CONNECT2, NULL, + (struct mbuf *)so2, NULL); splx(s); return (error); } @@ -296,8 +293,8 @@ sodisconnect(so) error = EALREADY; goto bad; } - error = (*so->so_proto->pr_usrreq)(so, PRU_DISCONNECT, - (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0); + error = (*so->so_proto->pr_usrreq)(so, PRU_DISCONNECT, NULL, NULL, + NULL); bad: splx(s); return (error); @@ -359,7 +356,7 @@ sosend(so, addr, uio, top, control, flags) #define snderr(errno) { error = errno; splx(s); goto release; } restart: - if (error = sblock(&so->so_snd, SBLOCKWAIT(flags))) + if ((error = sblock(&so->so_snd, SBLOCKWAIT(flags))) != 0) goto out; do { s = splsoftnet(); @@ -378,7 +375,7 @@ restart: space = sbspace(&so->so_snd); if (flags & MSG_OOB) space += 1024; - if (atomic && resid > so->so_snd.sb_hiwat || + if ((atomic && resid > so->so_snd.sb_hiwat) || clen > so->so_snd.sb_hiwat) snderr(EMSGSIZE); if (space < resid + clen && uio && @@ -456,9 +453,9 @@ nopages: if (dontroute) so->so_options |= SO_DONTROUTE; s = splsoftnet(); /* XXX */ - error = (*so->so_proto->pr_usrreq)(so, - (flags & MSG_OOB) ? PRU_SENDOOB : PRU_SEND, - top, addr, control); + error = (*so->so_proto->pr_usrreq)(so, (flags & MSG_OOB) ? + PRU_SENDOOB : PRU_SEND, + top, addr, control); splx(s); if (dontroute) so->so_options &= ~SO_DONTROUTE; @@ -510,7 +507,7 @@ soreceive(so, paddr, uio, mp0, controlp, flagsp) register int flags, len, error, s, offset; struct protosw *pr = so->so_proto; struct mbuf *nextrecord; - int moff, type; + int moff, type = 0; int orig_resid = uio->uio_resid; mp = mp0; @@ -525,7 +522,8 @@ soreceive(so, paddr, uio, mp0, controlp, flagsp) if (flags & MSG_OOB) { m = m_get(M_WAIT, MT_DATA); error = (*pr->pr_usrreq)(so, PRU_RCVOOB, m, - (struct mbuf *)(long)(flags & MSG_PEEK), (struct mbuf *)0); + (struct mbuf *)(long)(flags & MSG_PEEK), + NULL); if (error) goto bad; do { @@ -541,11 +539,10 @@ bad: if (mp) *mp = (struct mbuf *)0; if (so->so_state & SS_ISCONFIRMING && uio->uio_resid) - (*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0, - (struct mbuf *)0, (struct mbuf *)0); + (*pr->pr_usrreq)(so, PRU_RCVD, NULL, NULL, NULL); restart: - if (error = sblock(&so->so_rcv, SBLOCKWAIT(flags))) + if ((error = sblock(&so->so_rcv, SBLOCKWAIT(flags))) != 0) return (error); s = splsoftnet(); @@ -561,11 +558,11 @@ restart: * we have to do the receive in sections, and thus risk returning * a short count if a timeout or signal occurs after we start. */ - if (m == 0 || ((flags & MSG_DONTWAIT) == 0 && + if (m == 0 || (((flags & MSG_DONTWAIT) == 0 && so->so_rcv.sb_cc < uio->uio_resid) && (so->so_rcv.sb_cc < so->so_rcv.sb_lowat || ((flags & MSG_WAITALL) && uio->uio_resid <= so->so_rcv.sb_hiwat)) && - m->m_nextpkt == 0 && (pr->pr_flags & PR_ATOMIC) == 0) { + m->m_nextpkt == 0 && (pr->pr_flags & PR_ATOMIC) == 0)) { #ifdef DIAGNOSTIC if (m == 0 && so->so_rcv.sb_cc) panic("receive 1"); @@ -765,7 +762,7 @@ dontblock: splx(s); return (0); } - if (m = so->so_rcv.sb_mb) + if ((m = so->so_rcv.sb_mb) != NULL) nextrecord = m->m_nextpkt; } } @@ -779,9 +776,8 @@ dontblock: if (m == 0) so->so_rcv.sb_mb = nextrecord; if (pr->pr_flags & PR_WANTRCVD && so->so_pcb) - (*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0, - (struct mbuf *)(long)flags, (struct mbuf *)0, - (struct mbuf *)0); + (*pr->pr_usrreq)(so, PRU_RCVD, NULL, + (struct mbuf *)(long)flags, NULL); } if (orig_resid == uio->uio_resid && orig_resid && (flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) { @@ -809,8 +805,7 @@ soshutdown(so, how) if (how & FREAD) sorflush(so); if (how & FWRITE) - return ((*pr->pr_usrreq)(so, PRU_SHUTDOWN, - (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0)); + return (*pr->pr_usrreq)(so, PRU_SHUTDOWN, NULL, NULL, NULL); return (0); } diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index 683ce82651e..b414175685f 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -1,4 +1,5 @@ -/* $NetBSD: uipc_socket2.c,v 1.10 1995/08/16 01:03:19 mycroft Exp $ */ +/* $OpenBSD: uipc_socket2.c,v 1.2 1996/03/03 17:20:20 niklas Exp $ */ +/* $NetBSD: uipc_socket2.c,v 1.11 1996/02/04 02:17:55 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1988, 1990, 1993 @@ -45,6 +46,7 @@ #include #include #include +#include /* * Primitive routines for operating on sockets and socket buffers @@ -292,9 +294,10 @@ sb_lock(sb) while (sb->sb_flags & SB_LOCK) { sb->sb_flags |= SB_WANT; - if (error = tsleep((caddr_t)&sb->sb_flags, - (sb->sb_flags & SB_NOINTR) ? PSOCK : PSOCK|PCATCH, - netio, 0)) + error = tsleep((caddr_t)&sb->sb_flags, + (sb->sb_flags & SB_NOINTR) ? + PSOCK : PSOCK|PCATCH, netio, 0); + if (error) return (error); } sb->sb_flags |= SB_LOCK; @@ -454,7 +457,7 @@ sbappend(sb, m) if (m == 0) return; - if (n = sb->sb_mb) { + if ((n = sb->sb_mb) != NULL) { while (n->m_nextpkt) n = n->m_nextpkt; do { @@ -504,7 +507,7 @@ sbappendrecord(sb, m0) if (m0 == 0) return; - if (m = sb->sb_mb) + if ((m = sb->sb_mb) != NULL) while (m->m_nextpkt) m = m->m_nextpkt; /* @@ -540,7 +543,7 @@ sbinsertoob(sb, m0) if (m0 == 0) return; - for (mp = &sb->sb_mb; m = *mp; mp = &((*mp)->m_nextpkt)) { + for (mp = &sb->sb_mb; (m = *mp) != NULL; mp = &((*mp)->m_nextpkt)) { again: switch (m->m_type) { @@ -548,7 +551,7 @@ sbinsertoob(sb, m0) continue; /* WANT next train */ case MT_CONTROL: - if (m = m->m_next) + if ((m = m->m_next) != NULL) goto again; /* inspect THIS train further */ } break; @@ -609,7 +612,7 @@ panic("sbappendaddr"); m->m_next = control; for (n = m; n; n = n->m_next) sballoc(sb, n); - if (n = sb->sb_mb) { + if ((n = sb->sb_mb) != NULL) { while (n->m_nextpkt) n = n->m_nextpkt; n->m_nextpkt = m; @@ -641,7 +644,7 @@ sbappendcontrol(sb, m0, control) n->m_next = m0; /* concatenate data to control */ for (m = control; m; m = m->m_next) sballoc(sb, m); - if (n = sb->sb_mb) { + if ((n = sb->sb_mb) != NULL) { while (n->m_nextpkt) n = n->m_nextpkt; n->m_nextpkt = control; @@ -776,6 +779,6 @@ sbdroprecord(sb) do { sbfree(sb, m); MFREE(m, mn); - } while (m = mn); + } while ((m = mn) != NULL); } } diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index b3e7dc90167..61cad76d888 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -1,4 +1,5 @@ -/* $NetBSD: uipc_syscalls.c,v 1.17 1995/10/10 01:27:05 mycroft Exp $ */ +/* $OpenBSD: uipc_syscalls.c,v 1.2 1996/03/03 17:20:21 niklas Exp $ */ +/* $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1990, 1993 @@ -46,6 +47,8 @@ #include #include #include +#include +#include #ifdef KTRACE #include #endif @@ -56,12 +59,6 @@ /* * System call interface to the socket abstraction. */ -#if defined(COMPAT_43) || defined(COMPAT_SUNOS) || defined(COMPAT_LINUX) || \ - defined(COMPAT_HPUX) || defined(COMPAT_FREEBSD) -#define COMPAT_OLDSOCK -#define MSG_COMPAT 0x8000 -#endif - extern struct fileops socketops; int @@ -80,13 +77,14 @@ sys_socket(p, v, retval) struct file *fp; int fd, error; - if (error = falloc(p, &fp, &fd)) + if ((error = falloc(p, &fp, &fd)) != 0) return (error); fp->f_flag = FREAD|FWRITE; fp->f_type = DTYPE_SOCKET; fp->f_ops = &socketops; - if (error = socreate(SCARG(uap, domain), &so, SCARG(uap, type), - SCARG(uap, protocol))) { + error = socreate(SCARG(uap, domain), &so, SCARG(uap, type), + SCARG(uap, protocol)); + if (error) { fdp->fd_ofiles[fd] = 0; ffree(fp); } else { @@ -112,10 +110,11 @@ sys_bind(p, v, retval) struct mbuf *nam; int error; - if (error = getsock(p->p_fd, SCARG(uap, s), &fp)) + if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) return (error); - if (error = sockargs(&nam, SCARG(uap, name), SCARG(uap, namelen), - MT_SONAME)) + error = sockargs(&nam, SCARG(uap, name), SCARG(uap, namelen), + MT_SONAME); + if (error) return (error); error = sobind((struct socket *)fp->f_data, nam); m_freem(nam); @@ -136,7 +135,7 @@ sys_listen(p, v, retval) struct file *fp; int error; - if (error = getsock(p->p_fd, SCARG(uap, s), &fp)) + if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) return (error); return (solisten((struct socket *)fp->f_data, SCARG(uap, backlog))); } @@ -160,7 +159,7 @@ sys_accept(p, v, retval) if (SCARG(uap, name) && (error = copyin((caddr_t)SCARG(uap, anamelen), (caddr_t)&namelen, sizeof (namelen)))) return (error); - if (error = getsock(p->p_fd, SCARG(uap, s), &fp)) + if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) return (error); s = splsoftnet(); so = (struct socket *)fp->f_data; @@ -177,8 +176,9 @@ sys_accept(p, v, retval) so->so_error = ECONNABORTED; break; } - if (error = tsleep((caddr_t)&so->so_timeo, PSOCK | PCATCH, - netcon, 0)) { + error = tsleep((caddr_t)&so->so_timeo, PSOCK | PCATCH, + netcon, 0); + if (error) { splx(s); return (error); } @@ -189,7 +189,7 @@ sys_accept(p, v, retval) splx(s); return (error); } - if (error = falloc(p, &fp, &tmpfd)) { + if ((error = falloc(p, &fp, &tmpfd)) != 0) { splx(s); return (error); } @@ -237,13 +237,14 @@ sys_connect(p, v, retval) struct mbuf *nam; int error, s; - if (error = getsock(p->p_fd, SCARG(uap, s), &fp)) + if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) return (error); so = (struct socket *)fp->f_data; if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) return (EALREADY); - if (error = sockargs(&nam, SCARG(uap, name), SCARG(uap, namelen), - MT_SONAME)) + error = sockargs(&nam, SCARG(uap, name), SCARG(uap, namelen), + MT_SONAME); + if (error) return (error); error = soconnect(so, nam); if (error) @@ -253,10 +254,12 @@ sys_connect(p, v, retval) return (EINPROGRESS); } s = splsoftnet(); - while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) - if (error = tsleep((caddr_t)&so->so_timeo, PSOCK | PCATCH, - netcon, 0)) + while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) { + error = tsleep((caddr_t)&so->so_timeo, PSOCK | PCATCH, + netcon, 0); + if (error) break; + } if (error == 0) { error = so->so_error; so->so_error = 0; @@ -287,33 +290,35 @@ sys_socketpair(p, v, retval) struct socket *so1, *so2; int fd, error, sv[2]; - if (error = socreate(SCARG(uap, domain), &so1, SCARG(uap, type), - SCARG(uap, protocol))) + error = socreate(SCARG(uap, domain), &so1, SCARG(uap, type), + SCARG(uap, protocol)); + if (error) return (error); - if (error = socreate(SCARG(uap, domain), &so2, SCARG(uap, type), - SCARG(uap, protocol))) + error = socreate(SCARG(uap, domain), &so2, SCARG(uap, type), + SCARG(uap, protocol)); + if (error) goto free1; - if (error = falloc(p, &fp1, &fd)) + if ((error = falloc(p, &fp1, &fd)) != 0) goto free2; sv[0] = fd; fp1->f_flag = FREAD|FWRITE; fp1->f_type = DTYPE_SOCKET; fp1->f_ops = &socketops; fp1->f_data = (caddr_t)so1; - if (error = falloc(p, &fp2, &fd)) + if ((error = falloc(p, &fp2, &fd)) != 0) goto free3; fp2->f_flag = FREAD|FWRITE; fp2->f_type = DTYPE_SOCKET; fp2->f_ops = &socketops; fp2->f_data = (caddr_t)so2; sv[1] = fd; - if (error = soconnect2(so1, so2)) + if ((error = soconnect2(so1, so2)) != 0) goto free4; if (SCARG(uap, type) == SOCK_DGRAM) { /* * Datagram socket connection is asymmetric. */ - if (error = soconnect2(so2, so1)) + if ((error = soconnect2(so2, so1)) != 0) goto free4; } error = copyout((caddr_t)sv, (caddr_t)SCARG(uap, rsv), @@ -379,7 +384,8 @@ sys_sendmsg(p, v, retval) struct iovec aiov[UIO_SMALLIOV], *iov; int error; - if (error = copyin(SCARG(uap, msg), (caddr_t)&msg, sizeof (msg))) + error = copyin(SCARG(uap, msg), (caddr_t)&msg, sizeof (msg)); + if (error) return (error); if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) { if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) @@ -422,7 +428,7 @@ sendit(p, s, mp, flags, retsize) struct iovec *ktriov = NULL; #endif - if (error = getsock(p->p_fd, s, &fp)) + if ((error = getsock(p->p_fd, s, &fp)) != 0) return (error); auio.uio_iov = mp->msg_iov; auio.uio_iovcnt = mp->msg_iovlen; @@ -433,14 +439,18 @@ sendit(p, s, mp, flags, retsize) auio.uio_resid = 0; iov = mp->msg_iov; for (i = 0; i < mp->msg_iovlen; i++, iov++) { +#if 0 + /* cannot happen; iov_len is unsigned */ if (iov->iov_len < 0) return (EINVAL); +#endif if ((auio.uio_resid += iov->iov_len) < 0) return (EINVAL); } if (mp->msg_name) { - if (error = sockargs(&to, mp->msg_name, mp->msg_namelen, - MT_SONAME)) + error = sockargs(&to, mp->msg_name, mp->msg_namelen, + MT_SONAME); + if (error) return (error); } else to = 0; @@ -453,8 +463,9 @@ sendit(p, s, mp, flags, retsize) error = EINVAL; goto bad; } - if (error = sockargs(&control, mp->msg_control, - mp->msg_controllen, MT_CONTROL)) + error = sockargs(&control, mp->msg_control, + mp->msg_controllen, MT_CONTROL); + if (error) goto bad; #ifdef COMPAT_OLDSOCK if (mp->msg_flags == MSG_COMPAT) { @@ -483,8 +494,9 @@ sendit(p, s, mp, flags, retsize) } #endif len = auio.uio_resid; - if (error = sosend((struct socket *)fp->f_data, to, &auio, - (struct mbuf *)0, control, flags)) { + error = sosend((struct socket *)fp->f_data, to, &auio, + NULL, control, flags); + if (error) { if (auio.uio_resid != len && (error == ERESTART || error == EINTR || error == EWOULDBLOCK)) error = 0; @@ -526,8 +538,10 @@ sys_recvfrom(p, v, retval) int error; if (SCARG(uap, fromlenaddr)) { - if (error = copyin((caddr_t)SCARG(uap, fromlenaddr), - (caddr_t)&msg.msg_namelen, sizeof (msg.msg_namelen))) + error = copyin((caddr_t)SCARG(uap, fromlenaddr), + (caddr_t)&msg.msg_namelen, + sizeof (msg.msg_namelen)); + if (error) return (error); } else msg.msg_namelen = 0; @@ -539,7 +553,7 @@ sys_recvfrom(p, v, retval) msg.msg_control = 0; msg.msg_flags = SCARG(uap, flags); return (recvit(p, SCARG(uap, s), &msg, - (caddr_t)SCARG(uap, fromlenaddr), retval)); + (caddr_t)SCARG(uap, fromlenaddr), retval)); } int @@ -557,8 +571,9 @@ sys_recvmsg(p, v, retval) struct iovec aiov[UIO_SMALLIOV], *uiov, *iov; register int error; - if (error = copyin((caddr_t)SCARG(uap, msg), (caddr_t)&msg, - sizeof (msg))) + error = copyin((caddr_t)SCARG(uap, msg), (caddr_t)&msg, + sizeof (msg)); + if (error) return (error); if ((u_int)msg.msg_iovlen >= UIO_SMALLIOV) { if ((u_int)msg.msg_iovlen >= UIO_MAXIOV) @@ -575,8 +590,9 @@ sys_recvmsg(p, v, retval) #endif uiov = msg.msg_iov; msg.msg_iov = iov; - if (error = copyin((caddr_t)uiov, (caddr_t)iov, - (unsigned)(msg.msg_iovlen * sizeof (struct iovec)))) + error = copyin((caddr_t)uiov, (caddr_t)iov, + (unsigned)(msg.msg_iovlen * sizeof (struct iovec))); + if (error) goto done; if ((error = recvit(p, SCARG(uap, s), &msg, (caddr_t)0, retval)) == 0) { msg.msg_iov = uiov; @@ -607,7 +623,7 @@ recvit(p, s, mp, namelenp, retsize) struct iovec *ktriov = NULL; #endif - if (error = getsock(p->p_fd, s, &fp)) + if ((error = getsock(p->p_fd, s, &fp)) != 0) return (error); auio.uio_iov = mp->msg_iov; auio.uio_iovcnt = mp->msg_iovlen; @@ -618,8 +634,11 @@ recvit(p, s, mp, namelenp, retsize) auio.uio_resid = 0; iov = mp->msg_iov; for (i = 0; i < mp->msg_iovlen; i++, iov++) { +#if 0 + /* cannot happen iov_len is unsigned */ if (iov->iov_len < 0) return (EINVAL); +#endif if ((auio.uio_resid += iov->iov_len) < 0) return (EINVAL); } @@ -632,9 +651,10 @@ recvit(p, s, mp, namelenp, retsize) } #endif len = auio.uio_resid; - if (error = soreceive((struct socket *)fp->f_data, &from, &auio, - (struct mbuf **)0, mp->msg_control ? &control : (struct mbuf **)0, - &mp->msg_flags)) { + error = soreceive((struct socket *)fp->f_data, &from, &auio, + NULL, mp->msg_control ? &control : NULL, + &mp->msg_flags); + if (error) { if (auio.uio_resid != len && (error == ERESTART || error == EINTR || error == EWOULDBLOCK)) error = 0; @@ -663,8 +683,9 @@ recvit(p, s, mp, namelenp, retsize) if (len > from->m_len) len = from->m_len; /* else if len < from->m_len ??? */ - if (error = copyout(mtod(from, caddr_t), - (caddr_t)mp->msg_name, (unsigned)len)) + error = copyout(mtod(from, caddr_t), + (caddr_t)mp->msg_name, (unsigned)len); + if (error) goto out; } mp->msg_namelen = len; @@ -734,7 +755,7 @@ sys_shutdown(p, v, retval) struct file *fp; int error; - if (error = getsock(p->p_fd, SCARG(uap, s), &fp)) + if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) return (error); return (soshutdown((struct socket *)fp->f_data, SCARG(uap, how))); } @@ -757,7 +778,7 @@ sys_setsockopt(p, v, retval) struct mbuf *m = NULL; int error; - if (error = getsock(p->p_fd, SCARG(uap, s), &fp)) + if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) return (error); if (SCARG(uap, valsize) > MLEN) return (EINVAL); @@ -765,15 +786,16 @@ sys_setsockopt(p, v, retval) m = m_get(M_WAIT, MT_SOOPTS); if (m == NULL) return (ENOBUFS); - if (error = copyin(SCARG(uap, val), mtod(m, caddr_t), - (u_int)SCARG(uap, valsize))) { + error = copyin(SCARG(uap, val), mtod(m, caddr_t), + (u_int)SCARG(uap, valsize)); + if (error) { (void) m_free(m); return (error); } m->m_len = SCARG(uap, valsize); } return (sosetopt((struct socket *)fp->f_data, SCARG(uap, level), - SCARG(uap, name), m)); + SCARG(uap, name), m)); } /* ARGSUSED */ @@ -794,11 +816,12 @@ sys_getsockopt(p, v, retval) struct mbuf *m = NULL; int valsize, error; - if (error = getsock(p->p_fd, SCARG(uap, s), &fp)) + if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0) return (error); if (SCARG(uap, val)) { - if (error = copyin((caddr_t)SCARG(uap, avalsize), - (caddr_t)&valsize, sizeof (valsize))) + error = copyin((caddr_t)SCARG(uap, avalsize), + (caddr_t)&valsize, sizeof (valsize)); + if (error) return (error); } else valsize = 0; @@ -830,25 +853,25 @@ sys_pipe(p, v, retval) struct socket *rso, *wso; int fd, error; - if (error = socreate(AF_UNIX, &rso, SOCK_STREAM, 0)) + if ((error = socreate(AF_UNIX, &rso, SOCK_STREAM, 0)) != 0) return (error); - if (error = socreate(AF_UNIX, &wso, SOCK_STREAM, 0)) + if ((error = socreate(AF_UNIX, &wso, SOCK_STREAM, 0)) != 0) goto free1; - if (error = falloc(p, &rf, &fd)) + if ((error = falloc(p, &rf, &fd)) != 0) goto free2; retval[0] = fd; rf->f_flag = FREAD; rf->f_type = DTYPE_SOCKET; rf->f_ops = &socketops; rf->f_data = (caddr_t)rso; - if (error = falloc(p, &wf, &fd)) + if ((error = falloc(p, &wf, &fd)) != 0) goto free3; wf->f_flag = FWRITE; wf->f_type = DTYPE_SOCKET; wf->f_ops = &socketops; wf->f_data = (caddr_t)wso; retval[1] = fd; - if (error = unp_connect2(wso, rso)) + if ((error = unp_connect2(wso, rso)) != 0) goto free4; return (0); free4: @@ -884,16 +907,17 @@ sys_getsockname(p, v, retval) struct mbuf *m; int len, error; - if (error = getsock(p->p_fd, SCARG(uap, fdes), &fp)) + if ((error = getsock(p->p_fd, SCARG(uap, fdes), &fp)) != 0) return (error); - if (error = copyin((caddr_t)SCARG(uap, alen), (caddr_t)&len, - sizeof (len))) + error = copyin((caddr_t)SCARG(uap, alen), (caddr_t)&len, sizeof (len)); + if (error) return (error); so = (struct socket *)fp->f_data; m = m_getclr(M_WAIT, MT_SONAME); if (m == NULL) return (ENOBUFS); - if (error = (*so->so_proto->pr_usrreq)(so, PRU_SOCKADDR, 0, m, 0)) + error = (*so->so_proto->pr_usrreq)(so, PRU_SOCKADDR, 0, m, 0); + if (error) goto bad; if (len > m->m_len) len = m->m_len; @@ -926,23 +950,24 @@ sys_getpeername(p, v, retval) struct mbuf *m; int len, error; - if (error = getsock(p->p_fd, SCARG(uap, fdes), &fp)) + if ((error = getsock(p->p_fd, SCARG(uap, fdes), &fp)) != 0) return (error); so = (struct socket *)fp->f_data; if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) return (ENOTCONN); - if (error = - copyin((caddr_t)SCARG(uap, alen), (caddr_t)&len, sizeof (len))) + error = copyin((caddr_t)SCARG(uap, alen), (caddr_t)&len, sizeof (len)); + if (error) return (error); m = m_getclr(M_WAIT, MT_SONAME); if (m == NULL) return (ENOBUFS); - if (error = (*so->so_proto->pr_usrreq)(so, PRU_PEERADDR, 0, m, 0)) + error = (*so->so_proto->pr_usrreq)(so, PRU_PEERADDR, 0, m, 0); + if (error) goto bad; if (len > m->m_len) len = m->m_len; - if (error = - copyout(mtod(m, caddr_t), (caddr_t)SCARG(uap, asa), (u_int)len)) + error = copyout(mtod(m, caddr_t), (caddr_t)SCARG(uap, asa), (u_int)len); + if (error) goto bad; error = copyout((caddr_t)&len, (caddr_t)SCARG(uap, alen), sizeof (len)); bad: diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index 54ea1382f58..1251473a341 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -1,4 +1,5 @@ -/* $NetBSD: uipc_usrreq.c,v 1.15 1995/08/17 02:57:20 mycroft Exp $ */ +/* $OpenBSD: uipc_usrreq.c,v 1.2 1996/03/03 17:20:22 niklas Exp $ */ +/* $NetBSD: uipc_usrreq.c,v 1.18 1996/02/09 19:00:50 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1991, 1993 @@ -349,7 +350,7 @@ unp_attach(so) return (0); } -int +void unp_detach(unp) register struct unpcb *unp; { @@ -403,7 +404,7 @@ unp_bind(unp, nam, p) } else *(mtod(nam, caddr_t) + nam->m_len) = 0; /* SHOULD BE ABLE TO ADOPT EXISTING AND wakeup() ALA FIFO's */ - if (error = namei(&nd)) + if ((error = namei(&nd)) != 0) return (error); vp = nd.ni_vp; if (vp != NULL) { @@ -419,7 +420,8 @@ unp_bind(unp, nam, p) vattr.va_type = VSOCK; vattr.va_mode = ACCESSPERMS; VOP_LEASE(nd.ni_dvp, p, p->p_ucred, LEASE_WRITE); - if (error = VOP_CREATE(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr)) + error = VOP_CREATE(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, &vattr); + if (error) return (error); vp = nd.ni_vp; vp->v_socket = unp->unp_socket; @@ -448,14 +450,14 @@ unp_connect(so, nam, p) return (EMSGSIZE); } else *(mtod(nam, caddr_t) + nam->m_len) = 0; - if (error = namei(&nd)) + if ((error = namei(&nd)) != 0) return (error); vp = nd.ni_vp; if (vp->v_type != VSOCK) { error = ENOTSOCK; goto bad; } - if (error = VOP_ACCESS(vp, VWRITE, p->p_ucred, p)) + if ((error = VOP_ACCESS(vp, VWRITE, p->p_ucred, p)) != 0) goto bad; so2 = vp->v_socket; if (so2 == 0) { diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index 2522e213e63..6a626ca7aa3 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -1,4 +1,5 @@ -/* $NetBSD: vfs_cache.c,v 1.12 1995/09/08 14:15:07 ws Exp $ */ +/* $OpenBSD: vfs_cache.c,v 1.2 1996/03/03 17:20:23 niklas Exp $ */ +/* $NetBSD: vfs_cache.c,v 1.13 1996/02/04 02:18:09 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -166,6 +167,7 @@ cache_lookup(dvp, vpp, cnp) /* * Add an entry to the cache */ +void cache_enter(dvp, vp, cnp) struct vnode *dvp; struct vnode *vp; @@ -188,7 +190,7 @@ cache_enter(dvp, vp, cnp) malloc((u_long)sizeof *ncp, M_CACHE, M_WAITOK); bzero((char *)ncp, sizeof *ncp); numcache++; - } else if (ncp = nclruhead.tqh_first) { + } else if ((ncp = nclruhead.tqh_first) != NULL) { TAILQ_REMOVE(&nclruhead, ncp, nc_lru); if (ncp->nc_hash.le_prev != 0) { LIST_REMOVE(ncp, nc_hash); @@ -220,6 +222,7 @@ cache_enter(dvp, vp, cnp) /* * Name cache initialization, from vfs_init() when we are booting */ +void nchinit() { @@ -231,6 +234,7 @@ nchinit() * Cache flush, a particular vnode; called when a vnode is renamed to * hide entries that would now be invalid */ +void cache_purge(vp) struct vnode *vp; { @@ -257,6 +261,7 @@ cache_purge(vp) * if the cache lru chain is modified while we are dumping the * inode. This makes the algorithm O(n^2), but do you think I care? */ +void cache_purgevfs(mp) struct mount *mp; { diff --git a/sys/kern/vfs_cluster.c b/sys/kern/vfs_cluster.c index 049dd716990..bfc48c8c0ca 100644 --- a/sys/kern/vfs_cluster.c +++ b/sys/kern/vfs_cluster.c @@ -1,4 +1,5 @@ -/* $NetBSD: vfs_cluster.c,v 1.8 1995/07/24 21:19:50 cgd Exp $ */ +/* $OpenBSD: vfs_cluster.c,v 1.2 1996/03/03 17:20:25 niklas Exp $ */ +/* $NetBSD: vfs_cluster.c,v 1.10 1996/02/09 19:00:56 christos Exp $ */ /*- * Copyright (c) 1993 @@ -42,8 +43,9 @@ #include #include #include +#include #include -#include +#include #ifdef DEBUG #include @@ -108,6 +110,7 @@ int doclusterraz = 0; * rbp is the read-ahead block. * If either is NULL, then you don't have to do the I/O. */ +int cluster_read(vp, filesize, lblkno, size, cred, bpp) struct vnode *vp; u_quad_t filesize; @@ -683,7 +686,7 @@ redo: * case we don't want to write it twice). */ if (!incore(vp, start_lbn) || - last_bp == NULL && start_lbn == lbn) + (last_bp == NULL && start_lbn == lbn)) break; /* diff --git a/sys/kern/vfs_lockf.c b/sys/kern/vfs_lockf.c index d2de9557b3c..62dc36807ac 100644 --- a/sys/kern/vfs_lockf.c +++ b/sys/kern/vfs_lockf.c @@ -1,4 +1,5 @@ -/* $NetBSD: vfs_lockf.c,v 1.6 1995/03/19 23:45:03 mycroft Exp $ */ +/* $OpenBSD: vfs_lockf.c,v 1.2 1996/03/03 17:20:26 niklas Exp $ */ +/* $NetBSD: vfs_lockf.c,v 1.7 1996/02/04 02:18:21 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -179,7 +180,7 @@ lf_setlock(lock) /* * Scan lock list for this file looking for locks that would block us. */ - while (block = lf_getblock(lock)) { + while ((block = lf_getblock(lock)) != NULL) { /* * Free the structure and return if nonblocking. */ @@ -243,7 +244,8 @@ lf_setlock(lock) lf_printlist("lf_setlock", block); } #endif /* LOCKF_DEBUG */ - if (error = tsleep((caddr_t)lock, priority, lockstr, 0)) { + error = tsleep((caddr_t)lock, priority, lockstr, 0); + if (error) { /* * Delete ourselves from the waiting to lock list. */ @@ -278,7 +280,8 @@ lf_setlock(lock) block = *head; needtolink = 1; for (;;) { - if (ovcase = lf_findoverlap(block, lock, SELF, &prev, &overlap)) + ovcase = lf_findoverlap(block, lock, SELF, &prev, &overlap); + if (ovcase) block = overlap->lf_next; /* * Six cases: @@ -413,7 +416,8 @@ lf_clearlock(unlock) lf_print("lf_clearlock", unlock); #endif /* LOCKF_DEBUG */ prev = head; - while (ovcase = lf_findoverlap(lf, unlock, SELF, &prev, &overlap)) { + while ((ovcase = lf_findoverlap(lf, unlock, SELF, + &prev, &overlap)) != 0) { /* * Wakeup the list of locks to be retried. */ @@ -476,7 +480,7 @@ lf_getlock(lock, fl) lf_print("lf_getlock", lock); #endif /* LOCKF_DEBUG */ - if (block = lf_getblock(lock)) { + if ((block = lf_getblock(lock)) != NULL) { fl->l_type = block->lf_type; fl->l_whence = SEEK_SET; fl->l_start = block->lf_start; @@ -506,7 +510,8 @@ lf_getblock(lock) int ovcase; prev = lock->lf_head; - while (ovcase = lf_findoverlap(lf, lock, OTHERS, &prev, &overlap)) { + while ((ovcase = lf_findoverlap(lf, lock, OTHERS, + &prev, &overlap)) != 0) { /* * We've found an overlap, see if it blocks us */ diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index da127e73fe6..555da04b8aa 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -1,4 +1,5 @@ -/* $NetBSD: vfs_lookup.c,v 1.15 1995/03/08 01:20:50 cgd Exp $ */ +/* $OpenBSD: vfs_lookup.c,v 1.2 1996/03/03 17:20:27 niklas Exp $ */ +/* $NetBSD: vfs_lookup.c,v 1.17 1996/02/09 19:00:59 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -145,7 +146,7 @@ namei(ndp) VREF(dp); } ndp->ni_startdir = dp; - if (error = lookup(ndp)) { + if ((error = lookup(ndp)) != 0) { FREE(cnp->cn_pnbuf, M_NAMEI); return (error); } @@ -178,7 +179,8 @@ namei(ndp) auio.uio_segflg = UIO_SYSSPACE; auio.uio_procp = (struct proc *)0; auio.uio_resid = MAXPATHLEN; - if (error = VOP_READLINK(ndp->ni_vp, &auio, cnp->cn_cred)) { + error = VOP_READLINK(ndp->ni_vp, &auio, cnp->cn_cred); + if (error) { if (ndp->ni_pathlen > 1) free(cp, M_NAMEI); break; @@ -375,7 +377,7 @@ dirloop: */ unionlookup: ndp->ni_dvp = dp; - if (error = VOP_LOOKUP(dp, &ndp->ni_vp, cnp)) { + if ((error = VOP_LOOKUP(dp, &ndp->ni_vp, cnp)) != 0) { #ifdef DIAGNOSTIC if (ndp->ni_vp != NULL) panic("leaf should be empty"); @@ -442,7 +444,7 @@ unionlookup: sleep((caddr_t)mp, PVFS); continue; } - if (error = VFS_ROOT(dp->v_mountedhere, &tdp)) + if ((error = VFS_ROOT(dp->v_mountedhere, &tdp)) != 0) goto bad2; vput(dp); ndp->ni_vp = dp = tdp; @@ -587,7 +589,7 @@ relookup(dvp, vpp, cnp) /* * We now have a segment name to search for, and a directory to search. */ - if (error = VOP_LOOKUP(dp, vpp, cnp)) { + if ((error = VOP_LOOKUP(dp, vpp, cnp)) != 0) { #ifdef DIAGNOSTIC if (*vpp != NULL) panic("leaf should be empty"); diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index e6f57538ae7..5a3a8e7a340 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -1,4 +1,5 @@ -/* $NetBSD: vfs_vnops.c,v 1.19 1995/05/23 06:11:29 mycroft Exp $ */ +/* $OpenBSD: vfs_vnops.c,v 1.2 1996/03/03 17:20:28 niklas Exp $ */ +/* $NetBSD: vfs_vnops.c,v 1.20 1996/02/04 02:18:41 christos Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -62,6 +63,7 @@ struct fileops vnops = * Common code for vnode open operations. * Check permissions, and call the VOP_OPEN or VOP_CREATE routine. */ +int vn_open(ndp, fmode, cmode) register struct nameidata *ndp; int fmode, cmode; @@ -77,15 +79,16 @@ vn_open(ndp, fmode, cmode) ndp->ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF; if ((fmode & O_EXCL) == 0) ndp->ni_cnd.cn_flags |= FOLLOW; - if (error = namei(ndp)) + if ((error = namei(ndp)) != 0) return (error); if (ndp->ni_vp == NULL) { VATTR_NULL(&va); va.va_type = VREG; va.va_mode = cmode; VOP_LEASE(ndp->ni_dvp, p, cred, LEASE_WRITE); - if (error = VOP_CREATE(ndp->ni_dvp, &ndp->ni_vp, - &ndp->ni_cnd, &va)) + error = VOP_CREATE(ndp->ni_dvp, &ndp->ni_vp, + &ndp->ni_cnd, &va); + if (error) return (error); fmode &= ~O_TRUNC; vp = ndp->ni_vp; @@ -106,7 +109,7 @@ vn_open(ndp, fmode, cmode) } else { ndp->ni_cnd.cn_nameiop = LOOKUP; ndp->ni_cnd.cn_flags = FOLLOW | LOCKLEAF; - if (error = namei(ndp)) + if ((error = namei(ndp)) != 0) return (error); vp = ndp->ni_vp; } @@ -116,7 +119,7 @@ vn_open(ndp, fmode, cmode) } if ((fmode & O_CREAT) == 0) { if (fmode & FREAD) { - if (error = VOP_ACCESS(vp, VREAD, cred, p)) + if ((error = VOP_ACCESS(vp, VREAD, cred, p)) != 0) goto bad; } if (fmode & (FWRITE | O_TRUNC)) { @@ -124,8 +127,8 @@ vn_open(ndp, fmode, cmode) error = EISDIR; goto bad; } - if ((error = vn_writechk(vp)) || - (error = VOP_ACCESS(vp, VWRITE, cred, p))) + if ((error = vn_writechk(vp)) != 0 || + (error = VOP_ACCESS(vp, VWRITE, cred, p)) != 0) goto bad; } } @@ -135,10 +138,10 @@ vn_open(ndp, fmode, cmode) VOP_LOCK(vp); /* XXX */ VATTR_NULL(&va); va.va_size = 0; - if (error = VOP_SETATTR(vp, &va, cred, p)) + if ((error = VOP_SETATTR(vp, &va, cred, p)) != 0) goto bad; } - if (error = VOP_OPEN(vp, fmode, cred, p)) + if ((error = VOP_OPEN(vp, fmode, cred, p)) != 0) goto bad; if (fmode & FWRITE) vp->v_writecount++; @@ -153,6 +156,7 @@ bad: * The read-only status of the file system is checked. * Also, prototype text segments cannot be written. */ +int vn_writechk(vp) register struct vnode *vp; { @@ -166,6 +170,9 @@ vn_writechk(vp) switch (vp->v_type) { case VREG: case VDIR: case VLNK: return (EROFS); + case VNON: case VCHR: case VSOCK: + case VFIFO: case VBAD: case VBLK: + break; } } /* @@ -181,6 +188,7 @@ vn_writechk(vp) /* * Vnode close call */ +int vn_close(vp, flags, cred, p) register struct vnode *vp; int flags; @@ -199,6 +207,7 @@ vn_close(vp, flags, cred, p) /* * Package up an I/O request on a vnode into a uio and do it. */ +int vn_rdwr(rw, vp, base, len, offset, segflg, ioflg, cred, aresid, p) enum uio_rw rw; struct vnode *vp; @@ -244,6 +253,7 @@ vn_rdwr(rw, vp, base, len, offset, segflg, ioflg, cred, aresid, p) /* * File table vnode read routine. */ +int vn_read(fp, uio, cred) struct file *fp; struct uio *uio; @@ -266,6 +276,7 @@ vn_read(fp, uio, cred) /* * File table vnode write routine. */ +int vn_write(fp, uio, cred) struct file *fp; struct uio *uio; @@ -294,6 +305,7 @@ vn_write(fp, uio, cred) /* * File table vnode stat routine. */ +int vn_stat(vp, sb, p) struct vnode *vp; register struct stat *sb; @@ -356,6 +368,7 @@ vn_stat(vp, sb, p) /* * File table vnode ioctl routine. */ +int vn_ioctl(fp, com, data, p) struct file *fp; u_long com; @@ -371,7 +384,8 @@ vn_ioctl(fp, com, data, p) case VREG: case VDIR: if (com == FIONREAD) { - if (error = VOP_GETATTR(vp, &vattr, p->p_ucred, p)) + error = VOP_GETATTR(vp, &vattr, p->p_ucred, p); + if (error) return (error); *(int *)data = vattr.va_size - fp->f_offset; return (0); @@ -400,6 +414,7 @@ vn_ioctl(fp, com, data, p) /* * File table vnode select routine. */ +int vn_select(fp, which, p) struct file *fp; int which; @@ -407,12 +422,13 @@ vn_select(fp, which, p) { return (VOP_SELECT(((struct vnode *)fp->f_data), which, fp->f_flag, - fp->f_cred, p)); + fp->f_cred, p)); } /* * File table vnode close routine. */ +int vn_closefile(fp, p) struct file *fp; struct proc *p; -- 2.20.1