MCPcopy Index your code
hub / github.com/Xfennec/progress / find_fd_for_pid

Function find_fd_for_pid

progress.c:365–405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

363
364#ifdef __APPLE__
365int find_fd_for_pid(pid_t pid, int *fd_list, int max_fd)
366{
367int count = 0;
368int bufferSize = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, 0, 0);
369struct stat stat_buf;
370
371if (bufferSize < 0) {
372 printf("Error :/, cannot proc_pidinfo\n");
373 return 0;
374}
375struct proc_fdinfo *procFDInfo = (struct proc_fdinfo *)malloc(bufferSize);
376assert(procFDInfo != NULL);
377proc_pidinfo(pid, PROC_PIDLISTFDS, 0, procFDInfo, bufferSize);
378int numberOfProcFDs = bufferSize / PROC_PIDLISTFD_SIZE;
379int i;
380
381for(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}
404return count;
405}
406#endif // __APPLE__
407#ifdef __linux__
408int find_fd_for_pid(pid_t pid, int *fd_list, int max_fd)

Callers 1

monitor_processesFunction · 0.85

Calls 4

statClass · 0.85
is_ignored_fileFunction · 0.85
nperrorFunction · 0.85
nfprintfFunction · 0.85

Tested by

no test coverage detected