Print this page
3830 SIGQUEUE_MAX's limit of 32 is too low
Reviewed by: Cedric Blancher <cedric.blancher@gmail.com>
Reviewed by: John Kennedy <john.kennedy@delphix.com>
Reviewed by: Irek Szczesniak <iszczesniak@gmail.com>


   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  28 
  29 #pragma ident   "%Z%%M% %I%     %E% SMI"
  30 
  31 #include <sys/param.h>
  32 #include <sys/types.h>
  33 #include <sys/sysmacros.h>
  34 #include <sys/systm.h>
  35 #include <sys/errno.h>
  36 #include <sys/proc.h>
  37 #include <sys/procset.h>
  38 #include <sys/fault.h>
  39 #include <sys/signal.h>
  40 #include <sys/siginfo.h>
  41 #include <sys/debug.h>
  42 


  43 static int
  44 sigqkill(pid_t pid, sigsend_t *sigsend)
  45 {
  46         proc_t *p;
  47         int error;
  48 
  49         if ((uint_t)sigsend->sig >= NSIG)
  50                 return (EINVAL);
  51 
  52         if (pid == -1) {
  53                 procset_t set;
  54 
  55                 setprocset(&set, POP_AND, P_ALL, P_MYID, P_ALL, P_MYID);
  56                 error = sigsendset(&set, sigsend);
  57         } else if (pid > 0) {
  58                 mutex_enter(&pidlock);
  59                 if ((p = prfind(pid)) == NULL || p->p_stat == SIDL)
  60                         error = ESRCH;
  61                 else {
  62                         error = sigsendproc(p, sigsend);


 116  * The handling of small unions, like the sigval argument to sigqueue,
 117  * is architecture dependent.  We have adopted the convention that the
 118  * value itself is passed in the storage which crosses the kernel
 119  * protection boundary.  This procedure will accept a scalar argument,
 120  * and store it in the appropriate value member of the sigsend_t structure.
 121  */
 122 int
 123 sigqueue(pid_t pid, int sig, /* union sigval */ void *value,
 124         int si_code, int block)
 125 {
 126         int error;
 127         sigsend_t v;
 128         sigqhdr_t *sqh;
 129         proc_t *p = curproc;
 130 
 131         /* The si_code value must indicate the signal will be queued */
 132         if (pid <= 0 || !sigwillqueue(sig, si_code))
 133                 return (set_errno(EINVAL));
 134 
 135         if ((sqh = p->p_sigqhdr) == NULL) {







 136                 /* Allocate sigqueue pool first time */
 137                 sqh = sigqhdralloc(sizeof (sigqueue_t), _SIGQUEUE_MAX);
 138                 mutex_enter(&p->p_lock);
 139                 if (p->p_sigqhdr == NULL) {
 140                         /* hang the pool head on proc */
 141                         p->p_sigqhdr = sqh;
 142                 } else {
 143                         /* another lwp allocated the pool, free ours */
 144                         sigqhdrfree(sqh);
 145                         sqh = p->p_sigqhdr;
 146                 }
 147                 mutex_exit(&p->p_lock);
 148         }
 149 
 150         do {
 151                 bzero(&v, sizeof (v));
 152                 v.sig = sig;
 153                 v.checkperm = 1;
 154                 v.sicode = si_code;
 155                 v.value.sival_ptr = value;
 156                 if ((error = sigqkill(pid, &v)) != EAGAIN || !block)
 157                         break;




   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  28 


  29 #include <sys/param.h>
  30 #include <sys/types.h>
  31 #include <sys/sysmacros.h>
  32 #include <sys/systm.h>
  33 #include <sys/errno.h>
  34 #include <sys/proc.h>
  35 #include <sys/procset.h>
  36 #include <sys/fault.h>
  37 #include <sys/signal.h>
  38 #include <sys/siginfo.h>
  39 #include <sys/debug.h>
  40 
  41 extern rctl_hndl_t rc_process_sigqueue;
  42 
  43 static int
  44 sigqkill(pid_t pid, sigsend_t *sigsend)
  45 {
  46         proc_t *p;
  47         int error;
  48 
  49         if ((uint_t)sigsend->sig >= NSIG)
  50                 return (EINVAL);
  51 
  52         if (pid == -1) {
  53                 procset_t set;
  54 
  55                 setprocset(&set, POP_AND, P_ALL, P_MYID, P_ALL, P_MYID);
  56                 error = sigsendset(&set, sigsend);
  57         } else if (pid > 0) {
  58                 mutex_enter(&pidlock);
  59                 if ((p = prfind(pid)) == NULL || p->p_stat == SIDL)
  60                         error = ESRCH;
  61                 else {
  62                         error = sigsendproc(p, sigsend);


 116  * The handling of small unions, like the sigval argument to sigqueue,
 117  * is architecture dependent.  We have adopted the convention that the
 118  * value itself is passed in the storage which crosses the kernel
 119  * protection boundary.  This procedure will accept a scalar argument,
 120  * and store it in the appropriate value member of the sigsend_t structure.
 121  */
 122 int
 123 sigqueue(pid_t pid, int sig, /* union sigval */ void *value,
 124     int si_code, int block)
 125 {
 126         int error;
 127         sigsend_t v;
 128         sigqhdr_t *sqh;
 129         proc_t *p = curproc;
 130 
 131         /* The si_code value must indicate the signal will be queued */
 132         if (pid <= 0 || !sigwillqueue(sig, si_code))
 133                 return (set_errno(EINVAL));
 134 
 135         if ((sqh = p->p_sigqhdr) == NULL) {
 136                 rlim64_t sigqsz_max;
 137 
 138                 mutex_enter(&p->p_lock);
 139                 sigqsz_max = rctl_enforced_value(rc_process_sigqueue,
 140                     p->p_rctls, p);
 141                 mutex_exit(&p->p_lock);
 142 
 143                 /* Allocate sigqueue pool first time */
 144                 sqh = sigqhdralloc(sizeof (sigqueue_t), (uint_t)sigqsz_max);
 145                 mutex_enter(&p->p_lock);
 146                 if (p->p_sigqhdr == NULL) {
 147                         /* hang the pool head on proc */
 148                         p->p_sigqhdr = sqh;
 149                 } else {
 150                         /* another lwp allocated the pool, free ours */
 151                         sigqhdrfree(sqh);
 152                         sqh = p->p_sigqhdr;
 153                 }
 154                 mutex_exit(&p->p_lock);
 155         }
 156 
 157         do {
 158                 bzero(&v, sizeof (v));
 159                 v.sig = sig;
 160                 v.checkperm = 1;
 161                 v.sicode = si_code;
 162                 v.value.sival_ptr = value;
 163                 if ((error = sigqkill(pid, &v)) != EAGAIN || !block)
 164                         break;