Just went through an hour-long debugging session only to find that it was a fucking lock that should have been unlock in db.c

Many arch. changes, probably for better, probably for worse. Who knows.
This commit is contained in:
dcp1990 2005-06-19 04:46:15 +00:00
parent f751aad22f
commit db1b78014f
7 changed files with 60 additions and 35 deletions

View file

@ -27,7 +27,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
/* $Amigan: phoned/phoned/db.c,v 1.4 2005/06/19 01:17:55 dcp1990 Exp $ */ /* $Amigan: phoned/phoned/db.c,v 1.5 2005/06/19 04:46:15 dcp1990 Exp $ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <pthread.h> #include <pthread.h>
@ -160,6 +160,6 @@ short db_add_call(c, t)
return 0; return 0;
} }
sqlite3_free(sql); sqlite3_free(sql);
pthread_mutex_lock(&dbmx); pthread_mutex_unlock(&dbmx);
return 1; return 1;
} }

View file

@ -17,6 +17,9 @@ extern pthread_mutex_t logfmx;
extern struct conf cf; extern struct conf cf;
extern pthread_mutex_t cfmx; extern pthread_mutex_t cfmx;
extern cond_t* topcond; extern cond_t* topcond;
extern pthread_t networkth, modemth;
extern pthread_cond_t maincond;
#define WD_LOGS 0x1 #define WD_LOGS 0x1
#define WD_HANDLERS 0x2 #define WD_HANDLERS 0x2
#define WD_CONFIG 0x4 #define WD_CONFIG 0x4
@ -26,19 +29,17 @@ extern cond_t* topcond;
void shutd(whatdone) void shutd(whatdone)
int whatdone; int whatdone;
{ {
lprintf(fatal, "phoned shutting down...\n"); lprintf(fatal, "phoned shutting down (th %s)...\n", pthread_equal(pthread_self(), networkth) ? "network" : (pthread_equal(pthread_self(), modemth) ? "modem" : "other/main"));
pthread_mutex_lock(&cfmx); awaken_sel();
lprintf(info, "got cf lock"); unlink(SOCKETFILE);
if(whatdone & WD_MODEM) close_modem(cf.modemdev); if(whatdone & WD_MODEM) modem_wake();
pthread_mutex_unlock(&cfmx);
flush_lists(); flush_lists();
free_condition(topcond, 0x1); free_condition(topcond, 0x1);
pthread_mutex_lock(&logfmx);
pthread_mutex_unlock(&logfmx);
if(whatdone & WD_DBINIT) db_destroy(); if(whatdone & WD_DBINIT) db_destroy();
lprintf(info, "got log lock"); pthread_mutex_lock(&logfmx);
if(whatdone & WD_LOGS) fclose(logf); if(whatdone & WD_LOGS) fclose(logf);
unlink(SOCKETFILE); pthread_mutex_unlock(&logfmx);
pthread_cond_signal(&maincond);
} }
int open_logs(void) int open_logs(void)

View file

@ -8,6 +8,8 @@
#include <string.h> #include <string.h>
#include <getopt.h> #include <getopt.h>
#include <unistd.h> #include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <pthread.h> #include <pthread.h>
#include <phoned.h> #include <phoned.h>
@ -15,12 +17,23 @@ extern struct conf cf;
extern pthread_mutex_t cfmx; extern pthread_mutex_t cfmx;
extern pthread_t networkth; extern pthread_t networkth;
extern pthread_t modemth; extern pthread_t modemth;
pthread_t mainth;
pthread_cond_t maincond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t mainmx = PTHREAD_MUTEX_INITIALIZER;
void usage(argv) void usage(argv)
const char* argv; const char* argv;
{ {
fprintf(stderr, "%s: usage: %s [-hd] [-c config] [-l log]\n", argv, argv); fprintf(stderr, "%s: usage: %s [-hd] [-c config] [-l log]\n", argv, argv);
} }
void *mainthf(v)
void *v;
{
if(v == 0) v = 0;
pthread_mutex_lock(&mainmx);
pthread_cond_wait(&maincond, &mainmx);
pthread_mutex_unlock(&mainmx);
exit(0);
}
int main(argc, argv) int main(argc, argv)
int argc; int argc;
char* argv[]; char* argv[];
@ -55,6 +68,7 @@ int main(argc, argv)
initialize(); initialize();
pthread_create(&networkth, NULL, network, NULL); pthread_create(&networkth, NULL, network, NULL);
pthread_create(&modemth, NULL, modem_io, NULL); pthread_create(&modemth, NULL, modem_io, NULL);
pthread_create(&mainth, NULL, mainthf, NULL);
pthread_exit(NULL); pthread_exit(NULL);
return 0; return 0;
} }

View file

@ -70,7 +70,7 @@ extern modem_t rockwell;
void stmod(str) void stmod(str)
const char* str; const char* str;
{ {
if(pthread_mutex_trylock(&modemmx) != 0 && pthread_mutex_trylock(&miomx) == 0) { if(pthread_mutex_trylock(&modemmx) != 0 && pthread_mutex_trylock(&miomx) != 0) {
pthread_mutex_lock(&mpipemx); pthread_mutex_lock(&mpipemx);
write(modempipes[1], "G", 1); write(modempipes[1], "G", 1);
pthread_mutex_unlock(&mpipemx); pthread_mutex_unlock(&mpipemx);
@ -86,9 +86,15 @@ void stmod(str)
} }
void modem_wake(void) void modem_wake(void)
{ {
pthread_mutex_lock(&mpipemx); if(pthread_mutex_trylock(&miomx) != 0) {
write(modempipes[1], "D", 1); pthread_mutex_lock(&mpipemx);
pthread_mutex_unlock(&mpipemx); write(modempipes[1], "D", 1);
pthread_mutex_unlock(&mpipemx);
} else {
pthread_mutex_lock(&cfmx);
close_modem(cf.modemdev);
pthread_mutex_unlock(&cfmx);
}
} }
void give_me_modem(str) /* warning: deprecated! */ void give_me_modem(str) /* warning: deprecated! */
char *str; char *str;
@ -193,6 +199,7 @@ void *modem_io(k)
char cbuf[2]; char cbuf[2];
if(k == 0) k = 0; if(k == 0) k = 0;
*cbuf = '\0'; cbuf[1] = '\0'; *cbuf = '\0'; cbuf[1] = '\0';
fillset();
pthread_mutex_lock(&modemmx); pthread_mutex_lock(&modemmx);
pthread_mutex_lock(&miomx); pthread_mutex_lock(&miomx);
for(;;) { for(;;) {
@ -227,11 +234,18 @@ void *modem_io(k)
if(FD_ISSET(modempipes[0], &fds) != 0) { if(FD_ISSET(modempipes[0], &fds) != 0) {
read(modempipes[0], cbuf, 1); read(modempipes[0], cbuf, 1);
if(*cbuf == 'G') pthread_cond_wait(&mpcond, &modemmx); else { if(*cbuf == 'G') pthread_cond_wait(&mpcond, &modemmx); else {
pthread_mutex_unlock(&miomx);
pthread_mutex_unlock(&modemmx);
pthread_mutex_lock(&cfmx);
close_modem(cf.modemdev);
pthread_mutex_unlock(&cfmx);
pthread_exit(NULL);
break; break;
} }
} }
} }
} }
if(*cbuf == 'D') break;
} }
/* NOTREACHED */ /* NOTREACHED */
pthread_mutex_unlock(&miomx); pthread_mutex_unlock(&miomx);

