More little stuff.
-Erik
This commit is contained in:
parent
229dd2b905
commit
0a64de9b4f
2
Makefile
2
Makefile
@ -26,7 +26,7 @@ export VERSION
|
|||||||
# Set the following to `true' to make a debuggable build.
|
# Set the following to `true' to make a debuggable build.
|
||||||
# Leave this set to `false' for production use.
|
# Leave this set to `false' for production use.
|
||||||
# eg: `make DODEBUG=true tests'
|
# eg: `make DODEBUG=true tests'
|
||||||
DODEBUG = false
|
DODEBUG = true
|
||||||
|
|
||||||
# If you want a static binary, turn this on.
|
# If you want a static binary, turn this on.
|
||||||
DOSTATIC = false
|
DOSTATIC = false
|
||||||
|
5
kill.c
5
kill.c
@ -222,12 +222,15 @@ extern int kill_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
#ifdef BB_KILLALL
|
#ifdef BB_KILLALL
|
||||||
else {
|
else {
|
||||||
|
pid_t myPid=getpid();
|
||||||
/* Looks like they want to do a killall. Do that */
|
/* Looks like they want to do a killall. Do that */
|
||||||
while (--argc >= 0) {
|
while (--argc >= 0) {
|
||||||
pid_t* pidList;
|
pid_t* pidList;
|
||||||
|
|
||||||
pidList = findPidByName( *argv);
|
pidList = findPidByName( *argv);
|
||||||
for(; pidList && pidList!=0; pidList++) {
|
for(; pidList && *pidList!=0; pidList++) {
|
||||||
|
if (*pidList==myPid)
|
||||||
|
continue;
|
||||||
if (kill(*pidList, sig) != 0)
|
if (kill(*pidList, sig) != 0)
|
||||||
fatalError( "Could not kill pid '%d': %s\n", *pidList, strerror(errno));
|
fatalError( "Could not kill pid '%d': %s\n", *pidList, strerror(errno));
|
||||||
}
|
}
|
||||||
|
@ -222,12 +222,15 @@ extern int kill_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
#ifdef BB_KILLALL
|
#ifdef BB_KILLALL
|
||||||
else {
|
else {
|
||||||
|
pid_t myPid=getpid();
|
||||||
/* Looks like they want to do a killall. Do that */
|
/* Looks like they want to do a killall. Do that */
|
||||||
while (--argc >= 0) {
|
while (--argc >= 0) {
|
||||||
pid_t* pidList;
|
pid_t* pidList;
|
||||||
|
|
||||||
pidList = findPidByName( *argv);
|
pidList = findPidByName( *argv);
|
||||||
for(; pidList && pidList!=0; pidList++) {
|
for(; pidList && *pidList!=0; pidList++) {
|
||||||
|
if (*pidList==myPid)
|
||||||
|
continue;
|
||||||
if (kill(*pidList, sig) != 0)
|
if (kill(*pidList, sig) != 0)
|
||||||
fatalError( "Could not kill pid '%d': %s\n", *pidList, strerror(errno));
|
fatalError( "Could not kill pid '%d': %s\n", *pidList, strerror(errno));
|
||||||
}
|
}
|
||||||
|
28
utility.c
28
utility.c
@ -1291,12 +1291,21 @@ extern pid_t* findPidByName( char* pidName)
|
|||||||
|
|
||||||
/* Now search for a match */
|
/* Now search for a match */
|
||||||
for (i=1; i<pid_array[0] ; i++) {
|
for (i=1; i<pid_array[0] ; i++) {
|
||||||
|
char* p;
|
||||||
struct pid_info info;
|
struct pid_info info;
|
||||||
|
|
||||||
info.pid = pid_array[i];
|
info.pid = pid_array[i];
|
||||||
if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
|
if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
|
||||||
fatalError( "\nDEVPS_GET_PID_INFO: %s\n", strerror (errno));
|
fatalError( "\nDEVPS_GET_PID_INFO: %s\n", strerror (errno));
|
||||||
|
|
||||||
|
/* Make sure we only match on the process name */
|
||||||
|
p=info.command_line+1;
|
||||||
|
while ((*p != 0) && !isspace(*(p)) && (*(p-1) != '\\')) {
|
||||||
|
(p)++;
|
||||||
|
}
|
||||||
|
if (isspace(*(p)))
|
||||||
|
*p='\0';
|
||||||
|
|
||||||
if ((strstr(info.command_line, pidName) != NULL)) {
|
if ((strstr(info.command_line, pidName) != NULL)) {
|
||||||
pidList=realloc( pidList, sizeof(pid_t) * (j+2));
|
pidList=realloc( pidList, sizeof(pid_t) * (j+2));
|
||||||
if (pidList==NULL)
|
if (pidList==NULL)
|
||||||
@ -1304,6 +1313,7 @@ extern pid_t* findPidByName( char* pidName)
|
|||||||
pidList[j++]=info.pid;
|
pidList[j++]=info.pid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (pidList)
|
||||||
pidList[j]=0;
|
pidList[j]=0;
|
||||||
|
|
||||||
/* Free memory */
|
/* Free memory */
|
||||||
@ -1343,7 +1353,7 @@ extern pid_t* findPidByName( char* pidName)
|
|||||||
FILE *status;
|
FILE *status;
|
||||||
char filename[256];
|
char filename[256];
|
||||||
char buffer[256];
|
char buffer[256];
|
||||||
char* p;
|
char* p, *q;
|
||||||
|
|
||||||
/* If it isn't a number, we don't want it */
|
/* If it isn't a number, we don't want it */
|
||||||
if (!isdigit(*next->d_name))
|
if (!isdigit(*next->d_name))
|
||||||
@ -1358,15 +1368,25 @@ extern pid_t* findPidByName( char* pidName)
|
|||||||
fgets(buffer, 256, status);
|
fgets(buffer, 256, status);
|
||||||
fclose(status);
|
fclose(status);
|
||||||
|
|
||||||
if (((p=strstr(buffer, pidName)) != NULL)
|
/* Make sure we only match on the process name */
|
||||||
&& (strncmp(p, pidName, strlen(pidName)) != 0)) {
|
p=buffer+5; /* Skip the name */
|
||||||
|
while ((p)++) {
|
||||||
|
if (*p==0 || *p=='\n') {
|
||||||
|
*p='\0';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
p=buffer+6; /* Skip the "Name:\t" */
|
||||||
|
|
||||||
|
if (((q=strstr(q, pidName)) != NULL)
|
||||||
|
&& (strncmp(q, pidName, strlen(pidName)) != 0)) {
|
||||||
pidList=realloc( pidList, sizeof(pid_t) * (i+2));
|
pidList=realloc( pidList, sizeof(pid_t) * (i+2));
|
||||||
if (pidList==NULL)
|
if (pidList==NULL)
|
||||||
fatalError("out of memory\n");
|
fatalError("out of memory\n");
|
||||||
pidList[i++]=strtol(next->d_name, NULL, 0);
|
pidList[i++]=strtol(next->d_name, NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pidList!=NULL)
|
if (pidList)
|
||||||
pidList[i]=0;
|
pidList[i]=0;
|
||||||
return pidList;
|
return pidList;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user