I want to make a programm in C that receive a message from messaging queue. I have the existing code here :
typedef struct {
long id;
char mes[20];
} message;
int main() {
key_t cle = ftok(".",0);
if(cle == -1){
perror("ftok");
return -1;
}
int msqId = msgget(cle, IPC_CREAT | IPC_EXCL ) ;
if (msqId == -1) {
msqId = msgget(cle, IPC_EXCL);
if (msqId == -1) {
perror("msgget");
return -1;
}
}
message mes;
while (1) {
int received = msgrcv(msqId, &mes, sizeof(message)-sizeof(long), 0, 0);
if(received == -1){
perror("msgrcv");
return -1;
}
printf ("Server: message received.\n");
}
return 0;
}
And it gives me the following error : msgrcv: Permission denied
I also tried changing the path of ftok with : "/tmp", "/etc/passwd"