gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r32481 - msh/src


From: gnunet
Subject: [GNUnet-SVN] r32481 - msh/src
Date: Wed, 26 Feb 2014 15:09:56 +0100

Author: harsha
Date: 2014-02-26 15:09:56 +0100 (Wed, 26 Feb 2014)
New Revision: 32481

Modified:
   msh/src/msh.c
   msh/src/mtypes.h
   msh/src/server.c
Log:
Use different messages for STDOUT and STDERR streams.

Note that STDOUT, STDERR for child processes are still muxed together when a
pseudto-tty is allocated.



Modified: msh/src/msh.c
===================================================================
--- msh/src/msh.c       2014-02-26 14:07:09 UTC (rev 32480)
+++ msh/src/msh.c       2014-02-26 14:09:56 UTC (rev 32481)
@@ -109,6 +109,11 @@
 static struct GNUNET_DISK_FileHandle *fh_stdout;
 
 /**
+ * file handle for stdout
+ */
+static struct GNUNET_DISK_FileHandle *fh_stderr;
+
+/**
  * The command string (cmd + parameters)
  */
 static char *cmdstr;
@@ -277,6 +282,10 @@
   }
   if (NULL != fh_stdin)
     GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh_stdin));
+  if (NULL != fh_stdout)
+    GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh_stdout));
+  if (NULL != fh_stderr)
+    GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (fh_stderr));
 }
 
 
@@ -442,9 +451,12 @@
 {
   const struct MSH_MSG_CmdIO *msg;
   uint16_t size;
+  uint16_t mtype;
 
   msg = (const struct MSH_MSG_CmdIO *) msg_;
-  if (MSH_MTYPE_CMD_STREAM_STDOUT != ntohs (msg->header.type))
+  mtype = ntohs (msg->header.type);
+  if ( (MSH_MTYPE_CMD_STREAM_STDOUT != mtype)
+       && (MSH_MTYPE_CMD_STREAM_STDERR != mtype) )
   {
     GNUNET_break (0);
     GNUNET_SCHEDULER_shutdown ();
@@ -452,7 +464,19 @@
   }
   size = ntohs (msg->header.size);
   size -= sizeof (struct MSH_MSG_CmdIO);
-  GNUNET_break (size ==  GNUNET_DISK_file_write (fh_stdout, msg->data, size));
+  switch (mtype)
+  {
+  case MSH_MTYPE_CMD_STREAM_STDOUT:
+    GNUNET_break (size ==  GNUNET_DISK_file_write (fh_stdout, msg->data, 
size));
+    break;
+  case MSH_MTYPE_CMD_STREAM_STDERR:
+    if (NULL == fh_stderr)
+      break;
+    GNUNET_break (size == GNUNET_DISK_file_write (fh_stderr, msg->data, size));
+    break;
+  default:
+    GNUNET_assert (0);
+  }
   return GNUNET_OK;
 }
 
@@ -472,6 +496,7 @@
   LOG (GNUNET_ERROR_TYPE_INFO, "Executing remote command\n");
   fh_stdin = GNUNET_DISK_get_handle_from_native (stdin);
   fh_stdout = GNUNET_DISK_get_handle_from_native (stdout);
+  fh_stderr = GNUNET_DISK_get_handle_from_native (stderr);
   GNUNET_assert (NULL != fh_stdin);
   GNUNET_assert (NULL != fh_stdout);
   state = STATE_FORWARD_STREAMS;
@@ -735,6 +760,7 @@
     ret = handle_exec_begin (ctx, msg);
     break;
   case MSH_MTYPE_CMD_STREAM_STDOUT:
+  case MSH_MTYPE_CMD_STREAM_STDERR:
     ret = handle_cmd_output (ctx, msg);
     break;
   default:

Modified: msh/src/mtypes.h
===================================================================
--- msh/src/mtypes.h    2014-02-26 14:07:09 UTC (rev 32480)
+++ msh/src/mtypes.h    2014-02-26 14:09:56 UTC (rev 32481)
@@ -135,7 +135,9 @@
 
 #define MSH_MTYPE_SESSION_OPEN 209
 
+#define MSH_MTYPE_CMD_STREAM_STDERR 210
 
+
 /***********************/
 /* MSH waiter messages */
 /***********************/

Modified: msh/src/server.c
===================================================================
--- msh/src/server.c    2014-02-26 14:07:09 UTC (rev 32480)
+++ msh/src/server.c    2014-02-26 14:09:56 UTC (rev 32481)
@@ -516,11 +516,13 @@
  *
  * @param fd the file handler for the stream to redirect to the client
  * @param client the client to send to
+ * @param mtype the type denoting the stream (STDOUT/STDERR) of the fd
  * @return GNUNET_OK upon success; GNUNET_SYSERR upon error
  */
 static int
 redirect_stream (struct GNUNET_DISK_FileHandle *fd,
-                 struct GNUNET_SERVER_Client *client)
+                 struct GNUNET_SERVER_Client *client,
+                 uint16_t mtype)
 {
 
   struct MSH_MSG_CmdIO *msg;
@@ -534,7 +536,7 @@
     return GNUNET_SYSERR;
   msize = size + sizeof (struct MSH_MSG_CmdIO);
   msg = GNUNET_malloc (msize);
-  msg->header.type = htons (MSH_MTYPE_CMD_STREAM_STDOUT);
+  msg->header.type = htons (mtype);
   msg->header.size = htons (msize);
   memcpy (msg->data, data, size);
   GNUNET_SERVER_notification_context_unicast (daemon_serv_nc, client,
@@ -558,7 +560,8 @@
   if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
     return;
   if (GNUNET_SYSERR == redirect_stream (exec_ctx->fout,
-                                        exec_ctx->client))
+                                        exec_ctx->client,
+                                        MSH_MTYPE_CMD_STREAM_STDOUT))
   {
     if (GNUNET_SCHEDULER_NO_TASK == exec_ctx->ferr_task)
       GNUNET_SERVER_client_disconnect (exec_ctx->client);
@@ -585,7 +588,8 @@
   if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
     return;
   if (GNUNET_SYSERR == redirect_stream (exec_ctx->ferr,
-                                        exec_ctx->client))
+                                        exec_ctx->client,
+                                        MSH_MTYPE_CMD_STREAM_STDERR))
   {
     if (GNUNET_SCHEDULER_NO_TASK == exec_ctx->fout_task)
       GNUNET_SERVER_client_disconnect (exec_ctx->client);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]