From f23dfb66b9c1cf97dd03e788e86d5ec69733fc11 Mon Sep 17 00:00:00 2001 From: bagyenda <> Date: Wed, 4 Aug 2010 10:02:46 +0000 Subject: [PATCH] *** empty log message *** --- mbuni/ChangeLog | 2 ++ mbuni/extras/mmsbox-mm1/mmsbox_mm1.c | 39 ++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/mbuni/ChangeLog b/mbuni/ChangeLog index e174619..eb56af2 100644 --- a/mbuni/ChangeLog +++ b/mbuni/ChangeLog @@ -1,3 +1,5 @@ +2010-08-04 P. A. Bagyenda + * Fixed mmsbox-mm1 hangs under load, thanks to Piotr Isajew 2010-07-02 P. A. Bagyenda * Fixed crash due to octstr_delete on immutable string in mm7 receiver 2010-05-26 P. A. Bagyenda diff --git a/mbuni/extras/mmsbox-mm1/mmsbox_mm1.c b/mbuni/extras/mmsbox-mm1/mmsbox_mm1.c index 8213045..c7f0c87 100644 --- a/mbuni/extras/mmsbox-mm1/mmsbox_mm1.c +++ b/mbuni/extras/mmsbox-mm1/mmsbox_mm1.c @@ -359,7 +359,7 @@ static void handle_mm1(MM1Settings *mm1) { /* stop smsc, start GPRS, transact, stop GPRS, start SMSC. And so on. */ MM1Request *r; - + mms_info(0, "mmsbox-mm1", NULL, "handle_mm1 started"); mm1->sender_alive++; while ((r = gwlist_consume(mm1->requests)) != NULL) { @@ -512,10 +512,28 @@ static void handle_mm1(MM1Settings *mm1) octstr_destroy(body); octstr_destroy(ms); mms_destroy(m); - } while (gwlist_len(mm1->requests) > 0 && + r = NULL; + pid_t wp; + int st; + wp = waitpid(pid, &st, WNOHANG); + if(wp == pid && WIFEXITED(st)) { + mms_info(0, "mmsbox-mm1", NULL, "GPRS pid (%d) appears to be dead - quitting loop", pid); + goto after_gprs_dead; + } + } while (gwlist_len(mm1->requests) > 0 && (r = gwlist_consume(mm1->requests)) != NULL); kill_gprs: + if(r != NULL) { + if(r->waiter_exists) { + pthread_mutex_unlock(&r->mutex); + pthread_cond_signal(&r->cond); + } else{ + gw_free(r); + } + + + } if (pid > 0) { /* stop GPRS, restart SMSC connection. */ int xkill, status; pid_t wpid; @@ -532,7 +550,7 @@ static void handle_mm1(MM1Settings *mm1) } while (1); gwthread_sleep(2); } - + after_gprs_dead: if (mm1->smsc_on) { system(octstr_get_cstr(mm1->smsc_on)); gwthread_sleep(5); @@ -610,10 +628,13 @@ static Octstr *fetch_content(Octstr *url, Octstr *proxy, Octstr *body, int *hsta curl_easy_setopt(cl, CURLOPT_WRITEFUNCTION, write_octstr_data); curl_easy_setopt(cl, CURLOPT_WRITEDATA, s); curl_easy_setopt(cl, CURLOPT_NOSIGNAL, 1L); + curl_easy_setopt(cl, CURLOPT_TIMEOUT, 120L); + curl_easy_setopt(cl, CURLOPT_FORBID_REUSE, 1L); + curl_easy_setopt(cl, CURLOPT_CONNECTTIMEOUT, 40L); h = curl_slist_append(h, "Accept: */*"); if (body) { /* POST. */ - h = curl_slist_append(h, "Content-Type: application/vnd.wap.mms-message"); + h = curl_slist_append(h, "Content-Type: application/vnd.wap.mms-message"); curl_easy_setopt(cl, CURLOPT_POSTFIELDS, octstr_get_cstr(body)); curl_easy_setopt(cl, CURLOPT_POSTFIELDSIZE, octstr_len(body)); } @@ -635,7 +656,7 @@ static Octstr *fetch_content(Octstr *url, Octstr *proxy, Octstr *body, int *hsta #include -#define MAX_GPRS_WAIT 60 +#define MAX_GPRS_WAIT 80 #define GPRS_POLL 5 static long start_gprs(Octstr *cmd, Octstr *pid_cmd) { @@ -661,6 +682,14 @@ static long start_gprs(Octstr *cmd, Octstr *pid_cmd) WIFEXITED(status)) return -1; } while (GPRS_POLL*ct++ < MAX_GPRS_WAIT); + /* Timed out, but still need to wait for child pid, as + start-gprs script is still running and we don't need a + zombie */ + pid_t rpid; + int st; + + rpid = waitpid(pid, &st, 0); + mms_info(0, "mmsbox-mm1", NULL, "pid %d terminated", pid); return -1; } else if (pid == 0) { /* child. */ List *l = octstr_split_words(cmd);