moved winix directories to winixdsubdirectory
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@1028 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
19
winixd/main/Makefile
Normal file
19
winixd/main/Makefile
Normal file
@@ -0,0 +1,19 @@
|
||||
include Makefile.o.dep
|
||||
|
||||
|
||||
all: $(o)
|
||||
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) -c $(CXXFLAGS) $(CXXWINIXINCLUDEFLAGS) $<
|
||||
|
||||
|
||||
depend:
|
||||
makedepend -Y. $(CXXWINIXINCLUDEFLAGS) -f- *.cpp > Makefile.dep
|
||||
echo -n "o = " > Makefile.o.dep
|
||||
ls -1 *.cpp | xargs -I foo echo -n foo " " | sed -E "s/([^\.]*)\.cpp[ ]/\1\.o/g" >> Makefile.o.dep
|
||||
|
||||
clean:
|
||||
rm -f *.o
|
||||
|
||||
include Makefile.dep
|
||||
88
winixd/main/Makefile.dep
Normal file
88
winixd/main/Makefile.dep
Normal file
@@ -0,0 +1,88 @@
|
||||
# DO NOT DELETE
|
||||
|
||||
main.o: ../../winix/core/log.h ../../winix/core/textstream.h
|
||||
main.o: ../../winix/core/misc.h ../../winix/core/item.h
|
||||
main.o: ../../pikotools/space/space.h ../../pikotools/textstream/types.h
|
||||
main.o: ../../pikotools/date/date.h ../../winix/core/requesttypes.h
|
||||
main.o: ../../pikotools/textstream/textstream.h
|
||||
main.o: ../../pikotools/convert/convert.h ../../pikotools/convert/inttostr.h
|
||||
main.o: ../../pikotools/membuffer/membuffer.h
|
||||
main.o: ../../pikotools/textstream/types.h ../../pikotools/utf8/utf8.h
|
||||
main.o: ../../winix/core/winix_const.h ../../winix/core/logmanipulators.h
|
||||
main.o: ../../winix/core/slog.h ../../winix/core/cur.h
|
||||
main.o: ../../winix/core/request.h ../../winix/core/error.h
|
||||
main.o: ../../winix/core/config.h ../../pikotools/space/spaceparser.h
|
||||
main.o: ../../pikotools/space/space.h ../../winix/core/htmlfilter.h
|
||||
main.o: ../../winix/templates/htmltextstream.h ../../winix/core/textstream.h
|
||||
main.o: ../../pikotools/space/spacetojson.h ../../ezc/src/outstreams.h
|
||||
main.o: ../../winix/core/session.h ../../winix/core/user.h
|
||||
main.o: ../../winix/core/plugindata.h ../../winix/core/rebus.h
|
||||
main.o: ../../winix/core/ipban.h ../../winix/core/mount.h
|
||||
main.o: ../../winix/templates/locale.h ../../winix/core/slog.h
|
||||
main.o: ../../winix/core/app.h ../../winix/core/system.h
|
||||
main.o: ../../winix/core/job.h ../../winix/core/basethread.h
|
||||
main.o: ../../winix/core/synchro.h ../../winix/core/dirs.h
|
||||
main.o: ../../winix/core/dircontainer.h ../../winix/db/db.h
|
||||
main.o: ../../winix/db/dbbase.h ../../winix/db/dbconn.h
|
||||
main.o: ../../winix/db/dbtextstream.h ../../winix/core/error.h
|
||||
main.o: ../../winix/db/dbitemquery.h ../../winix/core/item.h
|
||||
main.o: ../../winix/db/dbitemcolumns.h ../../winix/core/user.h
|
||||
main.o: ../../winix/core/group.h ../../winix/core/dircontainer.h
|
||||
main.o: ../../winix/core/ugcontainer.h ../../winix/core/log.h
|
||||
main.o: ../../winix/notify/notify.h ../../winix/notify/notifypool.h
|
||||
main.o: ../../winix/templates/patterns.h ../../winix/templates/locale.h
|
||||
main.o: ../../winix/templates/localefilter.h ../../ezc/src/ezc.h
|
||||
main.o: ../../ezc/src/generator.h ../../ezc/src/blocks.h
|
||||
main.o: ../../ezc/src/cache.h ../../ezc/src/functions.h
|
||||
main.o: ../../ezc/src/funinfo.h ../../ezc/src/objects.h
|
||||
main.o: ../../ezc/src/pattern.h ../../ezc/src/patternparser.h
|
||||
main.o: ../../winix/notify/notifythread.h ../../winix/core/basethread.h
|
||||
main.o: ../../winix/notify/templatesnotify.h ../../winix/core/config.h
|
||||
main.o: ../../winix/core/users.h ../../winix/core/ugcontainer.h
|
||||
main.o: ../../winix/core/lastcontainer.h ../../winix/core/mounts.h
|
||||
main.o: ../../winix/core/mountparser.h ../../winix/core/crypt.h
|
||||
main.o: ../../winix/core/run.h ../../winix/core/users.h
|
||||
main.o: ../../winix/core/groups.h ../../winix/core/group.h
|
||||
main.o: ../../winix/core/loadavg.h ../../winix/core/image.h
|
||||
main.o: ../../winix/core/threadmanager.h ../../winix/core/timezones.h
|
||||
main.o: ../../winix/core/timezone.h ../../winix/core/sessionmanager.h
|
||||
main.o: ../../winix/core/sessioncontainer.h ../../winix/core/ipbancontainer.h
|
||||
main.o: ../../winix/core/sessionidmanager.h ../../tito/src/base64.h
|
||||
main.o: ../../tito/src/aes.h ../../winix/functions/functions.h
|
||||
main.o: ../../winix/functions/functionbase.h ../../winix/core/request.h
|
||||
main.o: ../../winix/core/system.h ../../winix/core/synchro.h
|
||||
main.o: ../../winix/functions/functionparser.h ../../winix/core/cur.h
|
||||
main.o: ../../winix/functions/account.h ../../winix/functions/adduser.h
|
||||
main.o: ../../winix/functions/cat.h ../../winix/functions/chmod.h
|
||||
main.o: ../../winix/functions/privchanger.h ../../winix/functions/chown.h
|
||||
main.o: ../../winix/functions/ckeditor.h ../../winix/functions/cp.h
|
||||
main.o: ../../winix/functions/default.h ../../winix/functions/download.h
|
||||
main.o: ../../winix/functions/emacs.h ../../winix/functions/env.h
|
||||
main.o: ../../winix/functions/imgcrop.h ../../winix/functions/last.h
|
||||
main.o: ../../winix/functions/login.h ../../winix/functions/logout.h
|
||||
main.o: ../../winix/functions/ln.h ../../winix/functions/ls.h
|
||||
main.o: ../../winix/functions/man.h ../../winix/functions/meta.h
|
||||
main.o: ../../winix/functions/mkdir.h ../../winix/functions/mv.h
|
||||
main.o: ../../winix/functions/nicedit.h ../../winix/functions/node.h
|
||||
main.o: ../../winix/functions/passwd.h ../../winix/functions/priv.h
|
||||
main.o: ../../winix/functions/pw.h ../../winix/functions/reload.h
|
||||
main.o: ../../winix/functions/rm.h ../../winix/functions/rmuser.h
|
||||
main.o: ../../winix/functions/sort.h ../../winix/functions/specialdefault.h
|
||||
main.o: ../../winix/functions/stat.h ../../winix/functions/subject.h
|
||||
main.o: ../../winix/functions/template.h ../../winix/functions/tinymce.h
|
||||
main.o: ../../winix/functions/uname.h ../../winix/functions/upload.h
|
||||
main.o: ../../winix/functions/uptime.h ../../winix/functions/who.h
|
||||
main.o: ../../winix/functions/vim.h ../../winix/core/htmlfilter.h
|
||||
main.o: ../../winix/templates/templates.h
|
||||
main.o: ../../winix/templates/patterncacher.h
|
||||
main.o: ../../winix/templates/indexpatterns.h
|
||||
main.o: ../../winix/templates/patterns.h
|
||||
main.o: ../../winix/templates/changepatterns.h
|
||||
main.o: ../../winix/templates/htmltextstream.h
|
||||
main.o: ../../winix/core/sessionmanager.h ../../winix/core/compress.h
|
||||
main.o: ../../winix/core/postparser.h ../../winix/core/httpsimpleparser.h
|
||||
main.o: ../../winix/core/plugin.h ../../winix/core/pluginmsg.h
|
||||
main.o: ../../winix/core/cookieparser.h ../../winix/core/postmultiparser.h
|
||||
main.o: ../../winix/core/acceptencodingparser.h
|
||||
main.o: ../../winix/core/acceptbaseparser.h ../../winix/core/plugin.h
|
||||
main.o: ../../winix/core/version.h
|
||||
1
winixd/main/Makefile.o.dep
Normal file
1
winixd/main/Makefile.o.dep
Normal file
@@ -0,0 +1 @@
|
||||
o = main.o
|
||||
250
winixd/main/main.cpp
Normal file
250
winixd/main/main.cpp
Normal file
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
* This file is a part of Winix
|
||||
* and is distributed under the 2-Clause BSD licence.
|
||||
* Author: Tomasz Sowa <t.sowa@ttmath.org>
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008-2014, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sys/param.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include "core/log.h"
|
||||
#include "core/slog.h"
|
||||
#include "core/app.h"
|
||||
#include "core/plugin.h"
|
||||
#include "core/version.h"
|
||||
#include "utf8/utf8.h"
|
||||
|
||||
|
||||
|
||||
namespace Winix
|
||||
{
|
||||
|
||||
Log log;
|
||||
Log nlog; // notify log (used by a notification thread)
|
||||
SLog slog; // session logger
|
||||
Plugin plugin;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
application object
|
||||
*/
|
||||
App app;
|
||||
|
||||
|
||||
|
||||
|
||||
void print_syntax()
|
||||
{
|
||||
std::cout << "Syntax:" << std::endl;
|
||||
std::cout << " winix config_file" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CreateNewDescriptor(int des_dst, int flags)
|
||||
{
|
||||
int descriptor;
|
||||
|
||||
descriptor = open("/dev/null", flags | O_NOCTTY);
|
||||
|
||||
if( descriptor != -1 )
|
||||
{
|
||||
dup2(descriptor, des_dst);
|
||||
|
||||
if( descriptor != des_dst )
|
||||
close(descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CloseDescriptors()
|
||||
{
|
||||
close(0);
|
||||
close(1);
|
||||
close(2);
|
||||
app.stdout_is_closed = true;
|
||||
|
||||
CreateNewDescriptor(0, O_RDONLY);
|
||||
CreateNewDescriptor(1, O_WRONLY);
|
||||
CreateNewDescriptor(2, O_WRONLY);
|
||||
}
|
||||
|
||||
|
||||
void LogInfo(LogManipulators log_level, const char * msg, bool put_version, const char * msg2)
|
||||
{
|
||||
log << log_level;
|
||||
log.PrintDate(PT::Date(std::time(0)), app.config.log_time_zone_id);
|
||||
log << ' ' << msg;
|
||||
|
||||
if( put_version )
|
||||
{
|
||||
log << ' ' << WINIX_VER_MAJOR
|
||||
<< '.' << WINIX_VER_MINOR
|
||||
<< '.' << WINIX_VER_REVISION;
|
||||
}
|
||||
|
||||
log << ' ' << msg2 << logend;
|
||||
}
|
||||
|
||||
|
||||
void SavePidFile()
|
||||
{
|
||||
if( !app.config.pid_file.empty() )
|
||||
{
|
||||
std::string file_name;
|
||||
PT::WideToUTF8(app.config.pid_file, file_name);
|
||||
std::ofstream file(file_name);
|
||||
|
||||
if( !file )
|
||||
{
|
||||
log << log1 << "I cannot save the pid to a file: " << app.config.pid_file << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
file << getpid() << "\n";
|
||||
file.close();
|
||||
log << log3 << "Process pid saved to: " << app.config.pid_file << logend;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void RemovePidFile()
|
||||
{
|
||||
if( !app.config.pid_file.empty() )
|
||||
{
|
||||
std::string file_name;
|
||||
PT::WideToUTF8(app.config.pid_file, file_name);
|
||||
unlink(file_name.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} // namespace Winix
|
||||
|
||||
|
||||
int main(int argv, char ** argc)
|
||||
{
|
||||
using Winix::app;
|
||||
|
||||
std::srand(std::time(0));
|
||||
|
||||
if( argv != 2 )
|
||||
{
|
||||
Winix::print_syntax();
|
||||
return 1;
|
||||
}
|
||||
|
||||
app.system.system_start = time(0);
|
||||
|
||||
if( !PT::UTF8ToWide(argc[1], app.config.config_file) )
|
||||
{
|
||||
std::wcout << "An incorrect UTF-8 path of the config file" << std::endl;
|
||||
return 6;
|
||||
}
|
||||
|
||||
if( !app.config.ReadConfig(true, false) ) /* errors to stdout, stdout in not closed */
|
||||
return 2;
|
||||
|
||||
if( app.stdout_is_closed || app.config.demonize )
|
||||
app.config.log_stdout = false;
|
||||
|
||||
if( !app.config.log_stdout )
|
||||
Winix::CloseDescriptors();
|
||||
|
||||
if( app.config.demonize && !app.Demonize() )
|
||||
return 4;
|
||||
|
||||
Winix::log.SetTimeZones(&app.system.time_zones);
|
||||
|
||||
Winix::log.Init(app.config.log_level, app.config.log_save_each_line, app.config.log_file,
|
||||
app.config.log_stdout, app.config.log_request);
|
||||
|
||||
Winix::nlog.Init(app.config.log_level, true, app.config.log_notify_file, false, 1);
|
||||
|
||||
Winix::LogInfo(Winix::log3, "booting Winix", true, "");
|
||||
|
||||
if( !app.InitFCGI() )
|
||||
return 5;
|
||||
|
||||
if( !app.DropPrivileges() )
|
||||
return 3;
|
||||
|
||||
app.LogUserGroups();
|
||||
Winix::log << Winix::log3 << "base_url: " << app.config.base_url << Winix::logend;
|
||||
Winix::SavePidFile();
|
||||
|
||||
// load plugins before loading sessions - session_manager.LoadSessions()
|
||||
// because some of the plugins can init its own sessions dates
|
||||
Winix::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() )
|
||||
{
|
||||
Winix::RemovePidFile();
|
||||
return 1;
|
||||
}
|
||||
|
||||
app.StartThreads();
|
||||
// now we have more threads, we should use Lock() and Unlock()
|
||||
|
||||
// saving all starting logs
|
||||
app.Lock();
|
||||
Winix::LogInfo(Winix::log1, "Winix", true, "started");
|
||||
Winix::log << Winix::logsave;
|
||||
app.Unlock();
|
||||
|
||||
// main loop
|
||||
app.Start();
|
||||
|
||||
app.Lock();
|
||||
Winix::plugin.Call((Winix::Session*)0, WINIX_CLOSE);
|
||||
app.Close();
|
||||
// now all sessions are cleared
|
||||
app.Unlock();
|
||||
|
||||
app.WaitForThreads();
|
||||
// now all others threads are terminated
|
||||
|
||||
Winix::LogInfo(Winix::log1, "Winix", true, "stopped");
|
||||
Winix::RemovePidFile();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user