delete unneeded header files
[unix-history] / usr / src / sys / kern / kern_sig.c
index fe42f91..82d2aba 100644 (file)
@@ -1,8 +1,15 @@
-/*     kern_sig.c      6.12    85/03/13        */
+/*
+ * Copyright (c) 1982, 1986 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ *
+ *     @(#)kern_sig.c  7.3 (Berkeley) %G%
+ */
 
 #include "../machine/reg.h"
 #include "../machine/pte.h"
 #include "../machine/psl.h"
 
 #include "../machine/reg.h"
 #include "../machine/pte.h"
 #include "../machine/psl.h"
+#include "../machine/mtpr.h"
 
 #include "param.h"
 #include "systm.h"
 
 #include "param.h"
 #include "systm.h"
@@ -12,7 +19,6 @@
 #include "proc.h"
 #include "timeb.h"
 #include "times.h"
 #include "proc.h"
 #include "timeb.h"
 #include "times.h"
-#include "conf.h"
 #include "buf.h"
 #include "mount.h"
 #include "text.h"
 #include "buf.h"
 #include "mount.h"
 #include "text.h"
@@ -23,6 +29,8 @@
 #include "kernel.h"
 
 #define        cantmask        (sigmask(SIGKILL)|sigmask(SIGCONT)|sigmask(SIGSTOP))
 #include "kernel.h"
 
 #define        cantmask        (sigmask(SIGKILL)|sigmask(SIGCONT)|sigmask(SIGSTOP))
+#define        stopsigmask     (sigmask(SIGSTOP)|sigmask(SIGTSTP)| \
+                       sigmask(SIGTTIN)|sigmask(SIGTTOU))
 
 /*
  * Generalized interface signal handler.
 
 /*
  * Generalized interface signal handler.
@@ -180,17 +188,43 @@ sigstack()
        }
 }
 
        }
 }
 
-/* KILL SHOULD BE UPDATED */
-
 kill()
 {
        register struct a {
                int     pid;
                int     signo;
        } *uap = (struct a *)u.u_ap;
 kill()
 {
        register struct a {
                int     pid;
                int     signo;
        } *uap = (struct a *)u.u_ap;
+       register struct proc *p;
 
 
-       u.u_error = kill1(uap->signo < 0,
-               uap->signo < 0 ? -uap->signo : uap->signo, uap->pid);
+       if (uap->signo < 0 || uap->signo > NSIG) {
+               u.u_error = EINVAL;
+               return;
+       }
+       if (uap->pid > 0) {
+               /* kill single process */
+               p = pfind(uap->pid);
+               if (p == 0) {
+                       u.u_error = ESRCH;
+                       return;
+               }
+               if (u.u_uid && u.u_uid != p->p_uid)
+                       u.u_error = EPERM;
+               else if (uap->signo)
+                       psignal(p, uap->signo);
+               return;
+       }
+       switch (uap->pid) {
+       case -1:                /* broadcast signal */
+               u.u_error = killpg1(uap->signo, 0, 1);
+               break;
+       case 0:                 /* signal own process group */
+               u.u_error = killpg1(uap->signo, 0, 0);
+               break;
+       default:                /* negative explicit process group */
+               u.u_error = killpg1(uap->signo, -uap->pid, 0);
+               break;
+       }
+       return;
 }
 
 killpg()
 }
 
 killpg()
@@ -200,55 +234,44 @@ killpg()
                int     signo;
        } *uap = (struct a *)u.u_ap;
 
                int     signo;
        } *uap = (struct a *)u.u_ap;
 
-       u.u_error = kill1(1, uap->signo, uap->pgrp);
+       if (uap->signo < 0 || uap->signo > NSIG) {
+               u.u_error = EINVAL;
+               return;
+       }
+       u.u_error = killpg1(uap->signo, uap->pgrp, 0);
 }
 
 /* KILL CODE SHOULDNT KNOW ABOUT PROCESS INTERNALS !?! */
 
 }
 
 /* KILL CODE SHOULDNT KNOW ABOUT PROCESS INTERNALS !?! */
 
