Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern signal(9) code: add some comments, improve/fix wron...



details:   https://anonhg.NetBSD.org/src/rev/f511c6630f45
branches:  trunk
changeset: 750201:f511c6630f45
user:      rmind <rmind%NetBSD.org@localhost>
date:      Sun Dec 20 04:49:09 2009 +0000

description:
signal(9) code: add some comments, improve/fix wrong ones.  While here, kill
trailing whitespaces, wrap long lines, etc.  No functional changes intended.

diffstat:

 sys/kern/kern_sig.c |  169 ++++++++++++++++++++++++---------------------------
 sys/kern/sys_sig.c  |  157 ++++++++++++++++++++++-------------------------
 2 files changed, 154 insertions(+), 172 deletions(-)

diffs (truncated from 909 to 300 lines):

diff -r 0210f4150fe1 -r f511c6630f45 sys/kern/kern_sig.c
--- a/sys/kern/kern_sig.c       Sun Dec 20 04:11:37 2009 +0000
+++ b/sys/kern/kern_sig.c       Sun Dec 20 04:49:09 2009 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_sig.c,v 1.300 2009/11/14 19:06:54 rmind Exp $     */
+/*     $NetBSD: kern_sig.c,v 1.301 2009/12/20 04:49:09 rmind Exp $     */
 
 /*-
  * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.300 2009/11/14 19:06:54 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.301 2009/12/20 04:49:09 rmind Exp $");
 
 #include "opt_ptrace.h"
 #include "opt_compat_sunos.h"
@@ -125,8 +125,8 @@
     (int (*)(struct lwp *, const char *))enosys;
 
 static struct pool_allocator sigactspool_allocator = {
-        .pa_alloc = sigacts_poolpage_alloc,
-       .pa_free = sigacts_poolpage_free,
+       .pa_alloc = sigacts_poolpage_alloc,
+       .pa_free = sigacts_poolpage_free
 };
 
 #ifdef DEBUG
@@ -135,9 +135,9 @@
 int    kern_logsigexit = 0;
 #endif
 
-static const char logcoredump[] =
+static const char logcoredump[] =
     "pid %d (%s), uid %d: exited on signal %d (core dumped)\n";
-static const char lognocoredump[] =
+static const char lognocoredump[] =
     "pid %d (%s), uid %d: exited on signal %d (core not dumped, err = %d)\n";
 
 static kauth_listener_t signal_listener;
@@ -166,7 +166,7 @@
 /*
  * signal_init:
  *
- *     Initialize global signal-related data structures.
+ *     Initialize global signal-related data structures.
  */
 void
 signal_init(void)
@@ -196,14 +196,14 @@
 /*
  * sigacts_poolpage_alloc:
  *
- *      Allocate a page for the sigacts memory pool.
+ *     Allocate a page for the sigacts memory pool.
  */
 static void *
 sigacts_poolpage_alloc(struct pool *pp, int flags)
 {
 
        return (void *)uvm_km_alloc(kernel_map,
-           (PAGE_SIZE)*2, (PAGE_SIZE)*2,
+           PAGE_SIZE * 2, PAGE_SIZE * 2,
            ((flags & PR_WAITOK) ? 0 : UVM_KMF_NOWAIT | UVM_KMF_TRYLOCK)
            | UVM_KMF_WIRED);
 }
@@ -211,21 +211,21 @@
 /*
  * sigacts_poolpage_free:
  *
- *      Free a page on behalf of the sigacts memory pool.
+ *     Free a page on behalf of the sigacts memory pool.
  */
 static void
 sigacts_poolpage_free(struct pool *pp, void *v)
 {
 
-        uvm_km_free(kernel_map, (vaddr_t)v, (PAGE_SIZE)*2, UVM_KMF_WIRED);
+       uvm_km_free(kernel_map, (vaddr_t)v, PAGE_SIZE * 2, UVM_KMF_WIRED);
 }
 
 /*
  * sigactsinit:
- * 
- *      Create an initial sigctx structure, using the same signal state as
- *      p.  If 'share' is set, share the sigctx_proc part, otherwise just
- *      copy it from parent.
+ *
+ *     Create an initial sigacts structure, using the same signal state
+ *     as of specified process.  If 'share' is set, share the sigacts by
+ *     holding a reference, otherwise just copy it from parent.
  */
 struct sigacts *
 sigactsinit(struct proc *pp, int share)
@@ -253,9 +253,8 @@
 
 /*
  * sigactsunshare:
- * 
- *     Make this process not share its sigctx, maintaining all
- *     signal state.
+ *
+ *     Make this process not share its sigacts, maintaining all signal state.
  */
 void
 sigactsunshare(struct proc *p)
@@ -276,7 +275,7 @@
 /*
  * sigactsfree;
  *
- *     Release a sigctx structure.
+ *     Release a sigacts structure.
  */
 void
 sigactsfree(struct sigacts *ps)
@@ -450,7 +449,7 @@
        if (ok != NULL) {
                if ((ok->ksi_flags & (KSI_QUEUED | KSI_FROMPOOL)) ==
                    KSI_FROMPOOL)
-                       return ok;
+                       return ok;
                if (KSI_EMPTY_P(ok))
                        return ok;
        }
@@ -519,7 +518,7 @@
 int
 sigget(sigpend_t *sp, ksiginfo_t *out, int signo, const sigset_t *mask)
 {
-        ksiginfo_t *ksi;
+       ksiginfo_t *ksi;
        sigset_t tset;
 
        /* If there's no pending set, the signal is from the debugger. */
@@ -533,8 +532,8 @@
                        __sigandset(&sp->sp_set, &tset);
                } else
                        tset = sp->sp_set;
