Ignore:
Timestamp:
Feb 25, 2011, 9:26:54 PM (13 years ago)
Author:
Bruno Cornec
Message:
  • Update mindi-busybox to 1.18.3 to avoid problems with the tar command which is now failing on recent versions with busybox 1.7.3
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mindi-busybox/libbb/find_pid_by_name.c

    r1765 r2725  
    55 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
    66 *
    7  * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
     7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
    88 */
    99
     
    3939*/
    4040
    41 /* find_pid_by_name()
     41static int comm_match(procps_status_t *p, const char *procName)
     42{
     43    int argv1idx;
     44    const char *argv1;
     45
     46    if (strncmp(p->comm, procName, 15) != 0)
     47        return 0; /* comm does not match */
     48
     49    /* In Linux, if comm is 15 chars, it is truncated.
     50     * (or maybe the name was exactly 15 chars, but there is
     51     * no way to know that) */
     52    if (p->comm[14] == '\0')
     53        return 1; /* comm is not truncated - matches */
     54
     55    /* comm is truncated, but first 15 chars match.
     56     * This can be crazily_long_script_name.sh!
     57     * The telltale sign is basename(argv[1]) == procName */
     58
     59    if (!p->argv0)
     60        return 0;
     61
     62    argv1idx = strlen(p->argv0) + 1;
     63    if (argv1idx >= p->argv_len)
     64        return 0;
     65    argv1 = p->argv0 + argv1idx;
     66
     67    if (strcmp(bb_basename(argv1), procName) != 0)
     68        return 0;
     69
     70    return 1;
     71}
     72
     73/* This finds the pid of the specified process.
     74 * Currently, it's implemented by rummaging through
     75 * the proc filesystem.
    4276 *
    43  *  Modified by Vladimir Oleynik for use with libbb/procps.c
    44  *  This finds the pid of the specified process.
    45  *  Currently, it's implemented by rummaging through
    46  *  the proc filesystem.
     77 * Returns a list of all matching PIDs
     78 * It is the caller's duty to free the returned pidlist.
    4779 *
    48  *  Returns a list of all matching PIDs
    49  *  It is the caller's duty to free the returned pidlist.
     80 * Modified by Vladimir Oleynik for use with libbb/procps.c
    5081 */
    51 pid_t* find_pid_by_name(const char* procName)
     82pid_t* FAST_FUNC find_pid_by_name(const char *procName)
    5283{
    5384    pid_t* pidList;
     
    5586    procps_status_t* p = NULL;
    5687
    57     pidList = xmalloc(sizeof(*pidList));
    58     while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_COMM|PSSCAN_ARGV0))) {
    59         if (
    60         /* we require comm to match and to not be truncated */
    61         /* in Linux, if comm is 15 chars, it may be a truncated
    62          * name, so we don't allow that to match */
    63             (!p->comm[sizeof(p->comm)-2] && strcmp(p->comm, procName) == 0)
     88    pidList = xzalloc(sizeof(*pidList));
     89    while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_COMM|PSSCAN_ARGVN|PSSCAN_EXE))) {
     90        if (comm_match(p, procName)
    6491        /* or we require argv0 to match (essential for matching reexeced /proc/self/exe)*/
    6592         || (p->argv0 && strcmp(bb_basename(p->argv0), procName) == 0)
    66         /* TOOD: we can also try exe, do we want that? */
     93        /* or we require /proc/PID/exe link to match */
     94         || (p->exe && strcmp(bb_basename(p->exe), procName) == 0)
    6795        ) {
    68             pidList = xrealloc(pidList, sizeof(*pidList) * (i+2));
     96            pidList = xrealloc_vector(pidList, 2, i);
    6997            pidList[i++] = p->pid;
    7098        }
     
    75103}
    76104
    77 pid_t *pidlist_reverse(pid_t *pidList)
     105pid_t* FAST_FUNC pidlist_reverse(pid_t *pidList)
    78106{
    79107    int i = 0;
Note: See TracChangeset for help on using the changeset viewer.