hi, i think you misuse the kthread_run,this a macro not a function. reference the define(linux-2.6.30-rc3): /** 13 * kthread_run - create and wake a thread. 14 * @threadfn: the function to run until signal_pending(current). 15 * @data: data ptr for @threadfn. 16 * @namefmt: printf-style name for the thread. 17 * 18 * Description: Convenient wrapper for kthread_create() followed by 19 * wake_up_process(). Returns the kthread or ERR_PTR(-ENOMEM). 20 */ 21 #define kthread_run(threadfn, data, namefmt, ...) \ 22 ({ \ 23 struct task_struct *__k \ 24 = kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \ 25 if (!IS_ERR(__k)) \ 26 wake_up_process(__k); \ 27 __k; \ 28 }) BRs Lin 2009/4/27 Mark Ryden <markryde@xxxxxxxxx>: > Hello, > The following module creates a UDP kernel socket which calls sock_recvms. > after insmoding the module , > netstat -nl | grep 4000 shows that indeed a socket was created and that it > listens on port 4000. > However, after running rmmod on the module, it does **not** close the socket. > netstat -nl | grep 4000 shows that it **does** exist; the "rmmod" > itself hangs, and > there are no kernel messages. > Any ideas? > > The code of the module is below: > > static int createUdpInSocket(void) > { > int res; > struct sockaddr_in server; > int servererror; > unsigned char *buf; > printk( KERN_ERR "createUdpInSocket\n" ); > > if( sock_create( PF_INET,SOCK_DGRAM,IPPROTO_UDP,&udpInserversocket)<0 ) { > printk(KERN_ERR "server: Error creating udpserversocket.\n" ); > return -EIO; > } > server.sin_family = AF_INET; > server.sin_addr.s_addr = INADDR_ANY; > server.sin_port = htons((unsigned short)4000); > servererror = udpInserversocket->ops->bind(udpInserversocket, > (struct sockaddr *) &server, sizeof(server) ); > { > struct msghdr msg; > struct iovec iov; > mm_segment_t oldfs; > int size = 0; > int len = 160; > iov.iov_base = buf; > msg.msg_flags = 0; > msg.msg_name = &server; > msg.msg_namelen = sizeof(struct sockaddr_in); > msg.msg_control = NULL; > msg.msg_controllen = 0; > msg.msg_iov = &iov; > msg.msg_iovlen = 1; > msg.msg_control = NULL; > > oldfs = get_fs(); > set_fs(KERNEL_DS); > printk("before sock_recvmsg in %s %s\n",__FUNCTION__,__FILE__); > size = sock_recvmsg(udpInserversocket,&msg,len,msg.msg_flags); > printk("after sock_recvmsg in %s %s\n",__FUNCTION__,__FILE__); > set_fs(oldfs); > > } > } > > > static int kernThread(void *arg) > { > allow_signal(SIGKILL); > > createUdpInSocket(); > > return 0; > } > > > static int __init nic_init(void) > { > int ret; > void *kdata; > p = kthread_run(kernThread,kdata,"myKernThread"); > > return 0; > } > > ////////////////////////////////////////////////////////////////////////////// > > static void __exit nic_exit(void) > { > printk("in nic_exit\n"); > if (p) > kthread_stop(p); > > if (udpInserversocket) > sock_release(udpInserversocket); > > } > > > ////////////////////////////////////////////////////////////////////////////// > > module_init(nic_init) > module_exit(nic_exit) > > Regards, > Mark Ryden > > -- > To unsubscribe from this list: send an email with > "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx > Please read the FAQ at http://kernelnewbies.org/FAQ > > -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