📄 main.c
字号:
/* $Id: main.c,v 1.19 2005/02/19 18:16:12 andrew Exp $ *//* * Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net> * * This program 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 2.1 of the License, or (at your option) any later version. * * This software 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <sys/param.h>#include <crm/crm.h>#include <crm/cib.h>#include <stdio.h>#include <sys/types.h>#include <unistd.h>#include <stdlib.h>#include <errno.h>#include <fcntl.h>#include <hb_api.h>#include <clplumbing/uids.h>#include <clplumbing/coredumps.h>#include <crm/common/ctrl.h>#include <crm/common/ipc.h>#include <tengine.h>#include <crm/dmalloc_wrapper.h>#define SYS_NAME CRM_SYSTEM_TENGINE#define OPTARGS "hVc"GMainLoop* mainloop = NULL;const char* crm_system_name = SYS_NAME;extern cib_t *te_cib_conn;void usage(const char* cmd, int exit_status);int init_start(void);gboolean tengine_shutdown(int nsig, gpointer unused);extern void te_update_confirm(const char *event, HA_Message *msg);intmain(int argc, char ** argv){ gboolean allow_cores = TRUE; int argerr = 0; int flag; crm_log_init(crm_system_name); set_crm_log_level(LOG_DEBUG); G_main_add_SignalHandler( G_PRIORITY_HIGH, SIGTERM, tengine_shutdown, NULL, NULL); crm_devel("Begining option processing"); while ((flag = getopt(argc, argv, OPTARGS)) != EOF) { switch(flag) { case 'V': alter_debug(DEBUG_INC); break; case 'h': /* Help message */ usage(crm_system_name, LSB_EXIT_OK); break; case 'c': allow_cores = TRUE; break; default: ++argerr; break; } } crm_devel("Option processing complete"); if (optind > argc) { ++argerr; } if (argerr) { usage(crm_system_name,LSB_EXIT_GENERIC); } /* read local config file */ crm_devel("Starting..."); return init_start();}intinit_start(void){ int init_ok = TRUE; init_client_ipc_comms( CRM_SYSTEM_CRMD, subsystem_msg_dispatch, (void*)process_te_message, &crm_ch); if(crm_ch != NULL) { send_hello_message(crm_ch, "1234", CRM_SYSTEM_TENGINE, "0", "1"); } else { init_ok = FALSE; crm_err("Could not connect to the CRMd"); } if(init_ok) { crm_trace("Creating CIB connection"); te_cib_conn = cib_new(); if(te_cib_conn == NULL) { init_ok = FALSE; } } if(init_ok) { crm_trace("Connecting to the CIB"); if(te_cib_conn->cmds->signon( te_cib_conn, cib_command) != cib_ok) { init_ok = FALSE; } } if(init_ok) { crm_trace("Setting CIB notification callback"); if(te_cib_conn->cmds->add_notify_callback( te_cib_conn, T_CIB_UPDATE_CONFIRM, te_update_confirm) != cib_ok) { crm_err("Could not set CIB notification callback"); init_ok = FALSE; } } if(init_ok && ST_OK != stonithd_signon(crm_system_name)) { crm_err("Could not sign up to stonithd");/* init_ok = FALSE; */ } if(init_ok && ST_OK != stonithd_set_stonith_ops_callback( tengine_stonith_callback, NULL)) { crm_err("Could not set stonith callback"); stonithd_signoff();/* init_ok = FALSE; */ } if(init_ok) { IPC_Channel *fence_ch = stonithd_input_IPC_channel(); if(fence_ch == NULL) { } else if(NULL == G_main_add_IPC_Channel( G_PRIORITY_LOW, fence_ch, FALSE, tengine_stonith_dispatch, NULL, tengine_stonith_connection_destroy)) { crm_err("Failed to add Fencing channel to our mainloop"); init_ok = FALSE; } } if(init_ok) { /* Create the mainloop and run it... */ crm_info("Starting %s", crm_system_name); mainloop = g_main_new(FALSE); g_main_run(mainloop); return_to_orig_privs(); crm_info("Exiting %s", crm_system_name); } else { crm_warn("Initialization errors, %s not starting.", crm_system_name); } if(init_ok) { return 0; } return 1;}voidusage(const char* cmd, int exit_status){ FILE* stream; stream = exit_status ? stderr : stdout; fprintf(stream, "usage: %s [-srkh]" "[-c configure file]\n", cmd);/* fprintf(stream, "\t-d\tsets debug level\n"); *//* fprintf(stream, "\t-s\tgets daemon status\n"); *//* fprintf(stream, "\t-r\trestarts daemon\n"); *//* fprintf(stream, "\t-k\tstops daemon\n"); *//* fprintf(stream, "\t-h\thelp message\n"); */ fflush(stream); exit(exit_status);}gbooleantengine_shutdown(int nsig, gpointer unused){ static int shuttingdown = 0; if (!shuttingdown) { shuttingdown = 1; } if (mainloop != NULL && g_main_is_running(mainloop)) { g_main_quit(mainloop); }else{ exit(LSB_EXIT_OK); } return TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -