[Mono-dev] Don't use non-standard /proc dir just to find out if a process is running
Robert Nagy
robert at openbsd.org
Fri Apr 2 19:53:56 EDT 2010
Hi
/proc is totally non-standard so I think this should be switched to
use kill to determinate if a process is running because since kill(2)
is POSIX we can rely on it basically everywhere.
In case of EPERM it's still okay to "find" the process because
we are not actually signalling the pid we are just asking kill() to
do error checking.
Index: io-layer/processes.c
===================================================================
--- io-layer/processes.c (revision 154739)
+++ io-layer/processes.c (working copy)
@@ -1650,11 +1650,13 @@
process_open_compare,
GUINT_TO_POINTER (pid), NULL, TRUE);
if (handle == 0) {
- gchar *dir = g_strdup_printf ("/proc/%d", pid);
- if (!access (dir, F_OK)) {
- /* Return a pseudo handle for processes we
- * don't have handles for
- */
+ /*
+ * Ignore EPERM so that even if the sending process is not the
+ * superuser and its' effective user ID does not match the
+ * effective user ID of the receiving process, we can safely
+ * return.
+ */
+ if ((kill(pid, 0) == 0) || (errno == EPERM)) {
return GINT_TO_POINTER (_WAPI_PROCESS_UNHANDLED + pid);
} else {
#ifdef DEBUG
More information about the Mono-devel-list
mailing list