00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 extern "C" {
00042 #include <unistd.h>
00043 #include <netinet/in.h>
00044 #include <signal.h>
00045 }
00046
00047 #include <fstream>
00048
00049 #include "consmgr.h"
00050 #include "cmconfig.h"
00051 #include "mastercont.h"
00052
00053
00054 static void usage(void);
00055
00056 int
00057 main(int argc, char *argv[])
00058 {
00059 int ch;
00060
00061
00062 std::ofstream *null = new std::ofstream("/dev/null");
00063 clog.rdbuf(null->rdbuf());
00064
00065 bool debug = false;
00066 bool foreground = false;
00067 Config *cnf = NULL;
00068
00069
00070 try {
00071 while ((ch = getopt(argc, argv, "c:fDtv")) != -1) {
00072 switch (ch) {
00073 case 'c':
00074 if (cnf)
00075 err(5,"Only one configuration file [currently] allowed");
00076 else
00077 cnf = ConfigFactory::config_object(optarg);
00078 break;
00079 case 'D':
00080 debug = true;
00081 break;
00082 case 'f':
00083 foreground = true;
00084 case 't':
00085
00086 break;
00087 case 'v':
00088 std::cout << "tcpsrv, part of consmgr, built " << __DATE__
00089 << " " << __TIME__ << endl;
00090 break;
00091 case '?':
00092 usage();
00093 exit(1);
00094 }
00095 }
00096
00097 if (cnf == NULL)
00098 cnf = ConfigFactory::config_object("/etc/consmgr.conf");
00099
00100 argc -= optind;
00101 argv += optind;
00102
00103 if (argc != 1) {
00104 usage();
00105 exit(1);
00106 }
00107 } catch (ConfigException &e) {
00108 cerr << e.what() << endl;
00109 exit(4);
00110 } catch (CMException &e) {
00111 cerr << e.what() << endl;
00112 exit(5);
00113 } catch (const string &error) {
00114 cerr << error << endl;
00115 exit(7);
00116 } catch (...) {
00117 cerr << "Other random exception thrown while parsing arguments"
00118 << endl;
00119 exit(7);
00120 }
00121
00122
00123
00124 if (debug) {
00125 clog.rdbuf(cerr.rdbuf());
00126 delete null;
00127 }
00128
00129
00130 try {
00131 cnf->load_entry(argv[0]);
00132 } catch (ConfigUnfoundException &e) {
00133
00134 cerr << e.what() << endl;
00135 exit(2);
00136 } CATCH_STR_OR_DIE(2) {
00137 cerr << "** Uncaught exception in Config::load_entry(" << argv[0]
00138 << ")!!" << endl;
00139 exit(2);
00140 }
00141
00142
00143 ConfigP config(cnf);
00144 MasterController::run(config, true);
00145
00146 exit(0);
00147 }
00148
00149 static void
00150 usage(void)
00151 {
00152 cerr << "Usage: " << __progname << " [-D] [-t] [-c <config-file>]"
00153 << " <connection-name>" << endl;
00154 return;
00155 }
00156