The workaround for the following problem is trivial, but I'm still curious about what's going on.
If you call msgget(2) with a positive key and a zero
when you run this shell script:
If you call msgget(2) with a positive key and a zero
msgflg
, it works as advertised. But if msgflg
is octal 0100, you get "Permission denied". No other bit in the final nine bits of the flag makes this happen. What's going on? For example, you get this (with a possibly different message ID):
Code:
ipcrm -q -1
set -e
cc -Werror -Wall 3a.c -o 3a
cc -Werror -Wall 3b.c -o 3b
cc -Werror -Wall 3c.c -o 3c
set +e
./3a
3932161
./3b
3932161
./3c
msgget: Permission denied
when you run this shell script:
Code:
#!/bin/sh
cat <<EOD > 3a.c
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdio.h>
int main(void)
{
int result=msgget(5,IPC_CREAT | 0777);
if(result==-1)
{
perror("msgget");
}
else
{
printf("%d\n",result);
}
return 0;
} /* main() */
EOD
cat <<EOD > 3b.c
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdio.h>
int main(void)
{
int result=msgget(5,0000);
if(result==-1)
{
perror("msgget");
}
else
{
printf("%d\n",result);
}
return 0;
} /* main() */
EOD
cat <<EOD > 3c.c
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdio.h>
int main(void)
{
int result=msgget(5,0100);
if(result==-1)
{
perror("msgget");
}
else
{
printf("%d\n",result);
}
return 0;
} /* main() */
EOD
set -v
ipcrm -q -1
set -e
cc -Werror -Wall 3a.c -o 3a
cc -Werror -Wall 3b.c -o 3b
cc -Werror -Wall 3c.c -o 3c
set +e
./3a
./3b
./3c