| 363 | |
| 364 | #ifdef __APPLE__ |
| 365 | int find_fd_for_pid(pid_t pid, int *fd_list, int max_fd) |
| 366 | { |
| 367 | int count = 0; |
| 368 | int bufferSize = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, 0, 0); |
| 369 | struct stat stat_buf; |
| 370 | |
| 371 | if (bufferSize < 0) { |
| 372 | printf("Error :/, cannot proc_pidinfo\n"); |
| 373 | return 0; |
| 374 | } |
| 375 | struct proc_fdinfo *procFDInfo = (struct proc_fdinfo *)malloc(bufferSize); |
| 376 | assert(procFDInfo != NULL); |
| 377 | proc_pidinfo(pid, PROC_PIDLISTFDS, 0, procFDInfo, bufferSize); |
| 378 | int numberOfProcFDs = bufferSize / PROC_PIDLISTFD_SIZE; |
| 379 | int i; |
| 380 | |
| 381 | for(i = 0; i < numberOfProcFDs; i++) { |
| 382 | if(procFDInfo[i].proc_fdtype == PROX_FDTYPE_VNODE) { |
| 383 | struct vnode_fdinfowithpath vnodeInfo; |
| 384 | proc_pidfdinfo(pid, procFDInfo[i].proc_fd, PROC_PIDFDVNODEPATHINFO, &vnodeInfo, PROC_PIDFDVNODEPATHINFO_SIZE); |
| 385 | if (stat(vnodeInfo.pvip.vip_path, &stat_buf) < 0) { |
| 386 | if (flag_debug) |
| 387 | perror("sstat"); |
| 388 | continue; |
| 389 | } |
| 390 | if (!S_ISREG(stat_buf.st_mode) && !S_ISBLK(stat_buf.st_mode)) |
| 391 | continue; |
| 392 | |
| 393 | if (is_ignored_file(vnodeInfo.pvip.vip_path)) |
| 394 | continue; |
| 395 | |
| 396 | // OK, we've found a potential interesting file. |
| 397 | |
| 398 | fd_list[count++] = procFDInfo[i].proc_fd; |
| 399 | //~ printf("[debug] %s\n",vnodeInfo.pvip.vip_path); |
| 400 | if(count == max_fd) |
| 401 | break; |
| 402 | } |
| 403 | } |
| 404 | return count; |
| 405 | } |
| 406 | #endif // __APPLE__ |
| 407 | #ifdef __linux__ |
| 408 | int find_fd_for_pid(pid_t pid, int *fd_list, int max_fd) |
no test coverage detected