sysv_msg.c (100076) | sysv_msg.c (100511) |
---|---|
1/* $FreeBSD: head/sys/kern/sysv_msg.c 100076 2002-07-15 13:17:23Z markm $ */ | 1/* $FreeBSD: head/sys/kern/sysv_msg.c 100511 2002-07-22 16:12:55Z alfred $ */ |
2 3/* 4 * Implementation of SVID messages 5 * 6 * Author: Daniel Boulet 7 * 8 * Copyright 1993 Daniel Boulet and RTMX Inc. 9 * --- 395 unchanged lines hidden (view full) --- 405 406 if (msqptr->msg_cbytes != 0) 407 panic("msg_cbytes is screwed up"); 408 if (msqptr->msg_qnum != 0) 409 panic("msg_qnum is screwed up"); 410 411 msqptr->msg_qbytes = 0; /* Mark it as free */ 412 | 2 3/* 4 * Implementation of SVID messages 5 * 6 * Author: Daniel Boulet 7 * 8 * Copyright 1993 Daniel Boulet and RTMX Inc. 9 * --- 395 unchanged lines hidden (view full) --- 405 406 if (msqptr->msg_cbytes != 0) 407 panic("msg_cbytes is screwed up"); 408 if (msqptr->msg_qnum != 0) 409 panic("msg_qnum is screwed up"); 410 411 msqptr->msg_qbytes = 0; /* Mark it as free */ 412 |
413 wakeup((caddr_t)msqptr); | 413 wakeup(msqptr); |
414 } 415 416 break; 417 418 case IPC_SET: 419 if ((error = ipcperm(td, &msqptr->msg_perm, IPC_M))) 420 goto done2; 421 if ((error = copyin(user_msqptr, &msqbuf, sizeof(msqbuf))) != 0) --- 27 unchanged lines hidden (view full) --- 449 450 case IPC_STAT: 451 if ((error = ipcperm(td, &msqptr->msg_perm, IPC_R))) { 452#ifdef MSG_DEBUG_OK 453 printf("requester doesn't have read access\n"); 454#endif 455 goto done2; 456 } | 414 } 415 416 break; 417 418 case IPC_SET: 419 if ((error = ipcperm(td, &msqptr->msg_perm, IPC_M))) 420 goto done2; 421 if ((error = copyin(user_msqptr, &msqbuf, sizeof(msqbuf))) != 0) --- 27 unchanged lines hidden (view full) --- 449 450 case IPC_STAT: 451 if ((error = ipcperm(td, &msqptr->msg_perm, IPC_R))) { 452#ifdef MSG_DEBUG_OK 453 printf("requester doesn't have read access\n"); 454#endif 455 goto done2; 456 } |
457 error = copyout((caddr_t)msqptr, user_msqptr, 458 sizeof(struct msqid_ds)); | 457 error = copyout(msqptr, user_msqptr, sizeof(struct msqid_ds)); |
459 break; 460 461 default: 462#ifdef MSG_DEBUG_OK 463 printf("invalid command %d\n", cmd); 464#endif 465 error = EINVAL; 466 goto done2; --- 261 unchanged lines hidden (view full) --- 728 printf("we own the msqid_ds\n"); 729#endif 730 msqptr->msg_perm.mode |= MSG_LOCKED; 731 we_own_it = 1; 732 } 733#ifdef MSG_DEBUG_OK 734 printf("goodnight\n"); 735#endif | 458 break; 459 460 default: 461#ifdef MSG_DEBUG_OK 462 printf("invalid command %d\n", cmd); 463#endif 464 error = EINVAL; 465 goto done2; --- 261 unchanged lines hidden (view full) --- 727 printf("we own the msqid_ds\n"); 728#endif 729 msqptr->msg_perm.mode |= MSG_LOCKED; 730 we_own_it = 1; 731 } 732#ifdef MSG_DEBUG_OK 733 printf("goodnight\n"); 734#endif |
736 error = tsleep((caddr_t)msqptr, (PZERO - 4) | PCATCH, | 735 error = tsleep(msqptr, (PZERO - 4) | PCATCH, |
737 "msgwait", 0); 738#ifdef MSG_DEBUG_OK 739 printf("good morning, error=%d\n", error); 740#endif 741 if (we_own_it) 742 msqptr->msg_perm.mode &= ~MSG_LOCKED; 743 if (error != 0) { 744#ifdef MSG_DEBUG_OK --- 85 unchanged lines hidden (view full) --- 830 831 if ((error = copyin(user_msgp, &msghdr->msg_type, 832 sizeof(msghdr->msg_type))) != 0) { 833#ifdef MSG_DEBUG_OK 834 printf("error %d copying the message type\n", error); 835#endif 836 msg_freehdr(msghdr); 837 msqptr->msg_perm.mode &= ~MSG_LOCKED; | 736 "msgwait", 0); 737#ifdef MSG_DEBUG_OK 738 printf("good morning, error=%d\n", error); 739#endif 740 if (we_own_it) 741 msqptr->msg_perm.mode &= ~MSG_LOCKED; 742 if (error != 0) { 743#ifdef MSG_DEBUG_OK --- 85 unchanged lines hidden (view full) --- 829 830 if ((error = copyin(user_msgp, &msghdr->msg_type, 831 sizeof(msghdr->msg_type))) != 0) { 832#ifdef MSG_DEBUG_OK 833 printf("error %d copying the message type\n", error); 834#endif 835 msg_freehdr(msghdr); 836 msqptr->msg_perm.mode &= ~MSG_LOCKED; |
838 wakeup((caddr_t)msqptr); | 837 wakeup(msqptr); |
839 goto done2; 840 } 841 user_msgp = (char *)user_msgp + sizeof(msghdr->msg_type); 842 843 /* 844 * Validate the message type 845 */ 846 847 if (msghdr->msg_type < 1) { 848 msg_freehdr(msghdr); 849 msqptr->msg_perm.mode &= ~MSG_LOCKED; | 838 goto done2; 839 } 840 user_msgp = (char *)user_msgp + sizeof(msghdr->msg_type); 841 842 /* 843 * Validate the message type 844 */ 845 846 if (msghdr->msg_type < 1) { 847 msg_freehdr(msghdr); 848 msqptr->msg_perm.mode &= ~MSG_LOCKED; |
850 wakeup((caddr_t)msqptr); | 849 wakeup(msqptr); |
851#ifdef MSG_DEBUG_OK 852 printf("mtype (%d) < 1\n", msghdr->msg_type); 853#endif 854 error = EINVAL; 855 goto done2; 856 } 857 858 /* --- 13 unchanged lines hidden (view full) --- 872 panic("next out of range #2"); 873 if ((error = copyin(user_msgp, &msgpool[next * msginfo.msgssz], 874 tlen)) != 0) { 875#ifdef MSG_DEBUG_OK 876 printf("error %d copying in message segment\n", error); 877#endif 878 msg_freehdr(msghdr); 879 msqptr->msg_perm.mode &= ~MSG_LOCKED; | 850#ifdef MSG_DEBUG_OK 851 printf("mtype (%d) < 1\n", msghdr->msg_type); 852#endif 853 error = EINVAL; 854 goto done2; 855 } 856 857 /* --- 13 unchanged lines hidden (view full) --- 871 panic("next out of range #2"); 872 if ((error = copyin(user_msgp, &msgpool[next * msginfo.msgssz], 873 tlen)) != 0) { 874#ifdef MSG_DEBUG_OK 875 printf("error %d copying in message segment\n", error); 876#endif 877 msg_freehdr(msghdr); 878 msqptr->msg_perm.mode &= ~MSG_LOCKED; |
880 wakeup((caddr_t)msqptr); | 879 wakeup(msqptr); |
881 goto done2; 882 } 883 msgsz -= tlen; 884 user_msgp = (char *)user_msgp + tlen; 885 next = msgmaps[next].next; 886 } 887 if (next != -1) 888 panic("didn't use all the msg segments"); --- 5 unchanged lines hidden (view full) --- 894 msqptr->msg_perm.mode &= ~MSG_LOCKED; 895 896 /* 897 * Make sure that the msqid_ds is still allocated. 898 */ 899 900 if (msqptr->msg_qbytes == 0) { 901 msg_freehdr(msghdr); | 880 goto done2; 881 } 882 msgsz -= tlen; 883 user_msgp = (char *)user_msgp + tlen; 884 next = msgmaps[next].next; 885 } 886 if (next != -1) 887 panic("didn't use all the msg segments"); --- 5 unchanged lines hidden (view full) --- 893 msqptr->msg_perm.mode &= ~MSG_LOCKED; 894 895 /* 896 * Make sure that the msqid_ds is still allocated. 897 */ 898 899 if (msqptr->msg_qbytes == 0) { 900 msg_freehdr(msghdr); |
902 wakeup((caddr_t)msqptr); | 901 wakeup(msqptr); |
903 error = EIDRM; 904 goto done2; 905 } 906 907 /* 908 * Put the message into the queue 909 */ 910 --- 6 unchanged lines hidden (view full) --- 917 } 918 msqptr->msg_last->msg_next = NULL; 919 920 msqptr->msg_cbytes += msghdr->msg_ts; 921 msqptr->msg_qnum++; 922 msqptr->msg_lspid = td->td_proc->p_pid; 923 msqptr->msg_stime = time_second; 924 | 902 error = EIDRM; 903 goto done2; 904 } 905 906 /* 907 * Put the message into the queue 908 */ 909 --- 6 unchanged lines hidden (view full) --- 916 } 917 msqptr->msg_last->msg_next = NULL; 918 919 msqptr->msg_cbytes += msghdr->msg_ts; 920 msqptr->msg_qnum++; 921 msqptr->msg_lspid = td->td_proc->p_pid; 922 msqptr->msg_stime = time_second; 923 |
925 wakeup((caddr_t)msqptr); | 924 wakeup(msqptr); |
926 td->td_retval[0] = 0; 927done2: 928 mtx_unlock(&Giant); 929 return (error); 930} 931 932#ifndef _SYS_SYSPROTO_H_ 933struct msgrcv_args { --- 171 unchanged lines hidden (view full) --- 1105 1106 /* 1107 * Wait for something to happen 1108 */ 1109 1110#ifdef MSG_DEBUG_OK 1111 printf("msgrcv: goodnight\n"); 1112#endif | 925 td->td_retval[0] = 0; 926done2: 927 mtx_unlock(&Giant); 928 return (error); 929} 930 931#ifndef _SYS_SYSPROTO_H_ 932struct msgrcv_args { --- 171 unchanged lines hidden (view full) --- 1104 1105 /* 1106 * Wait for something to happen 1107 */ 1108 1109#ifdef MSG_DEBUG_OK 1110 printf("msgrcv: goodnight\n"); 1111#endif |
1113 error = tsleep((caddr_t)msqptr, (PZERO - 4) | PCATCH, "msgwait", 1114 0); | 1112 error = tsleep(msqptr, (PZERO - 4) | PCATCH, "msgwait", 0); |
1115#ifdef MSG_DEBUG_OK 1116 printf("msgrcv: good morning (error=%d)\n", error); 1117#endif 1118 1119 if (error != 0) { 1120#ifdef MSG_DEBUG_OK 1121 printf("msgsnd: interrupted system call\n"); 1122#endif --- 38 unchanged lines hidden (view full) --- 1161#endif 1162 if (msgsz > msghdr->msg_ts) 1163 msgsz = msghdr->msg_ts; 1164 1165 /* 1166 * Return the type to the user. 1167 */ 1168 | 1113#ifdef MSG_DEBUG_OK 1114 printf("msgrcv: good morning (error=%d)\n", error); 1115#endif 1116 1117 if (error != 0) { 1118#ifdef MSG_DEBUG_OK 1119 printf("msgsnd: interrupted system call\n"); 1120#endif --- 38 unchanged lines hidden (view full) --- 1159#endif 1160 if (msgsz > msghdr->msg_ts) 1161 msgsz = msghdr->msg_ts; 1162 1163 /* 1164 * Return the type to the user. 1165 */ 1166 |
1169 error = copyout((caddr_t)&(msghdr->msg_type), user_msgp, | 1167 error = copyout(&(msghdr->msg_type), user_msgp, |
1170 sizeof(msghdr->msg_type)); 1171 if (error != 0) { 1172#ifdef MSG_DEBUG_OK 1173 printf("error (%d) copying out message type\n", error); 1174#endif 1175 msg_freehdr(msghdr); | 1168 sizeof(msghdr->msg_type)); 1169 if (error != 0) { 1170#ifdef MSG_DEBUG_OK 1171 printf("error (%d) copying out message type\n", error); 1172#endif 1173 msg_freehdr(msghdr); |
1176 wakeup((caddr_t)msqptr); | 1174 wakeup(msqptr); |
1177 goto done2; 1178 } 1179 user_msgp = (char *)user_msgp + sizeof(msghdr->msg_type); 1180 1181 /* 1182 * Return the segments to the user 1183 */ 1184 --- 4 unchanged lines hidden (view full) --- 1189 if (msgsz - len > msginfo.msgssz) 1190 tlen = msginfo.msgssz; 1191 else 1192 tlen = msgsz - len; 1193 if (next <= -1) 1194 panic("next too low #3"); 1195 if (next >= msginfo.msgseg) 1196 panic("next out of range #3"); | 1175 goto done2; 1176 } 1177 user_msgp = (char *)user_msgp + sizeof(msghdr->msg_type); 1178 1179 /* 1180 * Return the segments to the user 1181 */ 1182 --- 4 unchanged lines hidden (view full) --- 1187 if (msgsz - len > msginfo.msgssz) 1188 tlen = msginfo.msgssz; 1189 else 1190 tlen = msgsz - len; 1191 if (next <= -1) 1192 panic("next too low #3"); 1193 if (next >= msginfo.msgseg) 1194 panic("next out of range #3"); |
1197 error = copyout((caddr_t)&msgpool[next * msginfo.msgssz], | 1195 error = copyout(&msgpool[next * msginfo.msgssz], |
1198 user_msgp, tlen); 1199 if (error != 0) { 1200#ifdef MSG_DEBUG_OK 1201 printf("error (%d) copying out message segment\n", 1202 error); 1203#endif 1204 msg_freehdr(msghdr); | 1196 user_msgp, tlen); 1197 if (error != 0) { 1198#ifdef MSG_DEBUG_OK 1199 printf("error (%d) copying out message segment\n", 1200 error); 1201#endif 1202 msg_freehdr(msghdr); |
1205 wakeup((caddr_t)msqptr); | 1203 wakeup(msqptr); |
1206 goto done2; 1207 } 1208 user_msgp = (char *)user_msgp + tlen; 1209 next = msgmaps[next].next; 1210 } 1211 1212 /* 1213 * Done, return the actual number of bytes copied out. 1214 */ 1215 1216 msg_freehdr(msghdr); | 1204 goto done2; 1205 } 1206 user_msgp = (char *)user_msgp + tlen; 1207 next = msgmaps[next].next; 1208 } 1209 1210 /* 1211 * Done, return the actual number of bytes copied out. 1212 */ 1213 1214 msg_freehdr(msghdr); |
1217 wakeup((caddr_t)msqptr); | 1215 wakeup(msqptr); |
1218 td->td_retval[0] = msgsz; 1219done2: 1220 mtx_unlock(&Giant); 1221 return (error); 1222} 1223 1224static int 1225sysctl_msqids(SYSCTL_HANDLER_ARGS) --- 15 unchanged lines hidden --- | 1216 td->td_retval[0] = msgsz; 1217done2: 1218 mtx_unlock(&Giant); 1219 return (error); 1220} 1221 1222static int 1223sysctl_msqids(SYSCTL_HANDLER_ARGS) --- 15 unchanged lines hidden --- |