View file

@ -27,7 +27,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
/* $Amigan: phoned/phoned/notify.c,v 1.6 2005/06/19 02:47:45 dcp1990 Exp $ */ /* $Amigan: phoned/phoned/notify.c,v 1.7 2005/06/19 04:46:15 dcp1990 Exp $ */
#include <fcntl.h> #include <fcntl.h>
#include <ctype.h> #include <ctype.h>
#include <unistd.h> #include <unistd.h>
@ -79,6 +79,7 @@ void flush_lists(void)
{ {
pthread_mutex_lock(&addrmx); pthread_mutex_lock(&addrmx);
freeaddrl(top); freeaddrl(top);
top = 0;
pthread_mutex_unlock(&addrmx); pthread_mutex_unlock(&addrmx);
} }
int cid_notify(cid_t* c) int cid_notify(cid_t* c)

View file

@ -39,7 +39,6 @@ void handsig(sig)
int sig; int sig;
{ {
if(pthread_equal(pthread_self(), networkth)) { if(pthread_equal(pthread_self(), networkth)) {
lprintf(info, "siamo spesa");
return; return;
} }
signal(sig, handsig); signal(sig, handsig);
@ -47,11 +46,8 @@ void handsig(sig)
case SIGINT: case SIGINT:
case SIGTERM: case SIGTERM:
lprintf(fatal, "Received signal %d, cleaning up...\n", sig); 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); shutd(0x1 | 0x2 | 0x4 | 0x10 | 0x20);
lprintf(info, "returned from shutd()");
exit(0); exit(0);
break; break;
case SIGHUP: case SIGHUP:
@ -69,3 +65,9 @@ void install_handlers(void)
signal(SIGHUP, handsig); signal(SIGHUP, handsig);
signal(SIGTERM, handsig); signal(SIGTERM, handsig);
} }
void fillset(void)
{
sigset_t sset;
sigfillset(&sset);
pthread_sigmask(SIG_BLOCK, &sset, NULL);
}

