[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r28624 - msh/src
From: |
gnunet |
Subject: |
[GNUnet-SVN] r28624 - msh/src |
Date: |
Wed, 14 Aug 2013 16:59:18 +0200 |
Author: harsha
Date: 2013-08-14 16:59:17 +0200 (Wed, 14 Aug 2013)
New Revision: 28624
Modified:
msh/src/mshd-server.c
msh/src/mshd.c
msh/src/mshd_pmonitor.h
Log:
- fix subprocess pipes by making them blocking for the subprocess
Modified: msh/src/mshd-server.c
===================================================================
--- msh/src/mshd-server.c 2013-08-14 14:38:03 UTC (rev 28623)
+++ msh/src/mshd-server.c 2013-08-14 14:59:17 UTC (rev 28624)
@@ -152,11 +152,6 @@
struct GNUNET_SERVER_Client *client;
/**
- * The server to which this client has connected to
- */
- //struct GNUNET_SERVER_Handle *serv;
-
- /**
* the transmission handle
*/
struct GNUNET_SERVER_TransmitHandle *tx;
@@ -203,6 +198,7 @@
}
if (NULL != ctx->proc)
{
+ MSH_monitor_process_cancel (ctx->proc);
GNUNET_OS_process_destroy (ctx->proc); /* we leave the processes running */
}
GNUNET_DISK_file_close (ctx->fin);
@@ -227,10 +223,9 @@
{
struct MessageQueue *mq;
- GNUNET_SERVER_client_drop (ctx->client);
- GNUNET_SERVER_client_disconnect (ctx->client);
if (NULL != ctx->tx)
GNUNET_SERVER_notify_transmit_ready_cancel (ctx->tx);
+ GNUNET_SERVER_client_drop (ctx->client);
while (NULL != (mq = ctx->mq_head))
{
GNUNET_free (mq->msg);
@@ -523,7 +518,13 @@
}
-
+/**
+ * Initialise the local server
+ *
+ * @param unixpath the name to use while opening the abstract UNIX domain
socket
+ * for listening
+ * @return GNUNET_OK upon success; GNUNET_SYSERR upon failure
+ */
int
init_local_server (const char *unixpath)
{
@@ -565,6 +566,9 @@
}
+/**
+ * Shutdown the local server
+ */
void
shutdown_local_server ()
{
@@ -658,31 +662,41 @@
/**
* Task to read the output from a process and send it to client
*
- * @param cls the execution context
+ * @param cls the client context
* @param tc scheduler task context
*/
static void
read_fout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- struct ExecCtx *ctx = cls;
+ struct ClientCtx *ctx = cls;
+ struct ExecCtx *exec_ctx = ctx->exec_ctx;
struct MSH_MSG_CmdIO *msg;
static char data[MAX_IO_DATA];
ssize_t size;
uint16_t msize;
- ctx->fout_task = GNUNET_SCHEDULER_NO_TASK;
+ exec_ctx->fout_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
{
return;
}
- size = GNUNET_DISK_file_read_non_blocking (ctx->fout, data, MAX_IO_DATA);
- GNUNET_assert (size > 0);
+ size = GNUNET_DISK_file_read_non_blocking (exec_ctx->fout, data,
MAX_IO_DATA);
+ if (size <= 0)
+ {
+ GNUNET_break (GNUNET_SYSERR != size);
+ GNUNET_SERVER_client_disconnect (ctx->client);
+ destroy_client_ctx (ctx);
+ return;
+ }
msize = size + sizeof (struct MSH_MSG_CmdIO);
msg = GNUNET_malloc (msize);
msg->header.type = htons (MSH_MTYPE_CMD_STREAM_STDOUT);
msg->header.size = htons (msize);
memcpy (msg->data, data, size);
- queue_message (ctx->client_ctx, &msg->header, GNUNET_NO);
+ queue_message (ctx, &msg->header, GNUNET_NO);
+ exec_ctx->fout_task =
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
+ exec_ctx->fout, &read_fout, ctx);
}
@@ -704,7 +718,8 @@
LOG_DEBUG ("Command `%s' exited.\n", exec_ctx->args[0]);
GNUNET_OS_process_destroy (exec_ctx->proc);
exec_ctx->proc = NULL;
- destroy_client_ctx (ctx);
+ GNUNET_SCHEDULER_cancel (exec_ctx->fout_task);
+ exec_ctx->fout_task = GNUNET_SCHEDULER_add_now (&read_fout, ctx);
}
@@ -715,13 +730,13 @@
* @return GNUNET_OK upon success; GNUNET_SYSERR upon failure
*/
static int
-exec_proc (struct ExecCtx *ctx)
+proc_exec (struct ExecCtx *ctx)
{
struct GNUNET_DISK_PipeHandle *pin;
struct GNUNET_DISK_PipeHandle *pout;
- pin = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, 0, 0);
- pout = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_NO, 0, 0);
+ pin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, 0, 0);
+ pout = GNUNET_DISK_pipe (GNUNET_NO, GNUNET_YES, 0, 0);
GNUNET_assert ((NULL != pin && (NULL != pout)));
ctx->proc = GNUNET_OS_start_process_vap (GNUNET_NO,
GNUNET_OS_INHERIT_STD_NONE,
@@ -739,7 +754,7 @@
GNUNET_assert (GNUNET_OK == GNUNET_DISK_pipe_close (pout));
ctx->fout_task =
GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- ctx->fout, read_fout, ctx);
+ ctx->fout, &read_fout, ctx->client_ctx);
return GNUNET_OK;
}
@@ -748,7 +763,7 @@
* Functions with this signature are called whenever a message is
* received.
*
- * @param cls closure
+ * @param cls NULL
* @param client identification of the client
* @param message the actual message
*/
@@ -784,7 +799,9 @@
GNUNET_break (0);
goto err_ret;
}
- if (GNUNET_OK != exec_proc (exec_ctx))
+ GNUNET_SCHEDULER_cancel (exec_ctx->timeout_task);
+ exec_ctx->timeout_task = GNUNET_SCHEDULER_NO_TASK;
+ if (GNUNET_OK != proc_exec (exec_ctx))
{
GNUNET_break (0);
goto err_ret;
@@ -937,6 +954,13 @@
}
+/**
+ * Timeout task for timing out connections until they authenticate. Once
+ * authenticated the connection will not be timed out.
+ *
+ * @param cls the client context
+ * @param tc scheduler task context
+ */
static void
timeout_cb (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
@@ -947,8 +971,12 @@
destroy_client_ctx (ctx);
}
-static unsigned int conn_cnt;
+/**
+ * Create a client for the daemon server from a new client connection
+ *
+ * @param conn the connection to derive the client from
+ */
void
daemon_server_add_connection (struct GNUNET_CONNECTION_Handle *conn,
int conn_fd)
@@ -956,21 +984,24 @@
struct ClientCtx *ctx;
struct ExecCtx *exec_ctx;
- conn_cnt++;
ctx = GNUNET_malloc (sizeof (struct ClientCtx));
exec_ctx = GNUNET_malloc (sizeof (struct ExecCtx));
exec_ctx->client_ctx = ctx;
ctx->exec_ctx = exec_ctx;
-
exec_ctx->conn_fd = conn_fd;
ctx->client = GNUNET_SERVER_connect_socket (daemon_serv, conn);
GNUNET_SERVER_client_set_user_context (ctx->client, ctx);
exec_ctx->timeout_task =
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &timeout_cb,
ctx);
+ GNUNET_SCHEDULER_add_delayed
+ (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30),
+ &timeout_cb, ctx);
}
+/**
+ * Shutdown the daemon server
+ */
void
shutdown_daemon_server ()
{
@@ -980,3 +1011,5 @@
daemon_serv = NULL;
}
}
+
+/* End of mshd-server.c */
Modified: msh/src/mshd.c
===================================================================
--- msh/src/mshd.c 2013-08-14 14:38:03 UTC (rev 28623)
+++ msh/src/mshd.c 2013-08-14 14:59:17 UTC (rev 28624)
@@ -367,7 +367,6 @@
atask = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
{
- GNUNET_break (0);
goto clo_ret;
}
switch (listen_mode)
Modified: msh/src/mshd_pmonitor.h
===================================================================
--- msh/src/mshd_pmonitor.h 2013-08-14 14:38:03 UTC (rev 28623)
+++ msh/src/mshd_pmonitor.h 2013-08-14 14:59:17 UTC (rev 28624)
@@ -4,6 +4,9 @@
* @author Sree Harsha Totakura <address@hidden>
*/
+#ifndef MSHD_PMONITOR_H_
+#define MSHD_PMONITOR_H_
+
#include <gnunet/gnunet_os_lib.h>
/**
@@ -46,3 +49,18 @@
void
MSH_monitor_process (struct GNUNET_OS_Process *proc,
MSH_ProcExitCallback cb, void *cls);
+
+
+/**
+ * Stop monitoring a process
+ *
+ * @param proc
+ * @return GNUNET_OK upon success; GNUNET_SYSERR if the process is not being
+ * monitored earlier
+ */
+int
+MSH_monitor_process_cancel (struct GNUNET_OS_Process *proc);
+
+#endif /* MSHD_PMONITOR_H_ */
+
+/* End of mshd_pmonitor.h */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r28624 - msh/src,
gnunet <=