FreeCalypso > hg > freecalypso-sw
changeset 275:cedf09b6b5ac
started laying the foundation for fc-fsio host utility
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 23 Feb 2014 20:27:15 +0000 |
parents | e3f17ff16915 |
children | 909f00c15f27 |
files | .hgignore rvinterf/etmsync/Makefile rvinterf/etmsync/connect.c rvinterf/etmsync/fsiomain.c rvinterf/etmsync/launchrvif.c |
diffstat | 5 files changed, 199 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Fri Feb 07 08:32:25 2014 +0000 +++ b/.hgignore Sun Feb 23 20:27:15 2014 +0000 @@ -22,6 +22,7 @@ ^miscutil/imei-luhn$ +^rvinterf/etmsync/fc-fsio$ ^rvinterf/lowlevel/rvinterf$ ^rvinterf/lowlevel/rvtdump$ ^rvinterf/old/etmsend$
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/etmsync/Makefile Sun Feb 23 20:27:15 2014 +0000 @@ -0,0 +1,18 @@ +CC= gcc +CFLAGS= -O2 -I../include +PROGS= fc-fsio +INSTBIN=/usr/local/bin + +FSIO_OBJS= connect.o fsiomain.o launchrvif.o + +all: ${PROGS} + +fc-fsio: ${FSIO_OBJS} + ${CC} ${CFLAGS} -o $@ ${FSIO_OBJS} + +install: ${PROGS} + mkdir -p ${INSTBIN} + install -c ${PROGS} ${INSTBIN} + +clean: + rm -f *.o *.out *errs ${PROGS}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/etmsync/connect.c Sun Feb 23 20:27:15 2014 +0000 @@ -0,0 +1,55 @@ +/* + * Connecting to an already running rvinterf process + */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <stdio.h> +#include <string.h> +#include <strings.h> +#include <stdlib.h> +#include <unistd.h> +#include "pktmux.h" +#include "localsock.h" + +extern char *socket_pathname; +extern int sock; + +connect_local_socket() +{ + /* local socket binding voodoo copied from osmocon */ + struct sockaddr_un local; + unsigned int namelen; + int rc; + + sock = socket(AF_UNIX, SOCK_STREAM, 0); + if (sock < 0) { + perror("socket(AF_UNIX, SOCK_STREAM, 0)"); + exit(1); + } + + local.sun_family = AF_UNIX; + strncpy(local.sun_path, socket_pathname, sizeof(local.sun_path)); + local.sun_path[sizeof(local.sun_path) - 1] = '\0'; + + /* we use the same magic that X11 uses in Xtranssock.c for + * calculating the proper length of the sockaddr */ +#if defined(BSD44SOCKETS) || defined(__UNIXWARE__) + local.sun_len = strlen(local.sun_path); +#endif +#if defined(BSD44SOCKETS) || defined(SUN_LEN) + namelen = SUN_LEN(&local); +#else + namelen = strlen(local.sun_path) + + offsetof(struct sockaddr_un, sun_path) + 1; +#endif + + rc = connect(sock, (struct sockaddr *) &local, namelen); + if (rc != 0) { + perror(socket_pathname); + exit(1); + } + + return(0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/etmsync/fsiomain.c Sun Feb 23 20:27:15 2014 +0000 @@ -0,0 +1,63 @@ +/* + * This module contains the main() function for fc-fsio. + */ + +#include <stdio.h> +#include <stdlib.h> + +char *socket_pathname = "/tmp/rvinterf_socket"; +int sock; + +extern char *rvinterf_ttyport, *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt; + +main(argc, argv) + char **argv; +{ + extern int optind; + extern char *optarg; + int c, sopt = 0; + + while ((c = getopt(argc, argv, "B:l:p:s:w:")) != EOF) + switch (c) { + case 'B': + rvinterf_Bopt = optarg; + continue; + case 'l': + rvinterf_lopt = optarg; + continue; + case 'p': + rvinterf_ttyport = optarg; + continue; + case 's': + socket_pathname = optarg; + sopt++; + continue; + case 'w': + rvinterf_wopt = optarg; + continue; + case '?': + default: +usage: fprintf(stderr, + "usage: %s [options] [command]\n", argv[0]); + exit(1); + } + if (rvinterf_ttyport) { + if (sopt) { + fprintf(stderr, + "%s error: -p and -s options are mutually exclusive\n", + argv[0]); + exit(1); + } + launch_rvinterf(); + } else { + if (rvinterf_Bopt || rvinterf_lopt || rvinterf_wopt) { + fprintf(stderr, +"%s error: -B, -l and -w options are meaningful only when launching rvinterf\n", + argv[0]); + exit(1); + } + connect_local_socket(); + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/etmsync/launchrvif.c Sun Feb 23 20:27:15 2014 +0000 @@ -0,0 +1,62 @@ +/* + * This module implements the optional "behind the scenes" invokation + * of rvinterf from fc-fsio etc. + */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +static char rvinterf_pathname[] = "/usr/local/bin/rvinterf"; + +extern int sock; + +char *rvinterf_ttyport, *rvinterf_Bopt, *rvinterf_lopt, *rvinterf_wopt; + +launch_rvinterf() +{ + int sp[2], rc; + char *rvif_argv[11], Sarg[16], **ap; + + rc = socketpair(AF_UNIX, SOCK_STREAM, 0, sp); + if (rc < 0) { + perror("socketpair"); + exit(1); + } + sock = sp[0]; + sprintf(Sarg, "-S%d", sp[1]); + ap = rvif_argv; + *ap++ = "rvinterf"; + *ap++ = Sarg; + *ap++ = "-n"; + if (rvinterf_Bopt) { + *ap++ = "-B"; + *ap++ = rvinterf_Bopt; + } + if (rvinterf_lopt) { + *ap++ = "-l"; + *ap++ = rvinterf_lopt; + } + if (rvinterf_wopt) { + *ap++ = "-w"; + *ap++ = rvinterf_wopt; + } + *ap++ = rvinterf_ttyport; + *ap = 0; + rc = vfork(); + if (rc < 0) { + perror("vfork for launching rvinterf"); + exit(1); + } + if (!rc) { + /* we are in the child - do the exec */ + close(sp[0]); + execv(rvinterf_pathname, rvif_argv); + perror(rvinterf_pathname); + _exit(1); + } + close(sp[1]); + return 0; +}