View file

@ -60,9 +60,7 @@ void *handclient(k)
tf = fdopen(sk, "r+"); tf = fdopen(sk, "r+");
begin_dialogue(tf, sk); begin_dialogue(tf, sk);
fclose(tf); fclose(tf);
lprintf(info, "here");
pthread_exit(NULL); pthread_exit(NULL);
lprintf(info, "there");
return 0; return 0;
} }
#if 0 #if 0
@ -88,6 +86,7 @@ void *network(b)
pthread_t thr; pthread_t thr;
char cbuf[2]; char cbuf[2];
struct sockaddr_un it; struct sockaddr_un it;
fillset();
cbuf[0] = '\0'; cbuf[1] = '\0'; cbuf[0] = '\0'; cbuf[1] = '\0';
if(b == 0) b = 0; if(b == 0) b = 0;
if((s = socket(AF_LOCAL, SOCK_STREAM, 0)) == -1) { if((s = socket(AF_LOCAL, SOCK_STREAM, 0)) == -1) {
@ -117,10 +116,8 @@ void *network(b)
FD_SET(selpipes[0], &fds); FD_SET(selpipes[0], &fds);
switch(select(selpipes[0] + 1, &fds, NULL, NULL, NULL)) { /* this had better be a cancellation point... */ switch(select(selpipes[0] + 1, &fds, NULL, NULL, NULL)) { /* this had better be a cancellation point... */
case -1: case -1:
lprintf(error, "select: %s\n", strerror(errno)); lprintf(error, "network select: %s\n", strerror(errno));
pthread_exit(NULL); pthread_exit(NULL);
return (void*)0;
lprintf(error, "selet: \n");
break; break;
case 0: case 0:
/* NOTREACHED */ /* NOTREACHED */
@ -138,20 +135,16 @@ void *network(b)
exit(-3); exit(-3);
} }
pthread_create(&thr, NULL, handclient, (void*)sn); pthread_create(&thr, NULL, handclient, (void*)sn);
lprintf(info, "Incoming connection\n" lprintf(info, "Incoming connection\n");
,ilen);
} }
if(FD_ISSET(selpipes[0], &fds) != 0) { if(FD_ISSET(selpipes[0], &fds) != 0) {
char tbuf[2]; read(selpipes[0], cbuf, 1);
lprintf(info, "woken\n"); pthread_exit(NULL);
read(selpipes[0], tbuf, 1);
break;
} }
} }
} }
if(*cbuf != 0) break;
} }
lprintf(info, "still alive!");
close(s); close(s);
unlink(SOCKETFILE); unlink(SOCKETFILE);
pthread_exit(NULL); pthread_exit(NULL);