From 38dbccee02a051e8232c71c7e1b27fa311fc90a6 Mon Sep 17 00:00:00 2001 From: dcp1990 Date: Sun, 19 Jun 2005 02:47:43 +0000 Subject: [PATCH] Broken debugging stuff for no quitting --- include/phoned.h | 4 +++- phoned/init.c | 4 +++- phoned/modem.c | 10 +++++++++- phoned/notify.c | 4 ++-- phoned/signals.c | 12 ++++++++++-- phoned/socket.c | 39 ++++++++++++++++++++++++++++++++++----- 6 files changed, 61 insertions(+), 12 deletions(-) diff --git a/include/phoned.h b/include/phoned.h index 96d83bb..05a1cc9 100644 --- a/include/phoned.h +++ b/include/phoned.h @@ -3,7 +3,7 @@ * (C)2005, Dan Ponte * BSDL w/ advert. */ -/* $Amigan: phoned/include/phoned.h,v 1.18 2005/06/19 01:24:15 dcp1990 Exp $ */ +/* $Amigan: phoned/include/phoned.h,v 1.19 2005/06/19 02:47:43 dcp1990 Exp $ */ #include /* fugly, I know... */ #define VERSION "0.1" #define LOGFILE "/var/log/phoned.log" @@ -168,6 +168,8 @@ short db_init(char* dbfilename); short db_destroy(void); short db_add_call(cid_t* c, time_t t); void cid_handle(cid_t *c); +void awaken_sel(void); +void modem_wake(void); /* old stuff... void modem_pickup(void); void modem_hangup(void); diff --git a/phoned/init.c b/phoned/init.c index 9de5121..3cf93db 100644 --- a/phoned/init.c +++ b/phoned/init.c @@ -28,14 +28,16 @@ void shutd(whatdone) { lprintf(fatal, "phoned shutting down...\n"); pthread_mutex_lock(&cfmx); + lprintf(info, "got cf lock"); if(whatdone & WD_MODEM) close_modem(cf.modemdev); pthread_mutex_unlock(&cfmx); flush_lists(); free_condition(topcond, 0x1); pthread_mutex_lock(&logfmx); - if(whatdone & WD_LOGS) fclose(logf); pthread_mutex_unlock(&logfmx); if(whatdone & WD_DBINIT) db_destroy(); + lprintf(info, "got log lock"); + if(whatdone & WD_LOGS) fclose(logf); unlink(SOCKETFILE); } diff --git a/phoned/modem.c b/phoned/modem.c index de7aca9..527b487 100644 --- a/phoned/modem.c +++ b/phoned/modem.c @@ -84,6 +84,12 @@ void stmod(str) pthread_mutex_unlock(&modemmx); } } +void modem_wake(void) +{ + pthread_mutex_lock(&mpipemx); + write(modempipes[1], "D", 1); + pthread_mutex_unlock(&mpipemx); +} void give_me_modem(str) /* warning: deprecated! */ char *str; { @@ -220,7 +226,9 @@ void *modem_io(k) } if(FD_ISSET(modempipes[0], &fds) != 0) { read(modempipes[0], cbuf, 1); - pthread_cond_wait(&mpcond, &modemmx); + if(*cbuf == 'G') pthread_cond_wait(&mpcond, &modemmx); else { + break; + } } } } diff --git a/phoned/notify.c b/phoned/notify.c index 22b6597..ef3b23d 100644 --- a/phoned/notify.c +++ b/phoned/notify.c @@ -27,7 +27,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -/* $Amigan: phoned/phoned/notify.c,v 1.5 2005/06/19 01:35:50 dcp1990 Exp $ */ +/* $Amigan: phoned/phoned/notify.c,v 1.6 2005/06/19 02:47:45 dcp1990 Exp $ */ #include #include #include @@ -87,7 +87,7 @@ int cid_notify(cid_t* c) char* msg; int s; struct sockaddr_in sin; - char on = 0x1; + int on = 0x1; addrsll_t *cur; len = strlen(c->number) + strlen(c->name) + 8 + 5 + 4; msg = malloc(len * sizeof(char)); diff --git a/phoned/signals.c b/phoned/signals.c index 8a526b9..aa198fb 100644 --- a/phoned/signals.c +++ b/phoned/signals.c @@ -32,17 +32,25 @@ #include #include #include +#include #include - +extern pthread_t networkth; void handsig(sig) int sig; { + if(pthread_equal(pthread_self(), networkth)) { + lprintf(info, "siamo spesa"); + return; + } signal(sig, handsig); switch(sig) { case SIGINT: - case SIGQUIT: case SIGTERM: lprintf(fatal, "Received signal %d, cleaning up...\n", sig); + awaken_sel(); + lprintf(info, "woke up sel"); + modem_wake(); + lprintf(info, "woke up mod"); shutd(0x1 | 0x2 | 0x4 | 0x10 | 0x20); exit(0); break; diff --git a/phoned/socket.c b/phoned/socket.c index 1d848d9..63c17fd 100644 --- a/phoned/socket.c +++ b/phoned/socket.c @@ -50,6 +50,8 @@ extern pthread_mutex_t modemmx; extern pthread_mutex_t buffermx; pthread_t networkth; +int selpipes[2]; +pthread_mutex_t spipsmx; void *handclient(k) void* k; { @@ -58,10 +60,25 @@ void *handclient(k) tf = fdopen(sk, "r+"); begin_dialogue(tf, sk); fclose(tf); + lprintf(info, "here"); pthread_exit(NULL); + lprintf(info, "there"); return 0; } - +#if 0 +void clsck(sck) + void *sck; +{ + int s = (int)sck; + close(s); +} +#endif +void awaken_sel(void) +{ + pthread_mutex_lock(&spipsmx); + write(selpipes[1], "W", 1); + pthread_mutex_unlock(&spipsmx); +} void *network(b) void* b; { @@ -78,6 +95,9 @@ void *network(b) shutd(0x1|0x2|0x4|0x10|0x20); exit(-1); } + pthread_mutex_lock(&spipsmx); + pipe(selpipes); + pthread_mutex_unlock(&spipsmx); strcpy(it.sun_path, SOCKETFILE); it.sun_family = AF_LOCAL; if(bind(s, (struct sockaddr *)&it, 1 + strlen(it.sun_path) + @@ -94,11 +114,13 @@ void *network(b) for(;;) { FD_ZERO(&fds); FD_SET(s, &fds); - switch(select(s + 1, &fds, NULL, NULL, NULL)) { + FD_SET(selpipes[0], &fds); + switch(select(selpipes[0] + 1, &fds, NULL, NULL, NULL)) { /* this had better be a cancellation point... */ case -1: lprintf(error, "select: %s\n", strerror(errno)); - shutd(0x1|0x2|0x4|0x10|0x20); - exit(-1); + pthread_exit(NULL); + return (void*)0; + lprintf(error, "selet: \n"); break; case 0: /* NOTREACHED */ @@ -120,10 +142,17 @@ void *network(b) ,ilen); } + if(FD_ISSET(selpipes[0], &fds) != 0) { + char tbuf[2]; + lprintf(info, "woken\n"); + read(selpipes[0], tbuf, 1); + break; + } } } } - /* NOTREACHED */ + lprintf(info, "still alive!"); close(s); unlink(SOCKETFILE); + pthread_exit(NULL); }