Skip to contentSkip to conversation

Q: kernel/pids.c code

DISCUSSION Kirill Korotaev 1 participant 1 message Apr 14, 2004 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Hello all,

I have two questions both concerning code located in kernel/pids.c:

1. why do we hold task.struct pid_link pids[].pid in task_struct? I looked through the code and found that such solution is ugly at least because:
- it occupies at least 7*4=28 more integers in task_struct then could be. Note that this memory is not used everytime.
- pids can held reference to task_struct thus making it's lifetime longer and less predictable. Memory consumption is unpredictable.
- the code is really unreadable and messy
Why struct pid is not allocated in kmem_cache instead?

2. function switch_exec_pids() calls _detach_pid() 6 times and attach_pid() 8 times, i.e. we put 6 references and take 8. is it bug? if so, then it looks like
pids (SID and PGID) can leak (with corresponding task_structs)?

void switch_exec_pids(task_t *leader, task_t *thread)

{
         _detach_pid(leader, PIDTYPE_PID);
         _detach_pid(leader, PIDTYPE_TGID);
         _detach_pid(leader, PIDTYPE_PGID);
         _detach_pid(leader, PIDTYPE_SID);

         _detach_pid(thread, PIDTYPE_PID);
         _detach_pid(thread, PIDTYPE_TGID);

         leader->pid = leader->tgid = thread->pid;
         thread->pid = thread->tgid;

         attach_pid(thread, PIDTYPE_PID, thread->pid);
         attach_pid(thread, PIDTYPE_TGID, thread->tgid);
         attach_pid(thread, PIDTYPE_PGID, thread->pgrp);
         attach_pid(thread, PIDTYPE_SID, thread->session);

         attach_pid(leader, PIDTYPE_PID, leader->pid);
         attach_pid(leader, PIDTYPE_TGID, leader->tgid);
         attach_pid(leader, PIDTYPE_PGID, leader->pgrp);
         attach_pid(leader, PIDTYPE_SID, leader->session);
}

Kirill