1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
|
/*
* dproc.c -- Darwin process access functions for libproc-based lsof
*/
/*
* Portions Copyright 2005-2007 Apple Inc. All rights reserved.
*
* Copyright 2005 Purdue Research Foundation, West Lafayette, Indiana
* 47907. All rights reserved.
*
* Written by Allan Nathanson, Apple Inc., and Victor A. Abell, Purdue
* University.
*
* This software is not subject to any license of the American Telephone
* and Telegraph Company or the Regents of the University of California.
*
* Permission is granted to anyone to use this software for any purpose on
* any computer system, and to alter it and redistribute it freely, subject
* to the following restrictions:
*
* 1. Neither the authors, nor Apple Inc. nor Purdue University are
* responsible for any consequences of the use of this software.
*
* 2. The origin of this software must not be misrepresented, either
* by explicit claim or by omission. Credit to the authors, Apple
* Inc. and Purdue University must appear in documentation and sources.
* and sources.
*
* 3. Altered versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 4. This notice may not be removed or altered.
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright 2005-2007 Apple Inc. and Purdue Research Foundation.\nAll rights reserved.\n";
static char *rcsid = "$Id: dproc.c,v 1.8 2012/04/10 16:41:04 abe Exp $";
#endif
#include "lsof.h"
/*
* Local definitions
*/
#define PIDS_INCR (sizeof(int) * 32) /* PID space increment */
#define VIPS_INCR 16 /* Vips space increment */
#if DARWINV>=900
#define THREADS_INCR (sizeof(uint64_t) * 32) /* Threads space increment */
#endif /* DARWINV>=900 */
#ifdef PROC_PIDLISTFILEPORTS
#define FILEPORTS_INCR (sizeof(struct proc_fileportinfo) * 32) /* Fileports space increment */
#endif /* PROC_PIDLISTFILEPORTS */
/*
* Local static variables
*/
static struct proc_fdinfo *Fds = (struct proc_fdinfo *)NULL;
/* FD buffer */
static int NbPids = 0; /* bytes allocated to Pids */
static int NbFds = 0; /* bytes allocated to FDs */
static int *Pids = (int *)NULL; /* PID buffer */
#if DARWINV>=900
static int NbThreads = 0; /* Threads bytes allocated */
static uint64_t *Threads = (uint64_t *)NULL; /* Thread buffer */
#endif /* DARWINV>=900 */
#ifdef PROC_PIDLISTFILEPORTS
static struct proc_fileportinfo *Fps = (struct proc_fileportinfo *)NULL;
/* fileport buffer */
static int NbFps = 0; /* bytes allocated to fileports */
#endif /* PROC_PIDLISTFILEPORTS */
/*
* Local structure definitions
*/
static struct vips_info {
dev_t dev;
ino_t ino;
} *Vips = (struct vips_info *)NULL; /* recorded vnodes */
static int NbVips = 0; /* bytes allocated to Vips */
static int NVips = 0; /* entries allocated to Vips */
/*
* Local function prototypes
*/
_PROTOTYPE(static void enter_vn_text,(struct vnode_info_path *vip, int *n));
_PROTOTYPE(static void process_fds,(int pid, uint32_t n, int ckscko));
_PROTOTYPE(static void process_text,(int pid));
#if DARWINV>=900
_PROTOTYPE(static void process_threads,(int pid, uint32_t n));
#endif /* DARWINV>=900 */
#ifdef PROC_PIDLISTFILEPORTS
_PROTOTYPE(static void process_fileports,(int pid, int ckscko));
#endif /* PROC_PIDLISTFILEPORTS */
/*
* enter_vn_text() -- enter vnode information text reference
*/
static void
enter_vn_text(vip, n)
struct vnode_info_path *vip; /* vnode info */
int *n; /* number of vips[] entries in use */
{
int i;
/*
* Ignore the request if the vnode information has already been entered.
*/
for (i = 0; i < *n; i++) {
if ((vip->vip_vi.vi_stat.vst_dev == Vips[i].dev)
&& (vip->vip_vi.vi_stat.vst_ino == Vips[i].ino))
{
return;
}
}
/*
* Save the text file information.
*/
alloc_lfile(" txt", -1);
Cfp = (struct file *)NULL;
(void) enter_vnode_info(vip);
if (Lf->sf)
link_lfile();
/*
* Record the entry of the vnode information.
*/
if (i >= NVips) {
/*
* Allocate space for recording the vnode information.
*/
NVips += VIPS_INCR;
NbVips += (int)(VIPS_INCR * sizeof(struct vips_info));
if (!Vips)
Vips = (struct vips_info *)malloc((MALLOC_S)NbVips);
else
Vips = (struct vips_info *)realloc((MALLOC_P *)Vips,
(MALLOC_S)NbVips);
if (!Vips) {
(void) fprintf(stderr, "%s: PID %d: no text recording space\n",
Pn, Lp->pid);
Exit(1);
}
}
/*
* Record the vnode information.
*/
Vips[*n].dev = vip->vip_vi.vi_stat.vst_dev;
Vips[*n].ino = vip->vip_vi.vi_stat.vst_ino;
(*n)++;
}
/*
* gather_proc_info() -- gather process information
*/
void
gather_proc_info()
{
short cckreg; /* conditional status of regular file
* checking:
* 0 = unconditionally check
* 1 = conditionally check */
short ckscko; /* socket file only checking status:
* 0 = none
* 1 = check only socket files,
* including TCP and UDP
* streams with eXPORT data,
* where supported */
int cre, cres, ef, i, nb, np, pid;
short pss, sf;
struct proc_taskallinfo tai;
struct proc_vnodepathinfo vpi;
/*
* Define socket and regular file conditional processing flags.
*
* If only socket files have been selected, or socket files have been
* selected, ANDed with other selection options, enable the skipping of
* regular files.
*
* If socket files and some process options have been selected, enable
* conditional skipping of regular file; i.e., regular files will be skipped
* unless they belong to a process selected by one of the specified options.
*/
if (Selflags & SELNW) {
/*
* Some network files selection options have been specified.
*/
if (Fand || !(Selflags & ~SELNW)) {
/*
* Selection ANDing or only network file options have been
* specified, so set unconditional skipping of regular files
* and socket file only checking.
*/
cckreg = 0;
ckscko = 1;
} else {
/*
* If ORed file selection options have been specified, or no
* ORed process selection options have been specified, enable
* unconditional file checking and clear socket file only
* checking.
*
* If only ORed process selection options have been specified,
* enable conditional file skipping and socket file only checking.
*/
if ((Selflags & SELFILE) || !(Selflags & SELPROC))
cckreg = ckscko = 0;
else
cckreg = ckscko = 1;
}
} else {
/*
* No network file selection options were specified. Enable
* unconditional file checking and clear socket file only checking.
*/
cckreg = ckscko = 0;
}
/*
* Determine how many bytes are needed to contain the PIDs on the system;
* make sure sufficient buffer space is allocated to hold them (and a few
* extra); then read the list of PIDs.
*/
if ((nb = proc_listpids(PROC_ALL_PIDS, 0, NULL, 0)) <= 0) {
(void) fprintf(stderr, "%s: can't get PID byte count: %s\n",
Pn, strerror(errno));
Exit(1);
}
if (nb > NbPids) {
while (nb > NbPids) {
NbPids += PIDS_INCR;
}
if (!Pids)
Pids = (int *)malloc((MALLOC_S)NbPids);
else
Pids = (int *)realloc((MALLOC_P *)Pids, (MALLOC_S)NbPids);
if (!Pids) {
(void) fprintf(stderr,
"%s: can't allocate space for %d PIDs\n", Pn,
(int)(NbPids / sizeof(int *)));
Exit(1);
}
}
/*
* Get the list of PIDs.
*/
for (ef = 0; !ef;) {
if ((nb = proc_listpids(PROC_ALL_PIDS, 0, Pids, NbPids)) <= 0) {
(void) fprintf(stderr, "%s: can't get list of PIDs: %s\n",
Pn, strerror(errno));
Exit(1);
}
if ((nb + sizeof(int)) < NbPids) {
/*
* There is room in the buffer for at least one more PID.
*/
np = nb / sizeof(int);
ef = 1;
} else {
/*
* The PID buffer must be enlarged.
*/
NbPids += PIDS_INCR;
Pids = (int *)realloc((MALLOC_P *)Pids, (MALLOC_S)NbPids);
if (!Pids) {
(void) fprintf(stderr,
"%s: can't allocate space for %d PIDs\n", Pn,
(int)(NbPids / sizeof(int *)));
Exit(1);
}
}
}
/*
* Loop through the identified processes.
*/
for (i = 0; i < np; i++) {
if (!(pid = Pids[i]))
continue;
nb = proc_pidinfo(pid, PROC_PIDTASKALLINFO, 0, &tai, sizeof(tai));
if (nb <= 0) {
if ((errno == EPERM) || (errno == ESRCH))
continue;
if (!Fwarn) {
(void) fprintf(stderr, "%s: PID %d information error: %s\n",
Pn, pid, strerror(errno));
}
continue;
} else if (nb < sizeof(tai)) {
(void) fprintf(stderr,
"%s: PID %d: proc_pidinfo(PROC_PIDTASKALLINFO);\n",
Pn, pid);
(void) fprintf(stderr,
" too few bytes; expected %ld, got %d\n",
sizeof(tai), nb);
Exit(1);
}
/*
* Check for process or command exclusion.
*/
if (is_proc_excl((int)pid, (int)tai.pbsd.pbi_rgid,
(UID_ARG)tai.pbsd.pbi_uid, &pss, &sf))
{
continue;
}
tai.pbsd.pbi_comm[sizeof(tai.pbsd.pbi_comm) - 1] = '\0';
if (is_cmd_excl(tai.pbsd.pbi_comm, &pss, &sf))
continue;
if (tai.pbsd.pbi_name[0]) {
tai.pbsd.pbi_name[sizeof(tai.pbsd.pbi_name) - 1] = '\0';
if (is_cmd_excl(tai.pbsd.pbi_name, &pss, &sf))
continue;
}
if (cckreg) {
/*
* If conditional checking of regular files is enabled, enable
* socket file only checking, based on the process' selection
* status.
*/
ckscko = (sf & SELPROC) ? 0 : 1;
}
/*
* Get root and current directory information.
*/
if (!ckscko) {
nb = proc_pidinfo(pid, PROC_PIDVNODEPATHINFO, 0, &vpi,
sizeof(vpi));
if (nb <= 0) {
cre = errno;
cres = 1;
} else if (nb < sizeof(vpi)) {
(void) fprintf(stderr,
"%s: PID %d: proc_pidinfo(PROC_PIDVNODEPATHINFO);\n",
Pn, pid);
(void) fprintf(stderr,
" too few bytes; expected %ld, got %d\n",
sizeof(vpi), nb);
Exit(1);
} else
cres = 0;
}
/*
* Allocate local process space.
*/
alloc_lproc((int)pid, (int)tai.pbsd.pbi_rgid,
(int)tai.pbsd.pbi_ppid, (UID_ARG)tai.pbsd.pbi_uid,
(tai.pbsd.pbi_name[0] != '\0') ? tai.pbsd.pbi_name
: tai.pbsd.pbi_comm,
(int)pss, (int)sf);
Plf = (struct lfile *)NULL;
/*
* Save current working directory information.
*/
if (!ckscko) {
if (cres || vpi.pvi_cdir.vip_path[0]) {
alloc_lfile(CWD, -1);
Cfp = (struct file *)NULL;
if (cres) {
/*
* If the CWD|RTD information access error is ESRCH,
* ignore it; otherwise report the error's message in the
* CWD's NAME column.
*/
if (cre != ESRCH) {
(void) snpf(Namech, Namechl, "%s|%s info error: %s",
CWD + 1, RTD + 1, strerror(cre));
Namech[Namechl - 1] = '\0';
enter_nm(Namech);
if (Lf->sf)
link_lfile();
}
} else {
(void) enter_vnode_info(&vpi.pvi_cdir);
if (Lf->sf)
link_lfile();
}
}
}
/*
* Save root directory information.
*/
if (!ckscko) {
if (!cres && vpi.pvi_rdir.vip_path[0]) {
alloc_lfile(RTD, -1);
Cfp = (struct file *)NULL;
(void) enter_vnode_info(&vpi.pvi_rdir);
if (Lf->sf)
link_lfile();
}
}
#if DARWINV>=900
/*
* Check for per-thread current working directories
*/
if (!ckscko) {
if (tai.pbsd.pbi_flags & PROC_FLAG_THCWD) {
(void) process_threads(pid, tai.ptinfo.pti_threadnum);
}
}
#endif /* DARWINV>=900 */
/*
* Print text file information.
*/
if (!ckscko)
(void) process_text(pid);
#ifdef PROC_PIDLISTFILEPORTS
/*
* Loop through the fileports
*/
(void) process_fileports(pid, ckscko);
#endif /* PROC_PIDLISTFILEPORTS */
/*
* Loop through the file descriptors.
*/
(void) process_fds(pid, tai.pbsd.pbi_nfiles, ckscko);
/*
* Examine results.
*/
if (examine_lproc())
return;
}
}
/*
* initialize() -- perform all initialization
*/
void
initialize()
{
}
/*
* process_fds() -- process file descriptors
*/
static void
process_fds(pid, n, ckscko)
int pid; /* PID of interest */
uint32_t n; /* max FDs */
int ckscko; /* check socket files only */
{
int i, isock, nb, nf;
struct proc_fdinfo *fdp;
/*
* Make sure an FD buffer has been allocated.
*/
if (!Fds) {
NbFds = sizeof(struct proc_fdinfo) * n;
Fds = (struct proc_fdinfo *)malloc((MALLOC_S)NbFds);
} else if (NbFds < sizeof(struct proc_fdinfo) * n) {
/*
* More proc_fdinfo space is required. Allocate it.
*/
NbFds = sizeof(struct proc_fdinfo) * n;
Fds = (struct proc_fdinfo *)realloc((MALLOC_P *)Fds,
(MALLOC_S)NbFds);
}
if (!Fds) {
(void) fprintf(stderr,
"%s: PID %d: can't allocate space for %d FDs\n",
Pn, pid, (int)(NbFds / sizeof(struct proc_fdinfo)));
Exit(1);
}
/*
* Get FD information for the process.
*/
nb = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, Fds, NbFds);
if (nb <= 0) {
if (errno == ESRCH) {
/*
* Quit if no FD information is available for the process.
*/
return;
}
/*
* Make a dummy file entry with an error message in its NAME column.
*/
alloc_lfile(" err", -1);
(void) snpf(Namech, Namechl, "FD info error: %s", strerror(errno));
Namech[Namechl - 1] = '\0';
enter_nm(Namech);
if (Lf->sf)
link_lfile();
return;
}
nf = (int)(nb / sizeof(struct proc_fdinfo));
/*
* Loop through the file descriptors.
*/
for (i = 0; i < nf; i++) {
fdp = &Fds[i];
alloc_lfile(NULL, (int)fdp->proc_fd);
/*
* Process the file by its type.
*/
isock = 0;
switch (fdp->proc_fdtype) {
case PROX_FDTYPE_ATALK:
if (!ckscko)
(void) process_atalk(pid, fdp->proc_fd);
break;
case PROX_FDTYPE_FSEVENTS:
if (!ckscko)
(void) process_fsevents(pid, fdp->proc_fd);
break;
case PROX_FDTYPE_KQUEUE:
if (!ckscko)
(void) process_kqueue(pid, fdp->proc_fd);
break;
case PROX_FDTYPE_PIPE:
if (!ckscko)
(void) process_pipe(pid, fdp->proc_fd);
break;
case PROX_FDTYPE_PSEM:
if (!ckscko)
(void) process_psem(pid, fdp->proc_fd);
break;
case PROX_FDTYPE_SOCKET:
(void) process_socket(pid, fdp->proc_fd);
isock = 1;
break;
case PROX_FDTYPE_PSHM:
(void) process_pshm(pid, fdp->proc_fd);
break;
case PROX_FDTYPE_VNODE:
(void) process_vnode(pid, fdp->proc_fd);
break;
default:
(void) snpf(Namech, Namechl - 1, "unknown file type: %d",
fdp->proc_fdtype);
Namech[Namechl - 1] = '\0';
(void) enter_nm(Namech);
break;
}
if (Lf->sf) {
if (!ckscko || isock)
link_lfile();
}
}
}
#ifdef PROC_PIDLISTFILEPORTS
/*
* process_fileports() -- process fileports
*/
static void
process_fileports(pid, ckscko)
int pid; /* PID of interest */
int ckscko; /* check socket files only */
{
int ef, i, isock, nb = 0, nf;
struct proc_fileportinfo *fpi;
/*
* Get fileport information for the process.
*/
for (ef = 0; !ef;) {
nb = proc_pidinfo(pid, PROC_PIDLISTFILEPORTS, 0, Fps, NbFps);
if (nb == 0) {
/*
* Quit if no fileport information
*/
return;
} else if (nb < 0) {
if (errno == ESRCH) {
/*
* Quit if no fileport information is available for the process.
*/
return;
}
/*
* Make a dummy file entry with an error message in its NAME column.
*/
alloc_lfile(" err", -1);
(void) snpf(Namech, Namechl, "FILEPORT info error: %s", strerror(errno));
Namech[Namechl - 1] = '\0';
enter_nm(Namech);
if (Lf->sf)
link_lfile();
}
if ((nb + sizeof(struct proc_fileportinfo)) < NbFps) {
/*
* There is room in the buffer for at least one more fileport.
*/
ef = 1;
} else {
if (Fps && ((nb = proc_pidinfo(pid, PROC_PIDLISTFILEPORTS, 0, NULL, 0)) <= 0)) {
(void) fprintf(stderr, "%s: can't get fileport byte count: %s\n",
Pn, strerror(errno));
Exit(1);
}
/*
* The fileport buffer must be enlarged.
*/
while (nb > NbFps) {
NbFps += FILEPORTS_INCR;
}
if (!Fps)
Fps = (struct proc_fileportinfo *)malloc((MALLOC_S)NbFps);
else
Fps = (struct proc_fileportinfo *)realloc((MALLOC_P *)Fps, (MALLOC_S)NbFps);
}
}
/*
* Loop through the fileports.
*/
nf = (int)(nb / sizeof(struct proc_fileportinfo));
for (i = 0; i < nf; i++) {
fpi = &Fps[i];
/*
* fileport reported as "fp." with "(fileport=0xXXXX)" in the Name column
*/
alloc_lfile(" fp.", -1);
Lf->fileport = fpi->proc_fileport;
/*
* Process the file by its type.
*/
isock = 0;
switch (fpi->proc_fdtype) {
case PROX_FDTYPE_PIPE:
if (!ckscko)
(void) process_fileport_pipe(pid, fpi->proc_fileport);
break;
case PROX_FDTYPE_SOCKET:
(void) process_fileport_socket(pid, fpi->proc_fileport);
isock = 1;
break;
case PROX_FDTYPE_PSHM:
(void) process_fileport_pshm(pid, fpi->proc_fileport);
break;
case PROX_FDTYPE_VNODE:
(void) process_fileport_vnode(pid, fpi->proc_fileport);
break;
default:
(void) snpf(Namech, Namechl - 1, "unknown file type: %d",
fpi->proc_fileport);
Namech[Namechl - 1] = '\0';
(void) enter_nm(Namech);
break;
}
if (Lf->sf) {
if (!ckscko || isock)
link_lfile();
}
}
}
#endif /* PROC_PIDLISTFILEPORTS */
/*
* process_text() -- process text information
*/
static void
process_text(pid)
int pid; /* PID */
{
uint64_t a;
int i, n, nb;
struct proc_regionwithpathinfo rwpi;
for (a = (uint64_t)0, i = n = 0; i < 10000; i++) {
nb = proc_pidinfo(pid, PROC_PIDREGIONPATHINFO, a, &rwpi,
sizeof(rwpi));
if (nb <= 0) {
if ((errno == ESRCH) || (errno == EINVAL)) {
/*
* Quit if no more text information is available for the
* process.
*/
return;
}
/*
* Warn about all other errors via a NAME column message.
*/
alloc_lfile(" txt", -1);
Cfp = (struct file *)NULL;
(void) snpf(Namech, Namechl,
"region info error: %s", strerror(errno));
Namech[Namechl - 1] = '\0';
enter_nm(Namech);
if (Lf->sf)
link_lfile();
return;
} else if (nb < sizeof(rwpi)) {
(void) fprintf(stderr,
"%s: PID %d: proc_pidinfo(PROC_PIDREGIONPATHINFO);\n",
Pn, pid);
(void) fprintf(stderr,
" too few bytes; expected %ld, got %d\n",
sizeof(rwpi), nb);
Exit(1);
}
if (rwpi.prp_vip.vip_path[0])
enter_vn_text(&rwpi.prp_vip, &n);
a = rwpi.prp_prinfo.pri_address + rwpi.prp_prinfo.pri_size;
}
}
#if DARWINV>=900
/*
* process_threads() -- process thread information
*/
#define TWD " twd" /* per-thread current working directory
* fd name */
static void
process_threads(pid, n)
int pid; /* PID */
uint32_t n; /* number of threads */
{
int i, nb, nt;
/*
* Make sure a thread buffer has been allocated.
*/
n += 10;
if (n > NbThreads) {
while (n > NbThreads) {
NbThreads += THREADS_INCR;
}
if (!Threads)
Threads = (uint64_t *)malloc((MALLOC_S)NbThreads);
else
Threads = (uint64_t *)realloc((MALLOC_P *)Threads,
(MALLOC_S)NbThreads);
if (!Threads) {
(void) fprintf(stderr,
"%s: can't allocate space for %d Threads\n", Pn,
(int)(NbThreads / sizeof(int *)));
Exit(1);
}
}
/*
* Get thread information for the process.
*/
nb = proc_pidinfo(pid, PROC_PIDLISTTHREADS, 0, Threads, NbThreads);
if (nb <= 0) {
if (errno == ESRCH) {
/*
* Quit if no thread information is available for the
* process.
*/
return;
}
}
nt = (int)(nb / sizeof(uint64_t));
/*
* Loop through the threads.
*/
for (i = 0; i < nt; i++) {
uint64_t t;
struct proc_threadwithpathinfo tpi;
t = Threads[i];
nb = proc_pidinfo(pid, PROC_PIDTHREADPATHINFO, t, &tpi,
sizeof(tpi));
if (nb <= 0) {
if ((errno == ESRCH) || (errno == EINVAL)) {
/*
* Quit if no more thread information is available for the
* process.
*/
return;
}
/*
* Warn about all other errors via a NAME column message.
*/
alloc_lfile(TWD, -1);
Cfp = (struct file *)NULL;
(void) snpf(Namech, Namechl,
"thread info error: %s", strerror(errno));
Namech[Namechl - 1] = '\0';
enter_nm(Namech);
if (Lf->sf)
link_lfile();
return;
} else if (nb < sizeof(tpi)) {
(void) fprintf(stderr,
"%s: PID %d: proc_pidinfo(PROC_PIDTHREADPATHINFO);\n",
Pn, pid);
(void) fprintf(stderr,
" too few bytes; expected %ld, got %d\n",
sizeof(tpi), nb);
Exit(1);
}
if (tpi.pvip.vip_path[0]) {
alloc_lfile(TWD, -1);
Cfp = (struct file *)NULL;
(void) enter_vnode_info(&tpi.pvip);
if (Lf->sf)
link_lfile();
}
}
}
#endif /* DARWINV>=900 */
|