#include <mono/io-layer/daemon-private.h>
#include <mono/io-layer/socket-wrappers.h>
+#define LOGDEBUG(...)
#undef DEBUG
+// #define LOGDEBUG(...) g_message(__VA_ARGS__)
/* The shared thread codepath doesn't seem to work yet... */
#undef _POSIX_THREAD_PROCESS_SHARED
{
guint32 i;
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": Seeing if we should exit");
-#endif
+ LOGDEBUG ("%s: Seeing if we should exit", __func__);
if(nfds>1) {
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": Still got clients");
-#endif
+ LOGDEBUG ("%s: Still got clients", __func__);
return;
}
i<_wapi_shared_data[0]->num_segments * _WAPI_HANDLES_PER_SEGMENT;
i++) {
if(daemon_channel_data->open_handles[i]>0) {
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION
- ": Still got handle references");
-#endif
-
+ LOGDEBUG ("%s: Still got handle references", __func__);
_wapi_shared_data[0]->daemon_running=DAEMON_RUNNING;
return;
}
fds[0].events=POLLIN;
fds[0].revents=0;
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": Last connect check");
-#endif
+ LOGDEBUG ("%s: Last connect check", __func__);
if(poll (fds, 1, 0)>0) {
/* Someone did connect, so carry on running */
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION
- ": Someone connected");
-#endif
+ LOGDEBUG ("%s: Someone connected", __func__);
_wapi_shared_data[0]->daemon_running=DAEMON_RUNNING;
return;
}
#endif
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": Byebye");
-#endif
+ LOGDEBUG ("%s: Byebye", __func__);
cleanup ();
exit (0);
*/
static void signal_handler (int signo)
{
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": daemon received signal %d", signo);
-#endif
+ LOGDEBUG ("%s: daemon received signal %d", __func__, signo);
+
cleanup ();
exit (-1);
}
share_a->inode == share_b->inode);
}
+/* Catch this here rather than corrupt the shared data at runtime */
+#if MONO_SIZEOF_SUNPATH==0
+#error configure failed to discover size of unix socket path
+#endif
+
/*
* startup:
*
_wapi_shared_data[segment]->handles[idx].ref++;
channel_data->open_handles[handle]++;
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION
- ": handle 0x%x ref now %d (%d this process)", handle,
- _wapi_shared_data[segment]->handles[idx].ref,
- channel_data->open_handles[handle]);
-#endif
+ LOGDEBUG ("%s: handle 0x%x ref now %d (%d this process)", __func__, handle,
+ _wapi_shared_data[segment]->handles[idx].ref,
+ channel_data->open_handles[handle]);
}
/*
}
if (channel_data->open_handles[handle] == 0) {
- g_warning(G_GNUC_PRETTY_FUNCTION
- ": unref on %d called when ref was already 0",
- handle);
+ g_warning("%s: unref on %d called when ref was already 0", __func__, handle);
return TRUE;
}
_wapi_shared_data[segment]->handles[idx].ref--;
channel_data->open_handles[handle]--;
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION
- ": handle 0x%x ref now %d (%d this process)", handle,
+ LOGDEBUG ("%s: handle 0x%x ref now %d (%d this process)", __func__, handle,
_wapi_shared_data[segment]->handles[idx].ref,
channel_data->open_handles[handle]);
-#endif
if (_wapi_shared_data[segment]->handles[idx].ref == 0) {
gboolean was_file;
destroy=TRUE;
if (channel_data->open_handles[handle]!=0) {
- g_warning (G_GNUC_PRETTY_FUNCTION ": per-process open_handles mismatch, set to %d, should be 0",
- channel_data->open_handles[handle]);
+ g_warning ("%s: per-process open_handles mismatch, set to %d, should be 0",__func__, channel_data->open_handles[handle]);
}
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": Destroying handle 0x%x",
- handle);
-#endif
+ LOGDEBUG ("%s: Destroying handle 0x%x", __func__, handle);
/* if this was a file handle, save the device and
* inode numbers so we can scan the share info data
(gpointer *)&file_handle,
NULL);
if (ok == FALSE) {
- g_warning (G_GNUC_PRETTY_FUNCTION
- ": error looking up file handle %x",
- handle);
+ g_warning ("%s: error looking up file handle %x", __func__, handle);
} else {
device = file_handle->device;
inode = file_handle->inode;
if(fd == main_sock) {
/* We shouldn't be deleting the daemon's fd */
- g_warning (G_GNUC_PRETTY_FUNCTION ": Deleting daemon fd!");
+ g_warning ("%s: Deleting daemon fd!", __func__);
cleanup ();
exit (-1);
}
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": Removing client fd %d", fd);
-#endif
+ LOGDEBUG ("%s: Removing client fd %d", __func__, fd);
if (channel_data->io_source == 0) {
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": channel already closed for fd %d", fd);
-#endif
+ LOGDEBUG ("%s: channel already closed for fd %d", __func__, fd);
return;
}
handle_count=channel_data->open_handles[i];
for(j=0; j<handle_count; j++) {
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": closing handle 0x%x for client at index %d", i, g_io_channel_unix_get_fd (channel));
-#endif
+ LOGDEBUG ("%s: closing handle 0x%x for client at index %d", __func__, i, g_io_channel_unix_get_fd (channel));
/* Ignore the hint to the client to destroy
* the handle private data
*/
ok = _wapi_lookup_handle (handle, WAPI_HANDLE_FILE,
(gpointer *)&file_handle, NULL);
if (ok == FALSE) {
- g_warning (G_GNUC_PRETTY_FUNCTION
- ": error looking up file handle %p", handle);
+ g_warning ("%s: error looking up file handle %p", __func__, handle);
return(FALSE);
}
if (file_handle->device == sharekey->device &&
file_handle->inode == sharekey->inode) {
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": found one, handle %p",
- handle);
-#endif
+ LOGDEBUG ("%s: found one, handle %p", __func__, handle);
return(TRUE);
} else {
return(FALSE);
ShareKey sharekey;
gpointer file_handle;
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": Checking if anything has (dev 0x%llx, inode %lld) still open", device, inode);
-#endif
+ LOGDEBUG ("%s: Checking if anything has (dev 0x%llx, inode %lld) still open", __func__, device, inode);
sharekey.device = device;
sharekey.inode = inode;
/* Delete this share info, as the last handle to it
* has been closed
*/
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": Deleting share data for (dev 0x%llx inode %lld)", device, inode);
-#endif
+ LOGDEBUG ("%s: Deleting share data for (dev 0x%llx inode %lld)", __func__, device, inode);
g_hash_table_remove (file_share_hash, &sharekey);
}
ok=_wapi_lookup_handle (handle, WAPI_HANDLE_PROCESS,
(gpointer *)&process_handle, NULL);
if(ok==FALSE) {
- g_warning (G_GNUC_PRETTY_FUNCTION
- ": error looking up process handle %p", handle);
+ g_warning ("%s: error looking up process handle %p", __func__, handle);
return(FALSE);
}
ok=_wapi_lookup_handle (handle, WAPI_HANDLE_THREAD,
(gpointer *)&thread_handle, NULL);
if(ok==FALSE) {
- g_warning (G_GNUC_PRETTY_FUNCTION
- ": error looking up thread handle %p", handle);
+ g_warning ("%s: error looking up thread handle %p", __func__, handle);
return(FALSE);
}
* _wapi_handle_set_signal_state() unless we have
* process-shared pthread support.
*/
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": Set thread handle %p signalled, because its process died", handle);
-#endif
+ LOGDEBUG ("%s: Set thread handle %p signalled, because its process died", __func__, handle);
thread_handle->exitstatus=0;
(gpointer *)&process_handle_data,
NULL);
if(process_handle==0) {
-#ifdef DEBUG
/*
* This may happen if we use Process.EnableRaisingEvents +
* process.Exited event and the parent has finished.
*/
- g_warning (G_GNUC_PRETTY_FUNCTION
- ": Couldn't find handle for process %d!", pid);
-#endif
+ LOGDEBUG ("%s: Couldn't find handle for process %d!", __func__, pid);
} else {
/* Signal the handle. Don't use
* _wapi_handle_set_signal_state() unless we have
*/
struct timeval tv;
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION
- ": Set process %d exitstatus to %d", pid,
+ LOGDEBUG ("%s: Set process %d exitstatus to %d", __func__, pid,
WEXITSTATUS (status));
-#endif
/* If the child terminated due to the receipt of a signal,
* the exit status must be based on WTERMSIG, since WEXITSTATUS
check_processes=FALSE;
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": Reaping processes");
-#endif
+ LOGDEBUG ("%s: Reaping processes", __func__);
while(TRUE) {
pid=waitpid (-1, &status, WNOHANG);
return;
} else {
/* pid contains the ID of a dead process */
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": process %d reaped", pid);
-#endif
+ LOGDEBUG ( "%s: process %d reaped", __func__, pid);
process_post_mortem (pid, status);
}
}
ref_handle (channel_data, handle);
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": returning new handle 0x%x",
- handle);
-#endif
+ LOGDEBUG ("%s: returning new handle 0x%x", __func__, handle);
resp.type=WapiHandleResponseType_New;
resp.u.new.type=type;
if(shared->type!=WAPI_HANDLE_UNUSED && handle!=0) {
ref_handle (channel_data, handle);
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION
- ": returning new handle 0x%x", handle);
-#endif
+ LOGDEBUG ("%s: returning new handle 0x%x", __func__, handle);
resp.type=WapiHandleResponseType_Open;
resp.u.new.type=shared->type;
resp.type=WapiHandleResponseType_Close;
resp.u.close.destroy=unref_handle (channel_data, handle);
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": unreffing handle 0x%x", handle);
-#endif
-
+ LOGDEBUG ("%s: unreffing handle 0x%x", __func__, handle);
+
send_reply (channel, &resp);
}
resp.type=WapiHandleResponseType_Scratch;
resp.u.scratch.idx=_wapi_handle_scratch_store_internal (length, &resp.u.scratch.remap);
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": allocating scratch index 0x%x",
- resp.u.scratch.idx);
-#endif
+
+ LOGDEBUG ("%s: allocating scratch index 0x%x", __func__, resp.u.scratch.idx);
send_reply (channel, &resp);
}
resp.type=WapiHandleResponseType_ScratchFree;
_wapi_handle_scratch_delete_internal (scratch_idx);
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": deleting scratch index 0x%x",
- scratch_idx);
-#endif
+ LOGDEBUG ("%s: deleting scratch index 0x%x", __func__, scratch_idx);
send_reply (channel, &resp);
}
resp.type = WapiHandleResponseType_ProcessKill;
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": kill (%d, %d)",
- process_kill.pid, process_kill.signo);
-#endif
+ LOGDEBUG ("%s: kill (%d, %d)", __func__, process_kill.pid, process_kill.signo);
+
if (kill (process_kill.pid, process_kill.signo) == -1) {
resp.u.process_kill.err = errno;
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": kill (%d, %d) failed: %d",
- process_kill.pid, process_kill.signo, resp.u.process_kill.err);
-#endif
+ LOGDEBUG ("%s: kill (%d, %d) failed: %d", __func__, process_kill.pid, process_kill.signo, resp.u.process_kill.err);
}
send_reply (channel, &resp);
*/
process_handle_data->exec_errno=gerr->code;
} else {
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": forking");
-#endif
+ LOGDEBUG ("%s: forking", __func__);
/* Fork, exec cmd with args and optional env,
* and return the handles with pid and blank
}
#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION
- ": exec()ing [%s] in dir [%s]",
- cmd, dir);
+ LOGDEBUG ("%s: exec()ing [%s] in dir [%s]", __func__, cmd, dir);
{
i=0;
while(argv[i]!=NULL) {
- g_message ("arg %d: [%s]",
- i, argv[i]);
+ LOGDEBUG ("arg %d: [%s]", i, argv[i]);
i++;
}
i=0;
while(env[i]!=NULL) {
- g_message ("env %d: [%s]",
- i, env[i]);
+ LOGDEBUG ("env %d: [%s]", i, env[i]);
i++;
}
}
resp.type = WapiHandleResponseType_SetShare;
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": Setting share for file (dev:0x%llx, ino:%lld) mode 0x%x access 0x%x", set_share.device, set_share.inode, set_share.sharemode, set_share.access);
-#endif
+ LOGDEBUG ("%s: Setting share for file (dev:0x%llx, ino:%lld) mode 0x%x access 0x%x", __func__, set_share.device, set_share.inode, set_share.sharemode, set_share.access);
sharemode_set (set_share.device, set_share.inode, set_share.sharemode,
set_share.access);
resp.type = WapiHandleResponseType_GetOrSetShare;
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION
- ": Getting share status for file (dev:0x%llx, ino:%lld)",
- get_share.device, get_share.inode);
-#endif
+ LOGDEBUG ("%s: Getting share status for file (dev:0x%llx, ino:%lld)", __func__, get_share.device, get_share.inode);
resp.u.get_or_set_share.exists = sharemode_get (get_share.device, get_share.inode, &resp.u.get_or_set_share.sharemode, &resp.u.get_or_set_share.access);
if (resp.u.get_or_set_share.exists) {
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": Share mode: 0x%x",
- resp.u.get_or_set_share.sharemode);
-#endif
+ LOGDEBUG ("%s: Share mode: 0x%x", __func__, resp.u.get_or_set_share.sharemode);
} else {
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION
- ": file share info not already known, setting");
-#endif
+ LOGDEBUG ("%s: file share info not already known, setting", __func__);
sharemode_set (get_share.device, get_share.inode,
get_share.new_sharemode, get_share.new_access);
}
fds, &has_fds);
if(ret==0) {
/* Other end went away */
-#ifdef DEBUG
- g_message ("Read 0 bytes on fd %d, closing it",
+ LOGDEBUG ("Read 0 bytes on fd %d, closing it",
g_io_channel_unix_get_fd (channel));
-#endif
rem_fd (channel, channel_data);
return(FALSE);
}
-#ifdef DEBUG
- g_message ("Process request %d", req.type);
-#endif
+ LOGDEBUG ("Process request %d", req.type);
switch(req.type) {
case WapiHandleRequestType_New:
process_new (channel, channel_data, req.u.new.type);
}
if(has_fds==TRUE) {
-#ifdef DEBUG
- g_message (G_GNUC_PRETTY_FUNCTION ": closing %d", fds[0]);
- g_message (G_GNUC_PRETTY_FUNCTION ": closing %d", fds[1]);
- g_message (G_GNUC_PRETTY_FUNCTION ": closing %d", fds[2]);
-#endif
+ LOGDEBUG ("%s: closing %d", __func__, fds[0]);
+ LOGDEBUG ("%s: closing %d", __func__, fds[1]);
+ LOGDEBUG ("%s: closing %d", __func__, fds[2]);
close (fds[0]);
close (fds[1]);
GMainContext *context=data;
if(condition & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
-#ifdef DEBUG
- g_message ("fd %d error", fd);
-#endif
-
+ LOGDEBUG ("fd %d error", fd);
rem_fd (channel, channel_data);
return(FALSE);
}
- if(condition & (G_IO_IN | G_IO_PRI)) {
+ if(condition & (_IO_PRI)) {
if(fd==main_sock) {
int newsock;
struct sockaddr addr;
newsock=accept (main_sock, &addr, &addrlen);
if(newsock==-1) {
- g_critical ("accept error: %s",
- g_strerror (errno));
+ g_critical ("%s accept error: %s", __func__, g_strerror (errno));
cleanup ();
exit (-1);
}
-#ifdef DEBUG
- g_message ("accept returning %d", newsock);
-#endif
-
+ LOGDEBUG ("accept returning %d", newsock);
add_fd (newsock, context);
} else {
-#ifdef DEBUG
- g_message ("reading data on fd %d", fd);
-#endif
+ LOGDEBUG ("reading data on fd %d", fd);
return(read_message (channel, channel_data));
}
int ret;
GMainContext *context;
-#ifdef DEBUG
- g_message ("Starting up...");
-#endif
+ LOGDEBUG ("Starting up...");
_wapi_shared_data[0]=data;
_wapi_shared_scratch=scratch;
exit(-1);
}
-#ifdef DEBUG
- g_message("bound");
-#endif
+ LOGDEBUG("bound");
ret=listen(main_sock, 5);
if(ret==-1) {
_wapi_shared_data[0]->daemon_running=DAEMON_DIED_AT_STARTUP;
exit(-1);
}
-
-#ifdef DEBUG
- g_message("listening");
-#endif
+ LOGDEBUG("listening");
context = g_main_context_new ();
process_died ();
}
-#ifdef DEBUG
- g_message ("polling");
-#endif
+ LOGDEBUG ("polling");
/* Block until something happens. We don't use
* g_main_loop_run() because we rely on the SIGCHLD