aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-04-18 20:00:03 +0000
committerErik Andersen <andersen@codepoet.org>2000-04-18 20:00:03 +0000
commit0a64de9b4f7b3254008affe21b3ad4174c26f7f5 (patch)
treed1dc332e7cf63fdcc215b89044b334e17ce5abc5
parent229dd2b905e55ab486f5c77334453fdc61cda31b (diff)
downloadbusybox-w32-0a64de9b4f7b3254008affe21b3ad4174c26f7f5.tar.gz
busybox-w32-0a64de9b4f7b3254008affe21b3ad4174c26f7f5.tar.bz2
busybox-w32-0a64de9b4f7b3254008affe21b3ad4174c26f7f5.zip
More little stuff.
-Erik
-rw-r--r--Makefile2
-rw-r--r--kill.c5
-rw-r--r--procps/kill.c5
-rw-r--r--utility.c30
4 files changed, 34 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 30fd718f1..5d246f13e 100644
--- a/Makefile
+++ b/Makefile
@@ -26,7 +26,7 @@ export VERSION
26# Set the following to `true' to make a debuggable build. 26# Set the following to `true' to make a debuggable build.
27# Leave this set to `false' for production use. 27# Leave this set to `false' for production use.
28# eg: `make DODEBUG=true tests' 28# eg: `make DODEBUG=true tests'
29DODEBUG = false 29DODEBUG = true
30 30
31# If you want a static binary, turn this on. 31# If you want a static binary, turn this on.
32DOSTATIC = false 32DOSTATIC = false
diff --git a/kill.c b/kill.c
index db4842457..93f02eab4 100644
--- a/kill.c
+++ b/kill.c
@@ -222,12 +222,15 @@ extern int kill_main(int argc, char **argv)
222 } 222 }
223#ifdef BB_KILLALL 223#ifdef BB_KILLALL
224 else { 224 else {
225 pid_t myPid=getpid();
225 /* Looks like they want to do a killall. Do that */ 226 /* Looks like they want to do a killall. Do that */
226 while (--argc >= 0) { 227 while (--argc >= 0) {
227 pid_t* pidList; 228 pid_t* pidList;
228 229
229 pidList = findPidByName( *argv); 230 pidList = findPidByName( *argv);
230 for(; pidList && pidList!=0; pidList++) { 231 for(; pidList && *pidList!=0; pidList++) {
232 if (*pidList==myPid)
233 continue;
231 if (kill(*pidList, sig) != 0) 234 if (kill(*pidList, sig) != 0)
232 fatalError( "Could not kill pid '%d': %s\n", *pidList, strerror(errno)); 235 fatalError( "Could not kill pid '%d': %s\n", *pidList, strerror(errno));
233 } 236 }
diff --git a/procps/kill.c b/procps/kill.c
index db4842457..93f02eab4 100644
--- a/procps/kill.c
+++ b/procps/kill.c
@@ -222,12 +222,15 @@ extern int kill_main(int argc, char **argv)
222 } 222 }
223#ifdef BB_KILLALL 223#ifdef BB_KILLALL
224 else { 224 else {
225 pid_t myPid=getpid();
225 /* Looks like they want to do a killall. Do that */ 226 /* Looks like they want to do a killall. Do that */
226 while (--argc >= 0) { 227 while (--argc >= 0) {
227 pid_t* pidList; 228 pid_t* pidList;
228 229
229 pidList = findPidByName( *argv); 230 pidList = findPidByName( *argv);
230 for(; pidList && pidList!=0; pidList++) { 231 for(; pidList && *pidList!=0; pidList++) {
232 if (*pidList==myPid)
233 continue;
231 if (kill(*pidList, sig) != 0) 234 if (kill(*pidList, sig) != 0)
232 fatalError( "Could not kill pid '%d': %s\n", *pidList, strerror(errno)); 235 fatalError( "Could not kill pid '%d': %s\n", *pidList, strerror(errno));
233 } 236 }
diff --git a/utility.c b/utility.c
index b844c3b52..29934cdc3 100644
--- a/utility.c
+++ b/utility.c
@@ -1291,12 +1291,21 @@ extern pid_t* findPidByName( char* pidName)
1291 1291
1292 /* Now search for a match */ 1292 /* Now search for a match */
1293 for (i=1; i<pid_array[0] ; i++) { 1293 for (i=1; i<pid_array[0] ; i++) {
1294 char* p;
1294 struct pid_info info; 1295 struct pid_info info;
1295 1296
1296 info.pid = pid_array[i]; 1297 info.pid = pid_array[i];
1297 if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0) 1298 if (ioctl (fd, DEVPS_GET_PID_INFO, &info)<0)
1298 fatalError( "\nDEVPS_GET_PID_INFO: %s\n", strerror (errno)); 1299 fatalError( "\nDEVPS_GET_PID_INFO: %s\n", strerror (errno));
1299 1300
1301 /* Make sure we only match on the process name */
1302 p=info.command_line+1;
1303 while ((*p != 0) && !isspace(*(p)) && (*(p-1) != '\\')) {
1304 (p)++;
1305 }
1306 if (isspace(*(p)))
1307 *p='\0';
1308
1300 if ((strstr(info.command_line, pidName) != NULL)) { 1309 if ((strstr(info.command_line, pidName) != NULL)) {
1301 pidList=realloc( pidList, sizeof(pid_t) * (j+2)); 1310 pidList=realloc( pidList, sizeof(pid_t) * (j+2));
1302 if (pidList==NULL) 1311 if (pidList==NULL)
@@ -1304,7 +1313,8 @@ extern pid_t* findPidByName( char* pidName)
1304 pidList[j++]=info.pid; 1313 pidList[j++]=info.pid;
1305 } 1314 }
1306 } 1315 }
1307 pidList[j]=0; 1316 if (pidList)
1317 pidList[j]=0;
1308 1318
1309 /* Free memory */ 1319 /* Free memory */
1310 free( pid_array); 1320 free( pid_array);
@@ -1343,7 +1353,7 @@ extern pid_t* findPidByName( char* pidName)
1343 FILE *status; 1353 FILE *status;
1344 char filename[256]; 1354 char filename[256];
1345 char buffer[256]; 1355 char buffer[256];
1346 char* p; 1356 char* p, *q;
1347 1357
1348 /* If it isn't a number, we don't want it */ 1358 /* If it isn't a number, we don't want it */
1349 if (!isdigit(*next->d_name)) 1359 if (!isdigit(*next->d_name))
@@ -1358,15 +1368,25 @@ extern pid_t* findPidByName( char* pidName)
1358 fgets(buffer, 256, status); 1368 fgets(buffer, 256, status);
1359 fclose(status); 1369 fclose(status);
1360 1370
1361 if (((p=strstr(buffer, pidName)) != NULL) 1371 /* Make sure we only match on the process name */
1362 && (strncmp(p, pidName, strlen(pidName)) != 0)) { 1372 p=buffer+5; /* Skip the name */
1373 while ((p)++) {
1374 if (*p==0 || *p=='\n') {
1375 *p='\0';
1376 break;
1377 }
1378 }
1379 p=buffer+6; /* Skip the "Name:\t" */
1380
1381 if (((q=strstr(q, pidName)) != NULL)
1382 && (strncmp(q, pidName, strlen(pidName)) != 0)) {
1363 pidList=realloc( pidList, sizeof(pid_t) * (i+2)); 1383 pidList=realloc( pidList, sizeof(pid_t) * (i+2));
1364 if (pidList==NULL) 1384 if (pidList==NULL)
1365 fatalError("out of memory\n"); 1385 fatalError("out of memory\n");
1366 pidList[i++]=strtol(next->d_name, NULL, 0); 1386 pidList[i++]=strtol(next->d_name, NULL, 0);
1367 } 1387 }
1368 } 1388 }
1369 if (pidList!=NULL) 1389 if (pidList)
1370 pidList[i]=0; 1390 pidList[i]=0;
1371 return pidList; 1391 return pidList;
1372} 1392}