diff 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
line wrap: on
line diff
--- a/dep/animia/src/bsd.cpp	Fri Oct 06 06:18:53 2023 -0400
+++ b/dep/animia/src/bsd.cpp	Wed Oct 11 12:16:15 2023 -0400
@@ -78,8 +78,18 @@
 	/* note: this is OS X only right now. eventually, I'll find a way
 	   to do this in FreeBSD, OpenBSD and the like */
 	std::vector<std::string> ret;
+
+	if (pid == 0)
+		return ret;
+
 	int bufsz = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, NULL, 0);
+	if (bufsz == -1)
+		return ret;
+
 	struct proc_fdinfo* info = (struct proc_fdinfo*)malloc(bufsz);
+	if (!info)
+		return ret;
+
 	proc_pidinfo(pid, PROC_PIDLISTFDS, 0, info, bufsz);
 
 	// iterate over stuff
@@ -87,7 +97,14 @@
 	for (int i = 0; i < bufsz / sizeof(info[0]); i++) {
 		if (info[i].proc_fdtype == PROX_FDTYPE_VNODE) {
 			struct vnode_fdinfowithpath vnodeInfo;
-			proc_pidfdinfo(pid, info[i].proc_fd, PROC_PIDFDVNODEPATHINFO, &vnodeInfo, PROC_PIDFDVNODEPATHINFO_SIZE);
+
+			int sz = proc_pidfdinfo(pid, info[i].proc_fd, PROC_PIDFDVNODEPATHINFO, &vnodeInfo, PROC_PIDFDVNODEPATHINFO_SIZE);
+			if (sz != PROC_PIDFDVNODEPATHINFO_SIZE)
+				continue;
+
+			if (vnodeInfo.pfi.fi_openflags & O_WRONLY || vnodeInfo.pfi.fi_openflags & O_RDWR)
+				continue;
+
 			ret.push_back(vnodeInfo.pvip.vip_path);
 		}
 	}