Merging the savefile branch. I hope it works; I even don't remember it. default tip
authorLluís Batlle <viric@viric.name>
Thu, 20 Mar 2014 16:33:27 +0100
changeset 97 eea77d5a624c
parent 93 7d9b7a6da507 (current diff)
parent 96 d090ddac5131 (diff)
Merging the savefile branch. I hope it works; I even don't remember it.
--- a/Makefile	Thu Aug 21 23:21:22 2008 +0200
+++ b/Makefile	Thu Mar 20 16:33:27 2014 +0100
@@ -32,7 +32,7 @@
 	$(INSTALL) tm $(PREFIX)/bin
 
 tm: $(OBJECTS)
-	$(CC) -o $@ $(LINUX_LIBS) $^
+	$(CC) -o $@ $^ $(LINUX_LIBS)
 
 test_filter: test_filter.o filter.o simple_math.o filter_string.o error.o
 
--- a/app_control.c	Thu Aug 21 23:21:22 2008 +0200
+++ b/app_control.c	Thu Mar 20 16:33:27 2014 +0100
@@ -19,6 +19,8 @@
 
 static struct FilterRules *fr;
 
+int savefile = -1;
+
 void write_newline_cb(struct FilterRules *myfr,
         const struct FFilter *ff, char *obuf, int *olen,
         const char *ibuf, int pos)
@@ -107,6 +109,8 @@
             if (command_line.s_param.serve_eth)
                 s_eth_send_to_connected(stream_buffer, res);
 #endif /* linux */
+            if (savefile != -1)
+                write(savefile, stream_buffer, res);
         }
     }
     if (app_stderr != -1 && app_stdout != app_stderr &&
@@ -155,6 +159,8 @@
     {
         hex_dump("from local to app", buffer, size);
         write(app_stdin, buffer, size);
+        if (savefile != -1)
+            write(savefile, buffer, size);
     }
 }
 
@@ -167,6 +173,8 @@
                 command_line.s_param.echo_in_local_terminal)
             write(1, buffer, size);
         write(app_stdin, buffer, size);
+        if (savefile != -1)
+            write(savefile, buffer, size);
     }
 }
 
--- a/main.c	Thu Aug 21 23:21:22 2008 +0200
+++ b/main.c	Thu Mar 20 16:33:27 2014 +0100
@@ -55,6 +55,7 @@
 #ifdef linux
     printf(" -e dev[:port] Also serve/connect using raw ethernet, device 'dev'.\n");
     printf(" -c adr Connect to address (MAC if eth).\n");
+    printf(" -s fil Save the child stdin/stdout to the filename 'fil'.\n");
 #endif /* linux */
     printf(" -x     Send xterm's resize control string to clients.\n");
     return 0;
@@ -112,6 +113,7 @@
     command_line.s_param.echo_in_local_terminal = 0;
     command_line.s_param.send_xterm_resize = 0;
     command_line.s_param.serve_eth = 0;
+    command_line.s_param.savefile = 0;
 
     command_line.tcp_port = 40000; /* Arbitrary */
     command_line.eth_port = 100;   /* Arbitrary */
@@ -132,7 +134,7 @@
     extern int optind, opterr, optopt;
 
     while(1) {
-        c = my_getopt(argc, argv, "tp:nBxdPN:hwCED"
+        c = my_getopt(argc, argv, "s:tp:nBxdPN:hwCED"
 #ifdef linux
                 "c:e:"
 #endif /* linux */
@@ -192,6 +194,9 @@
                 parse_eth_device(optarg);
                 command_line.c_param.transport = ETHERNET;
                 break;
+            case 's':
+                command_line.s_param.savefile = strdup(optarg);
+                break;
             case '?':
                 error("Wrong option %c.\n", optopt);
         }
--- a/main.h	Thu Aug 21 23:21:22 2008 +0200
+++ b/main.h	Thu Mar 20 16:33:27 2014 +0100
@@ -23,6 +23,7 @@
         char client_may_close_app_stdin;
         char client_can_write;
         char nohup; /* detach from terminal as nohup */
+        char *savefile;
         char **command; /* ordono por exec */
     } s_param;
     struct {
--- a/server.c	Thu Aug 21 23:21:22 2008 +0200
+++ b/server.c	Thu Mar 20 16:33:27 2014 +0100
@@ -12,6 +12,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <string.h>
+#include <fcntl.h>
 
 #include "main.h"
 #include "handlers.h"
@@ -19,6 +20,9 @@
 /* signals.c */
 extern int child_died;
 
+/* app_control.c */
+extern int savefile;
+
 /*extern*/
 void fdset_dump(fd_set *set, int maxfd);
 
@@ -143,6 +147,12 @@
         s_eth_init();
 #endif /* linux */
 
+    if (command_line.s_param.savefile)
+    {
+        savefile = open(command_line.s_param.savefile,
+                O_CREAT | O_TRUNC | O_RDWR, 0666);
+    }
+
     child = fork_app(command_line.s_param.command);
 
     if (command_line.s_param.nohup)