2001-03-17 04:17:14 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Utility routines.
|
|
|
|
*
|
2003-07-15 02:51:08 +05:30
|
|
|
* Copyright (C) 1999-2003 by Erik Andersen <andersen@codepoet.org>
|
2001-03-17 04:17:14 +05:30
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "libbb.h"
|
|
|
|
|
2003-08-06 13:52:10 +05:30
|
|
|
#define COMM_LEN 16 /* synchronize with size of comm in struct task_struct
|
|
|
|
in /usr/include/linux/sched.h */
|
|
|
|
|
|
|
|
|
2001-03-17 04:17:14 +05:30
|
|
|
/* find_pid_by_name()
|
|
|
|
*
|
2002-10-22 17:51:15 +05:30
|
|
|
* Modified by Vladimir Oleynik for use with libbb/procps.c
|
2001-03-17 04:17:14 +05:30
|
|
|
* This finds the pid of the specified process.
|
|
|
|
* Currently, it's implemented by rummaging through
|
|
|
|
* the proc filesystem.
|
|
|
|
*
|
|
|
|
* Returns a list of all matching PIDs
|
|
|
|
*/
|
2002-10-22 17:51:15 +05:30
|
|
|
extern long* find_pid_by_name( const char* pidName)
|
2001-03-17 04:17:14 +05:30
|
|
|
{
|
2002-10-22 17:51:15 +05:30
|
|
|
long* pidList;
|
2001-03-17 04:17:14 +05:30
|
|
|
int i=0;
|
2002-10-22 17:51:15 +05:30
|
|
|
procps_status_t * p;
|
2001-03-17 04:17:14 +05:30
|
|
|
|
2002-10-22 17:51:15 +05:30
|
|
|
pidList = xmalloc(sizeof(long));
|
2003-07-03 15:37:04 +05:30
|
|
|
#ifdef CONFIG_SELINUX
|
|
|
|
while ((p = procps_scan(0, 0, NULL)) != 0) {
|
|
|
|
#else
|
2002-10-22 17:51:15 +05:30
|
|
|
while ((p = procps_scan(0)) != 0) {
|
2003-07-03 15:37:04 +05:30
|
|
|
#endif
|
2003-08-06 13:52:10 +05:30
|
|
|
if (strncmp(p->short_cmd, pidName, COMM_LEN-1) == 0) {
|
2001-12-06 20:22:32 +05:30
|
|
|
pidList=xrealloc( pidList, sizeof(long) * (i+2));
|
2002-10-22 17:51:15 +05:30
|
|
|
pidList[i++]=p->pid;
|
2001-03-17 04:17:14 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-22 17:51:15 +05:30
|
|
|
pidList[i] = i==0 ? -1 : 0;
|
2001-03-17 04:17:14 +05:30
|
|
|
return pidList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* END CODE */
|
|
|
|
/*
|
|
|
|
Local Variables:
|
|
|
|
c-file-style: "linux"
|
|
|
|
c-basic-offset: 4
|
|
|
|
tab-width: 4
|
|
|
|
End:
|
|
|
|
*/
|