-kill1(ispgrp, signo, who)
-       int ispgrp, signo, who;
+killpg1(signo, pgrp, all)
+       int signo, pgrp, all;
 {
        register struct proc *p;
 {
        register struct proc *p;
-       int f, priv = 0;
+       int f, error = 0;
 
 
-       if (signo < 0 || signo > NSIG)
-               return (EINVAL);
-       if (who > 0 && !ispgrp) {
-               p = pfind(who);
-               if (p == 0)
-                       return (ESRCH);
-               if (u.u_uid && u.u_uid != p->p_uid)
-                       return (EPERM);
-               if (signo)
-                       psignal(p, signo);
-               return (0);
-       }
-       if (who == -1 && u.u_uid == 0)
-               priv++, who = 0, ispgrp = 1;    /* like sending to pgrp */
-       else if (who == 0) {
+       if (!all && pgrp == 0) {
                /*
                 * Zero process id means send to my process group.
                 */
                /*
                 * Zero process id means send to my process group.
                 */
-               ispgrp = 1;
-               who = u.u_procp->p_pgrp;
-               if (who == 0)
-                       return (EINVAL);
+               pgrp = u.u_procp->p_pgrp;
+               if (pgrp == 0)
+                       return (ESRCH);
        }
        for (f = 0, p = allproc; p != NULL; p = p->p_nxt) {
        }
        for (f = 0, p = allproc; p != NULL; p = p->p_nxt) {
-               if (!ispgrp) {
-                       if (p->p_pid != who)
-                               continue;
-               } else if (p->p_pgrp != who && priv == 0 || p->p_ppid == 0 ||
-                   (p->p_flag&SSYS) || (priv && p == u.u_procp))
+               if ((p->p_pgrp != pgrp && !all) || p->p_ppid == 0 ||
+                   (p->p_flag&SSYS) || (all && p == u.u_procp))
                        continue;
                if (u.u_uid != 0 && u.u_uid != p->p_uid &&
                        continue;
                if (u.u_uid != 0 && u.u_uid != p->p_uid &&
-                   (signo != SIGCONT || !inferior(p)))
+                   (signo != SIGCONT || !inferior(p))) {
+                       if (!all)
+                               error = EPERM;
                        continue;
                        continue;
+               }
                f++;
                if (signo)
                        psignal(p, signo);
        }
                f++;
                if (signo)
                        psignal(p, signo);
        }
-       return (f == 0 ? ESRCH : 0);
+       return (error ? error : (f == 0 ? ESRCH : 0));
 }
 
 /*
 }
 
 /*
@@ -303,8 +326,6 @@ psignal(p, sig)
                else
                        action = SIG_DFL;
        }
                else
                        action = SIG_DFL;
        }
-#define        stops   (sigmask(SIGSTOP)|sigmask(SIGTSTP)| \
-                       sigmask(SIGTTIN)|sigmask(SIGTTOU))
        if (sig) {
                p->p_sig |= mask;
                switch (sig) {
        if (sig) {
                p->p_sig |= mask;
                switch (sig) {
@@ -320,7 +341,7 @@ psignal(p, sig)
                        break;
 
                case SIGCONT:
                        break;
 
                case SIGCONT:
-                       p->p_sig &= ~stops;
+                       p->p_sig &= ~stopsigmask;
                        break;
 
                case SIGSTOP:
                        break;
 
                case SIGSTOP:
@@ -331,7 +352,6 @@ psignal(p, sig)
                        break;
                }
        }
                        break;
                }
        }
-#undef stops
        /*
         * Defer further processing for signals which are held.
         */
        /*
         * Defer further processing for signals which are held.
         */
@@ -471,7 +491,6 @@ psignal(p, sig)
                 * It will either never be noticed, or noticed very soon.
                 */
                if (p == u.u_procp && !noproc)
                 * It will either never be noticed, or noticed very soon.
                 */
                if (p == u.u_procp && !noproc)
-#include "../vax/mtpr.h"
                        aston();
                goto out;
        }
                        aston();
                goto out;
        }
@@ -511,11 +530,10 @@ issig()
                if ((p->p_flag&STRC) == 0)
                        sigbits &= ~p->p_sigignore;
                if (p->p_flag&SVFORK)
                if ((p->p_flag&STRC) == 0)
                        sigbits &= ~p->p_sigignore;
                if (p->p_flag&SVFORK)
