X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=mono%2Fio-layer%2Fhandles.c;h=ac064054bd10240cc24a53c8c139e8595a27764e;hb=24748ce981a554c4a8f9529e5848a88c743a1901;hp=146c275cb5de7ba3198e16624933bd8b0398d963;hpb=e41cdd1666eb179e2a9bc83820f361fa5a56ceec;p=mono.git diff --git a/mono/io-layer/handles.c b/mono/io-layer/handles.c index 146c275cb5d..ac064054bd1 100644 --- a/mono/io-layer/handles.c +++ b/mono/io-layer/handles.c @@ -13,7 +13,9 @@ #include #include #include +#ifdef HAVE_SIGNAL_H #include +#endif #include #include #ifdef HAVE_SYS_SOCKET_H @@ -29,6 +31,9 @@ # include #endif #include +#ifdef HAVE_SYS_RESOURCE_H +# include +#endif #include #include @@ -37,9 +42,9 @@ #include #include #include -#include #include +#include #undef DEBUG_REFS #if 0 @@ -131,10 +136,10 @@ struct _WapiFileShareLayout *_wapi_fileshare_layout = NULL; * 4MB array. */ static GHashTable *file_share_hash; -static CRITICAL_SECTION file_share_hash_mutex; +static mono_mutex_t file_share_hash_mutex; -#define file_share_hash_lock() EnterCriticalSection (&file_share_hash_mutex) -#define file_share_hash_unlock() LeaveCriticalSection (&file_share_hash_mutex) +#define file_share_hash_lock() mono_mutex_lock (&file_share_hash_mutex) +#define file_share_hash_unlock() mono_mutex_unlock (&file_share_hash_mutex) guint32 _wapi_fd_reserve; @@ -207,13 +212,19 @@ static void handle_cleanup (void) if (file_share_hash) { g_hash_table_destroy (file_share_hash); - DeleteCriticalSection (&file_share_hash_mutex); + mono_mutex_destroy (&file_share_hash_mutex); } for (i = 0; i < _WAPI_PRIVATE_MAX_SLOTS; ++i) g_free (_wapi_private_handles [i]); } +int +wapi_getdtablesize (void) +{ + return eg_getdtablesize (); +} + /* * wapi_init: * @@ -224,8 +235,8 @@ wapi_init (void) { g_assert ((sizeof (handle_ops) / sizeof (handle_ops[0])) == WAPI_HANDLE_COUNT); - - _wapi_fd_reserve = getdtablesize(); + + _wapi_fd_reserve = wapi_getdtablesize (); /* This is needed by the code in _wapi_handle_new_internal */ _wapi_fd_reserve = (_wapi_fd_reserve + (_WAPI_HANDLE_INITIAL_COUNT - 1)) & ~(_WAPI_HANDLE_INITIAL_COUNT - 1); @@ -267,13 +278,7 @@ wapi_init (void) _wapi_global_signal_cond = &_WAPI_PRIVATE_HANDLES (GPOINTER_TO_UINT (_wapi_global_signal_handle)).signal_cond; _wapi_global_signal_mutex = &_WAPI_PRIVATE_HANDLES (GPOINTER_TO_UINT (_wapi_global_signal_handle)).signal_mutex; - - /* Using g_atexit here instead of an explicit function call in - * a cleanup routine lets us cope when a third-party library - * calls exit (eg if an X client loses the connection to its - * server.) - */ - g_atexit (handle_cleanup); + wapi_processes_init (); } void @@ -286,6 +291,7 @@ wapi_cleanup (void) _wapi_error_cleanup (); _wapi_thread_cleanup (); wapi_processes_cleanup (); + handle_cleanup (); } static void _wapi_handle_init_shared (struct _WapiHandleShared *handle, @@ -1633,7 +1639,7 @@ wapi_share_info_hash (gconstpointer data) return s->inode; } -gboolean _wapi_handle_get_or_set_share (dev_t device, ino_t inode, +gboolean _wapi_handle_get_or_set_share (guint64 device, guint64 inode, guint32 new_sharemode, guint32 new_access, guint32 *old_sharemode, @@ -1664,7 +1670,7 @@ gboolean _wapi_handle_get_or_set_share (dev_t device, ino_t inode, */ if (!file_share_hash) { file_share_hash = g_hash_table_new_full (wapi_share_info_hash, wapi_share_info_equal, NULL, g_free); - InitializeCriticalSection (&file_share_hash_mutex); + mono_mutex_init_recursive (&file_share_hash_mutex); } tmp.device = device; @@ -1800,8 +1806,6 @@ static void _wapi_handle_check_share_by_pid (struct _WapiFileShare *share_info) void _wapi_handle_check_share (struct _WapiFileShare *share_info, int fd) { gboolean found = FALSE, proc_fds = FALSE; - pid_t self = _wapi_getpid (); - int pid; int thr_ret, i; /* Prevents entries from expiring under us if we remove this @@ -1842,65 +1846,6 @@ void _wapi_handle_check_share (struct _WapiFileShare *share_info, int fd) } } - for (i = 0; i < _WAPI_HANDLE_INITIAL_COUNT; i++) { - struct _WapiHandleShared *shared; - struct _WapiHandle_process *process_handle; - - shared = &_wapi_shared_layout->handles[i]; - - if (shared->type == WAPI_HANDLE_PROCESS) { - DIR *fd_dir; - struct dirent *fd_entry; - char subdir[_POSIX_PATH_MAX]; - - process_handle = &shared->u.process; - pid = process_handle->id; - - /* Look in /proc//fd/ but ignore - * /proc//fd/, as we have the - * file open too - */ - g_snprintf (subdir, _POSIX_PATH_MAX, "/proc/%d/fd", - pid); - - fd_dir = opendir (subdir); - if (fd_dir == NULL) { - continue; - } - - DEBUG ("%s: Looking in %s", __func__, subdir); - - proc_fds = TRUE; - - while ((fd_entry = readdir (fd_dir)) != NULL) { - char path[_POSIX_PATH_MAX]; - struct stat link_stat; - - if (!strcmp (fd_entry->d_name, ".") || - !strcmp (fd_entry->d_name, "..") || - (pid == self && - fd == atoi (fd_entry->d_name))) { - continue; - } - - g_snprintf (path, _POSIX_PATH_MAX, - "/proc/%d/fd/%s", pid, - fd_entry->d_name); - - stat (path, &link_stat); - if (link_stat.st_dev == share_info->device && - link_stat.st_ino == share_info->inode) { - DEBUG ("%s: Found it at %s", - __func__, path); - - found = TRUE; - } - } - - closedir (fd_dir); - } - } - if (proc_fds == FALSE) { _wapi_handle_check_share_by_pid (share_info); } else if (found == FALSE) {