Ticket #8995: 0001-ps-fix-uid-and-gid-in-the-ps-output.patch

File 0001-ps-fix-uid-and-gid-in-the-ps-output.patch, 2.5 KB (added by Prasad, 12 years ago)
  • src/bin/ps.c

    From 1d9622648f0955eb55bd661b772ddf96fd58ff55 Mon Sep 17 00:00:00 2001
    From: Prasad Joshi <prasadjoshi.linux@gmail.com>
    Date: Mon, 17 Sep 2012 22:04:09 +0530
    Subject: [PATCH] ps: fix uid and gid in the ps output
    
    The function fill_team_info() completely ignored the user id and the
    group id of the process (fields info->uid and info->gid respectively).
    Since the info structure was zeroed earlier, the ps output showed uid
    and gid of each process equal to zero.
    
    For example:
    ~> useradd -s /bin/bash -n "Prasad Joshi" prasad
    password for user:
    repeat password:
    
    ~> su - prasad
    
    Welcome to the Haiku shell.
    
    ~> id
    uid=1000(prasad) gid=100(users) groups=100(users)
    
    ~> ps
    Team                                             Id #Threads  Gid  Uid
    ...
    ...
    /bin/bash -l                                    205        1    0    0
    /bin/bash                                       231        1    0    0
    /bin/ps                                         250        1    0    0
    
    The patch fixes the problem by properly initializing the members with
    effective uid and gid. Now the output looks like
    
    ~> ps
    /bin/bash -l                                    232        1    0    0
    /bin/bash                                       286        1  100 1000
    /bin/ps                                         397        1  100 1000
    
    Patch fixes the bug: https://dev.haiku-os.org/ticket/8995
    
    Signed-off-by: Prasad Joshi <prasadjoshi.linux@gmail.com>
    ---
     src/bin/ps.c               |    2 +-
     src/system/kernel/team.cpp |    4 ++--
     2 files changed, 3 insertions(+), 3 deletions(-)
    
    diff --git a/src/bin/ps.c b/src/bin/ps.c
    index 92416ce..bc5fb07 100644
    a b printTeamInfo(team_info *teamInfo, bool printHeader)  
    2929            "Uid");
    3030       
    3131    printf("%-50s %5ld %8ld %4d %4d\n", teamInfo->args, teamInfo->team,
    32         teamInfo->thread_count, teamInfo->uid, teamInfo->gid);
     32        teamInfo->thread_count, teamInfo->gid, teamInfo->uid);
    3333}
    3434
    3535
  • src/system/kernel/team.cpp

    diff --git a/src/system/kernel/team.cpp b/src/system/kernel/team.cpp
    index b794b07..62a3677 100644
    a b fill_team_info(Team* team, team_info* info, size_t size)  
    24942494    //info->area_count =
    24952495    info->debugger_nub_thread = team->debug_info.nub_thread;
    24962496    info->debugger_nub_port = team->debug_info.nub_port;
    2497     //info->uid =
    2498     //info->gid =
     2497    info->uid = team->effective_uid;
     2498    info->gid = team->effective_gid;
    24992499
    25002500    strlcpy(info->args, team->Args(), sizeof(info->args));
    25012501    info->argc = 1;