changed: now we use curl to fetch a page from the special thread when winix quits

(before we were using BSD's fetch)
fixed:   we didn't use FCGX_Finish_r() on the request made from the special thread
         so the thread hangs (now we can use pthread_join correctly from the main thread)



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@947 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
Tomasz Sowa 2014-02-11 21:00:32 +00:00
parent 7fa9314c6b
commit 145445c713
3 changed files with 24 additions and 18 deletions

View File

@ -51,7 +51,7 @@ winix.so: $(winix.src.files)
@cd ../ezc/src ; $(MAKE) -e
@cd ../tito/src ; $(MAKE) -e
@cd ../pikotools ; $(MAKE) -e
$(CXX) -shared -rdynamic -Wl,-whole-archive -o winix.so $(CXXFLAGS) $(CXXWINIXINCLUDEFLAGS) core/*.o db/*.o functions/*.o templates/*.o notify/*.o ../ezc/src/ezc.a ../tito/src/tito.a ../pikotools/utf8/utf8.a ../pikotools/space/space.a ../pikotools/mainparser/mainparser.a ../pikotools/date/date.a $(LDFLAGS) -lfcgi -lpq -lz -lfetch -lpthread -Wl,-no-whole-archive
$(CXX) -shared -rdynamic -Wl,-whole-archive -o winix.so $(CXXFLAGS) $(CXXWINIXINCLUDEFLAGS) core/*.o db/*.o functions/*.o templates/*.o notify/*.o ../ezc/src/ezc.a ../tito/src/tito.a ../pikotools/utf8/utf8.a ../pikotools/space/space.a ../pikotools/mainparser/mainparser.a ../pikotools/date/date.a $(LDFLAGS) -lfcgi -lpq -lz -lfetch -lpthread -lcurl -Wl,-no-whole-archive
winix: winix.so $(winix.src.files)

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010-2013, Tomasz Sowa
* Copyright (c) 2010-2014, Tomasz Sowa
* All rights reserved.
*
*/
@ -11,13 +11,11 @@
#include <pwd.h>
#include <grp.h>
#include <unistd.h>
#include <sys/param.h>
#include <cstdio>
#include <fetch.h>
#include <signal.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <utility>
#include <curl/curl.h>
#include "app.h"
#include "plugin.h"
#include "misc.h"
@ -398,14 +396,21 @@ void App::ClearAfterRequest()
void App::Start()
{
while( !synchro.was_stop_signal && FCGX_Accept_r(&fcgi_request) == 0 )
{
Lock();
if( !synchro.was_stop_signal )
if( synchro.was_stop_signal )
{
FCGX_Finish_r(&fcgi_request);
}
else
{
ProcessRequest();
}
Unlock();
}
@ -1633,10 +1638,7 @@ void App::Unlock()
void App::WaitForThreads()
{
// special thread hangs on fetchStatURL -- I don't know why
// but it doesn't matter, don't use pthread_join on it
//pthread_join(signal_thread, 0);
pthread_join(signal_thread, 0);
system.thread_manager.StopAll();
}
@ -1644,16 +1646,22 @@ void App::WaitForThreads()
void App::FetchPageOnExit()
{
// !! CHANGE ME use curl instead of BSD's fetch...
// this allows to port to Linux systems
// stupid trick to break FCGX_Accept_r() function
// even with FCGX_InitRequest(..., ..., FCGI_FAIL_ACCEPT_ON_INTR) the FCGX_Accept_r
// doesn't want to break on a signal
// so we request one page from the server for exiting from FCGX_Accept_r
url_stat url;
fetchStatURL(url_to_fetch_on_exit.c_str(), &url, "");
Lock();
CURL * curl = curl_easy_init();
Unlock();
if( curl )
{
curl_easy_setopt(curl, CURLOPT_URL, url_to_fetch_on_exit.c_str());
curl_easy_setopt(curl, CURLOPT_TCP_NODELAY, 1);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
}
@ -1679,8 +1687,6 @@ sigset_t set;
PT::WideToUTF8(app->config.base_url, app->url_to_fetch_on_exit, false);
app->Unlock();
// this thread will hang on this method
// but will be terminated when the main thread exits
app->FetchPageOnExit();
pthread_exit(0);