说明:我构建了IPC kernel module
。在Ubuntu系统上,它可以将IPC数据传输到另一台运行Ubuntu的计算机。我使用模块kernel_recvmsg
和kernel_sendmsg
通过网络传输IPC数据。
问题:当我对 printk
消息发表评论时(我的printk
代码 printk("this is IPC-data");
),并使用kernel_sendmsg
将IPC数据发送到另一台计算机,发生以下情况。
kernel_sendmsg
API返回-95。
#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */
有人能告诉我发生了什么和如何调试这个?
我的环境:
Ubuntu 12.04.3 LTS
Linux ubuntu 3.9.0-030900-generic #201304291257 SMP Mon Apr 29 17:06:25 UTC
2013 i686 i686 i386 GNU/Linux
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
当前代码:
// Save get_service transaction,
// when the service is in the remote,
// send this transaction to the remote
if( target_proc->pid==smg_pid && tr->code!=3)
{
proc->temp_t.data.reply= reply;
proc->temp_t.data.ref_add= 0;
if (!IS_ALIGNED(tr->offsets_size, sizeof(size_t))) {
binder_user_error("binder: %d:%d got transaction with "
"invalid offsets size, %zd\n",
proc->pid, thread->pid, tr->offsets_size);
return_error = BR_FAILED_REPLY;
goto err_temp_copy_data_failed;
}
proc->temp_t.tr=*tr;
if (copy_from_user(tr_data, tr->data.ptr.buffer, tr->data_size)) {
binder_user_error("binder: %d:%d got transaction with invalid "
"data ptr\n", proc->pid, thread->pid);
return_error = BR_FAILED_REPLY;
goto err_temp_copy_data_failed;
}
if (copy_from_user(tr_off, tr->data.ptr.offsets, tr->offsets_size)) {
binder_user_error("binder: %d:%d got transaction with invalid "
"data ptr\n", proc->pid, thread->pid);
return_error = BR_FAILED_REPLY;
goto err_temp_copy_data_failed;
}
proc->temp_t.tr.data.ptr.buffer = tr_data;
proc->temp_t.tr.data.ptr.offsets = tr_off;
binder_debug(BINDER_DEBUG_SOCKET, "proc->temp_t set tr.data_size=%d tr.offsets_size=%d", proc->temp_t.tr.data_size,proc->temp_t.tr.offsets_size);
}
if((proc->for_ip && tr->code==3 && target_proc->pid==smg_pid)|| (target_proc->ip && proc->pid!=smg_pid))
{
binder_debug(SOCKET_DEBUG_REQ, "this is ipc data");
// sock_t=kzalloc(sizeof(*sock_t), GFP_KERNEL);
sock_t.reply= reply;
if (!IS_ALIGNED(tr->offsets_size, sizeof(size_t))) {
binder_user_error("binder: %d:%d got transaction with "
"invalid offsets size, %zd\n",
proc->pid, thread->pid, tr->offsets_size);
return_error = BR_FAILED_REPLY;
goto err_temp_copy_data_failed;
}
if(target_proc->ip)
success=send_add_t(proc,&sock_t,tr,target_proc->ip);
else
success=send_add_t(proc,&sock_t,tr,proc->for_ip);
// kfree(sock_t);
if(success<0){
return_error = BR_FAILED_REPLY;
goto err_send_remote_failed;
}
target_proc->rcomplete=1;
}
int send_add_t(struct binder_proc *proc,struct tr_ref *rref,struct binder_transaction_data *tr ,int tget_ip)
{
int count;
struct remote_tr remote_tr;
remote_tr.fops = add_t_remote;
remote_tr.pid=proc->pid;
remote_tr.rref=*rref;
remote_tr.tr=*tr;
count=send(newsock[tget_ip],&remote_tr,sizeof(remote_tr));
binder_debug(SOCKET_DEBUG_REQ, "Send tr.data_size=%d tr.offsets_size=%d count=%d", tr->data_size,tr->offsets_size,count);
count=send(newsock[tget_ip],(void *) tr->data.ptr.buffer,tr->data_size);
send(newsock[tget_ip],(void *) tr->data.ptr.offsets,tr->offsets_size);
proc->r_has=tget_ip;
// do_gettimeofday(&tv2);
// binder_debug(SOCKET_TIME,"can recv time =%ld.%ldus\n",tv2.tv_sec,tv2.tv_usec);
// binder_debug(SOCKET_TIME,"recv to send finish=%ldus",(tv2.tv_sec-tv3.tv_sec)*1000000L+tv2.tv_usec-tv3.tv_usec);
// binder_debug(SOCKET_DEBUG_REQ, "Send tr->code=%d count=%d", tr->code,count);
return count;
}
int send(struct socket* send,void* buf, int len)
{
struct msghdr msg;
struct kvec iov={
.iov_base = buf,
.iov_len = len,
};
int size = 0;
if(!send)
return 0;
size = kernel_sendmsg(send,&msg,&iov,1,len);
return size;
}
答案 0 :(得分:1)
我通过修改发送功能解决了这个问题。
struct msghdr msg = {。msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL};
int send(struct socket* send,void* buf, int len)
{
struct msghdr msg= {.msg_flags= MSG_DONTWAIT+MSG_NOSIGNAL};
struct kvec iov={
.iov_base = buf,
.iov_len = len,
};
int size = 0;
if(!send)
return 0;
size = kernel_sendmsg(send,&msg,&iov,1,len);
return size;
}