📄 main.cpp
字号:
/* * (c) Copyright 2008 Philipp Skadorov (philipp_s@users.sourceforge.net) * * This file is part of FREESECS. * * FREESECS 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, either version 3 of the License, or * (at your option) any later version. * * FREESECS 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 FREESECS, see COPYING. * If not, see <http://www.gnu.org/licenses/>. */#include <unistd.h>#include <stdlib.h>#include <getopt.h>#include <sys/types.h>#include <sys/stat.h>#include "log.h"#include "registrar.h"#include "hsms_cnx.h"#include "hsms_factory.h"using namespace freesecs;static int daemonize();static void print_help();static void print_version();static void process();hsms_factory_t hsms_factory;int main(int argc, char *argv[]){ int c; int daemonize_flag = 1; while (1) { int option_index = 0; static struct option long_options[] = { {"nodaemon", 0, 0, 0}, {"help", 0, 0, 0}, {"version", 0, 0, 0}, {0, 0, 0, 0} }; c = getopt_long (argc, argv, "nhv", long_options, &option_index); if(c == -1) break; switch(c) { case 'n': daemonize_flag = 0; break; case 'h': print_help(); exit(0); break; case 'v': print_version(); exit(0); case '?': fprintf(stderr, "unknown argument: %c\n", optopt); print_help(); exit(1); break; } } if(daemonize_flag) { daemonize(); } process(); exit(0);}static int daemonize(){ int res; if(-1 == (res = daemon(0,0))) { TRACE_CRITICAL("failed to daemonize"); } umask(0); return res;}static void print_help(){ fprintf(stdout, "Usage: hsmsd [OPTION]\n"); fprintf(stdout, "Starts HSMS stack daemon process\n"); fprintf(stdout, "\t -h --help\t\t\tdisplay this message\n"); fprintf(stdout, "\t -v --version\t\t\tprint version\n"); fprintf(stdout, "\t -n --nodaemon\t\t\tdon't fork to background\n");}static void print_version(){ fprintf(stdout, "Version: %s\n", PACKAGE_STRING);}#include "timer.h"void process(){ hsmsd_client_registrar_t r; if(hsms_factory.NO_ERR != hsms_factory.parse_config("/etc/hsms.xml")) { fprintf(stderr, "hsms config parsed with errors:\n"); hsms_factory_t::error_container_t::iterator it = hsms_factory.errors.begin(); while(it < hsms_factory.errors.end()) { fprintf(stderr,(it++)->c_str()); } exit(-1); } while(1) r.process();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -