MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sys_msgget

Function sys_msgget

freebsd/kern/sysv_msg.c:644–758  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

642#endif
643
644int
645sys_msgget(struct thread *td, struct msgget_args *uap)
646{
647 int msqid, error = 0;
648 int key = uap->key;
649 int msgflg = uap->msgflg;
650 struct ucred *cred = td->td_ucred;
651 struct msqid_kernel *msqkptr = NULL;
652
653 DPRINTF(("msgget(0x%x, 0%o)\n", key, msgflg));
654
655 if (msg_find_prison(cred) == NULL)
656 return (ENOSYS);
657
658 mtx_lock(&msq_mtx);
659 if (key != IPC_PRIVATE) {
660 for (msqid = 0; msqid < msginfo.msgmni; msqid++) {
661 msqkptr = &msqids[msqid];
662 if (msqkptr->u.msg_qbytes != 0 &&
663 msqkptr->cred != NULL &&
664 msqkptr->cred->cr_prison == cred->cr_prison &&
665 msqkptr->u.msg_perm.key == key)
666 break;
667 }
668 if (msqid < msginfo.msgmni) {
669 DPRINTF(("found public key\n"));
670 if ((msgflg & IPC_CREAT) && (msgflg & IPC_EXCL)) {
671 DPRINTF(("not exclusive\n"));
672 error = EEXIST;
673 goto done2;
674 }
675 AUDIT_ARG_SVIPC_ID(IXSEQ_TO_IPCID(msqid,
676 msqkptr->u.msg_perm));
677 if ((error = ipcperm(td, &msqkptr->u.msg_perm,
678 msgflg & 0700))) {
679 DPRINTF(("requester doesn't have 0%o access\n",
680 msgflg & 0700));
681 goto done2;
682 }
683#ifdef MAC
684 error = mac_sysvmsq_check_msqget(cred, msqkptr);
685 if (error != 0)
686 goto done2;
687#endif
688 goto found;
689 }
690 }
691
692 DPRINTF(("need to allocate the msqid_ds\n"));
693 if (key == IPC_PRIVATE || (msgflg & IPC_CREAT)) {
694 for (msqid = 0; msqid < msginfo.msgmni; msqid++) {
695 /*
696 * Look for an unallocated and unlocked msqid_ds.
697 * msqid_ds's can be locked by msgsnd or msgrcv while
698 * they are copying the message in/out. We can't
699 * re-use the entry until they release it.
700 */
701 msqkptr = &msqids[msqid];

Callers

nothing calls this directly

Calls 8

msg_find_prisonFunction · 0.85
ipcpermFunction · 0.85
mac_sysvmsq_check_msqgetFunction · 0.85
mac_sysvmsq_createFunction · 0.85
mtx_lockFunction · 0.70
racct_addFunction · 0.70
crholdFunction · 0.70
mtx_unlockFunction · 0.70

Tested by

no test coverage detected