| 642 | #endif |
| 643 | |
| 644 | int |
| 645 | sys_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]; |
nothing calls this directly
no test coverage detected