⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ttest.c

📁 linux集群服务器软件代码包
💻 C
字号:
/* $Id: ttest.c,v 1.16 2005/01/26 13:31:01 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 <stdio.h>#include <sys/types.h>#include <unistd.h>#include <stdlib.h>#include <errno.h>#include <fcntl.h>#include <crm/common/ipc.h>#include <crm/common/xml.h>#include <crm/msg_xml.h>#include <crm/cib.h>#define OPTARGS	"V?X:"#include <getopt.h>#include <glib.h>#include <tengine.h>#include <clplumbing/GSource.h>extern gboolean unpack_graph(crm_data_t *xml_graph);extern gboolean initiate_transition(void);extern gboolean initialize_graph(void);GMainLoop*  mainloop = NULL;intmain(int argc, char **argv){	int flag;	int argerr = 0;	crm_data_t *xml_graph = NULL;	HA_Message *cmd = NULL;		const char *xml_file = NULL;		IPC_Channel* channels[2];  	cl_log_set_entity("ttest");	cl_log_set_facility(LOG_USER);	while (1) {		int option_index = 0;		static struct option long_options[] = {			/* Top-level Options */			{"daemon", 0, 0, 0},      			{0, 0, 0, 0}		};    		flag = getopt_long(argc, argv, OPTARGS,				   long_options, &option_index);		if (flag == -1)			break;    		switch(flag) {			case 0:				printf("option %s", long_options[option_index].name);				if (optarg)					printf(" with arg %s", optarg);				printf("\n");    				break;      				/* a sample test for multiple instance				   if (digit_optind != 0 && digit_optind != this_option_optind)				   printf ("digits occur in two different argv-elements.\n");				   digit_optind = this_option_optind;				   printf ("option %c\n", c);				*/      			case 'X':				xml_file = crm_strdup(optarg);				break;			case 'V':				alter_debug(DEBUG_INC);				break;			default:				printf("?? getopt returned character code 0%o ??\n", flag);				++argerr;				break;		}	}  	if (optind < argc) {		printf("non-option ARGV-elements: ");		while (optind < argc)			printf("%s ", argv[optind++]);		printf("\n");	}  	if (optind > argc) {		++argerr;	}  	if (argerr) {		crm_err("%d errors in option parsing", argerr);	}  	crm_trace("Initializing graph...");	initialize_graph();		crm_debug("=#=#=#=#= Getting XML =#=#=#=#=");	if(xml_file != NULL) {		FILE *xml_strm = fopen(xml_file, "r");		xml_graph = file2xml(xml_strm);			} else {		xml_graph = file2xml(stdin);	}  #ifdef MTRACE  	mtrace();#endif	if (ipc_channel_pair(channels) != IPC_OK) {		cl_perror("Can't create ipc channel pair");		exit(1);	}	crm_ch = channels[0];/* 	fcntl(channels[0]->ops->get_send_select_fd(channels[0]), F_SETFL, O_NONBLOCK); *//* 	fcntl(channels[0]->ops->get_recv_select_fd(channels[0]), F_SETFL, O_NONBLOCK); *//* 	fcntl(channels[1]->ops->get_send_select_fd(channels[0]), F_SETFL, O_NONBLOCK); *//* 	fcntl(channels[1]->ops->get_recv_select_fd(channels[0]), F_SETFL, O_NONBLOCK); */		G_main_add_IPC_Channel(G_PRIORITY_LOW,			       channels[1], FALSE,			       subsystem_msg_dispatch,			       (void*)process_te_message, 			       default_ipc_connection_destroy);	/* send transition graph over IPC instead */	cmd = create_request(CRM_OP_TRANSITION, xml_graph, NULL,			     CRM_SYSTEM_TENGINE, CRM_SYSTEM_TENGINE, NULL);		send_ipc_message(channels[0], cmd);	free_xml(xml_graph);    /* Create the mainloop and run it... */	mainloop = g_main_new(FALSE);	crm_debug("Starting mainloop");	g_main_run(mainloop);	initialize_graph();	#ifdef MTRACE  	muntrace();#endif	crm_trace("Transition complete...");	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -