diff options
author | erik <erik@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-04-18 20:00:03 +0000 |
---|---|---|
committer | erik <erik@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-04-18 20:00:03 +0000 |
commit | 19666e3281793c285534240304639d9915819b48 (patch) | |
tree | d1dc332e7cf63fdcc215b89044b334e17ce5abc5 /utility.c | |
parent | 6bdc693ceb9670c765cc294410d845c33e256d6e (diff) | |
download | busybox-w32-19666e3281793c285534240304639d9915819b48.tar.gz busybox-w32-19666e3281793c285534240304639d9915819b48.tar.bz2 busybox-w32-19666e3281793c285534240304639d9915819b48.zip |
More little stuff.
-Erik
git-svn-id: svn://busybox.net/trunk/busybox@475 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to '')
-rw-r--r-- | utility.c | 30 |
1 files changed, 25 insertions, 5 deletions
@@ -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 | } |