• Eric W. Biederman's avatar
    [PATCH] proc: refactor reading directories of tasks · 0bc58a91
    Eric W. Biederman authored
    There are a couple of problems this patch addresses.
    - /proc/<tgid>/task currently does not work correctly if you stop reading
      in the middle of a directory.
    
    - /proc/ currently requires a full pass through the task list with
      the tasklist lock held, to determine there are no more processes to read.
    
    - The hand rolled integer to string conversion does not properly running
      out of buffer space.
    
    - We seem to be batching reading of pids from the tasklist without reason,
      and complicating the logic of the code.
    
    This patch addresses that by changing how tasks are processed.  A
    first_<task_type> function is built that handles restarts, and a
    next_<task_type> function is built that just advances to the next task.
    
    first_<task_type> when it detects a restart usually uses find_task_by_pid.  If
    that doesn't work because there has been a seek on the directory, or we have
    already given a complete directory listing, it first checks the number tasks
    of that type, and only if we are under that count does it walk through all of
    the tasks to find the one we are interested in.
    
    The code that fills in the directory is simpler because there is only a single
    for loop.
    
    The hand rolled integer to string conversion is replaced by snprintf which
    should handle the the out of buffer case correctly.
    Signed-off-by: default avatarEric W. Biederman <ebiederm@xmission.com>
    Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
    0bc58a91
base.c 54.5 KB