aboutsummaryrefslogtreecommitdiffstats
path: root/daemon/mutatorserver.c
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2017-03-05 14:19:21 +0000
committerbloodstalker <thabogre@gmail.com>2017-03-05 14:19:21 +0000
commit8909daf1fab3a6b976b6ebbc0682febe67aeb9ab (patch)
tree23b1c5feb8f09c91ee589f633a55b72a58cae835 /daemon/mutatorserver.c
parentgeneral fixes (diff)
downloadmutator-8909daf1fab3a6b976b6ebbc0682febe67aeb9ab.tar.gz
mutator-8909daf1fab3a6b976b6ebbc0682febe67aeb9ab.zip
now the server sends something when the client snds a bad command so the client wont hang.
Diffstat (limited to '')
-rw-r--r--daemon/mutatorserver.c34
1 files changed, 33 insertions, 1 deletions
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");