opts.cc

00001 /* 
00002    EyeDB Object Database Management System
00003    Copyright (C) 1994-2008 SYSRA
00004    
00005    EyeDB is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009    
00010    EyeDB is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014    
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with this library; if not, write to the Free Software
00017    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA 
00018 */
00019 
00020 /*
00021    Author: Eric Viara <viara@sysra.com>
00022 */
00023 
00024 
00025 // 3/6/05: should be splitted into opts.cc, init.cc, version.cc
00026 
00027 #include "eyedbconfig.h"
00028 #include "eyedb_p.h"
00029 #include "eyedb/DBM_Database.h"
00030 #include "eyedb/GenHashTable.h"
00031 #include <eyedblib/m_malloc.h>
00032 #include <eyedbsm/smd.h>
00033 #include "oqlctb.h"
00034 #include <eyedb/ThreadPoolManager.h>
00035 #include <eyedblib/m_mem.h>
00036 #include "lib/m_mem_p.h"
00037 #include "comp_time.h"
00038 #include "GetOpt.h"
00039 #include <sstream>
00040 
00041 #define USE_POSTINIT
00042 
00043 #define USE_GETOPT
00044 
00045 #define ONE_K 1024
00046 
00047 using namespace std;
00048 
00049 extern int RPC_MIN_SIZE;
00050 
00051 /*
00052 p_ProbeHandle *eyedb_probe_h;
00053 static const char *eyedb_probe_name = getenv("EYEDBPROBE");
00054 */
00055 
00056 extern void (*rpc_release_all)(void);
00057 
00058 namespace eyedb {
00059 
00060   static void
00061   stop_on_error(Status status, void *)
00062   {
00063     fprintf(stderr, "<<< catching eyedb error >>>\n");
00064     status->print(stderr);
00065 
00066     fprintf(stderr, "continue> ");
00067 
00068     while (getchar() != '\n')
00069       ;
00070   }
00071 
00072   static void
00073   echo_on_error(Status status, void *)
00074   {
00075     fprintf(stderr, "<<< catching eyedb error >>>\n");
00076     status->print(stderr);
00077   }
00078 
00079   static void
00080   abort_on_error(Status status, void *)
00081   {
00082     fprintf(stderr, "<<< catching eyedb error >>>\n");
00083     status->print(stderr);
00084     abort();
00085   }
00086 
00087   static char *LogName;
00088   static int LogLevel;
00089 
00090   inline static void check(const char *prog, const char *opt, int i, int argc,
00091                            char *argv[])
00092   {
00093     if (i >= argc - 1 || *argv[i+1] == '-')
00094       {
00095         fprintf(stderr, "%s: missing argument after option '%s'\n", prog, opt);
00096         exit(1);
00097       }
00098   }
00099 
00100   void
00101   printVersion()
00102   {
00103     printf("EyeDB Copyright (C) 1994-2008 SYSRA\n");
00104     printf(" Version      V%s\n", getVersion());
00105     printf(" Compiled     %s\n", getCompilationTime());
00106     printf(" Architecture %s\n", Architecture::getArchitecture()->getArch());
00107     exit(0);
00108   }
00109 
00110   char *prog_name = "<unknown>";
00111 
00112   static void
00113   ask_for_user()
00114   {
00115     char userauth[32];
00116     fprintf(stderr, "user authentication: ");
00117     fflush(stderr);
00118     if (!fgets(userauth, sizeof(userauth)-1, stdin))
00119       exit(1);
00120     userauth[strlen(userauth)-1] = 0;
00121     Connection::setDefaultUser(userauth);
00122   }
00123 
00124   static void
00125   ask_for_passwd()
00126   {
00127     Connection::setDefaultPasswd(getpass("password authentication: "));
00128   }
00129 
00130 #define ON_OFF(OPT, MTH) \
00131 do { \
00132   check(argv[0], "-" OPT, i, argc, argv); \
00133   const char *sx = argv[++i]; \
00134   if (!strcmp(sx, "on")) \
00135     Log::MTH(True); \
00136   else if (!strcmp(sx, "off")) \
00137     Log::MTH(False); \
00138   else \
00139     { \
00140       fprintf(stderr, "-%s option: 'on' or 'off' expected\n", OPT); \
00141       exit(1); \
00142     } \
00143   i++; \
00144 } while(0)
00145 
00146   static void
00147   make_options(int &argc, char *argv[], ostream *usage_ostr,
00148                std::ostream *help_ostr, string *listen = 0,
00149                bool purgeargv = true)
00150   {
00151     int n = 1;
00152 
00153     static const char *opt_prefix = "-eyedb";
00154     static int len_opt_prefix = strlen(opt_prefix);
00155     static const char *opt_sv_prefix = "-eyedbsv";
00156     static int len_opt_sv_prefix = strlen(opt_sv_prefix);
00157 
00158     // disconnect this condition because it should work also for
00159     // local opening mode
00160 
00161     if (getenv("RPC_MIN_SIZE")) {
00162       RPC_MIN_SIZE = atoi(getenv("RPC_MIN_SIZE"));
00163       printf("RPC_MIN_SIZE %u\n", RPC_MIN_SIZE);
00164     }
00165 
00166     const std::string prefix = "";
00167     std::vector<string> error_v;
00168     error_v.push_back("status");
00169     error_v.push_back("exception");
00170     error_v.push_back("abort");
00171     error_v.push_back("stop");
00172     error_v.push_back("echo");
00173     OptionChoiceType errorChoice("error", error_v, "status");
00174 
00175     static const std::string user_opt = "user";
00176     static const std::string passwd_opt = "passwd";
00177     //static const std::string auth_opt = "auth";
00178     static const std::string listen_opt = "listen";
00179     static const std::string host_opt = "host";
00180     static const std::string port_opt = "port";
00181     static const std::string inet_opt = "inet";
00182 #ifdef HAVE_EYEDBSMD
00183     static const std::string smd_port_opt = "smd-port";
00184 #endif
00185     static const std::string maximum_server_memory_size_opt = "maximum-server-memory-size";
00186     static const std::string default_file_mask_opt = "default-file-mask";
00187     static const std::string default_file_group_opt = "default-file-group";
00188     static const std::string dbm_opt = "dbm";
00189     static const std::string granted_dbm_opt = "granted-dbm";
00190     static const std::string default_dbm_opt = "default-dbm";
00191     static const std::string conf_opt = "conf";
00192     static const std::string server_conf_opt = "server-conf";
00193     static const std::string logdev_opt = "logdev";
00194     static const std::string logmask_opt = "logmask";
00195     static const std::string logdate_opt = "logdate";
00196     static const std::string logtimer_opt = "logtimer";
00197     static const std::string logpid_opt = "logpid";
00198     static const std::string logprog_opt = "logprog";
00199     static const std::string error_policy_opt = "error-policy";
00200     static const std::string trans_def_mag_opt = "trans-def-mag";
00201     static const std::string arch_opt = "arch";
00202     static const std::string version_opt = "version";
00203     static const std::string help_logmask_opt = "help-logmask";
00204     static const std::string help_eyedb_options_opt = "help-eyedb-options";
00205 
00206     Option opts[32];
00207 
00208     unsigned int opt_cnt = 0;
00209 
00210     opts[opt_cnt++] = 
00211       Option('U', prefix + user_opt, OptionStringType(),
00212              Option::MandatoryValue, OptionDesc("User name", "USER|@"));
00213 
00214     opts[opt_cnt++] = 
00215       Option('P', prefix + passwd_opt, OptionStringType(),
00216              Option::OptionalValue,  OptionDesc("Password", "PASSWD"));
00217 
00218     if (listen) {
00219       opts[opt_cnt++] = 
00220         Option(listen_opt, OptionStringType(),
00221                Option::MandatoryValue,
00222                OptionDesc("listen host and ports", "[HOST:]PORT"));
00223 
00224       opts[opt_cnt++] = 
00225         Option(prefix + granted_dbm_opt, OptionStringType(),
00226                Option::MandatoryValue,
00227                OptionDesc("Granted EYEDBDBM database files", "DBMFILES"));
00228 
00229       opts[opt_cnt++] = 
00230         Option(prefix + default_dbm_opt, OptionStringType(),
00231                Option::MandatoryValue,
00232                OptionDesc("Default EYEDBDBM database file", "DBMFILE"));
00233     }
00234     else {
00235       opts[opt_cnt++] = 
00236         Option(prefix + host_opt, OptionStringType(), Option::MandatoryValue,
00237                OptionDesc("eyedbd host", "HOST"));
00238 
00239       opts[opt_cnt++] = 
00240         Option(prefix + port_opt, OptionStringType(), Option::MandatoryValue,
00241                OptionDesc("eyedbd port", "PORT"));
00242 
00243       opts[opt_cnt++] = 
00244         Option(prefix + inet_opt, OptionStringType(), 0,
00245                OptionDesc("Use the tcp_port variable if port is not set"));
00246 
00247       opts[opt_cnt++] = 
00248         Option(prefix + dbm_opt, OptionStringType(), Option::MandatoryValue,
00249                OptionDesc("EYEDBDBM database file", "DBMFILE"));
00250     }
00251 
00252 
00253     opts[opt_cnt++] = 
00254       Option(prefix + conf_opt, OptionStringType(), Option::MandatoryValue,
00255              OptionDesc("Client Configuration file", "CONFFILE"));
00256 
00257     opts[opt_cnt++] = 
00258       Option(prefix + server_conf_opt, OptionStringType(),
00259              Option::MandatoryValue,
00260              OptionDesc(std::string("Server Configuration file") +
00261                         (listen ? "" : " (used for local opening)"),
00262                         "CONFFILE"));
00263 
00264 #ifdef HAVE_EYEDBSMD
00265     opts[opt_cnt++] = 
00266       Option(prefix + smd_port_opt, OptionStringType(), Option::MandatoryValue,
00267              OptionDesc(std::string("eyedbsmd port") +
00268                         (listen ? "" : " (used for local opening)"),
00269                         "PORT"));
00270 #endif
00271     
00272     opts[opt_cnt++] = 
00273       Option(prefix + default_file_mask_opt, OptionIntType(), Option::MandatoryValue,
00274              OptionDesc("Default file mask", "MASK"));
00275     
00276     opts[opt_cnt++] = 
00277       Option(prefix + default_file_group_opt, OptionStringType(), Option::MandatoryValue,
00278              OptionDesc("Default file group", "GROUP"));
00279     
00280     opts[opt_cnt++] = 
00281       Option(prefix + maximum_server_memory_size_opt, OptionIntType(), Option::MandatoryValue,
00282              OptionDesc("Maximum server memory size (in Mb)",
00283                         "SIZE"));
00284     
00285     opts[opt_cnt++] = 
00286       Option(prefix + logdev_opt, OptionStringType(), Option::MandatoryValue,
00287              OptionDesc("Output log file", "LOGFILE"));
00288 
00289     opts[opt_cnt++] = 
00290       Option(prefix + logmask_opt, OptionStringType(), Option::MandatoryValue,
00291              OptionDesc("Output log mask", "MASK"));
00292 
00293     opts[opt_cnt++] = 
00294       Option(prefix + logdate_opt, OptionBoolType(), Option::MandatoryValue,
00295              OptionDesc("Control date display in output log", "on|off"));
00296 
00297     opts[opt_cnt++] = 
00298       Option(prefix + logtimer_opt, OptionBoolType(), Option::MandatoryValue,
00299              OptionDesc("Control timer display in output log", "on|off"));
00300 
00301     opts[opt_cnt++] = 
00302       Option(prefix + logpid_opt, OptionBoolType(), Option::MandatoryValue,
00303              OptionDesc("Control pid display in output log", "on|off"));
00304 
00305     opts[opt_cnt++] = 
00306       Option(prefix + logprog_opt, OptionBoolType(), Option::MandatoryValue,
00307              OptionDesc("Control progname display in output log", "on|off"));
00308 
00309     opts[opt_cnt++] = 
00310       Option(prefix + error_policy_opt, errorChoice, Option::MandatoryValue,
00311              OptionDesc("Control error policy: status|exception|abort|stop|echo",
00312                         "VALUE"));
00313     opts[opt_cnt++] = 
00314       Option(prefix + trans_def_mag_opt, OptionIntType(), Option::MandatoryValue,
00315              OptionDesc("Default transaction magnitude order",
00316                         "MAGORDER"));
00317 
00318     opts[opt_cnt++] = 
00319       Option(prefix + arch_opt, OptionBoolType(), 0,
00320              OptionDesc("Display the client architecture"));
00321 
00322     opts[opt_cnt++] = 
00323       Option('v', prefix + version_opt, OptionBoolType(), 0,
00324              OptionDesc("Display the version"));
00325 
00326     opts[opt_cnt++] = 
00327       Option(prefix + help_logmask_opt, OptionBoolType(), 0,
00328              OptionDesc("Display logmask usage"));
00329 
00330     opts[opt_cnt++] = 
00331       Option(prefix + help_eyedb_options_opt, OptionBoolType(), 0,
00332              OptionDesc("Display this message"));
00333 
00334     GetOpt getopt(argv[0], opts, opt_cnt,
00335                   GetOpt::SkipUnknownOption|(purgeargv ? GetOpt::PurgeArgv : 0));
00336 
00337     if (usage_ostr) {
00338       getopt.usage("", "");
00339       return;
00340     }
00341 
00342     if (help_ostr) {
00343       getopt.help(*help_ostr, "  ");
00344       return;
00345     }
00346 
00347     if (!getopt.parse(argc, argv)) {
00348       getopt.usage("\n");
00349       exit(0);
00350     }
00351 
00352     prog_name = strdup(argv[0]);
00353 
00354     GetOpt::Map &map = getopt.getMap();
00355 
00356     if (map.find(help_eyedb_options_opt) != map.end()) {
00357       cerr << "Common Options:\n";
00358       getopt.help(cerr, "  ");
00359       exit(0);
00360     }
00361 
00362     if (map.find(help_logmask_opt) != map.end()) {
00363       cerr << Log::getUsage() << endl;
00364       exit(0);
00365     }
00366 
00367     if (map.find(conf_opt) != map.end()) {
00368       Status s = ClientConfig::setConfigFile(map[conf_opt].value.c_str());
00369       if (s) {
00370         s->print(stderr);
00371         exit(1);
00372       }
00373     }
00374 
00375     if (map.find(server_conf_opt) != map.end()) {
00376       Status s = ServerConfig::setConfigFile(map[server_conf_opt].value.c_str());
00377       if (s) {
00378         s->print(stderr);
00379         exit(1);
00380       }
00381     }
00382 
00383     if (map.find(port_opt) != map.end())
00384       Connection::setDefaultIDBPort(map[port_opt].value.c_str());
00385     else if (map.find(inet_opt) != map.end())
00386       Connection::setDefaultIDBPort(ClientConfig::getCValue("tcp_port"));
00387 
00388     if (map.find(host_opt) != map.end())
00389       Connection::setDefaultHost(map[host_opt].value.c_str());
00390 
00391     if (map.find(listen_opt) != map.end()) {
00392       assert(listen);
00393       if (listen)
00394         *listen = map[listen_opt].value;
00395       else
00396         getopt.usage("\n");
00397 
00398       ServerConfig::getInstance()->setValue("listen",
00399                                             map[listen_opt].value.c_str());
00400     }
00401 
00402     if (map.find(granted_dbm_opt) != map.end())
00403       ServerConfig::getInstance()->setValue("granted_dbm",
00404                                             map[granted_dbm_opt].value.c_str());
00405 
00406     if (map.find(default_dbm_opt) != map.end())
00407       ServerConfig::getInstance()->setValue("default_dbm",
00408                                             map[default_dbm_opt].value.c_str());
00409 
00410     if (map.find(dbm_opt) != map.end())
00411       Database::setDefaultDBMDB(map[dbm_opt].value.c_str());
00412 
00413     if (map.find(user_opt) != map.end()) {
00414       if (map[user_opt].value.length() != 0)
00415         Connection::setDefaultUser(map[user_opt].value.c_str());
00416       else
00417         ask_for_user();
00418     }
00419 
00420     const char *pwd = ClientConfig::getCValue("passwd");
00421     if (pwd)
00422       Connection::setDefaultPasswd(pwd);
00423 
00424     if (map.find(passwd_opt) != map.end()) {
00425       if (map[passwd_opt].value.length() != 0)
00426         Connection::setDefaultPasswd(map[passwd_opt].value.c_str());
00427       else {
00428         ask_for_passwd();
00429       }
00430     }
00431 
00432 #if 0
00433     if (map.find(auth_opt) != map.end()) {
00434       if (map[auth_opt].value.length() != 0)
00435         Connection::setDefaultPasswd(map[user_opt].value.c_str());
00436       else {
00437         ask_for_user();
00438         ask_for_passwd();
00439       }
00440     }
00441 #endif
00442 
00443     if (map.find(version_opt) != map.end()) {
00444       printVersion();
00445       exit(0);
00446     }
00447 
00448     if (map.find(arch_opt) != map.end()) {
00449       printf("%s\n", Architecture::getArchitecture()->getArch());
00450       exit(0);
00451     }
00452 
00453     if (map.find(logdev_opt) != map.end())
00454       LogName = strdup(map[logdev_opt].value.c_str());
00455 
00456     if (map.find(logpid_opt) != map.end()) {
00457       bool b = ((OptionBoolType *)map[logpid_opt].type)->getBoolValue
00458         (map[logpid_opt].value);
00459       Log::setLogPid(b ? True : False);
00460     }
00461 
00462     if (map.find(logdate_opt) != map.end()) {
00463       bool b = ((OptionBoolType *)map[logdate_opt].type)->getBoolValue
00464         (map[logdate_opt].value);
00465       Log::setLogDate(b ? True : False);
00466     }
00467 
00468     if (map.find(logtimer_opt) != map.end()) {
00469       bool b = ((OptionBoolType *)map[logtimer_opt].type)->getBoolValue
00470         (map[logtimer_opt].value);
00471       Log::setLogTimer(b ? True : False);
00472     }
00473 
00474     if (map.find(logprog_opt) != map.end()) {
00475       bool b = ((OptionBoolType *)map[logprog_opt].type)->getBoolValue
00476         (map[logprog_opt].value);
00477       Log::setLogProgName(b ? True : False);
00478     }
00479 
00480     if (map.find(logmask_opt) != map.end()) {
00481       Status s = Log::setLogMask(map[logmask_opt].value.c_str());
00482       if (s) {
00483         s->print(stderr);
00484         exit(1);
00485       }
00486     }
00487 
00488     if (map.find(default_file_mask_opt) != map.end()) {
00489       ServerConfig::getInstance()->setValue
00490         ("default_file_mask", map[default_file_mask_opt].value.c_str());
00491     }
00492 
00493     if (map.find(default_file_group_opt) != map.end()) {
00494       ServerConfig::getInstance()->setValue
00495         ("default_file_group", map[default_file_group_opt].value.c_str());
00496     }
00497 
00498     if (map.find(maximum_server_memory_size_opt) != map.end()) {
00499       ServerConfig::getInstance()->setValue
00500         ("maximum_memory_size",
00501          map[maximum_server_memory_size_opt].value.c_str());
00502     }
00503 
00504 #ifndef USE_POSTINIT
00505     const char *max_memsize = ServerConfig::getSValue("maximum_memory_size");
00506     if (max_memsize) {
00507       m_set_maxsize(atoi(max_memsize) * ONE_K * ONE_K);
00508     }
00509 #endif
00510 
00511 #ifdef HAVE_EYEDBSMD
00512     if (map.find(smd_port_opt) != map.end()) {
00513 #ifndef USE_POSTINIT
00514       smd_set_port(map[smd_port_opt].value.c_str());
00515 #endif
00516       ServerConfig::getInstance()->setValue("smdport",
00517                                             map[smd_port_opt].value.c_str());
00518     }
00519 #ifndef USE_POSTINIT
00520     else {
00521       const char *smdport = ServerConfig::getSValue("smdport");
00522       if (smdport)
00523         smd_set_port(smdport);
00524     }
00525 #endif
00526 #endif
00527 
00528     if (map.find(trans_def_mag_opt) != map.end())
00529       TransactionParams::setGlobalDefaultMagOrder(atoi(map[trans_def_mag_opt].value.c_str()));
00530  
00531     if (map.find(error_policy_opt) != map.end()) {
00532       const char *policy = map[error_policy_opt].value.c_str();
00533 
00534       if (!strcmp(policy, "status"))
00535         Exception::setMode(Exception::StatusMode);
00536       else if (!strcmp(policy, "exception"))
00537         Exception::setMode(Exception::ExceptionMode);
00538       else if (!strcmp(policy, "abort"))
00539         Exception::setHandler(abort_on_error);
00540       else if (!strcmp(policy, "stop"))
00541         Exception::setHandler(stop_on_error);
00542       else if (!strcmp(policy, "echo"))
00543         Exception::setHandler(echo_on_error);
00544       else
00545         exit(1);
00546     }
00547   }
00548 
00549    void print_standard_usage(GetOpt &getopt, const std::string &append,
00550                              ostream &os, bool server)
00551   {
00552     getopt.usage(" " + append, "usage: ", os);
00553     os << "\n\nCommon Options:\n";
00554     print_common_usage(os, server);
00555     os << '\n';
00556   }
00557 
00558 
00559   void print_standard_help(GetOpt &getopt,
00560                            const std::vector<std::string> &options,
00561                            ostream &os, bool server)
00562   {
00563     os << "Program Options:\n";
00564     getopt.help(os, "  ");
00565     unsigned int size = options.size();
00566     for (unsigned int n = 0; n < size; n += 2)
00567       getopt.helpLine(options[n], options[n+1], os);
00568 
00569     print_use_help(os);
00570   }
00571 
00572   void print_common_usage(ostream &os, bool server)
00573   {
00574     int argc = 1;
00575     char *argv[] = {""};
00576     string listen;
00577     make_options(argc, argv, &os, 0, server ? &listen : 0);
00578   }
00579 
00580   void print_use_help(ostream &os)
00581   {
00582     os << "\nUse --help-eyedb-options for a list of common options.\n";
00583   }
00584 
00585   void print_common_help(ostream &os, bool server)
00586   {
00587     int argc = 1;
00588     char *argv[] = {""};
00589     string listen;
00590     make_options(argc, argv, 0, &os, server ? &listen : 0);
00591   }
00592 
00593 #include <pthread.h>
00594 
00595   static void
00596   checkLinkedWithMt()
00597   {
00598     if (getenv("EYEDBNOMT"))
00599       return;
00600 
00601     pthread_mutex_t mp;
00602     pthread_mutex_init(&mp, NULL);
00603     pthread_mutex_lock(&mp);
00604 
00605     if (!pthread_mutex_trylock(&mp)) {
00606       fprintf(stderr, "eyedb fatal error: this program has not been linked "
00607               "with the thread library: flag -mt or -lpthread\n");
00608       exit(1);
00609     }
00610   }
00611 
00612   static FILE *fd_stream;
00613   static char file_stream[128];
00614 
00615   static void
00616   stream_init()
00617   {
00618     if (fd_stream)
00619       return;
00620 
00621     const char *tmpdir = ServerConfig::getSValue("tmpdir");
00622     if (!tmpdir)
00623       tmpdir = "/tmp";
00624     char *s = tempnam(tmpdir, "eyedb_");
00625     strcpy(file_stream, s);
00626     free(s);
00627 
00628     fd_stream = fopen(file_stream, "w");
00629     if (fd_stream)
00630       fclose(fd_stream);
00631     fd_stream = fopen(file_stream, "r+");
00632   }
00633 
00634   static void
00635   stream_release()
00636   {
00637     if (fd_stream != 0)
00638       {
00639         fclose(fd_stream);
00640         remove(file_stream);
00641       }
00642   }
00643 
00644   static inline int
00645   has_zero(const char *buf, int n)
00646   {
00647     const char *p = buf;
00648 
00649     while (n--)
00650       if (!*p++)
00651         return 1;
00652 
00653     return 0;
00654   }
00655 
00656   //
00657   // Warning: this converter is not thread-safe
00658   //
00659 
00660   ostream& convert_to_stream(ostream &os)
00661   {
00662     static char c;
00663     stream_init();
00664     fwrite(&c, 1, 1, fd_stream);
00665 
00666     rewind(fd_stream);
00667 
00668     int n;
00669     char buf[4096];
00670   
00671     while ((n = fread(buf, 1, (sizeof buf)-1, fd_stream)) > 0)
00672       {
00673         if (isBackendInterrupted()) {
00674           setBackendInterrupt(False);
00675           return os << "Interrupted!";
00676         }
00677 
00678         buf[n] = 0;
00679         os << buf;
00680         if (has_zero(buf, n))
00681           break;
00682       }
00683 
00684     rewind(fd_stream);
00685 
00686     return os;
00687   }
00688 
00689   FILE *
00690   get_file(Bool init)
00691   {
00692     stream_init();
00693     if (init)
00694       rewind(fd_stream);
00695     return fd_stream;
00696   }
00697 
00698   void
00699   release_all()
00700   {
00701     eyedb::release();
00702   }
00703 
00704   static void preinit()
00705   {
00706     static bool initialized = false;
00707 
00708     if (initialized)
00709       return;
00710 
00711     initialized = true;
00712 
00713     rpc_release_all = release_all;
00714 
00715     checkLinkedWithMt();
00716 
00717     //stream_init();
00718     Architecture::init();
00719     Class::init();
00720     Basic::init();
00721     AgregatClass::init();
00722     RecMode::init();
00723     //Connection::init();
00724     Exception::init();
00725     Database::init();
00726     //DBM_Database::init();
00727     CollectionClass::init();
00728     ClassConversion::init();
00729     ThreadPoolManager::init();
00730     oqml_initialize();
00731 
00732     rpcFeInit();
00733     eyedbsm::init();
00734     GenHashTable h(1, 1); // hack
00735     syscls::init();
00736     oqlctb::init();
00737     utils::init();
00738 
00739     DBM_Database::init();
00740 
00741     // WARNING: in the case of eyedb is dynamically loaded in
00742     // a program (for instance php), one must not call atexit
00743     atexit(release_all);
00744 
00745     /*
00746       if (eyedb_probe_name)
00747       eyedb_probe_h = p_probeInit(eyedb_probe_name);
00748     */
00749 
00750     ios::sync_with_stdio();
00751   }
00752 
00753 
00754   static void postinit()
00755   {
00756 #ifdef HAVE_EYEDBSMD
00757     const char *smdport = ServerConfig::getSValue("smdport");
00758     if (smdport)
00759       smd_set_port(smdport);
00760 #endif
00761 
00762     const char *max_memsize = ServerConfig::getSValue("maximum_memory_size");
00763     if (max_memsize) {
00764       m_set_maxsize(atoi(max_memsize) * ONE_K * ONE_K);
00765     }
00766 
00767     Connection::init();
00768   }
00769 
00770   void release()
00771   {
00772     static int release;
00773 
00774     if (release)
00775       return;
00776 
00777     release = 1;
00778 
00779     oqml_release();
00780 
00781     Config::_release();
00782     Architecture::_release();
00783 
00784     DBM_Database::_dble_underscore_release();
00785     Database::_release();
00786     Class::_release();
00787     Basic::_release();
00788     AgregatClass::_release();
00789     RecMode::_release();
00790     Connection::_release();
00791     Exception::_release();
00792     CollectionClass::_release();
00793     ClassConversion::_release();
00794     ThreadPoolManager::_release();
00795 
00796     rpcFeRelease();
00797 
00798     eyedbsm::release();
00799     oqlctb::release();
00800     utils::release();
00801     syscls::release();
00802 
00803     stream_release();
00804 
00805     /*
00806       if (eyedb_probe_h)
00807       p_probeSave(eyedb_probe_h, eyedb_probe_name);
00808     */
00809 
00810 #ifdef SOCKET_PROFILE
00811     unsigned int read_cnt, read_tm_cnt, write_cnt, byte_read_cnt, byte_write_cnt;
00812 
00813     rpc_getStats(&read_cnt, &read_tm_cnt, &write_cnt,
00814                  &byte_read_cnt, &byte_write_cnt);
00815 
00816     cout << "RPC read        : " << read_cnt << endl;
00817     cout << "RPC read_tm     : " << read_tm_cnt << endl;
00818     cout << "RPC write       : " << write_cnt << endl;
00819     cout << "RPC bytes read  : " << byte_read_cnt << endl;
00820     cout << "RPC bytes write : " << byte_write_cnt << endl;
00821 #endif
00822   }
00823 
00824   void init(int &argc, char *argv[], string *listen, bool purgeargv)
00825   {
00826     static bool initialized = false;
00827 
00828     if (initialized)
00829       return;
00830 
00831     initialized = true;
00832 
00833     preinit();
00834 
00835     make_options(argc, argv, 0, 0, listen, purgeargv); 
00836 
00837     postinit();
00838 
00839     Status status = Log::init(argv[0], LogName);
00840     if (status)
00841       {
00842         status->print(stderr);
00843         exit(1);
00844       }
00845   }
00846 
00847   extern void IDB_releaseConn();
00848 
00849   void init(int &argc, char *argv[])
00850   {
00851     init(argc, argv, 0, true);
00852   }
00853 
00854   void init() {
00855     preinit();
00856     postinit();
00857   }
00858 
00859   void idbRelease(void)
00860   {
00861     DBM_Database::_release();
00862     IDB_releaseConn();
00863   }
00864 }

Generated on Mon Dec 22 18:16:00 2008 for eyedb by  doxygen 1.5.3