aboutsummaryrefslogtreecommitdiff
path: root/libbb/find_pid_by_name.c
diff options
context:
space:
mode:
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2005-10-06 12:10:48 +0000
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2005-10-06 12:10:48 +0000
commit56b217117afe70384ea27ba9ecbe0831623e7e48 (patch)
treed963d3fc50c71d20964db43601029d2aec0c47ac /libbb/find_pid_by_name.c
parent14b1c1da9ad7b5078086f821496b828cfd55c06d (diff)
downloadbusybox-w32-56b217117afe70384ea27ba9ecbe0831623e7e48.tar.gz
busybox-w32-56b217117afe70384ea27ba9ecbe0831623e7e48.tar.bz2
busybox-w32-56b217117afe70384ea27ba9ecbe0831623e7e48.zip
- add llist_free_one() and llist_free() to libbb; Add a bit of documentation.
- change llist_add_to_end as proposed by vodz in http://busybox.net/lists/busybox/2005-September/016411.html - remove unneeded includes, add short boilerplate and copyright to llist.c - move COMM_LEN from find_pid_by_name to libbb.h and use it in procps_status_t - add reverse_pidlist() to find_pid_by_name. Will be needed for pidof.
Diffstat (limited to 'libbb/find_pid_by_name.c')
-rw-r--r--libbb/find_pid_by_name.c37
1 files changed, 19 insertions, 18 deletions
diff --git a/libbb/find_pid_by_name.c b/libbb/find_pid_by_name.c
index 570e7bd93..966595ddb 100644
--- a/libbb/find_pid_by_name.c
+++ b/libbb/find_pid_by_name.c
@@ -4,19 +4,7 @@
4 * 4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org> 5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * Licensed under the GPL v2, see the file LICENSE in this tarball.
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */ 8 */
21 9
22#include <stdio.h> 10#include <stdio.h>
@@ -25,10 +13,6 @@
25#include <stdlib.h> 13#include <stdlib.h>
26#include "libbb.h" 14#include "libbb.h"
27 15
28#define COMM_LEN 16 /* synchronize with size of comm in struct task_struct
29 in /usr/include/linux/sched.h */
30
31
32/* find_pid_by_name() 16/* find_pid_by_name()
33 * 17 *
34 * Modified by Vladimir Oleynik for use with libbb/procps.c 18 * Modified by Vladimir Oleynik for use with libbb/procps.c
@@ -37,6 +21,7 @@
37 * the proc filesystem. 21 * the proc filesystem.
38 * 22 *
39 * Returns a list of all matching PIDs 23 * Returns a list of all matching PIDs
24 * It is the caller's duty to free the returned pidlist.
40 */ 25 */
41extern long* find_pid_by_name( const char* pidName) 26extern long* find_pid_by_name( const char* pidName)
42{ 27{
@@ -45,7 +30,7 @@ extern long* find_pid_by_name( const char* pidName)
45 procps_status_t * p; 30 procps_status_t * p;
46 31
47 pidList = xmalloc(sizeof(long)); 32 pidList = xmalloc(sizeof(long));
48 while ((p = procps_scan(0)) != 0) 33 while ((p = procps_scan(0)) != 0)
49 { 34 {
50 if (strncmp(p->short_cmd, pidName, COMM_LEN-1) == 0) { 35 if (strncmp(p->short_cmd, pidName, COMM_LEN-1) == 0) {
51 pidList=xrealloc( pidList, sizeof(long) * (i+2)); 36 pidList=xrealloc( pidList, sizeof(long) * (i+2));
@@ -57,6 +42,22 @@ extern long* find_pid_by_name( const char* pidName)
57 return pidList; 42 return pidList;
58} 43}
59 44
45extern long *pidlist_reverse(long *pidList)
46{
47 int i=0;
48 while (pidList[i] > 0 && i++);
49 if ( i-- > 0) {
50 long k;
51 int j;
52 for (j = 0; i > j; i--, j++) {
53 k = pidList[i];
54 pidList[i] = pidList[j];
55 pidList[j] = k;
56 }
57 }
58 return pidList;
59}
60
60/* END CODE */ 61/* END CODE */
61/* 62/*
62Local Variables: 63Local Variables: