BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / kern / kern_sig.c
index 1dd810a..3cfdbe8 100644 (file)
@@ -2,9 +2,35 @@
  * Copyright (c) 1982, 1986, 1989, 1991 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1982, 1986, 1989, 1991 Regents of the University of California.
  * All rights reserved.
  *
- * %sccs.include.redist.c%
+ * 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.
  *
  *
- *     @(#)kern_sig.c  7.29 (Berkeley) %G%
+ * 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.
+ *
+ *     @(#)kern_sig.c  7.35 (Berkeley) 6/28/91
  */
 
 #define        SIGPROP         /* include signal properties table */
  */
 
 #define        SIGPROP         /* include signal properties table */
@@ -25,6 +51,8 @@
 #include "wait.h"
 #include "ktrace.h"
 
 #include "wait.h"
 #include "ktrace.h"
 
+#include "machine/cpu.h"
+
 #include "vm/vm.h"
 #include "kinfo_proc.h"
 #include "user.h"              /* for coredump */
 #include "vm/vm.h"
 #include "kinfo_proc.h"
 #include "user.h"              /* for coredump */
@@ -458,7 +486,7 @@ killpg1(cp, signo, pgid, all)
                }
                for (p = pgrp->pg_mem; p != NULL; p = p->p_pgrpnxt) {
                        if (p->p_pid <= 1 || p->p_flag&SSYS ||
                }
                for (p = pgrp->pg_mem; p != NULL; p = p->p_pgrpnxt) {
                        if (p->p_pid <= 1 || p->p_flag&SSYS ||
-                           !CANSIGNAL(cp, pc, p, signo))
+                           p->p_stat == SZOMB || !CANSIGNAL(cp, pc, p, signo))
                                continue;
                        nfound++;
                        if (signo)
                                continue;
                        nfound++;
                        if (signo)
@@ -713,7 +741,7 @@ psignal(p, sig)
                 * It will either never be noticed, or noticed very soon.
                 */
                if (p == curproc)
                 * It will either never be noticed, or noticed very soon.
                 */
                if (p == curproc)
-                       aston();
+                       signotify(p);
                goto out;
        }
        /*NOTREACHED*/
                goto out;
        }
        /*NOTREACHED*/
@@ -973,9 +1001,8 @@ sigexit(p, sig)
 
 /*
  * Create a core dump.
 
 /*
  * Create a core dump.
- * The file name should probably be "core.progname"
- * (or "mos.progname", or "dram.progname", or ...).
- * Core dumps aren't created if the process 
+ * The file name is "core.progname".
+ * Core dumps are not created if the process is setuid.
  */
 coredump(p)
        register struct proc *p;
  */
 coredump(p)
        register struct proc *p;
@@ -985,8 +1012,9 @@ coredump(p)
        register struct ucred *cred = pcred->pc_ucred;
        register struct vmspace *vm = p->p_vmspace;
        struct vattr vattr;
        register struct ucred *cred = pcred->pc_ucred;
        register struct vmspace *vm = p->p_vmspace;
        struct vattr vattr;
-       int error;
+       int error, error1;
        struct nameidata nd;
        struct nameidata nd;
+       char name[MAXCOMLEN+6]; /* core.progname */
 
        if (pcred->p_svuid != pcred->p_ruid ||
            pcred->p_svgid != pcred->p_rgid)
 
        if (pcred->p_svuid != pcred->p_ruid ||
            pcred->p_svgid != pcred->p_rgid)
@@ -994,47 +1022,51 @@ coredump(p)
        if (ctob(UPAGES + vm->vm_dsize + vm->vm_ssize) >=
            p->p_rlimit[RLIMIT_CORE].rlim_cur)
                return (EFAULT);
        if (ctob(UPAGES + vm->vm_dsize + vm->vm_ssize) >=
            p->p_rlimit[RLIMIT_CORE].rlim_cur)
                return (EFAULT);
+       sprintf(name, "core.%s", p->p_comm);
+       nd.ni_dirp = name;
        nd.ni_segflg = UIO_SYSSPACE;
        nd.ni_segflg = UIO_SYSSPACE;
