c - Error in msgrcv: Invalid Arguments -


I am writing a code on a UNIX system in C. I have created a message queue server every time I get a new message I The fork and baby process handles the new customer. The server waits for the new customer here is the code.

  for (;;) {struct my_msgbuf buf; If (MSGRCV (MScDID, and (BF.M.T.P.), Size (BF), 1, 0) == -1) Peer ("MSGRCV"); If ((pid = fork ()) <0) false ("fork"); If (pid == 0) {// child code}} now code works for the first time, but msgrcv returns the following error on the second visit - msgrcv: invalid instead Argument is waiting for new messages.   

MSGRCV a msgsz parameter, but it It is not the size of a struct my_msgbuf ; rather, it is the number of bytes in the mtext [] area of ​​the structure.

You are not really going to use struct msgbuf , I think it would be normal to define your own with the appropriate place. You have this method, your Buf declaration allocates only 1 byte, and then the code tells the kernel that you have sizeof buf bytes, which you do not. As a result, the code is called to call undefined behavior or UB.

This can not be understood by EINVAL , but one must always correct known bugs and retest because UB taints further analysis ...


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -