Re: 'kill' to kernel thread

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 27 Jan 2002 02:00:56 -0800
Swapnil Nagle <swaps@protonic.com> wrote:

SN> 
SN> Have a look at:
SN> http://www.scs.ch/~frey/linux/kernelthreads.html
SN> 
SN> or the oprofile.c file in OProfile source code.
SN> 

But I start the thread with kernel_thread in start_kernel: it isn't in a
module. And I have another problem also:

Here is the code:

----------------------------
int somi_recv_info_d(void *arg)
{
	struct socket *sock;
	struct sock *sk;

	mm_segment_t oldfs;
	struct msghdr msg;
	struct iovec  iov;

	struct sockaddr_in sin;
	struct somi_mig_tbl smtab;
	int ret;

	strcpy(current->comm, "SOMI_recvd");
	daemonize(); /* Set priority, grp, session, etc. so that it belongs to
family of kernel threads. */

	/* mask all signals except SIGKILL,SIGIO and SIGSTOP */
	spin_lock_irq(&current->sigmask_lock);
        siginitsetinv(&current->blocked, sigmask(SIGIO) | sigmask(SIGKILL)
| sigmask(SIGSTOP) );        recalc_sigpending(current);
	spin_unlock_irq(&current->sigmask_lock);

	if(sock_create(PF_INET, SOCK_DGRAM, IPPROTO_UDP, &sock) < 0) {
#ifdef CONFIG_SOMI_DEBUG
		printk("SOMI: Can't create socket in somi_recv_info\n");
#endif //CONFIG_SOMI_DEBUG
		return -1;
	}

	if(somi_init_socket(sock, SOMI_RECVD_PORT) < 0) {
#ifdef CONFIG_SOMI_DEBUG
		printk("SOMI: Could not bind\n");
#endif
		sock_release(sock);
		return -1;
	}

	iov.iov_len        = sizeof(struct somi_mig_tbl);
	iov.iov_base       = (char *)&smtab;

	msg.msg_name       = &sin;
	msg.msg_namelen    = sizeof(struct sockaddr_in);
	msg.msg_iov        = &iov;
	msg.msg_iovlen     = 1;
	msg.msg_control    = NULL;
	msg.msg_controllen = 0;
	msg.msg_flags      = 0; 

	while(1) {
                oldfs = get_fs(); 
		set_fs(KERNEL_DS);

                printk("SOMI: before sock_recvmsg\n");
		printk("SOMI: This was added to check what the problem with NULL
POINTERS is.\n\n");---------->	ret = sock_recvmsg(sock, &msg, sizeof(smtab), 0);
		printk("SOMI: after sock_recvmsg\n");

		if(ret != sizeof(smtab)) {
#ifdef CONFIG_SOMI_DEBUG
---------->		printk("SOMI: Invalid message from %lu:%d; recd %d
bytes\n",sin.sin_addr.s_addr, sin.sin_port, ret);#endif
						break;
                } else {
#ifdef CONFIG_SOMI_DEBUG
			printk("SOMI: Message recd from %lu:%d:\n",sin.sin_addr.s_addr,
sin.sin_port);#endif
			if(smtab.flag == 0) { // UDP
				if((sk = udp_v4_lookup(0, 0, smtab.old_ip, smtab.old_port,
0)) == NULL) {#ifdef CONFIG_SOMI_DEBUG
					printk("SOMI: sk struct not found for modification: port
value is %d", ntohs(smtab.old_port));#endif
					goto loop;
				}
				sk->somi_sport = smtab.new_port;
				if(!smtab.new_ip) {
					sk->somi_saddr = sin.sin_addr.s_addr;
				}
				else
					sk->somi_saddr = smtab.new_ip;

				printk("SOMI: set the IP:port to %lu:%d\n",
sk->somi_saddr, sk->somi_sport);			}
		} // else
	loop:
		set_fs(oldfs);
        } // while
	set_fs(oldfs);
	printk("SOMI: exiting from somi_recvd!\n");
	return 0;
----------------------------------
On entering init 6/0, when sending TERM and KILL signals to processes,
this thread receives invalid messages (size: -512 bytes). This is printed
on the terminal, and then this goes in an infinite loop. I added the
'break' later; It exits, but why should it receive any invalid message, if
the kernel gives it a SIGTERM or SIGKILL?

Also, another problem I face is: after receiving one or two messages, it
again goes in sock_recvmsg(I see the two printk'ed messages: before
sock_recvmsg and the NULL pointer one.).  The kernel then does a panic,
and value of EIP is 0. It tries to access virtual mem. locn. 0. (Shown
this place by an arrow in the code).


--- 

  - Amit
http://amitshah.nav.to/
amitshah@gmx.net
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux