*/
guint32 _wapi_shm_mapped_segments;
+guint32 _wapi_fd_offset_table_size;
+gpointer *_wapi_fd_offset_table=NULL;
+
static void shared_init (void)
{
struct sockaddr_un shared_socket_address;
gboolean tried_once=FALSE;
int ret;
-
+ int thr_ret;
+
_wapi_shared_data=g_new0 (struct _WapiHandleShared_list *, 1);
_wapi_private_data=g_new0 (struct _WapiHandlePrivate_list *, 1);
-
+
attach_again:
#ifndef DISABLE_SHARED_HANDLES
shared=_wapi_shm_attach (&_wapi_shared_data[0],
&_wapi_shared_scratch);
if(shared==FALSE) {
- g_warning ("Failed to attach shared memory! "
- "Falling back to non-shared handles");
+ g_warning (
+ "Failed to attach shared memory! "
+ "Falling back to non-shared handles\n"
+ "See: http://www.go-mono.com/issues.html#wapi for details");
}
#endif /* DISABLE_SHARED_HANDLES */
}
goto attach_again;
}
+ } else {
+ _wapi_fd_offset_table_size = _wapi_shared_data[0]->fd_offset_table_size;
+ _wapi_fd_offset_table=g_new0 (gpointer, _wapi_fd_offset_table_size);
}
}
_wapi_shared_data[0]->num_segments=1;
_wapi_shared_scratch=g_new0 (struct _WapiHandleScratch, 1);
+
+ _wapi_fd_offset_table_size=getdtablesize ();
+ _wapi_fd_offset_table=g_new0 (gpointer,
+ _wapi_fd_offset_table_size);
}
_wapi_private_data[0]=g_new0 (struct _WapiHandlePrivate_list, 1);
_wapi_shm_mapped_segments=1;
- pthread_mutexattr_init (&mutex_shared_attr);
- pthread_condattr_init (&cond_shared_attr);
-
+ thr_ret = pthread_mutexattr_init (&mutex_shared_attr);
+ g_assert (thr_ret == 0);
+
+ thr_ret = pthread_condattr_init (&cond_shared_attr);
+ g_assert (thr_ret == 0);
+
#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1
- pthread_mutexattr_setpshared (&mutex_shared_attr,
- PTHREAD_PROCESS_SHARED);
- pthread_condattr_setpshared (&cond_shared_attr,
- PTHREAD_PROCESS_SHARED);
+ thr_ret = pthread_mutexattr_setpshared (&mutex_shared_attr,
+ PTHREAD_PROCESS_SHARED);
+ g_assert (thr_ret == 0);
+
+ thr_ret = pthread_condattr_setpshared (&cond_shared_attr,
+ PTHREAD_PROCESS_SHARED);
+ g_assert (thr_ret == 0);
#else
- pthread_cond_init(&_wapi_private_data[0]->signal_cond, NULL);
- mono_mutex_init(&_wapi_private_data[0]->signal_mutex, NULL);
+ thr_ret = pthread_cond_init(&_wapi_private_data[0]->signal_cond, NULL);
+ g_assert (thr_ret == 0);
+
+ thr_ret = mono_mutex_init(&_wapi_private_data[0]->signal_mutex, NULL);
+ g_assert (thr_ret == 0);
#endif
}
guint32 segment, idx;
guint32 i, j;
static guint32 last=1;
+ int thr_ret;
+ guint32 num_segments = _wapi_handle_get_shared_segment (0)->num_segments;
/* A linear scan should be fast enough. Start from the last
* allocation, assuming that handles are allocated more often
#endif
again:
_wapi_handle_segment (GUINT_TO_POINTER (last), &segment, &idx);
- for(i=segment; i<_wapi_handle_get_shared_segment (0)->num_segments;
- i++) {
+ for(i=segment; i < num_segments; i++) {
if(i!=segment) {
idx=0;
}
for(j=idx; j<_WAPI_HANDLES_PER_SEGMENT; j++) {
struct _WapiHandleShared *shared;
- /* Make sure we dont try and assign handle 0 */
- if (i==0 && j==0) {
+ /* Make sure we dont try and assign the
+ * handles that would clash with fds
+ */
+ if ((i * _WAPI_HANDLES_PER_SEGMENT + j) < _wapi_fd_offset_table_size) {
+ i = _wapi_fd_offset_table_size / _WAPI_HANDLES_PER_SEGMENT;
+ j = _wapi_fd_offset_table_size - (i * _WAPI_HANDLES_PER_SEGMENT);
+
+ if (i >= num_segments) {
+ /* Need to get the caller to
+ * add more shared segments
+ */
+ return(0);
+ }
+
continue;
}
shared->type=type;
shared->signalled=FALSE;
#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1
- mono_mutex_init (&shared->signal_mutex, &mutex_shared_attr);
- pthread_cond_init (&shared->signal_cond, &cond_shared_attr);
+ thr_ret = mono_mutex_init (&shared->signal_mutex, &mutex_shared_attr);
+ g_assert (thr_ret == 0);
+
+ thr_ret = pthread_cond_init (&shared->signal_cond, &cond_shared_attr);
+ g_assert (thr_ret == 0);
#else
- pthread_cond_init(&shared->signal_cond, NULL);
- mono_mutex_init(&shared->signal_mutex, NULL);
+ thr_ret = pthread_cond_init(&shared->signal_cond, NULL);
+ g_assert (thr_ret == 0);
+
+ thr_ret = mono_mutex_init(&shared->signal_mutex, NULL);
+ g_assert (thr_ret == 0);
#endif
return(_wapi_handle_index (i, j));
{
static mono_once_t shared_init_once = MONO_ONCE_INIT;
static pthread_mutex_t scan_mutex=PTHREAD_MUTEX_INITIALIZER;
- guint32 handle_idx, idx, segment;
+ guint32 handle_idx = 0, idx, segment;
gpointer handle;
WapiHandleRequest new={0};
WapiHandleResponse new_resp={0};
#if HAVE_BOEHM_GC
gboolean tried_collect=FALSE;
#endif
+ int thr_ret;
mono_once (&shared_init_once, shared_init);
-
+
again:
if(shared==TRUE) {
new.type=WapiHandleRequestType_New;
g_assert_not_reached ();
}
} else {
- pthread_mutex_lock (&scan_mutex);
- handle_idx=_wapi_handle_new_internal (type);
- if(handle_idx==0) {
+ pthread_cleanup_push ((void(*)(void *))pthread_mutex_unlock,
+ (void *)&scan_mutex);
+ thr_ret = pthread_mutex_lock (&scan_mutex);
+ g_assert (thr_ret == 0);
+
+ while ((handle_idx = _wapi_handle_new_internal (type)) == 0) {
/* Try and get a new segment, and have another go */
segment=_wapi_handle_get_shared_segment (0)->num_segments;
_wapi_handle_ensure_mapped (segment);
if(_wapi_handle_get_shared_segment (segment)!=NULL) {
/* Got a new segment */
_wapi_handle_get_shared_segment (0)->num_segments++;
- handle_idx=_wapi_handle_new_internal (type);
} else {
/* Map failed. Just return 0 meaning
* "out of handles"
_wapi_handle_segment (GUINT_TO_POINTER (handle_idx), &segment, &idx);
_wapi_handle_get_shared_segment (segment)->handles[idx].ref++;
- pthread_mutex_unlock (&scan_mutex);
+
+ thr_ret = pthread_mutex_unlock (&scan_mutex);
+ g_assert (thr_ret == 0);
+ pthread_cleanup_pop (0);
}
+ /* Make sure we left the space for fd mappings */
+ g_assert (handle_idx >= _wapi_fd_offset_table_size);
+
if(handle_idx==0) {
g_warning (G_GNUC_PRETTY_FUNCTION ": Ran out of handles!");
}
#if !defined(_POSIX_THREAD_PROCESS_SHARED) || _POSIX_THREAD_PROCESS_SHARED == -1
- mono_mutex_init (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_mutex, &mutex_shared_attr);
- pthread_cond_init (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_cond, &cond_shared_attr);
+ thr_ret = mono_mutex_init (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_mutex, &mutex_shared_attr);
+ g_assert (thr_ret == 0);
+
+ thr_ret = pthread_cond_init (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_cond, &cond_shared_attr);
+ g_assert (thr_ret == 0);
#endif
handle=GUINT_TO_POINTER (handle_idx);
gpointer *shared, gpointer *private)
{
struct _WapiHandleShared *shared_handle_data;
- struct _WapiHandlePrivate *private_handle_data;
+ struct _WapiHandlePrivate *private_handle_data = NULL;
guint32 idx;
guint32 segment;
+ g_assert (GPOINTER_TO_UINT (handle) >= _wapi_fd_offset_table_size);
+
_wapi_handle_segment (handle, &segment, &idx);
_wapi_handle_ensure_mapped (segment);
void _wapi_handle_ref (gpointer handle)
{
+ g_assert (GPOINTER_TO_UINT (handle) >= _wapi_fd_offset_table_size);
+
if(shared==TRUE) {
WapiHandleRequest req={0};
WapiHandleResponse resp={0};
}
}
+/* The handle must not be locked on entry to this function */
void _wapi_handle_unref (gpointer handle)
{
guint32 idx, segment;
- gboolean destroy;
-
+ gboolean destroy = FALSE;
+ int thr_ret;
+
+ g_assert (GPOINTER_TO_UINT (handle) >= _wapi_fd_offset_table_size);
+
_wapi_handle_segment (handle, &segment, &idx);
if(shared==TRUE) {
if(shared==FALSE) {
_wapi_handle_ops_close_shared (handle);
- mono_mutex_destroy (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_mutex);
- pthread_cond_destroy (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_cond);
memset (&_wapi_handle_get_shared_segment (segment)->handles[idx].u, '\0', sizeof(_wapi_handle_get_shared_segment (segment)->handles[idx].u));
-
- }
- else {
- mono_mutex_destroy (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_mutex);
- pthread_cond_destroy (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_cond);
}
_wapi_handle_ops_close_private (handle);
_wapi_handle_get_shared_segment (segment)->handles[idx].type=WAPI_HANDLE_UNUSED;
+ _wapi_handle_get_private_segment (segment)->handles[idx].type=WAPI_HANDLE_UNUSED;
+
+ /* Destroy the mutex and cond var. We hope nobody
+ * tried to grab them between the handle unlock and
+ * now, but pthreads doesn't have a
+ * "unlock_and_destroy" atomic function.
+ */
+ thr_ret = mono_mutex_destroy (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_mutex);
+ g_assert (thr_ret == 0);
+
+ thr_ret = pthread_cond_destroy (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_cond);
+ g_assert (thr_ret == 0);
}
}
static guint32 _wapi_handle_scratch_locate_space (guint32 bytes)
{
guint32 idx=0, last_idx=0;
- struct _WapiScratchHeader *hdr, *last_hdr;
+ struct _WapiScratchHeader *hdr, *last_hdr = NULL;
gboolean last_was_free=FALSE;
guchar *storage=_wapi_shared_scratch->scratch_data;
guint32 _wapi_handle_scratch_store (gconstpointer data, guint32 bytes)
{
- guint32 idx, store_bytes;
+ guint32 idx = 0, store_bytes;
gboolean remap;
-
+ int thr_ret;
+ guint32 ret = 0;
+
#ifdef DEBUG
g_message (G_GNUC_PRETTY_FUNCTION ": storing %d bytes", bytes);
#endif
/* Align bytes to 32 bits (needed for sparc at least) */
store_bytes = (((bytes) + 3) & (~3));
- pthread_mutex_lock (&_wapi_scratch_mutex);
-
+ pthread_cleanup_push ((void(*)(void *))pthread_mutex_unlock,
+ (void *)&_wapi_scratch_mutex);
+ thr_ret = pthread_mutex_lock (&_wapi_scratch_mutex);
+ g_assert (thr_ret == 0);
+
if(shared==TRUE) {
WapiHandleRequest scratch={0};
WapiHandleResponse scratch_resp={0};
idx=_wapi_handle_scratch_store_internal (store_bytes, &remap);
if(idx==0) {
/* Failed to allocate space */
- pthread_mutex_unlock (&_wapi_scratch_mutex);
- return(0);
+ goto cleanup;
}
}
-
+ ret = idx;
+
#ifdef DEBUG
g_message (G_GNUC_PRETTY_FUNCTION
": stored [%s] at %d (len %d, aligned len %d)",
memcpy (&_wapi_shared_scratch->scratch_data[idx], data, bytes);
- pthread_mutex_unlock (&_wapi_scratch_mutex);
+cleanup:
+ thr_ret = pthread_mutex_unlock (&_wapi_scratch_mutex);
+ g_assert (thr_ret == 0);
+ pthread_cleanup_pop (0);
- return(idx);
+ return(ret);
}
guint32 _wapi_handle_scratch_store_string_array (gchar **data)
struct _WapiScratchHeader *hdr;
gpointer ret;
guchar *storage;
+ int thr_ret;
if(idx < HDRSIZE || idx > _wapi_shared_scratch->data_len) {
return(NULL);
}
- pthread_mutex_lock (&_wapi_scratch_mutex);
+ pthread_cleanup_push ((void(*)(void *))pthread_mutex_unlock,
+ (void *)&_wapi_scratch_mutex);
+ thr_ret = pthread_mutex_lock (&_wapi_scratch_mutex);
+ g_assert (thr_ret == 0);
storage=_wapi_shared_scratch->scratch_data;
ret=g_malloc0 (hdr->length+1);
memcpy (ret, &storage[idx], hdr->length);
- pthread_mutex_unlock (&_wapi_scratch_mutex);
+ thr_ret = pthread_mutex_unlock (&_wapi_scratch_mutex);
+ g_assert (thr_ret == 0);
+ pthread_cleanup_pop (0);
return(ret);
}
{
struct _WapiScratchHeader *hdr;
guchar *storage;
+ int thr_ret;
if(idx < HDRSIZE || idx > _wapi_shared_scratch->data_len) {
return;
}
- pthread_mutex_lock (&_wapi_scratch_mutex);
+ pthread_cleanup_push ((void(*)(void *))pthread_mutex_unlock,
+ (void *)&_wapi_scratch_mutex);
+ thr_ret = pthread_mutex_lock (&_wapi_scratch_mutex);
+ g_assert (thr_ret == 0);
storage=_wapi_shared_scratch->scratch_data;
* free, but the _store() function will do that anyway.
*/
- pthread_mutex_unlock (&_wapi_scratch_mutex);
+ thr_ret = pthread_mutex_unlock (&_wapi_scratch_mutex);
+ g_assert (thr_ret == 0);
+ pthread_cleanup_pop (0);
}
void _wapi_handle_scratch_delete (guint32 idx)
guint32 idx, segment;
WapiHandleType type;
+ if (GPOINTER_TO_UINT (handle) < _wapi_fd_offset_table_size) {
+ handle = _wapi_handle_fd_offset_to_handle (handle);
+ }
+
_wapi_handle_segment (handle, &segment, &idx);
type=_wapi_handle_get_shared_segment (segment)->handles[idx].type;
guint32 idx, segment;
WapiHandleType type;
+ if (GPOINTER_TO_UINT (handle) < _wapi_fd_offset_table_size) {
+ handle = _wapi_handle_fd_offset_to_handle (handle);
+ }
+
_wapi_handle_segment (handle, &segment, &idx);
type=_wapi_handle_get_shared_segment (segment)->handles[idx].type;
guint32 idx, segment;
WapiHandleType type;
+ if (GPOINTER_TO_UINT (handle) < _wapi_fd_offset_table_size) {
+ handle = _wapi_handle_fd_offset_to_handle (handle);
+ }
+
_wapi_handle_segment (handle, &segment, &idx);
type=_wapi_handle_get_shared_segment (segment)->handles[idx].type;
guint32 idx, segment;
WapiHandleType type;
+ if (GPOINTER_TO_UINT (handle) < _wapi_fd_offset_table_size) {
+ handle = _wapi_handle_fd_offset_to_handle (handle);
+ }
+
_wapi_handle_segment (handle, &segment, &idx);
type=_wapi_handle_get_shared_segment (segment)->handles[idx].type;
guint32 idx, segment;
WapiHandleType type;
+ if (GPOINTER_TO_UINT (handle) < _wapi_fd_offset_table_size) {
+ handle = _wapi_handle_fd_offset_to_handle (handle);
+ }
+
_wapi_handle_segment (handle, &segment, &idx);
type=_wapi_handle_get_shared_segment (segment)->handles[idx].type;
guint32 idx, segment;
WapiHandleType type;
+ if (GPOINTER_TO_UINT (handle) < _wapi_fd_offset_table_size) {
+ handle = _wapi_handle_fd_offset_to_handle (handle);
+ }
+
_wapi_handle_segment (handle, &segment, &idx);
type=_wapi_handle_get_shared_segment (segment)->handles[idx].type;
*/
gboolean CloseHandle(gpointer handle)
{
+ if (GPOINTER_TO_UINT (handle) < _wapi_fd_offset_table_size) {
+ handle = _wapi_handle_fd_offset_to_handle (handle);
+ }
+
+ if (handle == NULL) {
+ return(FALSE);
+ }
+
_wapi_handle_unref (handle);
return(TRUE);
{
guint32 count, i, iter=0;
gboolean ret;
+ int thr_ret;
/* Lock all the handles, with backoff */
again:
for(i=0; i<numhandles; i++) {
guint32 idx, segment;
+ gpointer handle = handles[i];
+
+ if (GPOINTER_TO_UINT (handle) < _wapi_fd_offset_table_size) {
+ handle = _wapi_handle_fd_offset_to_handle (handle);
+ }
- _wapi_handle_segment (handles[i], &segment, &idx);
+ _wapi_handle_segment (handle, &segment, &idx);
#ifdef DEBUG
g_message (G_GNUC_PRETTY_FUNCTION ": attempting to lock %p",
- handles[i]);
+ handle);
#endif
ret=mono_mutex_trylock (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_mutex);
struct timespec sleepytime;
#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": attempt failed for %p", handles[i]);
+ g_message (G_GNUC_PRETTY_FUNCTION ": attempt failed for %p: %s", handle, strerror (ret));
#endif
while(i--) {
- _wapi_handle_segment (handles[i], &segment, &idx);
- mono_mutex_unlock (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_mutex);
+ handle = handles[i];
+
+ if (GPOINTER_TO_UINT (handle) < _wapi_fd_offset_table_size) {
+ handle = _wapi_handle_fd_offset_to_handle (handle);
+ }
+
+ _wapi_handle_segment (handle, &segment, &idx);
+ thr_ret = mono_mutex_unlock (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_mutex);
+ g_assert (thr_ret == 0);
}
/* If iter ever reaches 100 the nanosleep will
for(i=0; i<numhandles; i++) {
guint32 idx, segment;
-
- _wapi_handle_segment (handles[i], &segment, &idx);
+ gpointer handle = handles[i];
+
+ if (GPOINTER_TO_UINT (handle) < _wapi_fd_offset_table_size) {
+ handle = _wapi_handle_fd_offset_to_handle (handle);
+ }
+
+ _wapi_handle_ref (handle);
+
+ _wapi_handle_segment (handle, &segment, &idx);
#ifdef DEBUG
g_message (G_GNUC_PRETTY_FUNCTION ": Checking handle %p",
- handles[i]);
+ handle);
#endif
- if(((_wapi_handle_test_capabilities (handles[i], WAPI_HANDLE_CAP_OWN)==TRUE) &&
- (_wapi_handle_ops_isowned (handles[i])==TRUE)) ||
+ if(((_wapi_handle_test_capabilities (handle, WAPI_HANDLE_CAP_OWN)==TRUE) &&
+ (_wapi_handle_ops_isowned (handle)==TRUE)) ||
(_wapi_handle_get_shared_segment (segment)->handles[idx].signalled==TRUE)) {
count++;
#ifdef DEBUG
g_message (G_GNUC_PRETTY_FUNCTION
- ": Handle %p signalled", handles[i]);
+ ": Handle %p signalled", handle);
#endif
if(*lowest>i) {
*lowest=i;
void _wapi_handle_unlock_handles (guint32 numhandles, gpointer *handles)
{
guint32 i;
+ int thr_ret;
for(i=0; i<numhandles; i++) {
guint32 idx, segment;
-
- _wapi_handle_segment (handles[i], &segment, &idx);
+ gpointer handle = handles[i];
+
+ if (GPOINTER_TO_UINT (handle) < _wapi_fd_offset_table_size) {
+ handle = _wapi_handle_fd_offset_to_handle (handle);
+ }
+
+ _wapi_handle_segment (handle, &segment, &idx);
#ifdef DEBUG
g_message (G_GNUC_PRETTY_FUNCTION ": unlocking handle %p",
- handles[i]);
+ handle);
#endif
- mono_mutex_unlock (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_mutex);
+ thr_ret = mono_mutex_unlock (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_mutex);
+ g_assert (thr_ret == 0);
+
+ _wapi_handle_unref (handle);
}
}
#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1
guint32 idx, segment;
+ if (GPOINTER_TO_UINT (handle) < _wapi_fd_offset_table_size) {
+ handle = _wapi_handle_fd_offset_to_handle (handle);
+ }
+
_wapi_handle_segment (handle, &segment, &idx);
return(mono_cond_wait (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_cond,
struct timespec fake_timeout;
int ret;
+ if (GPOINTER_TO_UINT (handle) < _wapi_fd_offset_table_size) {
+ handle = _wapi_handle_fd_offset_to_handle (handle);
+ }
+
_wapi_handle_segment (handle, &segment, &idx);
_wapi_calc_timeout (&fake_timeout, 100);
#if defined(_POSIX_THREAD_PROCESS_SHARED) && _POSIX_THREAD_PROCESS_SHARED != -1
guint32 idx, segment;
+ if (GPOINTER_TO_UINT (handle) < _wapi_fd_offset_table_size) {
+ handle = _wapi_handle_fd_offset_to_handle (handle);
+ }
+
_wapi_handle_segment (handle, &segment, &idx);
return(mono_cond_timedwait (&_wapi_handle_get_shared_segment (segment)->handles[idx].signal_cond,
struct timespec fake_timeout;
int ret;
+ if (GPOINTER_TO_UINT (handle) < _wapi_fd_offset_table_size) {
+ handle = _wapi_handle_fd_offset_to_handle (handle);
+ }
+
_wapi_handle_segment (handle, &segment, &idx);
_wapi_calc_timeout (&fake_timeout, 100);
* exec_errno will be set, and the handle will be
* signalled immediately.
*/
- if(process_handle==0 || thread_handle==0) {
+ if(*process_handle==0 || *thread_handle==0) {
return(FALSE);
} else {
+ /* This call returns new handles, so we need to do
+ * a little bookkeeping
+ */
+ if (_wapi_private_data != NULL) {
+ guint32 segment, idx;
+
+ _wapi_handle_segment (*process_handle,
+ &segment, &idx);
+ _wapi_handle_ensure_mapped (segment);
+ _wapi_handle_get_private_segment (segment)->handles[idx].type = WAPI_HANDLE_PROCESS;
+
+ _wapi_handle_segment (*thread_handle,
+ &segment, &idx);
+ _wapi_handle_ensure_mapped (segment);
+ _wapi_handle_get_private_segment (segment)->handles[idx].type = WAPI_HANDLE_THREAD;
+ }
+
return(TRUE);
}
} else {
}
gboolean
-_wapi_handle_process_kill (gpointer process, guint32 signo, gint *errnum)
+_wapi_handle_process_kill (pid_t process, guint32 signo, gint *errnum)
{
WapiHandleRequest killproc = {0};
WapiHandleResponse killprocresp = {0};
}
killproc.type = WapiHandleRequestType_ProcessKill;
- killproc.u.process_kill.pid = GPOINTER_TO_UINT (process);
+ killproc.u.process_kill.pid = process;
killproc.u.process_kill.signo = signo;
_wapi_daemon_request_response (daemon_sock, &killproc, &killprocresp);
return (result == 0);
}
+gboolean _wapi_handle_get_or_set_share (dev_t device, ino_t inode,
+ guint32 new_sharemode,
+ guint32 new_access,
+ guint32 *old_sharemode,
+ guint32 *old_access)
+{
+ WapiHandleRequest req = {0};
+ WapiHandleResponse resp = {0};
+
+ if(shared != TRUE) {
+ /* No daemon means we don't know if a file is sharable.
+ * We're running in our own little world if this is
+ * the case, so there's no point in pretending that
+ * the file isn't sharable.
+ */
+ return(FALSE);
+ }
+
+ req.type = WapiHandleRequestType_GetOrSetShare;
+ req.u.get_or_set_share.device = device;
+ req.u.get_or_set_share.inode = inode;
+ req.u.get_or_set_share.new_sharemode = new_sharemode;
+ req.u.get_or_set_share.new_access = new_access;
+
+ _wapi_daemon_request_response (daemon_sock, &req, &resp);
+ if (resp.type != WapiHandleResponseType_GetOrSetShare) {
+ g_warning (G_GNUC_PRETTY_FUNCTION
+ ": bogus daemon response, type %d", resp.type);
+ g_assert_not_reached ();
+ }
+
+ *old_sharemode = resp.u.get_or_set_share.sharemode;
+ *old_access = resp.u.get_or_set_share.access;
+
+ return(resp.u.get_or_set_share.exists);
+}
+
+void _wapi_handle_set_share (dev_t device, ino_t inode, guint32 sharemode,
+ guint32 access)
+{
+ WapiHandleRequest req = {0};
+ WapiHandleResponse resp = {0};
+
+ if(shared != TRUE) {
+ /* No daemon, so there's no one else to tell about
+ * file sharing.
+ */
+ return;
+ }
+
+ req.type = WapiHandleRequestType_SetShare;
+ req.u.set_share.device = device;
+ req.u.set_share.inode = inode;
+ req.u.set_share.sharemode = sharemode;
+ req.u.set_share.access = access;
+
+ _wapi_daemon_request_response (daemon_sock, &req, &resp);
+ if (resp.type != WapiHandleResponseType_SetShare) {
+ g_warning (G_GNUC_PRETTY_FUNCTION
+ ": bogus daemon response, type %d", resp.type);
+ g_assert_not_reached ();
+ }
+}