- now the mess with threads has gone away

- we have a class BaseThread -- this is a base class -- we can inherit from it when
  creating a new thread
- others treads are correctly stopped (when signal comes) -- pthread_join
- we have a special thread only for signals



git-svn-id: svn://ttmath.org/publicrep/winix/trunk@685 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-12-02 01:02:02 +00:00
parent 08e53919e2
commit 35efed9fef
52 changed files with 2464 additions and 1825 deletions

View File

@@ -10,19 +10,22 @@ main.o: ../db/dbitemcolumns.h ../core/user.h ../core/group.h ../core/thread.h
main.o: ../core/dircontainer.h ../core/ugcontainer.h ../core/request.h
main.o: ../core/requesttypes.h ../core/session.h ../core/error.h
main.o: ../core/user.h ../core/plugindata.h ../core/rebus.h
main.o: ../templates/htmltextstream.h ../core/mounts.h ../core/mount.h
main.o: ../core/mountparser.h ../core/users.h ../core/ugcontainer.h
main.o: ../core/lastcontainer.h ../core/groups.h ../core/group.h
main.o: ../core/loadavg.h ../core/sessionmanager.h ../core/sessioncontainer.h
main.o: ../core/notify.h ../templatesnotify/templatesnotify.h
main.o: ../../ezc/src/ezc.h ../../ezc/src/utf8.h ../../ezc/src/generator.h
main.o: ../../ezc/src/pattern.h ../../ezc/src/functions.h
main.o: ../../ezc/src/funinfo.h ../../ezc/src/stringconv.h ../core/mount.h
main.o: ../core/config.h ../templates/misc.h ../templates/localefilter.h
main.o: ../templates/locale.h ../core/confparser.h
main.o: ../templates/htmltextstream.h ../functions/functions.h
main.o: ../templates/htmltextstream.h ../templatesnotify/notify.h
main.o: ../templatesnotify/notifypool.h ../templates/locale.h
main.o: ../core/confparser.h ../templates/misc.h ../templates/localefilter.h
main.o: ../templates/locale.h ../../ezc/src/ezc.h ../../ezc/src/utf8.h
main.o: ../../ezc/src/generator.h ../../ezc/src/pattern.h
main.o: ../../ezc/src/functions.h ../../ezc/src/funinfo.h
main.o: ../../ezc/src/stringconv.h ../templates/htmltextstream.h
main.o: ../templatesnotify/notifythread.h ../core/basethread.h
main.o: ../core/synchro.h ../templatesnotify/templatesnotify.h
main.o: ../core/config.h ../core/users.h ../core/ugcontainer.h
main.o: ../core/lastcontainer.h ../core/mounts.h ../core/mount.h
main.o: ../core/mountparser.h ../core/users.h ../core/groups.h
main.o: ../core/group.h ../core/loadavg.h ../core/sessionmanager.h
main.o: ../core/sessioncontainer.h ../functions/functions.h
main.o: ../functions/functionbase.h ../core/request.h ../core/system.h
main.o: ../core/notify.h ../functions/functionparser.h ../functions/adduser.h
main.o: ../functions/functionparser.h ../functions/adduser.h
main.o: ../functions/cat.h ../functions/chmod.h ../functions/privchanger.h
main.o: ../functions/chown.h ../functions/ckeditor.h ../functions/cp.h
main.o: ../functions/createthread.h ../functions/default.h

View File

@@ -9,11 +9,8 @@
#include <cstdlib>
#include <ctime>
#include <signal.h>
#include <iostream>
#include <sys/param.h>
#include <cstdio>
#include <fetch.h>
#include "core/log.h"
#include "core/app.h"
@@ -32,30 +29,6 @@ Plugin plugin;
App app;
static std::string url_to_fetch_on_exit;
void fetch_page_on_exit()
{
// 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
FILE * f = fetchGetURL(url_to_fetch_on_exit.c_str(), "");
if( f )
fclose(f);
}
void signal_term(int)
{
FCGX_ShutdownPending();
app.WasStopSignal();
fetch_page_on_exit();
}
void print_syntax()
@@ -78,7 +51,6 @@ int main(int argv, char ** argc)
app.system.system_start = time(0);
app.config.config_file = argc[1];
//app.config.config_file = "/home/tomek/roboczy/slimaczek.pl/slimaczek.conf.loc";
if( !app.config.ReadConfig(true, false) ) /* errors to stdout, stdout in not closed */
return 2;
@@ -121,34 +93,10 @@ int main(int argv, char ** argc)
// because some of the plugins can init its own sessions dates
plugin.LoadPlugins(app.config.plugins_dir, app.config.plugin_file);
// app.Init() starts other threads as well (they will be waiting on the lock)
if( !app.Init() )
return 1;
// ----
/*
struct sigaction act, old_act;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
act.sa_handler = signal_term;
sigaction(SIGINT, &act, &old_act);
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
act.sa_handler = signal_term;
sigaction(SIGTERM, &act, &old_act);
*/
// ----
Ezc::WideToUTF8(app.config.base_url, url_to_fetch_on_exit);
signal(SIGTERM, signal_term);
signal(SIGINT, signal_term);
log.PutDate(log1);
log << "winix started" << logend << logsavenow;
@@ -157,10 +105,20 @@ sigaction(SIGTERM, &act, &old_act);
// !! zrobic wyjatek dla root
//app.db.CheckAllUrlSubject();
app.StartThreads();
// now we have more threads, we should use Lock() and Unlock()
// main loop
app.Start();
app.Lock();
plugin.Call(WINIX_CLOSE);
app.Close();
app.Unlock();
app.WaitForThreads();
// now all others threads are terminated
log.PutDate(log1);
log << "winix stopped" << logend << logsavenow;