From 8d2903d41567301600ef949fbc44398a089280fa Mon Sep 17 00:00:00 2001 From: dcp1990 Date: Mon, 20 Jun 2005 02:06:45 +0000 Subject: [PATCH] Socket config, and no need to awaken_sel() --- phoned/config.l | 1 + phoned/config.y | 16 +++++++++++++++- phoned/init.c | 6 ++++-- phoned/main.c | 1 + phoned/phoned.conf | 1 + phoned/socket.c | 10 ++++++++-- 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/phoned/config.l b/phoned/config.l index 5123095..8a6e0fe 100644 --- a/phoned/config.l +++ b/phoned/config.l @@ -18,6 +18,7 @@ extern pthread_mutex_t cfmx; main return MAIN; loglevel pthread_mutex_lock(&cfmx); cf.loglevels = LL_CRITICAL|LL_FATAL; pthread_mutex_unlock(&cfmx); return LLEVEL; database return DB; +socket return SOCK; all yylval.number = LL_ALL; return LNUML; debug yylval.number = LL_DEBUG; return LNUML; info yylval.number = LL_INFO; return LNUML; diff --git a/phoned/config.y b/phoned/config.y index 59c21ed..77a4d99 100644 --- a/phoned/config.y +++ b/phoned/config.y @@ -34,7 +34,7 @@ int yywrap(void) } %} %token NOTIFY OBRACE CBRACE SCOLON QUOTE MODDEV MAIN LLEVEL OR -%token FILTERS ACTION NAME PHNUM FILTER FLAGS DB +%token FILTERS ACTION NAME PHNUM FILTER FLAGS DB SOCK /* HANGUP IGNOREIT PLAY RECORD */ %token LNUML ACTN FLAG %token IPADDR PATH REGEX FNAME @@ -66,6 +66,8 @@ directive: loglevel | database + | + socket ; notify: NOTIFY iplist @@ -84,6 +86,18 @@ ipadr: addtoaddrs($1); } ; +socket: + SOCK sockpath + ; +sockpath: + QUOTE PATH QUOTE + { + lprintf(debug, "Socket path == %s\n", $2); + pthread_mutex_lock(&cfmx); + cf.sockfile = $2; + pthread_mutex_unlock(&cfmx); + } + ; database: DB dbpath ; diff --git a/phoned/init.c b/phoned/init.c index c571477..a2c2a65 100644 --- a/phoned/init.c +++ b/phoned/init.c @@ -30,8 +30,10 @@ void shutd(whatdone) int whatdone; { lprintf(fatal, "phoned shutting down (th %s)...\n", pthread_equal(pthread_self(), networkth) ? "network" : (pthread_equal(pthread_self(), modemth) ? "modem" : "other/main")); - awaken_sel(); - unlink(SOCKETFILE); + /* awaken_sel(); */ + pthread_mutex_lock(&cfmx); + unlink(cf.sockfile); + pthread_mutex_unlock(&cfmx); if(whatdone & WD_MODEM) modem_wake(); flush_lists(); flush_logins(); diff --git a/phoned/main.c b/phoned/main.c index 13e61b1..8c22c36 100644 --- a/phoned/main.c +++ b/phoned/main.c @@ -43,6 +43,7 @@ int main(argc, argv) cf.cfile = CONFIGFILE; cf.dbfile = DBFILE; cf.logfile = LOGFILE; + cf.sockfile = SOCKETFILE; #define OPTSTRING "dhc:l:" while((c = getopt(argc, argv, OPTSTRING)) != -1) switch(c) { diff --git a/phoned/phoned.conf b/phoned/phoned.conf index 32ba85d..838a70f 100644 --- a/phoned/phoned.conf +++ b/phoned/phoned.conf @@ -2,6 +2,7 @@ main { modemdev "/dev/cuaa2"; loglevel all; database "./phoned.db"; + socket "/tmp/phoned1.sock"; }; filters { filter test1 { diff --git a/phoned/socket.c b/phoned/socket.c index f89e614..6fdaf0d 100644 --- a/phoned/socket.c +++ b/phoned/socket.c @@ -49,6 +49,8 @@ extern pthread_mutex_t modemmx; extern pthread_mutex_t buffermx; +extern pthread_mutex_t cfmx; +extern struct conf cf; pthread_t networkth; int selpipes[2]; pthread_mutex_t spipsmx; @@ -97,7 +99,9 @@ void *network(b) pthread_mutex_lock(&spipsmx); pipe(selpipes); pthread_mutex_unlock(&spipsmx); - strcpy(it.sun_path, SOCKETFILE); + pthread_mutex_lock(&cfmx); + strcpy(it.sun_path, cf.sockfile); + pthread_mutex_unlock(&cfmx); it.sun_family = AF_LOCAL; if(bind(s, (struct sockaddr *)&it, 1 + strlen(it.sun_path) + sizeof(it.sun_family)) == -1) { @@ -146,6 +150,8 @@ void *network(b) if(*cbuf != 0) break; } close(s); - unlink(SOCKETFILE); + pthread_mutex_lock(&cfmx); + unlink(cf.sockfile); + pthread_mutex_unlock(&cfmx); pthread_exit(NULL); }