aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--daemon/mutatorclient.c30
-rw-r--r--daemon/mutatorserver.c34
2 files changed, 60 insertions, 4 deletions
diff --git a/daemon/mutatorclient.c b/daemon/mutatorclient.c
index 5686783..b60c02d 100644
--- a/daemon/mutatorclient.c
+++ b/daemon/mutatorclient.c
@@ -19,6 +19,12 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/
/**********************************************************************************************************************/
+/*macros*/
+#define __DBG
+#if 0
+#undef __DBG
+#endif
+/**********************************************************************************************************************/
/*inclusion directive*/
#include "mutatorclient.h"
/*standard header libraries*/
@@ -34,6 +40,7 @@ int main(int argc, char *argv[])
struct sockaddr_in server;
char message[1000];
char server_reply[2000];
+ int recvlength;
/*create socket*/
sock = socket(AF_INET, SOCK_STREAM, 0);
@@ -87,15 +94,32 @@ int main(int argc, char *argv[])
sleep(1);
fflush(stdin);
+#if defined(__DBG)
+ puts("checkpoint 1");
+#endif
+
/*recieve a reply from the server*/
- if (recv(sock, server_reply, 2000, 0) < 0)
+ recvlength = recv(sock, server_reply, 2000, 0);
+
+#if defined(__DBG)
+ puts("checkpoint 2");
+#endif
+
+ if (recvlength < 0)
{
puts("recv failed.");
break;
}
+ else if (recvlength == 0)
+ {
+ puts("server sent no output.");
+ }
+ else
+ {
+ puts("server reply: ");
+ puts(server_reply);
+ }
- puts("server reply: ");
- puts(server_reply);
for (int i = 0; i < 2000; ++i)
{
diff --git a/daemon/mutatorserver.c b/daemon/mutatorserver.c
index bc683f8..331bd58 100644
--- a/daemon/mutatorserver.c
+++ b/daemon/mutatorserver.c
@@ -19,6 +19,12 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/
/**********************************************************************************************************************/
+/*macros*/
+#define __DBG
+#if 0
+#undef __DBG
+#endif
+/**********************************************************************************************************************/
/*inclusion directive*/
#include "mutatorserver.h"
/*standard headers*/
@@ -36,6 +42,7 @@ int main (int argc, char *argv[])
char client_message[2000];
FILE* clientistream;
char runresponse[4000];
+ char NOOUT[]="command did not return any output. could be an error or not.";
/*create socket*/
socket_desc = socket(AF_INET, SOCK_STREAM, 0);
@@ -81,8 +88,12 @@ int main (int argc, char *argv[])
{
fflush(stdin);
+ puts("got command from client.");
+
/*open pipe, run command*/
- if (!(clientistream = popen(client_message, "r")))
+ clientistream = popen(client_message, "r");
+
+ if (clientistream == NULL)
{
perror("client command did not run successfully.");
}
@@ -93,17 +104,38 @@ int main (int argc, char *argv[])
client_message[i] = 0;
}
+ if (fgets(runresponse, sizeof(runresponse), clientistream) == NULL)
+ {
+ /*say there was nothing on stdout to send.*/
+ write(client_sock, NOOUT, strlen(NOOUT));
+ }
+
+ rewind(clientistream);
+
while (fgets(runresponse, sizeof(runresponse), clientistream) != NULL)
{
+#if defined(__DBG)
+ puts("command stdout:");
+ puts(runresponse);
+#endif
write(client_sock, runresponse, strlen(runresponse));
}
+
puts("response sent to client.");
fflush(stdout);
/*close pipe*/
pclose(clientistream);
+
+#if defined(__DBG)
+ puts("checkpoint 1");
+#endif
}
+#if defined(__DBG)
+ puts("checkpoint 10");
+#endif
+
if (read_size == 0)
{
puts("client disconnected");