Secure OS Software for Linux
1752794 Members
6198 Online
108789 Solutions
New Discussion юеВ

How to use IPC msg Q's, msgget etc. ??

 
SOLVED
Go to solution
Kevin Swift
Occasional Contributor

How to use IPC msg Q's, msgget etc. ??

I am trying to use IPC message queues. On HPLX but they do not seem to work.

msgget seems to return a handle but if I try to use this in any way I get EACCES or EPERM.

ipcs(8) also reports nothing.

Is there some configuration I need to make to set permissions for message queues?

4 REPLIES 4
Ron Vladick
Advisor

Re: How to use IPC msg Q's, msgget etc. ??

What compartment are you in when you are trying to use msgget, msgrcv?

Are you trying to talk from Compartment to Compartment? if so what are your rules?





Kevin Swift
Occasional Contributor

Re: How to use IPC msg Q's, msgget etc. ??

Here's a bit more detail.

I have a new compartment

IPC is between processes in the same compartment.

I wrote a little test program which works fine on other linux but not on HP-LX. (attached)

Is there anything I need to configure for IPC? I found no mention in the man pages.

On other linux the test program reports:-

mid is 196613 and errno is 0
msgctl/STAT return is 0 and errno is 0
msgctl/SET return is 0 and errno is 0
msgsnd return is 0 and errno is 0


and ipcs -q reports

key msqid owner perms used-bytes messages
0x00000000 229382 omu104 660 10 1

on HP-LX I just get.
mid is 163845 and errno is 0
msgctl/STAT return is -1 and errno is 13
msgctl/SET return is -1 and errno is 1
msgsnd return is -1 and errno is 13

and ipcs never reports anything.


Thanks,


Kevin
Ron Vladick
Advisor
Solution

Re: How to use IPC msg Q's, msgget etc. ??

Kevin,

Thanks for the attacthment.

I was able to run this program successfully, here were my steps.

1) create a new compartment
/sbin/tlcompadd

2) change into this compartment
/sbin/tlsetcomp

3) no rules will be required if you stay in the same comparment.

BTW I did get the errors if I tried to run this program from the "system" compartment.

Here are my results and an strace of the success:

[tlinuxadm@viper tlinuxadm]$ /sbin/tlsetcomp msg1
sh-2.04$ ls
a.out message.c
sh-2.04$ ./a.out
mid is 294919 and errno is 0
msgctl/STAT return is 0 and errno is 0
msgctl/SET return is 0 and errno is 0
msgsnd return is 0 and errno is 0

sh-2.04$ ipcs -q
------ Message Queues --------
key msqid owner perms used-bytes messages
0x0000000c 131074 tlinuxadm 660 0 0
0x00000000 294919 104 660 10 1

sh-2.04$ strace ./a.out

execve("./a.out", ["./a.out"], [/* 24 vars */]) = 0

uname({sys="Linux",

node="viper.idev.atl.hp.com", ...}) = 0

brk(0) = 0x8049954

old_mmap(NULL, 4096, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40017000

open("/etc/ld.so.preload", O_RDONLY) = -1 ENOENT (No such file or directory)

open("/etc/ld.so.cache", O_RDONLY) = 3

fstat64(3, {st_mode=S_IFREG|0644, st_size=32402, ...}) = 0

old_mmap(NULL, 32402, PROT_READ, MAP_PRIVATE, 3, 0) = 0x40018000

close(3) = 0

open("/lib/i686/libc.so.6", O_RDONLY) = 3

read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\200\302"..., 1024) = 1024

fstat64(3, {st_mode=S_IFREG|0755,
st_size=5634864, ...}) = 0

old_mmap(NULL, 1242920, PROT_READ|PROT_EXEC,

MAP_PRIVATE, 3, 0) = 0x40020000

mprotect(0x40146000, 38696, PROT_NONE) = 0

old_mmap(0x40146000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x125000) = 0x40146000

old_mmap(0x4014c000, 14120, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x4014c000

close(3) = 0

munmap(0x40018000, 32402) = 0

getpid() = 1556

msgget(IPC_PRIVATE, 0x1b0|0660) = 327688

fstat64(1, {st_mode=S_IFCHR|0620,

st_rdev=makedev(136, 1), ...}) = 0

mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40018000

ioctl(1, TCGETS, {B38400 opost isig icanon echo ...}) = 0

write(1, "mid is 327688 and errno is 0\n", 29mid is 327688 and errno is 0
) = 29

msgctl(327688, MSG_???, 0xbffff200) = 0

write(1, "msgctl/STAT return is 0 and errn"..., 39msgctl/STAT return is 0 and errno is 0
) = 39

msgctl(327688, MSG_???, 0xbffff200) = 0

write(1, "msgctl/SET return is 0 and errno"..., 38msgctl/SET return is 0 and errno is 0
) = 38

msgsnd(327688, {1, "123456789\0"}, 10, 0) = 0

write(1, "msgsnd return is 0 and errno is "..., 34msgsnd return is 0 and errno is 0
) = 34

munmap(0x40018000, 4096) = 0
_exit(34) = ?
sh-2.04$
Kevin Swift
Occasional Contributor

Re: How to use IPC msg Q's, msgget etc. ??

Thanks for that, It seems that all my testing happend in the system compartment, clearly not a good idea!


Kevin