diff --git a/sls/trunk/Makefile.am b/sls/trunk/Makefile.am index 406cbbf899ea6737394aac4390c4e1533a114549..0b5ba4ad5bf4e73fc1ae9a31608dcf5c9c20f461 100644 --- a/sls/trunk/Makefile.am +++ b/sls/trunk/Makefile.am @@ -24,6 +24,8 @@ sls_SOURCES= src/sls.hh \ src/option.cc \ src/database.hh \ src/database.cc \ + src/cron.hh \ + src/cron.cc \ src/server.hh \ src/server.cc diff --git a/sls/trunk/src/cron.cc b/sls/trunk/src/cron.cc new file mode 100644 index 0000000000000000000000000000000000000000..d21ceb7be178fcfbbd0550e3349010b7d12ca2c5 --- /dev/null +++ b/sls/trunk/src/cron.cc @@ -0,0 +1,20 @@ +/* + This file is part of SLS. + Copyright (C) 2008 Sebastien LUTTRINGER + + SLS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + SLS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with SLS; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "sls.hh" +#include "cron.hh" diff --git a/sls/trunk/src/cron.hh b/sls/trunk/src/cron.hh new file mode 100644 index 0000000000000000000000000000000000000000..e8093811a6cba66b5e3645cca869c4be1fb64a88 --- /dev/null +++ b/sls/trunk/src/cron.hh @@ -0,0 +1,22 @@ +/* + This file is part of SLS. + Copyright (C) 2008 Sebastien LUTTRINGER + + SLS is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + SLS is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with SLS; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef CRON_HH +# define CRON_HH + +#endif diff --git a/sls/trunk/src/option.cc b/sls/trunk/src/option.cc index f56cba96a258b0ddebaa59baaf82d158c99f35ca..9630fa8b8935b95789528ef43962d38a83768ff3 100644 --- a/sls/trunk/src/option.cc +++ b/sls/trunk/src/option.cc @@ -29,9 +29,8 @@ Option::Option() { verbose = false; database = "/var/db/sls.db"; port = 18136; - maxthread = 200; + maxconn = 200; daemon = true; - closefd = true; logfile = "/var/log/sls"; pidfile = "/var/lock/sls.pid"; } @@ -47,11 +46,10 @@ void Option::usage(const char *name, ostream &out) const { << "-v | --verbose : Set verbose mode." << std::endl << "-V | --version : Print version and exit." << std::endl << "-p | --port p : sls listen on port p (def: 18136)." << std::endl - << "-t | --max-thread p : Maximun number of thread (def: 200)." << std::endl + << "-m | --max-conn p : Maximun number of connection (def: 200)." << std::endl << "-P | --pid-file : Path to pid file (def: /var/lock/sls.pid)." << std::endl << "-l | --log-file : Path to log file (def: /var/log/sls)." << std::endl - << "-D | --debug : Run with verbose and not in daemon mode." << std::endl - << "-n | --no-close : Don't close stdin,stdout and stderr." << std::endl; + << "-D | --debug : Run with verbose and not in daemon mode." << std::endl; } /*! @@ -69,16 +67,15 @@ Option &Option::load(int argc, char *argv[]) { {"verbose", 0, 0, 'v'}, {"version", 0, 0, 'V'}, {"port", 0, 0, 'p'}, - {"max-thread", 0, 0, 't'}, + {"max-conn", 0, 0, 'm'}, {"pid-file", 0, 0, 'P'}, {"log-file", 0, 0, 'l'}, {"debug", 0, 0, 'D'}, - {"no-close", 0, 0, 'n'}, {0, 0, 0, 0}, }; int option; - while ((option = getopt_long(argc, argv, "hvnVDd:p:P:l:t:", lopt, 0)) != -1) { + while ((option = getopt_long(argc, argv, "hvnVDd:p:P:l:m:", lopt, 0)) != -1) { switch (option) { case 'h': usage(*argv, std::cout); @@ -86,8 +83,8 @@ Option &Option::load(int argc, char *argv[]) { case 'p': port = atoi(optarg); break; - case 't': - maxthread = atoi(optarg); + case 'm': + maxconn = atoi(optarg); break; case 'd': database = optarg; @@ -106,9 +103,6 @@ Option &Option::load(int argc, char *argv[]) { case 'v': verbose = true; break; - case 'n': - closefd = false; - break; case '?': usage(*argv, std::cerr); exit(ERR_USAGE); @@ -124,19 +118,46 @@ Option &Option::load(int argc, char *argv[]) { } Option &Option::loadenv() { -// const char *senv; + const char *senv; + + // Get log file path + if ((senv = getenv("SLS_LOG_FILE")) != 0 && *senv != 0) + logfile = senv; + + // Get pid file path + if ((senv = getenv("SLS_PID_FILE")) != 0 && *senv != 0) + pidfile = senv; + + // Get DB file path + if ((senv = getenv("SLS_DB_FILE")) != 0 && *senv != 0) + database = senv; -// // Get history path -// if ((senv = getenv("SLC_HISTORY_FILE")) != 0 && *senv != 0) -// history_file = senv; + // Get port + if ((senv = getenv("SLS_PORT")) != 0 && *senv != 0) + port = atoi(senv); -// // Get history size -// if ((senv = getenv("SLC_HISTORY_SIZE")) != 0 && *senv != 0) -// history_size = atoi(senv); + // Get max connection + if ((senv = getenv("SLS_MAX_CONN")) != 0 && *senv != 0) + maxconn = atoi(senv); -// // Get log size -// if ((senv = getenv("SLC_LOG_SIZE")) != 0 && *senv != 0) -// log_size = atoi(senv); + // Get debug state + if ((senv = getenv("SLS_DEBUG")) != 0) { + daemon = false; + verbose = true; + } + + // Get verbose state + if ((senv = getenv("SLS_VERBOSE")) != 0) + verbose = true; return *this; } + +void Option::print(ostream &s) const { + s << "Database file: " << database << std::endl + << "Log file: " << logfile << std::endl + << "Pid file: " << pidfile << std::endl + << "TCP Port: " << port << std::endl + << "Max conn: " << maxconn << std::endl + << "Debug mode: " << !daemon << std::endl; +} diff --git a/sls/trunk/src/option.hh b/sls/trunk/src/option.hh index 11dd07f0862fd7258ac6f9325544f5abe531fc33..3944860fd07095cd222d375931aea7da023932bd 100644 --- a/sls/trunk/src/option.hh +++ b/sls/trunk/src/option.hh @@ -27,18 +27,17 @@ struct Option { void usage(const char *name, ostream &out) const; - friend ostream &operator<<(ostream &, const Option &); + void print(ostream &s = std::cout) const; bool verbose; string database; // socket option int port; - size_t maxthread; + size_t maxconn; // daemon options bool daemon; - bool closefd; string pidfile; string logfile; diff --git a/sls/trunk/src/sls.cc b/sls/trunk/src/sls.cc index a6344a6a23ce438cf056dbd7e2aedc21a21eb7b5..e1bfcf41f107e8bcaad55b109516f87be76b8fce 100644 --- a/sls/trunk/src/sls.cc +++ b/sls/trunk/src/sls.cc @@ -27,18 +27,19 @@ #include #include #include +#include Option O; Database D; Server S; +// Cron C int main(int argc, char *argv[]) { try { - // Load options - O.load(argc, argv); O.loadenv(); + O.load(argc, argv); // Daemonize if (O.daemon) { @@ -64,12 +65,25 @@ int main(int argc, char *argv[]) daemon(0, 1); } + // Options print + if (O.verbose) { + if (!isatty(STDOUT_FILENO)) { + time_t t = time(0); + std::cout << "-------------------------------------" << std::endl + <<"sls start at " << ctime(&t); + } + O.print(std::cout); + } + // Open DB D.open(O.database); + // Start time manager + //C.start(); + // start network S.start(); - S.listen(O.maxthread); + S.listen(O.maxconn); // Close DB D.close(); diff --git a/sls/trunk/test/env.sh b/sls/trunk/test/env.sh new file mode 100644 index 0000000000000000000000000000000000000000..edf3835ee5674eff77ab564a74264b41287730e9 --- /dev/null +++ b/sls/trunk/test/env.sh @@ -0,0 +1,4 @@ +export SLS_LOG_FILE=./logfile +export SLS_PID_FILE=./pidfile +export SLS_DB_FILE=test/good2.db +export SLS_DEBUG="" diff --git a/sls/trunk/test/good2.db b/sls/trunk/test/good2.db new file mode 100644 index 0000000000000000000000000000000000000000..15d55b12c05822cb42a48f8e316bb219f31b2ab0 Binary files /dev/null and b/sls/trunk/test/good2.db differ