| 535 | |
| 536 | |
| 537 | signed char get_fdinfo(pid_t pid, int fdnum, fdinfo_t *fd_info) |
| 538 | { |
| 539 | struct stat stat_buf; |
| 540 | #ifdef __linux__ |
| 541 | char fdpath[MAXPATHLEN + 1]; |
| 542 | char line[LINE_LEN]; |
| 543 | FILE *fp; |
| 544 | int flags; |
| 545 | #endif |
| 546 | struct timezone tz; |
| 547 | |
| 548 | fd_info->num = fdnum; |
| 549 | fd_info->mode = PM_NONE; |
| 550 | |
| 551 | #ifdef __APPLE__ |
| 552 | struct vnode_fdinfowithpath vnodeInfo; |
| 553 | if (proc_pidfdinfo(pid, fdnum, PROC_PIDFDVNODEPATHINFO, &vnodeInfo, PROC_PIDFDVNODEPATHINFO_SIZE) <= 0) |
| 554 | return 0; |
| 555 | strncpy(fd_info->name, vnodeInfo.pvip.vip_path, MAXPATHLEN); |
| 556 | #endif // __APPLE__ |
| 557 | #ifdef __linux__ |
| 558 | ssize_t len; |
| 559 | snprintf(fdpath, MAXPATHLEN, "%s/%d/fd/%d", PROC_PATH, pid, fdnum); |
| 560 | |
| 561 | len=readlink(fdpath, fd_info->name, MAXPATHLEN); |
| 562 | if (len != -1) |
| 563 | fd_info->name[len] = 0; |
| 564 | else { |
| 565 | //~ nperror("readlink"); |
| 566 | return 0; |
| 567 | } |
| 568 | #endif |
| 569 | #ifdef __FreeBSD__ |
| 570 | struct procstat *procstat; |
| 571 | struct kinfo_proc *procs; |
| 572 | unsigned int proc_count; |
| 573 | |
| 574 | struct kinfo_proc *proc; |
| 575 | struct filestat *fstat; |
| 576 | struct filestat_list *fstat_list; |
| 577 | |
| 578 | int i; |
| 579 | |
| 580 | procstat = procstat_open_sysctl(); |
| 581 | assert(procstat != NULL); |
| 582 | |
| 583 | procs = procstat_getprocs(procstat, KERN_PROC_PID, pid, &proc_count); |
| 584 | if (procs == NULL) |
| 585 | goto done; |
| 586 | |
| 587 | for (i = 0; i < proc_count; i++) { |
| 588 | proc = &procs[i]; |
| 589 | |
| 590 | fstat_list = procstat_getfiles(procstat, proc, 0); |
| 591 | if (fstat_list == NULL) |
| 592 | continue; |
| 593 | |
| 594 | gettimeofday(&fd_info->tv, &tz); |
no test coverage detected