3 #include "../../gsmstate.h" 12 #include "../../gsmcomon.h" 13 #include "../devfunc.h" 16 #include "../../../helper/string.h" 25 if (asprintf(&ret,
"exec %s", proxy_command) < 0) {
32 # define _PATH_BSHELL "/bin/sh" 46 if ((shell = getenv(
"SHELL")) == NULL || *shell ==
'\0') {
51 if (pipe(pin) < 0 || pipe(pout) < 0) {
52 GSM_OSErrorInfo(s,
"Could not create pipes to communicate with the proxy");
57 if (command_string == NULL) {
60 dbgprintf(NULL,
"Executing proxy command: %.500s", command_string);
63 if ((pid = fork()) == 0) {
64 const char * argv[10];
72 if (dup2(pin[0], 0) < 0)
77 if (dup2(pout[1], 1) < 0)
78 perror(
"dup2 stdout");
86 argv[2] = command_string;
91 signal(SIGPIPE, SIG_DFL);
92 execv(argv[0], (
char **)argv);
108 free(command_string);
111 proxydata->
hRead = pout[0];
112 proxydata->
hWrite = pin[1];
125 if (proxy_command_pid > 1)
126 kill(proxy_command_pid, SIGHUP);
138 struct timeval timeout2;
143 FD_SET(d->
hRead, &readfds);
146 timeout2.tv_usec = 50000;
148 if (select(d->
hRead+1, &readfds, NULL, NULL, &timeout2)) {
149 actual = read(d->
hRead, buf, nbytes);
158 sigset_t oldset, newset;
161 struct timespec ts = {0};
163 sigemptyset(&newset);
164 sigaddset(&newset, SIGPIPE);
165 pthread_sigmask(SIG_BLOCK, &newset, &oldset);
167 result = write(fd, buf, len);
169 while (sigtimedwait(&newset, &si, &ts)>=0 || errno != EAGAIN);
170 pthread_sigmask(SIG_SETMASK, &oldset, 0);
180 const unsigned char *buffer = (
const unsigned char *)buf;
185 if (errno == EAGAIN) {
189 if (actual != nbytes) {
191 smprintf(s,
"Wanted to write %ld bytes, but %ld were written\n",
192 (
long)nbytes, (
long)actual);
199 }
while (actual < nbytes);
GSM_Config * CurrentConfig
void kill_proxy_command(pid_t proxy_command_pid)
static char * expand_proxy_command(const char *proxy_command)
GSM_Device_ProxyData Proxy
GSM_Error proxy_close(GSM_StateMachine *s)
union GSM_Device::@0 Data
GSM_ConnectionType ConnectionType
static ssize_t write_nosigpipe(int fd, const void *buf, size_t len)
GSM_Error proxy_open(GSM_StateMachine *s)
int proxy_write(GSM_StateMachine *s, const void *buf, size_t nbytes)
static GSM_Error proxy_connect(GSM_StateMachine *s, GSM_Device_ProxyData *proxydata, const char *proxy_command)
int proxy_read(GSM_StateMachine *s, void *buf, size_t nbytes)
void GSM_OSErrorInfo(GSM_StateMachine *s, const char *description)
GSM_Device_Functions ProxyDevice
int smprintf(GSM_StateMachine *s, const char *format,...)