comparison dep/animia/src/bsd.cpp @ 78:1ce00c1c8ddc

dep/animia: update to upstream
author Paper <mrpapersonic@gmail.com>
date Wed, 11 Oct 2023 12:16:15 -0400
parents 4c6dd5999b39
children eab9e623eb84
comparison
equal deleted inserted replaced
77:6f7385bd334c 78:1ce00c1c8ddc
76 76
77 std::vector<std::string> get_open_files(int pid) { 77 std::vector<std::string> get_open_files(int pid) {
78 /* note: this is OS X only right now. eventually, I'll find a way 78 /* note: this is OS X only right now. eventually, I'll find a way
79 to do this in FreeBSD, OpenBSD and the like */ 79 to do this in FreeBSD, OpenBSD and the like */
80 std::vector<std::string> ret; 80 std::vector<std::string> ret;
81
82 if (pid == 0)
83 return ret;
84
81 int bufsz = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, NULL, 0); 85 int bufsz = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, NULL, 0);
86 if (bufsz == -1)
87 return ret;
88
82 struct proc_fdinfo* info = (struct proc_fdinfo*)malloc(bufsz); 89 struct proc_fdinfo* info = (struct proc_fdinfo*)malloc(bufsz);
90 if (!info)
91 return ret;
92
83 proc_pidinfo(pid, PROC_PIDLISTFDS, 0, info, bufsz); 93 proc_pidinfo(pid, PROC_PIDLISTFDS, 0, info, bufsz);
84 94
85 // iterate over stuff 95 // iterate over stuff
86 ret.reserve(bufsz / sizeof(info[0])); 96 ret.reserve(bufsz / sizeof(info[0]));
87 for (int i = 0; i < bufsz / sizeof(info[0]); i++) { 97 for (int i = 0; i < bufsz / sizeof(info[0]); i++) {
88 if (info[i].proc_fdtype == PROX_FDTYPE_VNODE) { 98 if (info[i].proc_fdtype == PROX_FDTYPE_VNODE) {
89 struct vnode_fdinfowithpath vnodeInfo; 99 struct vnode_fdinfowithpath vnodeInfo;
90 proc_pidfdinfo(pid, info[i].proc_fd, PROC_PIDFDVNODEPATHINFO, &vnodeInfo, PROC_PIDFDVNODEPATHINFO_SIZE); 100
101 int sz = proc_pidfdinfo(pid, info[i].proc_fd, PROC_PIDFDVNODEPATHINFO, &vnodeInfo, PROC_PIDFDVNODEPATHINFO_SIZE);
102 if (sz != PROC_PIDFDVNODEPATHINFO_SIZE)
103 continue;
104
105 if (vnodeInfo.pfi.fi_openflags & O_WRONLY || vnodeInfo.pfi.fi_openflags & O_RDWR)
106 continue;
107
91 ret.push_back(vnodeInfo.pvip.vip_path); 108 ret.push_back(vnodeInfo.pvip.vip_path);
92 } 109 }
93 } 110 }
94 return ret; 111 return ret;
95 } 112 }