X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=libbb%2Ffind_pid_by_name.c;h=05f7f968f872cfb443166ea9a03bd7d8e3f49123;hb=35fb51272863c8723a40e59d2024c7f4c9ec8946;hp=966595ddb8470c4b123df5c1914017b7604de479;hpb=56b217117afe70384ea27ba9ecbe0831623e7e48;p=oweals%2Fbusybox.git diff --git a/libbb/find_pid_by_name.c b/libbb/find_pid_by_name.c index 966595ddb..05f7f968f 100644 --- a/libbb/find_pid_by_name.c +++ b/libbb/find_pid_by_name.c @@ -4,13 +4,9 @@ * * Copyright (C) 1999-2004 by Erik Andersen * - * Licensed under the GPL v2, see the file LICENSE in this tarball. + * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. */ -#include -#include -#include -#include #include "libbb.h" /* find_pid_by_name() @@ -23,31 +19,31 @@ * Returns a list of all matching PIDs * It is the caller's duty to free the returned pidlist. */ -extern long* find_pid_by_name( const char* pidName) +pid_t* find_pid_by_name(const char* procName) { - long* pidList; - int i=0; - procps_status_t * p; + pid_t* pidList; + int i = 0; + procps_status_t* p; - pidList = xmalloc(sizeof(long)); - while ((p = procps_scan(0)) != 0) - { - if (strncmp(p->short_cmd, pidName, COMM_LEN-1) == 0) { - pidList=xrealloc( pidList, sizeof(long) * (i+2)); - pidList[i++]=p->pid; + pidList = xmalloc(sizeof(*pidList)); + while ((p = procps_scan(0)) != 0) { + if (strncmp(p->short_cmd, procName, COMM_LEN-1) == 0) { + pidList = xrealloc(pidList, sizeof(*pidList) * (i+2)); + pidList[i++] = p->pid; } } - pidList[i] = i==0 ? -1 : 0; + pidList[i] = 0; return pidList; } -extern long *pidlist_reverse(long *pidList) +pid_t *pidlist_reverse(pid_t *pidList) { - int i=0; - while (pidList[i] > 0 && i++); - if ( i-- > 0) { - long k; + int i = 0; + while (pidList[i]) + i++; + if (--i >= 0) { + pid_t k; int j; for (j = 0; i > j; i--, j++) { k = pidList[i]; @@ -57,12 +53,3 @@ extern long *pidlist_reverse(long *pidList) } return pidList; } - -/* END CODE */ -/* -Local Variables: -c-file-style: "linux" -c-basic-offset: 4 -tab-width: 4 -End: -*/