Fixing a few bugs. The program runs well in Linux and Mac OS X.
authorviric@llimona
Wed, 26 Sep 2007 23:44:20 +0200
changeset 49 1cead94cfd99
parent 48 ffea64c65751
child 50 2c88b9d375d7
Fixing a few bugs. The program runs well in Linux and Mac OS X.
Makefile
app_control.c
app_term.c
client.c
main.c
server.c
signals.c
user_term.c
--- a/Makefile	Wed Sep 26 23:43:55 2007 +0200
+++ b/Makefile	Wed Sep 26 23:44:20 2007 +0200
@@ -1,5 +1,12 @@
 CC=gcc
 CFLAGS=-g -Wall -O0
+ifeq ($(shell uname),Linux)
+LINUX_OBJECTS=eth_linux.o \
+	eth_proto.o \
+	eth_server.o \
+	eth_client.o
+LINUX_LIBS=-lutil
+endif
 OBJECTS=main.o unix_client.o unix_server.o error.o signals.o gen_sockets.o \
 	app_control.o \
 	client.o \
@@ -13,18 +20,14 @@
 	dump.o \
 	filter.o \
 	filter_string.o \
-	filter_telnet.o \
-	eth_linux.o \
-	eth_proto.o \
-	eth_server.o \
-	eth_client.o
+	filter_telnet.o $(LINUX_OBJECTS)
 
-all: tm test_filter
+all: tm
 
 tm: $(OBJECTS)
-	$(CC) -o $@ -lutil $^
+	$(CC) -o $@ $(LINUX_LIBS) $^
 
-test_filter: test_filter.o filter.o simple_math.o filter_string.o
+test_filter: test_filter.o filter.o simple_math.o filter_string.o error.o
 
 clean:
 	rm -f $(OBJECTS) stdinmix
--- a/app_control.c	Wed Sep 26 23:43:55 2007 +0200
+++ b/app_control.c	Wed Sep 26 23:44:20 2007 +0200
@@ -83,9 +83,9 @@
             close(app_stdout);
             if (!command_line.s_param.nohup)
                 close(1);
-            app_stdout = -1;
             if (app_stdout == app_stderr || app_stderr == -1)
                 return -1;
+            app_stdout = -1;
         } else
         {
             hex_dump("from app", stream_buffer, res);
@@ -95,8 +95,10 @@
                 s_unix_send_to_connected(stream_buffer, res);
             if (command_line.s_param.serve_tcp)
                 s_tcp_send_to_connected(stream_buffer, res);
+#ifdef linux
             if (command_line.s_param.serve_eth)
                 s_eth_send_to_connected(stream_buffer, res);
+#endif /* linux */
         }
     }
     if (app_stderr != -1 && app_stdout != app_stderr &&
@@ -120,8 +122,10 @@
                 s_unix_send_to_connected(stream_buffer, res);
             if (command_line.s_param.serve_tcp)
                 s_tcp_send_to_connected(stream_buffer, res);
+#ifdef linux
             if (command_line.s_param.serve_eth)
                 s_eth_send_to_connected(stream_buffer, res);
+#endif /* linux */
         }
     }
     return 0;
--- a/app_term.c	Wed Sep 26 23:43:55 2007 +0200
+++ b/app_term.c	Wed Sep 26 23:44:20 2007 +0200
@@ -6,7 +6,11 @@
 #include <sys/select.h>
 #include <sys/ioctl.h>
 #include <termios.h>
-#include <pty.h>
+#ifdef __APPLE__
+  #include <util.h>
+#else
+  #include <pty.h>
+#endif
 
 #include "main.h"
 
@@ -122,7 +126,6 @@
 
             if (command_line.s_param.run_in_subterminal)
             {
-                int pid;
                 int res;
                 res = setsid();
                 if (res < 0)
--- a/client.c	Wed Sep 26 23:43:55 2007 +0200
+++ b/client.c	Wed Sep 26 23:44:20 2007 +0200
@@ -73,13 +73,16 @@
         net_prepare_read_fdset = c_unix_prepare_read_fdset;
         net_process_read_fdset = c_unix_process_read_fdset;
         net_send = c_unix_send;
-    } else if (command_line.c_param.transport == ETHERNET)
+    }
+#ifdef linux
+    else if (command_line.c_param.transport == ETHERNET)
     {
         c_eth_init();
         net_prepare_read_fdset = c_eth_prepare_read_fdset;
         net_process_read_fdset = c_eth_process_read_fdset;
         net_send = c_eth_send_to_connected;
     }
+#endif /* linux */
 
     if (command_line.c_param.raw_mode)
         prepare_user_terminal();