-#define bit(a) (1<<(a-1))
-                       sigbits &= ~(bit(SIGSTOP)|bit(SIGTSTP)|bit(SIGTTIN)|bit(SIGTTOU));
+                       sigbits &= ~stopsigmask;
                if (sigbits == 0)
                        break;
                if (sigbits == 0)
                        break;
-               sig = ffs(sigbits);
+               sig = ffs((long)sigbits);
                mask = sigmask(sig);
                p->p_sig &= ~mask;              /* take the signal! */
                p->p_cursig = sig;
                mask = sigmask(sig);
                p->p_sig &= ~mask;              /* take the signal! */
                p->p_cursig = sig;
@@ -560,7 +578,7 @@ issig()
                                continue;
                        }
                }
                                continue;
                        }
                }
-               switch (u.u_signal[sig]) {
+               switch ((int)u.u_signal[sig]) {
 
                case SIG_DFL:
                        /*
 
                case SIG_DFL:
                        /*
@@ -746,6 +764,8 @@ core()
        if (ctob(UPAGES+u.u_dsize+u.u_ssize) >=
            u.u_rlimit[RLIMIT_CORE].rlim_cur)
                return (0);
        if (ctob(UPAGES+u.u_dsize+u.u_ssize) >=
            u.u_rlimit[RLIMIT_CORE].rlim_cur)
                return (0);
+       if (u.u_procp->p_textp && access(u.u_procp->p_textp->x_iptr, IREAD))
+               return (0);
        u.u_error = 0;
        ndp->ni_nameiop = CREATE | FOLLOW;
        ndp->ni_segflg = UIO_SYSSPACE;
        u.u_error = 0;
        ndp->ni_nameiop = CREATE | FOLLOW;
        ndp->ni_segflg = UIO_SYSSPACE;
@@ -764,22 +784,30 @@ core()
                u.u_error = EFAULT;
                goto out;
        }
                u.u_error = EFAULT;
                goto out;
        }
+#ifdef MMAP
+       { register int fd;
+       /* unmasp funky devices in the user's address space */
+       for (fd = 0; fd < u.u_lastfile; fd++)
+               if (u.u_ofile[fd] && (u.u_pofile[fd] & UF_MAPPED))
+                       munmapfd(fd);
+       }
+#endif
        itrunc(ip, (u_long)0);
        u.u_acflag |= ACORE;
        u.u_error = rdwri(UIO_WRITE, ip,
            (caddr_t)&u,
            ctob(UPAGES),
        itrunc(ip, (u_long)0);
        u.u_acflag |= ACORE;
        u.u_error = rdwri(UIO_WRITE, ip,
            (caddr_t)&u,
            ctob(UPAGES),
-           0, 1, (int *)0);
+           (off_t)0, 1, (int *)0);
        if (u.u_error == 0)
                u.u_error = rdwri(UIO_WRITE, ip,
                    (caddr_t)ctob(dptov(u.u_procp, 0)),
        if (u.u_error == 0)
                u.u_error = rdwri(UIO_WRITE, ip,
                    (caddr_t)ctob(dptov(u.u_procp, 0)),
-                   ctob(u.u_dsize),
-                   ctob(UPAGES), 0, (int *)0);
+                   (int)ctob(u.u_dsize),
+                   (off_t)ctob(UPAGES), 0, (int *)0);
        if (u.u_error == 0)
                u.u_error = rdwri(UIO_WRITE, ip,
                    (caddr_t)ctob(sptov(u.u_procp, u.u_ssize - 1)),
        if (u.u_error == 0)
                u.u_error = rdwri(UIO_WRITE, ip,
                    (caddr_t)ctob(sptov(u.u_procp, u.u_ssize - 1)),
-                   ctob(u.u_ssize),
-                   ctob(UPAGES)+ctob(u.u_dsize), 0, (int *)0);
+                   (int)ctob(u.u_ssize),
+                   (off_t)ctob(UPAGES)+ctob(u.u_dsize), 0, (int *)0);
 out:
        iput(ip);
        return (u.u_error == 0);
 out:
        iput(ip);
        return (u.u_error == 0);