# HG changeset patch # User Mychaela Falconia # Date 1540683310 0 # Node ID 67d683a87b1db56925d3cbf747769d9f800a90b8 # Parent cb3e8d080a23b51cc9330a8c4da345f20e88fefb rvinterf client refactoring: libinterf created diff -r cb3e8d080a23 -r 67d683a87b1d rvinterf/Makefile --- a/rvinterf/Makefile Fri Oct 26 07:29:50 2018 +0000 +++ b/rvinterf/Makefile Sat Oct 27 23:35:10 2018 +0000 @@ -1,14 +1,16 @@ PROGDIR=asyncshell ctracedec etmsync lowlevel rvtat tmsh -LIBDIR= libasync libg23 +LIBDIR= libasync libg23 libinterf SUBDIR= ${PROGDIR} ${LIBDIR} INCLUDE_INSTALL_DIR= /opt/freecalypso/include/rvinterf all: ${SUBDIR} -asyncshell: libasync libg23 +asyncshell: libasync libg23 libinterf +etmsync: libinterf lowlevel: libg23 -tmsh: libasync +rvtat: libinterf +tmsh: libasync libinterf ${SUBDIR}: FRC cd $@; ${MAKE} ${MFLAGS} diff -r cb3e8d080a23 -r 67d683a87b1d rvinterf/libinterf/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/libinterf/Makefile Sat Oct 27 23:35:10 2018 +0000 @@ -0,0 +1,13 @@ +CC= gcc +CFLAGS= -O2 -I../include +OBJS= connect.o launchrvif.o +LIB= libinterf.a + +all: ${LIB} + +${LIB}: ${OBJS} + ar rcu $@ ${OBJS} + ranlib $@ + +clean: + rm -f *.[oa] errs diff -r cb3e8d080a23 -r 67d683a87b1d rvinterf/libinterf/connect.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/libinterf/connect.c Sat Oct 27 23:35:10 2018 +0000 @@ -0,0 +1,56 @@ +/* + * Connecting to an already running rvinterf process + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "pktmux.h" +#include "localsock.h" +#include "exitcodes.h" + +char *socket_pathname = "/tmp/rvinterf_socket"; +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(ERROR_UNIX); + } + + 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(ERROR_RVINTERF); + } + + return(0); +} diff -r cb3e8d080a23 -r 67d683a87b1d rvinterf/libinterf/launchrvif.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rvinterf/libinterf/launchrvif.c Sat Oct 27 23:35:10 2018 +0000 @@ -0,0 +1,63 @@ +/* + * This module implements the optional "behind the scenes" invokation + * of rvinterf from client programs. + */ + +#include +#include +#include +#include +#include +#include "exitcodes.h" + +static char rvinterf_pathname[] = "/opt/freecalypso/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(ERROR_UNIX); + } + 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(ERROR_UNIX); + } + 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; +}