--- a/main.c	Wed Sep 26 23:43:55 2007 +0200
+++ b/main.c	Wed Sep 26 23:44:20 2007 +0200
@@ -52,8 +52,10 @@
             "any\n"
            "        Unix socket.\n");
     printf(" -E     Echo remote input to the server terminal.\n");
+#ifdef linux
     printf(" -e dev Serve/connect using raw ethernet, device 'dev'.\n");
     printf(" -c adr Connect to address (MAC if eth).\n");
+#endif /* linux */
     printf(" -r     Send xterm's resize control string to clients.\n");
     return 0;
 }
@@ -114,7 +116,11 @@
     extern int optind, opterr, optopt;
 
     while(1) {
-        c = my_getopt(argc, argv, "tp:nBrdPN:c:hwxEe:");
+        c = my_getopt(argc, argv, "tp:nBrdPN:hwxE"
+#ifdef linux
+                "c:e:"
+#endif /* linux */
+                );
 
         if (c == -1)
             break;
--- a/server.c	Wed Sep 26 23:43:55 2007 +0200
+++ b/server.c	Wed Sep 26 23:44:20 2007 +0200
@@ -34,8 +34,10 @@
             s_unix_prepare_read_fdset(&read_set, &maxfd);
         if (command_line.s_param.serve_tcp)
             s_tcp_prepare_read_fdset(&read_set, &maxfd);
+#ifdef linux
         if (command_line.s_param.serve_eth)
             s_eth_prepare_read_fdset(&read_set, &maxfd);
+#endif /* linux */
 
         /* Will block */
         res = select(maxfd + 1, &read_set, 0, 0, 0);
@@ -64,8 +66,10 @@
             s_unix_process_read_fdset(&read_set);
         if (command_line.s_param.serve_tcp)
             s_tcp_process_read_fdset(&read_set);
+#ifdef linux
         if (command_line.s_param.serve_eth)
             s_eth_process_read_fdset(&read_set);
+#endif /* linux */
     } while(1);
 }
 
@@ -85,8 +89,10 @@
     if (command_line.s_param.serve_tcp)
         s_tcp_update_served(command_line.s_param.max_served);
 
+#ifdef linux
     if (command_line.s_param.serve_eth)
         s_eth_init();
+#endif /* linux */
 
     child = fork_app(command_line.s_param.command);
 
@@ -109,8 +115,10 @@
     if (command_line.s_param.serve_tcp)
         s_tcp_shutdown();
 
+#ifdef linux
     if (command_line.s_param.serve_eth)
         s_eth_shutdown();
+#endif /* linux */
 
     if (!command_line.s_param.nohup &&
             command_line.s_param.run_in_subterminal)
--- a/signals.c	Wed Sep 26 23:43:55 2007 +0200
+++ b/signals.c	Wed Sep 26 23:44:20 2007 +0200
@@ -32,8 +32,10 @@
         s_unix_send_to_connected(xterm_str, len);
     if (command_line.s_param.serve_tcp)
         s_tcp_send_to_connected(xterm_str, len);
+#ifdef linux
     if (command_line.s_param.serve_eth)
         s_eth_send_to_connected(xterm_str, len);
+#endif /* linux */
 }
 
 void install_signal_forwarders(int _child)
--- a/user_term.c	Wed Sep 26 23:43:55 2007 +0200
+++ b/user_term.c	Wed Sep 26 23:44:20 2007 +0200
@@ -4,6 +4,7 @@
 #include <fcntl.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdio.h>
 #include <sys/ioctl.h>
 #include <termios.h>
 
@@ -24,10 +25,10 @@
     memcpy(&saved_tios, &tios, sizeof(struct termios));
     is_tios_saved = 1;
 
-    tios.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN);
+    tios.c_lflag &= ~(ECHO | ECHONL | ICANON);
     /*cfmakeraw(&tios);*/
 
-    res = tcsetattr(1, TCSANOW, &tios);
+    res = tcsetattr(0, TCSANOW, &tios);
     if (res == -1)
         error("tcsetatttr");
 }
@@ -35,9 +36,14 @@
 void restore_user_terminal()
 {
     int res;
-    res = tcsetattr(1, TCSANOW, &saved_tios);
+    res = tcsetattr(0, TCSANOW, &saved_tios);
     if (res == -1)
-        error("tcsetatttr");
+    {
+        /* cannot call error(), because it calls finish(), then
+         * restore_user_terminal() */
+        fprintf(stderr,"tcsetatttr failed: %s", strerror(errno));
+        exit(-1);
+    }
 }
 
 void finish(int ret)