Enabling message queue in 2.6.10 kernel

From: Chinmaya Mishra
Date: Fri Jul 07 2006 - 05:56:38 EST


Hi All,
I am trying for message queue in linux-2.6.10 kernel.
I export sys_msgget(), sys_msgctl(), sys_msgsnd() and sys_msgrcv() in
the kernel with following EXPORT_SYMBOL(sys_msgget) and so on.
Then compile the kernel, boot with the new image.

My code is like this.
#include <linux/module.h>
#include <linux/kernel.h>

#include <linux/types.h>
#include <linux/ipc.h>
#include <linux/msg.h>
#include <linux/syscalls.h>

#include <asm/system.h>

int msqid, ret;
/* this is the thread function that we are executing */
void mymsgSend(void)
{
struct msgbuf sbuf;
printk("Start send message \n");
memset(&sbuf, '\0', sizeof(sbuf));
if((msqid = sys_msgget((key_t)1234, 0666 | IPC_CREAT )) < 0) {
printk("Err: sys_msgget \n");
return ;
}
sbuf.mtype = 1;
//sprintf(sbuf.mtext,"a");
ret = sys_msgsnd(msqid, &sbuf, sizeof(sbuf), IPC_NOWAIT);
printk("Send ret = %d \n", ret);
if (ret < 0) {
printk("Err: sys_msgsnd \n");
return ;
}
return ;
}

void mymsgRecv(void)
{
int msqid;
struct msgbuf rbuf;
printk("Start recv message \n");
memset(&rbuf, '\0', sizeof(rbuf));
if ((msqid = sys_msgget((key_t)1234, 0666)) < 0) {
printk("Err: sys_msgget \n");
return ;
}
rbuf.mtype = 1;
ret = sys_msgrcv(msqid, (struct msgbuf *)&rbuf, sizeof(rbuf), rbuf.mtype, IPC_NOWAIT);
printk("Recv ret = %d \n", ret);
if (ret < 0) {
printk("Err: sys_msgrcv \n");
return ;
}
printk("Mesg Recv = %s \n", rbuf.mtext);
return;
}

/* load the module */
int init_module(void)
{
mymsgSend();
msleep(1000);
mymsgRecv();
}
return(0);
}

/* remove the module */
void cleanup_module(void)
{
printk("Stop Kernel Thread \n");
sys_msgctl(msqid, IPC_RMID, NULL);
return;
}


But the out put messages in # dmesg <enter> is like this

Start send message
Send ret = -14
Err: sys_msgsnd
Start recv message
Recv ret = -42
Err: sys_msgrcv
Stop Kernel Thread

Is there any thing I am missing. Please help soon.


With Regards,
Chinmaya.
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/