[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r28514 - msh/src
From: |
gnunet |
Subject: |
[GNUnet-SVN] r28514 - msh/src |
Date: |
Mon, 12 Aug 2013 11:39:27 +0200 |
Author: harsha
Date: 2013-08-12 11:39:27 +0200 (Mon, 12 Aug 2013)
New Revision: 28514
Modified:
msh/src/mshd-server.c
msh/src/mshd.c
msh/src/mshd_pmonitor.c
Log:
- fixes
Modified: msh/src/mshd-server.c
===================================================================
--- msh/src/mshd-server.c 2013-08-11 23:46:26 UTC (rev 28513)
+++ msh/src/mshd-server.c 2013-08-12 09:39:27 UTC (rev 28514)
@@ -477,6 +477,8 @@
{
struct ClientCtx *ctx;
+ if (NULL == client) /* Server shutting down */
+ return;
ctx = GNUNET_malloc (sizeof (struct ClientCtx ));
ctx->client = client;
GNUNET_SERVER_client_set_user_context (client, ctx);
@@ -527,7 +529,11 @@
void
shutdown_local_server ()
{
- GNUNET_SERVER_destroy (local_serv);
+ if (NULL != local_serv)
+ {
+ GNUNET_SERVER_destroy (local_serv);
+ local_serv = NULL;
+ }
}
@@ -820,5 +826,9 @@
void
shutdown_daemon_server ()
{
- GNUNET_SERVER_destroy (daemon_serv);
+ if (NULL != daemon_serv)
+ {
+ GNUNET_SERVER_destroy (daemon_serv);
+ daemon_serv = NULL;
+ }
}
Modified: msh/src/mshd.c
===================================================================
--- msh/src/mshd.c 2013-08-11 23:46:26 UTC (rev 28513)
+++ msh/src/mshd.c 2013-08-12 09:39:27 UTC (rev 28514)
@@ -239,6 +239,11 @@
static char *unixpath;
/**
+ * shutdown task
+ */
+GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
+
+/**
* Random hashcode for authentication
*/
struct GNUNET_HashCode shash;
@@ -260,6 +265,22 @@
/**
+ * Perform cleanup for shutdown
+ *
+ * @param cls NULL
+ * @param tc scheduler task context
+ */
+static void
+do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ shutdown_task = GNUNET_SCHEDULER_NO_TASK;
+ shutdown_local_server ();
+ shutdown_daemon_server ();
+ MSH_pmonitor_shutdown ();
+}
+
+
+/**
* Callback function invoked for each interface found.
*
* @param cls closure
@@ -395,6 +416,24 @@
/**
+ * Callbacks of this type can be supplied to MSH_monitor_process() to be
+ * notified when the corresponding processes exits.
+ *
+ * @param cls the closure passed to MSH_monitor_process()
+ * @param type the process status type
+ * @param long the return/exit code of the process
+ */
+static void
+proc_exit_cb (void *cls, enum GNUNET_OS_ProcessStatusType type, int code)
+{
+ GNUNET_OS_process_destroy (proc);
+ proc = NULL;
+ LOG (GNUNET_ERROR_TYPE_INFO, "Main process died. Exiting.\n");
+ GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
* Task for running a round
*
* @param cls NULL
@@ -431,11 +470,14 @@
pid = (intmax_t) getpid ();
dtemp = GNUNET_DISK_mkdtemp ("mshd");
GNUNET_assert (NULL != dtemp);
- GNUNET_assert (0 < asprintf (&unixpath, "%s/%j.sock", dtemp, pid));
+ GNUNET_assert (0 < asprintf (&unixpath, "%s/%ju.sock", dtemp, pid));
GNUNET_free (dtemp);
init_local_server (unixpath);
init_daemon_server (listen_socket);
listen_socket = NULL;
+ MSH_pmonitor_init ();
+ shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &do_shutdown, NULL);
if (0 == rank)
{
setenv (MSHD_SOCK_NAME, unixpath, 1);
@@ -451,6 +493,7 @@
GNUNET_SCHEDULER_shutdown ();
return;
}
+ MSH_monitor_process (proc, &proc_exit_cb, NULL);
}
}
@@ -794,7 +837,7 @@
width = (nproc - 1) % rwidth;
cpys = NULL;
cpys = GNUNET_malloc (msize * width);
- sreqs = GNUNET_malloc (width);
+ sreqs = GNUNET_malloc (width * sizeof (MPI_Request));
for (cnt=0; cnt < width; cnt++)
{
(void) memcpy (&cpys[cnt], msg, msize);
@@ -1052,15 +1095,16 @@
addressmap_destroy (addrmap);
if (NULL != rmap)
reverse_map_destroy (rmap);
- GNUNET_break (MPI_SUCCESS == MPI_Finalize());
GNUNET_free_non_null (s_addrs);
if (NULL != run_args)
free_argv (run_args);
if (NULL != unixpath)
{
- (void) unlink (unixpath);
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_DISK_directory_remove (dirname (unixpath)));
GNUNET_free (unixpath);
}
LOG_DEBUG ("Returning\n");
+ GNUNET_break (MPI_SUCCESS == MPI_Finalize());
return ret;
}
Modified: msh/src/mshd_pmonitor.c
===================================================================
--- msh/src/mshd_pmonitor.c 2013-08-11 23:46:26 UTC (rev 28513)
+++ msh/src/mshd_pmonitor.c 2013-08-12 09:39:27 UTC (rev 28514)
@@ -125,6 +125,7 @@
goto resume;
cb = ctx->cb;
cb_cls = ctx->cls;
+ GNUNET_CONTAINER_multihashmap32_remove (map, (uint32_t) cid, ctx);
GNUNET_free (ctx);
resume:
@@ -172,6 +173,8 @@
GNUNET_assert (NULL != (shc_chld = GNUNET_SIGNAL_handler_install
(GNUNET_SIGCHLD, &sighandler_child_death)));
pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
+ map = GNUNET_CONTAINER_multihashmap32_create (10);
+ GNUNET_assert (NULL != map);
child_death_task_id =
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
pr, &child_death_task, NULL);
@@ -193,14 +196,13 @@
cleanup_iterator (void *cls, uint32_t key, void *value)
{
struct MonitorCtx *ctx = value;
- pid_t pid;
- pid = GNUNET_OS_process_get_pid (ctx->proc);
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multihashmap32_remove (map,
- (uint32_t) pid,
+ key,
ctx));
GNUNET_free (ctx);
+ return GNUNET_YES;
}
@@ -211,10 +213,13 @@
MSH_pmonitor_shutdown ()
{
/* fixme clear monitoring contexts */
+ GNUNET_assert (NULL != map);
GNUNET_break (GNUNET_SYSERR !=
GNUNET_CONTAINER_multihashmap32_iterate (map,
&cleanup_iterator,
NULL));
+ GNUNET_CONTAINER_multihashmap32_destroy (map);
+ map = NULL;
GNUNET_assert (NULL != sigpipe);
GNUNET_assert (NULL != shc_chld);
if (GNUNET_SCHEDULER_NO_TASK != child_death_task_id)
@@ -246,6 +251,7 @@
GNUNET_assert (NULL != map);
pid = GNUNET_OS_process_get_pid (proc);
+ ctx = GNUNET_malloc (sizeof (struct MonitorCtx));
ctx->proc = proc;
ctx->cb = cb;
ctx->cls = cls;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r28514 - msh/src,
gnunet <=