changeset 195:549e6cd1e77d

rvinterf: support for socketpair invokation
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 26 Nov 2013 20:23:38 +0000
parents 9e4771bf865f
children 3daa8ebbe74d
files rvinterf/lowlevel/localsock.c rvinterf/lowlevel/output.c rvinterf/lowlevel/rvifmain.c rvinterf/lowlevel/rvtdump.c
diffstat 4 files changed, 45 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/rvinterf/lowlevel/localsock.c	Mon Nov 25 06:17:04 2013 +0000
+++ b/rvinterf/lowlevel/localsock.c	Tue Nov 26 20:23:38 2013 +0000
@@ -18,6 +18,7 @@
 extern struct client *client_head;
 extern int max_fd;
 extern char *socket_pathname;
+extern int socketpair_fd;
 
 create_listener_socket()
 {
@@ -112,6 +113,24 @@
 	return(0);
 }
 
+create_socketpair_client()
+{
+	struct client *cli;
+
+	if (socketpair_fd > max_fd)
+		max_fd = socketpair_fd;
+	cli = malloc(sizeof(struct client));
+	if (!cli) {
+		perror("rvinterf: malloc for socketpair client");
+		exit(1);
+	}
+	bzero(cli, sizeof(struct client));
+	cli->fd = socketpair_fd;
+	client_head = cli;
+	prep_for_length_rx(cli);
+	return(0);
+}
+
 send_local_msg_to_client(cli, msg)
 	struct client *cli;
 	char *msg;
--- a/rvinterf/lowlevel/output.c	Mon Nov 25 06:17:04 2013 +0000
+++ b/rvinterf/lowlevel/output.c	Tue Nov 26 20:23:38 2013 +0000
@@ -10,7 +10,7 @@
 #include <unistd.h>
 #include <time.h>
 
-extern int background;
+extern int no_output;
 extern FILE *logF;
 extern time_t logtime;
 
@@ -22,7 +22,7 @@
 {
 	struct tm *curtm;
 
-	if (!background)
+	if (!no_output)
 		printf("%s\n", item);
 	if (!logF)
 		return;
--- a/rvinterf/lowlevel/rvifmain.c	Mon Nov 25 06:17:04 2013 +0000
+++ b/rvinterf/lowlevel/rvifmain.c	Tue Nov 26 20:23:38 2013 +0000
@@ -22,11 +22,12 @@
 extern size_t rxpkt_len;
 
 struct client *client_head;
+int socketpair_fd;
 
 char *logfname;
 FILE *logF;
 time_t logtime;
-int background;
+int background, no_output;
 int max_fd;
 
 char *socket_pathname = "/tmp/rvinterf_socket";
@@ -42,10 +43,13 @@
 	fd_set fds;
 	struct client *cli, **clip;
 
-	while ((c = getopt(argc, argv, "bB:d:l:s:w:")) != EOF)
+	while ((c = getopt(argc, argv, "bB:d:l:ns:S:w:")) != EOF)
 		switch (c) {
 		case 'b':
 			background++;
+			/* FALL THRU */
+		case 'n':
+			no_output++;
 			continue;
 		case 'B':
 			baudrate_name = optarg;
@@ -59,6 +63,9 @@
 		case 's':
 			socket_pathname = optarg;
 			continue;
+		case 'S':
+			socketpair_fd = atoi(optarg);
+			continue;
 		case 'w':
 			wakeup_after_sec = strtoul(optarg, 0, 0);
 			continue;
@@ -86,7 +93,10 @@
 		fprintf(logF, "*** Log of rvinterf session ***\n");
 		setlinebuf(logF);
 	}
-	create_listener_socket();
+	if (socketpair_fd)
+		create_socketpair_client();
+	else
+		create_listener_socket();
 	if (background) {
 		c = fork();
 		if (c < 0) {
@@ -102,7 +112,8 @@
 	for (;;) {
 		FD_ZERO(&fds);
 		FD_SET(target_fd, &fds);
-		FD_SET(listener, &fds);
+		if (listener)
+			FD_SET(listener, &fds);
 		for (clip = &client_head; cli = *clip; ) {
 			if (cli->rx_state == 2) {
 				close(cli->fd);
@@ -113,6 +124,8 @@
 			FD_SET(cli->fd, &fds);
 			clip = &cli->next;
 		}
+		if (socketpair_fd && !client_head)
+			exit(0);
 		c = select(max_fd+1, &fds, 0, 0, 0);
 		time(&logtime);
 		if (c < 0) {
@@ -123,7 +136,7 @@
 		}
 		if (FD_ISSET(target_fd, &fds))
 			process_serial_rx();
-		if (FD_ISSET(listener, &fds))
+		if (listener && FD_ISSET(listener, &fds))
 			handle_listener_select();
 		for (cli = client_head; cli; cli = cli->next)
 			if (FD_ISSET(cli->fd, &fds))
@@ -137,25 +150,25 @@
 	case RVT_RV_HEADER:
 		if (rxpkt_len < 6)
 			goto unknown;
-		if (!background || logF)
+		if (!no_output || logF)
 			print_rv_trace();
 		if (client_head)
 			forward_rv_trace();
 		return;
 	case RVT_L1_HEADER:
-		if (!background || logF)
+		if (!no_output || logF)
 			print_l1_trace();
 		if (client_head)
 			forward_nonrvt_pkt();
 		return;
 	case RVT_L23_HEADER:
-		if (!background || logF)
+		if (!no_output || logF)
 			print_g23_trace();
 		if (client_head)
 			forward_nonrvt_pkt();
 		return;
 	case RVT_TM_HEADER:
-		if (!background || logF)
+		if (!no_output || logF)
 			print_etm_output_raw();
 		if (client_head)
 			forward_nonrvt_pkt();
--- a/rvinterf/lowlevel/rvtdump.c	Mon Nov 25 06:17:04 2013 +0000
+++ b/rvinterf/lowlevel/rvtdump.c	Tue Nov 26 20:23:38 2013 +0000
@@ -21,6 +21,7 @@
 FILE *logF;
 time_t logtime;
 int background;
+int no_output;	/* for output.c */
 
 main(argc, argv)
 	char **argv;
@@ -34,6 +35,7 @@
 		switch (c) {
 		case 'b':
 			background++;
+			no_output++;	/* for output.c */
 			continue;
 		case 'B':
 			baudrate_name = optarg;