-               
-               /* If there are no signals pending, that's it. */
+
+               /* If there are no signals pending - return. */
                if ((signo = firstsig(&tset)) == 0)
                        goto out;
        } else {
@@ -545,34 +544,32 @@
 
        /* Find siginfo and copy it out. */
        CIRCLEQ_FOREACH(ksi, &sp->sp_info, ksi_list) {
-               if (ksi->ksi_signo == signo) {
-                       CIRCLEQ_REMOVE(&sp->sp_info, ksi, ksi_list);
-                       KASSERT((ksi->ksi_flags & KSI_FROMPOOL) != 0);
-                       KASSERT((ksi->ksi_flags & KSI_QUEUED) != 0);
-                       ksi->ksi_flags &= ~KSI_QUEUED;
-                       if (out != NULL) {
-                               memcpy(out, ksi, sizeof(*out));
-                               out->ksi_flags &= ~(KSI_FROMPOOL | KSI_QUEUED);
-                       }
-                       ksiginfo_free(ksi);
-                       return signo;
+               if (ksi->ksi_signo != signo)
+                       continue;
+               CIRCLEQ_REMOVE(&sp->sp_info, ksi, ksi_list);
+               KASSERT((ksi->ksi_flags & KSI_FROMPOOL) != 0);
+               KASSERT((ksi->ksi_flags & KSI_QUEUED) != 0);
+               ksi->ksi_flags &= ~KSI_QUEUED;
+               if (out != NULL) {
+                       memcpy(out, ksi, sizeof(*out));
+                       out->ksi_flags &= ~(KSI_FROMPOOL | KSI_QUEUED);
                }
+               ksiginfo_free(ksi);     /* XXXSMP */
+               return signo;
        }
-
 out:
-       /* If there's no siginfo, then manufacture it. */
+       /* If there is no siginfo, then manufacture it. */
        if (out != NULL) {
                KSI_INIT(out);
                out->ksi_info._signo = signo;
                out->ksi_info._code = SI_NOINFO;
        }
-
        return signo;
 }
 
 /*
  * sigput:
- * 
+ *
  *     Append a new ksiginfo element to the list of pending ksiginfo's.
  */
 static void
@@ -687,10 +684,12 @@
        return 0;
 }
 
+#ifdef KERN_SA
+
 /*
  * siginfo_alloc:
  *
- *      Allocate a new siginfo_t structure from the pool.
+ *     Allocate a new siginfo_t structure from the pool.
  */
 siginfo_t *
 siginfo_alloc(int flags)
@@ -702,7 +701,7 @@
 /*
  * siginfo_free:
  *
- *      Return a siginfo_t structure to the pool.
+ *     Return a siginfo_t structure to the pool.
  */
 void
 siginfo_free(void *arg)
@@ -711,6 +710,8 @@
        pool_cache_put(siginfo_cache, arg);
 }
 
+#endif
+
 void
 getucontext(struct lwp *l, ucontext_t *ucp)
 {
@@ -818,8 +819,7 @@
 }
 
 /*
- * Common code for kill process group/broadcast kill.  cp is calling
- * process.
+ * killpg1: common code for kill process group/broadcast kill.
  */
 int
 killpg1(struct lwp *l, ksiginfo_t *ksi, int pgid, int all)
@@ -837,7 +837,7 @@
        mutex_enter(proc_lock);
        if (all) {
                /*
-                * broadcast
+                * Broadcast.
                 */
                PROCLIST_FOREACH(p, &allproc) {
                        if (p->p_pid <= 1 || p == cp ||
@@ -855,9 +855,7 @@
                }
        } else {
                if (pgid == 0)
-                       /*
-                        * zero pgid means send to my process group.
-                        */
+                       /* Zero pgid means send to my process group. */
                        pgrp = cp->p_pgrp;
                else {
                        pgrp = pg_find(pgid, PFIND_LOCKED);
@@ -877,13 +875,13 @@
                        mutex_exit(p->p_lock);
                }
        }
-  out:
+out:
        mutex_exit(proc_lock);
-       return (nfound ? 0 : ESRCH);
+       return nfound ? 0 : ESRCH;
 }
 
 /*
- * Send a signal to a process group. If checktty is 1, limit to members
+ * Send a signal to a process group.  If checktty is set, limit to members
  * which have a controlling terminal.
  */
 void
@@ -906,9 +904,8 @@
 
        KASSERT(!cpu_intr_p());
        KASSERT(mutex_owned(proc_lock));
+       KASSERT(pgrp != NULL);
 
-       if (__predict_false(pgrp == 0))
-               return;
        LIST_FOREACH(p, &pgrp->pg_members, p_pglist)
                if (checkctty == 0 || p->p_lflag & PL_CONTROLT)
                        kpsignal(p, ksi, data);
@@ -943,8 +940,7 @@
                l->l_ru.ru_nsignals++;
                kpsendsig(l, ksi, mask);
                mutex_exit(p->p_lock);
-               ktrpsig(signo, SIGACTION_PS(ps, signo).sa_handler,
-                   mask, ksi);
+               ktrpsig(signo, SIGACTION_PS(ps, signo).sa_handler, mask, ksi);
        } else {
                /* XXX for core dump/debugger */
                p->p_sigctx.ps_lwp = l->l_lid;
@@ -1043,7 +1039,7 @@
 /*
  * sigismasked:
  *
- *      Returns true if signal is ignored or masked for the specified LWP.
+ *     Returns true if signal is ignored or masked for the specified LWP.
  */



Home | Main Index | Thread Index | Old Index