sysv_msg.c (220399) | sysv_msg.c (223825) |
---|---|
1/*- 2 * Implementation of SVID messages 3 * 4 * Author: Daniel Boulet 5 * 6 * Copyright 1993 Daniel Boulet and RTMX Inc. 7 * 8 * This system call was implemented by Daniel Boulet under contract from RTMX. --- 34 unchanged lines hidden (view full) --- 43 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 45 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 46 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 47 * SUCH DAMAGE. 48 */ 49 50#include <sys/cdefs.h> | 1/*- 2 * Implementation of SVID messages 3 * 4 * Author: Daniel Boulet 5 * 6 * Copyright 1993 Daniel Boulet and RTMX Inc. 7 * 8 * This system call was implemented by Daniel Boulet under contract from RTMX. --- 34 unchanged lines hidden (view full) --- 43 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 45 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 46 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 47 * SUCH DAMAGE. 48 */ 49 50#include <sys/cdefs.h> |
51__FBSDID("$FreeBSD: head/sys/kern/sysv_msg.c 220399 2011-04-06 19:08:50Z trasz $"); | 51__FBSDID("$FreeBSD: head/sys/kern/sysv_msg.c 223825 2011-07-06 20:06:44Z trasz $"); |
52 53#include "opt_compat.h" 54#include "opt_sysvipc.h" 55 56#include <sys/param.h> 57#include <sys/systm.h> 58#include <sys/sysproto.h> 59#include <sys/kernel.h> --- 555 unchanged lines hidden (view full) --- 615 (msqkptr->u.msg_perm.mode & MSG_LOCKED) == 0) 616 break; 617 } 618 if (msqid == msginfo.msgmni) { 619 DPRINTF(("no more msqid_ds's available\n")); 620 error = ENOSPC; 621 goto done2; 622 } | 52 53#include "opt_compat.h" 54#include "opt_sysvipc.h" 55 56#include <sys/param.h> 57#include <sys/systm.h> 58#include <sys/sysproto.h> 59#include <sys/kernel.h> --- 555 unchanged lines hidden (view full) --- 615 (msqkptr->u.msg_perm.mode & MSG_LOCKED) == 0) 616 break; 617 } 618 if (msqid == msginfo.msgmni) { 619 DPRINTF(("no more msqid_ds's available\n")); 620 error = ENOSPC; 621 goto done2; 622 } |
623#ifdef RACCT |
|
623 PROC_LOCK(td->td_proc); 624 error = racct_add(td->td_proc, RACCT_NMSGQ, 1); 625 PROC_UNLOCK(td->td_proc); 626 if (error != 0) { 627 error = ENOSPC; 628 goto done2; 629 } | 624 PROC_LOCK(td->td_proc); 625 error = racct_add(td->td_proc, RACCT_NMSGQ, 1); 626 PROC_UNLOCK(td->td_proc); 627 if (error != 0) { 628 error = ENOSPC; 629 goto done2; 630 } |
631#endif |
|
630 DPRINTF(("msqid %d is available\n", msqid)); 631 msqkptr->u.msg_perm.key = key; 632 msqkptr->u.msg_perm.cuid = cred->cr_uid; 633 msqkptr->u.msg_perm.uid = cred->cr_uid; 634 msqkptr->u.msg_perm.cgid = cred->cr_gid; 635 msqkptr->u.msg_perm.gid = cred->cr_gid; 636 msqkptr->u.msg_perm.mode = (msgflg & 0777); 637 msqkptr->cred = crhold(cred); --- 42 unchanged lines hidden (view full) --- 680 size_t msgsz; 681 int msgflg; 682 long mtype; 683{ 684 int msqix, segs_needed, error = 0; 685 register struct msqid_kernel *msqkptr; 686 register struct msg *msghdr; 687 short next; | 632 DPRINTF(("msqid %d is available\n", msqid)); 633 msqkptr->u.msg_perm.key = key; 634 msqkptr->u.msg_perm.cuid = cred->cr_uid; 635 msqkptr->u.msg_perm.uid = cred->cr_uid; 636 msqkptr->u.msg_perm.cgid = cred->cr_gid; 637 msqkptr->u.msg_perm.gid = cred->cr_gid; 638 msqkptr->u.msg_perm.mode = (msgflg & 0777); 639 msqkptr->cred = crhold(cred); --- 42 unchanged lines hidden (view full) --- 682 size_t msgsz; 683 int msgflg; 684 long mtype; 685{ 686 int msqix, segs_needed, error = 0; 687 register struct msqid_kernel *msqkptr; 688 register struct msg *msghdr; 689 short next; |
690#ifdef RACCT |
|
688 size_t saved_msgsz; | 691 size_t saved_msgsz; |
692#endif |
|
689 690 if (!prison_allow(td->td_ucred, PR_ALLOW_SYSVIPC)) 691 return (ENOSYS); 692 693 mtx_lock(&msq_mtx); 694 msqix = IPCID_TO_IX(msqid); 695 696 if (msqix < 0 || msqix >= msginfo.msgmni) { --- 21 unchanged lines hidden (view full) --- 718 } 719 720#ifdef MAC 721 error = mac_sysvmsq_check_msqsnd(td->td_ucred, msqkptr); 722 if (error != 0) 723 goto done2; 724#endif 725 | 693 694 if (!prison_allow(td->td_ucred, PR_ALLOW_SYSVIPC)) 695 return (ENOSYS); 696 697 mtx_lock(&msq_mtx); 698 msqix = IPCID_TO_IX(msqid); 699 700 if (msqix < 0 || msqix >= msginfo.msgmni) { --- 21 unchanged lines hidden (view full) --- 722 } 723 724#ifdef MAC 725 error = mac_sysvmsq_check_msqsnd(td->td_ucred, msqkptr); 726 if (error != 0) 727 goto done2; 728#endif 729 |
730#ifdef RACCT |
|
726 PROC_LOCK(td->td_proc); 727 if (racct_add(td->td_proc, RACCT_MSGQQUEUED, 1)) { 728 PROC_UNLOCK(td->td_proc); 729 error = EAGAIN; 730 goto done2; 731 } 732 saved_msgsz = msgsz; 733 if (racct_add(td->td_proc, RACCT_MSGQSIZE, msgsz)) { 734 racct_sub(td->td_proc, RACCT_MSGQQUEUED, 1); 735 PROC_UNLOCK(td->td_proc); 736 error = EAGAIN; 737 goto done2; 738 } 739 PROC_UNLOCK(td->td_proc); | 731 PROC_LOCK(td->td_proc); 732 if (racct_add(td->td_proc, RACCT_MSGQQUEUED, 1)) { 733 PROC_UNLOCK(td->td_proc); 734 error = EAGAIN; 735 goto done2; 736 } 737 saved_msgsz = msgsz; 738 if (racct_add(td->td_proc, RACCT_MSGQSIZE, msgsz)) { 739 racct_sub(td->td_proc, RACCT_MSGQQUEUED, 1); 740 PROC_UNLOCK(td->td_proc); 741 error = EAGAIN; 742 goto done2; 743 } 744 PROC_UNLOCK(td->td_proc); |
745#endif |
|
740 741 segs_needed = (msgsz + msginfo.msgssz - 1) / msginfo.msgssz; 742 DPRINTF(("msgsz=%zu, msgssz=%d, segs_needed=%d\n", msgsz, 743 msginfo.msgssz, segs_needed)); 744 for (;;) { 745 int need_more_resources = 0; 746 747 /* --- 238 unchanged lines hidden (view full) --- 986 msqkptr->u.msg_cbytes += msghdr->msg_ts; 987 msqkptr->u.msg_qnum++; 988 msqkptr->u.msg_lspid = td->td_proc->p_pid; 989 msqkptr->u.msg_stime = time_second; 990 991 wakeup(msqkptr); 992 td->td_retval[0] = 0; 993done3: | 746 747 segs_needed = (msgsz + msginfo.msgssz - 1) / msginfo.msgssz; 748 DPRINTF(("msgsz=%zu, msgssz=%d, segs_needed=%d\n", msgsz, 749 msginfo.msgssz, segs_needed)); 750 for (;;) { 751 int need_more_resources = 0; 752 753 /* --- 238 unchanged lines hidden (view full) --- 992 msqkptr->u.msg_cbytes += msghdr->msg_ts; 993 msqkptr->u.msg_qnum++; 994 msqkptr->u.msg_lspid = td->td_proc->p_pid; 995 msqkptr->u.msg_stime = time_second; 996 997 wakeup(msqkptr); 998 td->td_retval[0] = 0; 999done3: |
1000#ifdef RACCT |
|
994 if (error != 0) { 995 PROC_LOCK(td->td_proc); 996 racct_sub(td->td_proc, RACCT_MSGQQUEUED, 1); 997 racct_sub(td->td_proc, RACCT_MSGQSIZE, saved_msgsz); 998 PROC_UNLOCK(td->td_proc); 999 } | 1001 if (error != 0) { 1002 PROC_LOCK(td->td_proc); 1003 racct_sub(td->td_proc, RACCT_MSGQQUEUED, 1); 1004 racct_sub(td->td_proc, RACCT_MSGQSIZE, saved_msgsz); 1005 PROC_UNLOCK(td->td_proc); 1006 } |
1007#endif |
|
1000done2: 1001 mtx_unlock(&msq_mtx); 1002 return (error); 1003} 1004 1005int 1006msgsnd(td, uap) 1007 struct thread *td; --- 575 unchanged lines hidden --- | 1008done2: 1009 mtx_unlock(&msq_mtx); 1010 return (error); 1011} 1012 1013int 1014msgsnd(td, uap) 1015 struct thread *td; --- 575 unchanged lines hidden --- |