-       nd.ni_dirp = "core";
-       if (error = vn_open(&nd, p, FCREAT|FWRITE, 0644))
+       if (error = vn_open(&nd, p, O_CREAT|FWRITE, 0644))
                return (error);
        vp = nd.ni_vp;
                return (error);
        vp = nd.ni_vp;
-       VOP_LOCK(vp);
        if (vp->v_type != VREG || VOP_GETATTR(vp, &vattr, cred, p) ||
            vattr.va_nlink != 1) {
        if (vp->v_type != VREG || VOP_GETATTR(vp, &vattr, cred, p) ||
            vattr.va_nlink != 1) {
-               vput(vp);
-               return (EFAULT);
+               error = EFAULT;
+               goto out;
        }
        VATTR_NULL(&vattr);
        vattr.va_size = 0;
        VOP_SETATTR(vp, &vattr, cred, p);
        p->p_acflag |= ACORE;
        }
        VATTR_NULL(&vattr);
        vattr.va_size = 0;
        VOP_SETATTR(vp, &vattr, cred, p);
        p->p_acflag |= ACORE;
-       bcopy(p, &u.u_kproc.kp_proc, sizeof(struct proc));
-       fill_eproc(p, &u.u_kproc.kp_eproc);
+       bcopy(p, &p->p_addr->u_kproc.kp_proc, sizeof(struct proc));
+       fill_eproc(p, &p->p_addr->u_kproc.kp_eproc);
 #ifdef HPUXCOMPAT
        /*
         * BLETCH!  If we loaded from an HPUX format binary file
         * we have to dump an HPUX style user struct so that the
         * HPUX debuggers can grok it.
         */
 #ifdef HPUXCOMPAT
        /*
         * BLETCH!  If we loaded from an HPUX format binary file
         * we have to dump an HPUX style user struct so that the
         * HPUX debuggers can grok it.
         */
-       if (u.u_pcb.pcb_flags & PCB_HPUXBIN)
+       if (p->p_addr->u_pcb.pcb_flags & PCB_HPUXBIN)
                error = hpuxdumpu(vp, cred);
        else
 #endif
                error = hpuxdumpu(vp, cred);
        else
 #endif
-       error = vn_rdwr(UIO_WRITE, vp, (caddr_t)&p->p_addr, ctob(UPAGES),
-           (off_t)0, UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, cred, (int *)0,
-           (struct proc *)0);
+       error = vn_rdwr(UIO_WRITE, vp, (caddr_t) p->p_addr, ctob(UPAGES),
+           (off_t)0, UIO_SYSSPACE, IO_NODELOCKED|IO_UNIT, cred, (int *) NULL,
+           p);
        if (error == 0)
                error = vn_rdwr(UIO_WRITE, vp, vm->vm_daddr,
                    (int)ctob(vm->vm_dsize), (off_t)ctob(UPAGES), UIO_USERSPACE,
        if (error == 0)
                error = vn_rdwr(UIO_WRITE, vp, vm->vm_daddr,
                    (int)ctob(vm->vm_dsize), (off_t)ctob(UPAGES), UIO_USERSPACE,
-                   IO_NODELOCKED|IO_UNIT, cred, (int *)0, p);
+                   IO_NODELOCKED|IO_UNIT, cred, (int *) NULL, p);
        if (error == 0)
                error = vn_rdwr(UIO_WRITE, vp,
        if (error == 0)
                error = vn_rdwr(UIO_WRITE, vp,
-                   trunc_page(USRSTACK - ctob(vm->vm_ssize)),
+                   (caddr_t) trunc_page(USRSTACK - ctob(vm->vm_ssize)),
                    round_page(ctob(vm->vm_ssize)),
                    (off_t)ctob(UPAGES) + ctob(vm->vm_dsize), UIO_USERSPACE,
                    round_page(ctob(vm->vm_ssize)),
                    (off_t)ctob(UPAGES) + ctob(vm->vm_dsize), UIO_USERSPACE,
-                   IO_NODELOCKED|IO_UNIT, cred, (int *)0, p);
-       vput(vp);
+                   IO_NODELOCKED|IO_UNIT, cred, (int *) NULL, p);
+out:
+       VOP_UNLOCK(vp);
+       error1 = vn_close(vp, FWRITE, cred, p);
+       if (error == 0)
+               error = error1;
        return (error);
 }
 
        return (error);
 }