Hiya-
I'm working through Chap. 12 of Matthew & Stones' "Beginning Linux
Programming", and in a sample program (msg2.c) on message queues, in the
"sender" program the following lines makes the program fail:
...
if (msgsnd(msgid, (void *)&some_data, BUFSIZ, 0) == -1) {
fprintf(stderr, "msgsnd failed\n");
exit(EXIT_FAILURE);
}
...
After a lot of back and forth, it seems to fail because of BUFSIZ. If I
arbitrarily make the first line:
if (msgsnd(msgid, (void *)&some_data, 1024, 0) == -1) {
it works.
Any hints? This is on Linux 2.0.32...
I don't know if I'm giving the right amount of info or not enough, thus
I append the whole program below.
TIA. Bob L.
--
http://www.veryComputer.com/~rm*/
---
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
struct my_msg_st {
long int my_msg_type;
char some_text[BUFSIZ];
int main()Quote:};
{
int running = 1;
struct my_msg_st some_data;
int msgid;
char buffer[BUFSIZ];
msgid = msgget((key_t)1234, 0666 | IPC_CREAT);
if (msgid == -1) {
fprintf(stderr, "msgget failed\n");
exit(EXIT_FAILURE);
}
while(running) {
printf("Enter some text: ");
fgets(buffer, BUFSIZ, stdin);
some_data.my_msg_type = 1;
strcpy(some_data.some_text, buffer);
if (msgsnd(msgid, (void *)&some_data, 1024, 0) == -1) {
/* if (msgsnd(msgid, (void *)&some_data, BUFSIZ, 0) == -1) { */
fprintf(stderr, "msgsnd failed\n");
exit(EXIT_FAILURE);
}
if (strncmp(buffer, "end", 3) == 0) {
running = 0;
}
}
exit(EXIT_SUCCESS);
------END--------Quote:}