2008-03-26 10:11:27

by Midhun A

[permalink] [raw]
Subject: Userspace - Kernel Space "Connector" test

Hi All,

I want to use the Connector module (CONFIG_CONNECTOR) for Kernel
space to User space communication. My kernel version is 2.6.22.
Before using it, I am trying out the example programs in the
Documentation folder. I have cn_test.c built into the kernel (not
loaded as a module) and I have compiled ucon.c.

When I run ucon, the programs hangs at the point it polls the socket.

while (!need_exit) {

printf("Entered While\n");
pfd.events = POLLIN;
printf("1\n");
pfd.revents = 0;
printf("1.1\n");
-> switch (poll(&pfd, 1, -1)) {

The source code is the same as in the kernel/Documentation/Connector folder.

How do I get to know whether it is listening to the same socket as
cn_test is sending message on?

Thanks,
Midhun.


P.S.: I am not subscribed to the list. Please CC me.


2008-03-27 14:35:23

by Evgeniy Polyakov

[permalink] [raw]
Subject: Re: Userspace - Kernel Space "Connector" test

Hi.

On Wed, Mar 26, 2008 at 03:41:16PM +0530, Midhun A ([email protected]) wrote:
> I want to use the Connector module (CONFIG_CONNECTOR) for Kernel
> space to User space communication. My kernel version is 2.6.22.
> Before using it, I am trying out the example programs in the
> Documentation folder. I have cn_test.c built into the kernel (not
> loaded as a module) and I have compiled ucon.c.

You have to use smaller index than 32 or increase CN_NETLINK_USERS
parameter in include/linux/connector.h

Currently all kernel users fit that limitation, which is ok.

Also, parameter used in bind() is a bitmap of requested groups, to
listen on 0x123 idx you have to add it via setsockopt(), which is
commented in ucon.c.

So, either switch to smaller group number (connector index) or increase
above limit. If you will select the former case (it is simpler from
userspace point of view), you have to change bind() group, note that it
is a bitmap, os group N equals to (1<<N) bind() value. If you will
select the latter case and recompile connector module, then you have to
uncomment setsockopt() code in ucon.c

Both methods work, and you will get something like this:
$ sudo ./ucon
Thu Mar 27 17:29:19 2008 : [123.457] [00000002.00000000].
Thu Mar 27 17:29:20 2008 : [123.457] [00000003.00000000].
Thu Mar 27 17:29:21 2008 : [123.457] [00000004.00000000].
Thu Mar 27 17:29:22 2008 : [123.457] [00000005.00000000].
Thu Mar 27 17:29:23 2008 : [123.457] [00000006.00000000].

--
Evgeniy Polyakov