Fix sigpipe

This commit is contained in:
dcp1990 2005-06-25 02:43:54 +00:00
parent 4d915009cb
commit 6e41a8cc5e
4 changed files with 121 additions and 9 deletions

View File

@ -3,7 +3,7 @@
* (C)2005, Dan Ponte
* BSDL w/ advert.
*/
/* $Amigan: phoned/include/phoned.h,v 1.27 2005/06/23 22:06:58 dcp1990 Exp $ */
/* $Amigan: phoned/include/phoned.h,v 1.28 2005/06/25 02:43:54 dcp1990 Exp $ */
#include <pcre.h> /* fugly, I know... */
#define VERSION "0.1"
#define LOGFILE "-"
@ -204,6 +204,7 @@ short db_check_crend(char *loginna, char *pass);
cid_t *decode_sdmf(unsigned char *s);
cid_t *decode_mdmf(unsigned char *s);
void voice_init(void);
int dialogue_with_modem(int (*cback)(int, void*), void *arg);
/* old stuff...
void modem_pickup(void);
void modem_hangup(void);

View File

@ -27,18 +27,20 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* $Amigan: phoned/phonectl/phonectl.c,v 1.5 2005/06/23 22:07:01 dcp1990 Exp $ */
/* $Amigan: phoned/phonectl/phonectl.c,v 1.6 2005/06/25 02:43:54 dcp1990 Exp $ */
/* system includes */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <netdb.h>
#include <netinet/in.h>
#include <getopt.h>
#include <errno.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/socket.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <sys/un.h>
/* us */
@ -59,6 +61,12 @@ int main(argc, argv)
perror("conn");
exit(-1);
}
#if 0
if(setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char*)&on, sizeof(on)) < 0) {
perror("setsockopt");
exit(-1);
}
#endif
if(argc == 1) {
while(!feof(stdin)) {
fputs("phonectl> ", stdout);
@ -69,8 +77,8 @@ int main(argc, argv)
close(s);
return 0;
}
write(s, buff, strlen(buff) + 1);
read(s, buff, sizeof(buff));
send(s, buff, strlen(buff) + 1, 0x0);
recv(s, buff, sizeof(buff), 0x0);
fputs(buff, stdout);
}
}

View File

@ -42,7 +42,6 @@
#include <sys/types.h>
#include <sys/select.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <errno.h>
#include <poll.h>
#include <pthread.h>
@ -84,6 +83,26 @@ void stmod(str)
pthread_mutex_unlock(&modemmx);
}
}
int dialogue_with_modem(cback, arg)
int (*cback)(int, void*);
void *arg;
{
int rc;
if(pthread_mutex_trylock(&modemmx) != 0 && pthread_mutex_trylock(&miomx) != 0) {
pthread_mutex_lock(&mpipemx);
write(modempipes[1], "G", 1);
pthread_mutex_unlock(&mpipemx);
pthread_mutex_lock(&modemmx);
rc = cback(modemfd, arg);
pthread_cond_signal(&mpcond);
pthread_mutex_unlock(&modemmx);
} else {
pthread_mutex_lock(&modemmx);
rc = cback(modemfd, arg);
pthread_mutex_unlock(&modemmx);
}
return rc;
}
char *sendwr(str, bufferback, howmuch)
const char *str;
char *bufferback;
@ -208,7 +227,9 @@ void modem_hread(char* cbuf)
if((buffer[0] == '8' && buffer[1] == '0') || (buffer[0] == '0' && buffer[1] == '4'))
doing_cid = 1;
if(cbuf[0] == '\n') {
#ifdef MODEMSAID
lprintf(debug, "Modem said %s", buffer);
#endif
if(doing_cid) {
cid_t *rc;
rc = parse_cid(buffer);
@ -246,9 +267,6 @@ void *modem_io(k)
pthread_mutex_lock(&modemmx);
pthread_mutex_lock(&miomx);
for(;;) {
pthread_mutex_lock(&cfmx);
/* dotm = cf.modem_tm; */
pthread_mutex_unlock(&cfmx);
FD_ZERO(&fds);
FD_SET(modemfd, &fds);
FD_SET(modempipes[0], &fds);

View File

@ -28,13 +28,20 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/* $Amigan: phoned/phoned/remote.c,v 1.12 2005/06/23 22:07:02 dcp1990 Exp $ */
/* $Amigan: phoned/phoned/remote.c,v 1.13 2005/06/25 02:43:54 dcp1990 Exp $ */
/* system includes */
#include <string.h>
#include <stdio.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/select.h>
#include <sys/ioctl.h>
#include <ctype.h>
#include <sys/uio.h>
#include <errno.h>
/* us */
#include <phoned.h>
@ -201,6 +208,76 @@ short log_in_user(loginna, pass, lnt)
return 0;
}
int dialogue_cb(fd, sck)
int fd;
void *sck;
{
FILE *so = (FILE*)sck;
int s;
fd_set fds;
fd_set ex;
char buffer[3];
char lastc = 0x0;
int rc;
s = fileno(so);
memset(buffer, 0, sizeof(buffer));
for(;;) {
FD_ZERO(&fds);
FD_ZERO(&ex);
FD_SET(s, &ex);
FD_SET(fd, &fds);
FD_SET(s, &fds);
switch(select(s + 1, &fds, NULL, &ex, NULL)) {
case -1:
lprintf(error, "select on modem: %s", strerror(errno));
return 0;
case 0:
/* WON'T HAPPEN */
break;
default:
{
lprintf(debug, "Defaulted!");
if(FD_ISSET(s, &ex) != 0) {
lprintf(debug, "Exceptional.");
return 0;
}
if(FD_ISSET(fd, &fds) != 0) {
rc = read(fd, buffer, 1);
if(rc == -1) {
lprintf(error, "read(): %s", strerror(errno));
return 0;
}
rc = send(s, buffer, 1, 0x0);
lprintf(debug, "rc=%d", rc);
if(rc == -1) {
lprintf(error, "send(): %s", strerror(errno));
return 0;
}
}
if(FD_ISSET(s, &fds) != 0) {
rc = recv(s, buffer, 1, 0x0);
lprintf(debug, "rcv=%d", rc);
if(rc == 0) {
lprintf(debug, "Socket closed! Got zero!\n");
return 0;
} else if(rc == -1) {
lprintf(debug, "recv(): %s", strerror(errno));
return 0;
}
if(lastc == '%' && *buffer == 'q') return 1;
lastc = *buffer;
rc = write(fd, buffer, 1);
if(rc == -1) {
lprintf(error, "write(): %s", strerror(errno));
return 0;
}
}
}
}
}
/* NOTREACHED */
return 1;
}
char *parse_command(cmd, cont, s)
const char *cmd;
short *cont;
@ -274,6 +351,14 @@ char *parse_command(cmd, cont, s)
cid_handle(&c);
*cont = 0;
RNF("500 OK: Handler tested.\n");
} else if(CHK("mdlg")) {
int rc;
rc = dialogue_with_modem(&dialogue_cb, (void*)s->fpo);
if(!rc) {
return NULL;
} else {
RNF("500 OK: Dialogue finished");
}
} else if(CHK("tparse")) {
cid_t* rc;
rc = parse_cid("802701083132323130383234070F5354414E444953482048454154494E020A343031333937333337325C\n");