00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <unistd.h>
00021 #include <stdlib.h>
00022 #include <getopt.h>
00023 #include <sys/types.h>
00024 #include <sys/stat.h>
00025 #include "log.h"
00026 #include "registrar.h"
00027 #include "hsms_cnx.h"
00028 #include "hsms_factory.h"
00029
00030 using namespace freesecs;
00031
00032 static int daemonize();
00033 static void print_help();
00034 static void print_version();
00035 static void process();
00036
00037 hsms_factory_t hsms_factory;
00038
00039 int main(int argc, char *argv[])
00040 {
00041 int c;
00042 int daemonize_flag = 1;
00043
00044 while (1)
00045 {
00046 int option_index = 0;
00047 static struct option long_options[] =
00048 {
00049 {"nodaemon", 0, 0, 0},
00050 {"help", 0, 0, 0},
00051 {"version", 0, 0, 0},
00052 {0, 0, 0, 0}
00053 };
00054
00055 c = getopt_long (argc, argv, "nhv",
00056 long_options, &option_index);
00057
00058 if(c == -1)
00059 break;
00060
00061 switch(c)
00062 {
00063 case 'n':
00064 daemonize_flag = 0;
00065 break;
00066 case 'h':
00067 print_help();
00068 exit(0);
00069 break;
00070 case 'v':
00071 print_version();
00072 exit(0);
00073 case '?':
00074 fprintf(stderr, "unknown argument: %c\n", optopt);
00075 print_help();
00076 exit(1);
00077 break;
00078 }
00079 }
00080
00081 if(daemonize_flag)
00082 {
00083 daemonize();
00084 }
00085
00086 process();
00087
00088 exit(0);
00089 }
00090
00091 static int daemonize()
00092 {
00093 int res;
00094 if(-1 == (res = daemon(0,0)))
00095 {
00096 TRACE_CRITICAL("failed to daemonize");
00097 }
00098 umask(0);
00099 return res;
00100 }
00101
00102 static void print_help()
00103 {
00104 fprintf(stdout, "Usage: hsmsd [OPTION]\n");
00105 fprintf(stdout, "Starts HSMS stack daemon process\n");
00106 fprintf(stdout, "\t -h --help\t\t\tdisplay this message\n");
00107 fprintf(stdout, "\t -v --version\t\t\tprint version\n");
00108 fprintf(stdout, "\t -n --nodaemon\t\t\tdon't fork to background\n");
00109 }
00110
00111 static void print_version()
00112 {
00113 fprintf(stdout, "Version: %s\n", PACKAGE_STRING);
00114 }
00115
00116 #include "timer.h"
00117 void process()
00118 {
00119 hsmsd_client_registrar_t r;
00120
00121 if(hsms_factory.NO_ERR != hsms_factory.parse_config("/etc/hsms.xml"))
00122 {
00123 fprintf(stderr, "hsms config parsed with errors:\n");
00124 hsms_factory_t::error_container_t::iterator it = hsms_factory.errors.begin();
00125 while(it < hsms_factory.errors.end())
00126 {
00127 fprintf(stderr,(it++)->c_str());
00128 }
00129 exit(-1);
00130 }
00131 while(1)
00132 r.process();
00133 }