Where to initialize field of a process

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

 



I added a new field in the task_struct. This field is the head of a double
linked list (I used linux/list.h). The idea is that child has the same list
(when created) than its parent. So, I done the following:

In task_struct:

struct task_struct {
...
#ifdef CONFIG_ELSA
/* List of BANK to which the process belong - Used by ELSA */
	struct list_head bank_head;
#endif
};


To initialize this field, I added two things in kernel/fork.c:

1) in copy_process(), I added the line:

        ...
	SET_LINKS(p);
	if (p->ptrace & PT_PTRACED)
		__ptrace_link(p, current->parent);

#ifdef CONFIG_ELSA
	/* child is in the same BANK as parent */
	INIT_LIST_HEAD(&(p->bank_head));
#endif
	
	attach_pid(p, PIDTYPE_PID, p->pid);
        ...

  This function is called by do_fork to create the new process so It seems to be
the right place to initialize the field. 

2) in do_fork(), I add a call to a function that "hard copy" a list of banks
from the parent to the child. 

                ...
       		if (clone_flags & CLONE_VFORK) {
			wait_for_completion(&vfork);
			if (unlikely (current->ptrace & PT_TRACE_VFORK_DONE))
				ptrace_notify ((PTRACE_EVENT_VFORK_DONE << 8) | SIGTRAP);
		} else
			/*
			 * Let the child process run first, to avoid most of the
			 * COW overhead when the child exec()s afterwards.
			 */
			set_need_resched();

#ifdef CONFIG_ELSA
		/* child is in the same BANK as parent */
		if (p->pid != 0)
			elsa_copy_parent_bank(p);
#endif
	}
	return pid;
}

  Again it seems to be the right place. I had a test concerning the pid because
process init doesn't have parent but I don't know how this process is created (I
mean it can not be fork from its parent...). 

  I'd like to know if I add initialization in the right place? I ask that
because when I boot the modified kernel it didn't boot. I recompiled it with
additionnal debugging symbols, sysreq  and serial support for the console to see
where is the problem but after adding debugging support everything works. So
maybe there is an error that occurs under special conditions...

Thank you for your help
Guillaume    

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[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