char *xml_text = NULL; xmlNodePtr output = NULL;
char *admin_input_xml = NULL; crm_data_t *output = NULL;
main(int argc, char **argv){	int option_index = 0;	int argerr = 0;	int flag;	int level = 0;	char *xml_text = NULL;	xmlNodePtr output = NULL;		static struct option long_options[] = {		/* Top-level Options */		{CRM_OP_CIB_ERASE,   0, 0, 'E'},		{CRM_OP_CIB_QUERY,   0, 0, 'Q'},		{CRM_OP_CIB_CREATE,  0, 0, 'C'},		{CRM_OP_CIB_REPLACE, 0, 0, 'R'},		{CRM_OP_CIB_UPDATE,  0, 0, 'U'},		{CRM_OP_CIB_DELETE,  0, 0, 'D'},		{CRM_OP_CIB_BUMP,    0, 0, 'B'},		{CRM_OP_CIB_SYNC,    0, 0, 'S'},		{CRM_OP_CIB_SLAVE,   0, 0, 'r'},		{CRM_OP_CIB_MASTER,  0, 0, 'w'},		{CRM_OP_CIB_ISMASTER,0, 0, 'M'},				{"local",	 0, 0, 'l'},		{"sync-call",	 0, 0, 's'},		{"host",	 0, 0, 'h'},		{F_CRM_DATA,          1, 0, 'X'},		{"verbose",      0, 0, 'V'},		{"help",         0, 0, '?'},		{"reference",    1, 0, 0},		{XML_ATTR_TIMEOUT,	 1, 0, 't'},		/* common options */		{XML_ATTR_ID, 1, 0, 'i'},		{"obj_type", 1, 0, 'o'},		{0, 0, 0, 0}	};	if(argc < 2) {		usage(crm_system_name, LSB_EXIT_EINVAL);	}	/* Redirect messages from glib functions to our handler */	g_log_set_handler(NULL,			  G_LOG_LEVEL_ERROR      | G_LOG_LEVEL_CRITICAL			  | G_LOG_LEVEL_WARNING  | G_LOG_LEVEL_MESSAGE			  | G_LOG_LEVEL_INFO     | G_LOG_LEVEL_DEBUG			  | G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL,			  cl_glib_msg_handler, NULL);	/* and for good measure... */	g_log_set_always_fatal((GLogLevelFlags)0);    		cl_log_set_entity(crm_system_name);	cl_log_set_facility(LOG_USER);	while (1) {		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");	if (safe_str_eq("reference", long_options[option_index].name)) {		this_msg_reference = crm_strdup(optarg);	} else {		printf("Long option (--%s) is not (yet?) properly supported\n",		       long_options[option_index].name);		++argerr;	}	break;			case 't':				message_timeout_ms = atoi(optarg);				if(message_timeout_ms < 1) {					message_timeout_ms = 30*1000;				}				break;							case 'E':				cib_action = crm_strdup(CRM_OP_CIB_ERASE);				break;			case 'Q':				cib_action = crm_strdup(CRM_OP_CIB_QUERY);				break;			case 'S':				cib_action = crm_strdup(CRM_OP_CIB_SYNC);				break;			case 'U':				cib_action = crm_strdup(CRM_OP_CIB_UPDATE);				break;			case 'R':				cib_action = crm_strdup(CRM_OP_CIB_REPLACE);				break;			case 'C':				cib_action = crm_strdup(CRM_OP_CIB_CREATE);				break;			case 'D':				cib_action = crm_strdup(CRM_OP_CIB_DELETE);				break;			case 'M':				cib_action = crm_strdup(CRM_OP_CIB_ISMASTER);				command_options |= cib_scope_local;				break;			case 'B':				cib_action = crm_strdup(CRM_OP_CIB_BUMP);				break;			case 'r':				cib_action = crm_strdup(CRM_OP_CIB_SLAVE);				break;			case 'w':				cib_action = crm_strdup(CRM_OP_CIB_MASTER);				command_options |= cib_scope_local;				break;			case 'V':				level = get_crm_log_level();				command_options = command_options | cib_verbose;				cl_log_enable_stderr(TRUE);				set_crm_log_level(level+1);				break;			case '?':				usage(crm_system_name, LSB_EXIT_OK);				break;			case 'i':				crm_verbose("Option %c => %s", flag, optarg);				id = crm_strdup(optarg);				break;			case 'o':				crm_verbose("Option %c => %s", flag, optarg);				obj_type = crm_strdup(optarg);				break;			case 'X':				xml_text = crm_strdup(optarg);				break;			case 'h':				host = crm_strdup(optarg);				break;			case 'l':				command_options |= cib_scope_local;				break;			case 's':				command_options |= cib_sync_call;				break;			default:				printf("Argument code 0%o (%c)"				       " is not (?yet?) supported\n",				       flag, 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(cib_action == NULL) {		usage(crm_system_name, cib_operation);	}		if (argerr) {		usage(crm_system_name, LSB_EXIT_GENERIC);	}	exit_code = do_init();	if(exit_code != cib_ok) {		crm_err("Init failed, could not perform requested operations");		fprintf(stderr, "Init failed, could not perform requested operations\n");		return -exit_code;	}	exit_code = do_work(xml_text, command_options, &output);	if (exit_code > 0) {		/* wait for the reply by creating a mainloop and running it until		 * the callbacks are invoked...		 */		IPC_Channel *ch = the_cib->cmds->channel(the_cib);		request_id = exit_code;				if(ch == NULL) {			crm_err("Connection to CIB is corrupt");			return 2;		}		mainloop = g_main_new(FALSE);		crm_debug("Setting operation timeout to %dms",			  message_timeout_ms);		message_timer_id = Gmain_timeout_add(			message_timeout_ms, admin_message_timeout, NULL);		crm_debug("%s waiting for reply from the local CIB",			 crm_system_name);				crm_info("Starting mainloop");		g_main_run(mainloop);			} else if(exit_code < 0) {		crm_err("Call failed: %s", cib_error2string(exit_code));		fprintf(stderr, "Call failed: %s\n",			cib_error2string(exit_code));		operation_status = exit_code;	}	if(output != NULL) {		char *buffer = dump_xml_formatted(output);		fprintf(stdout, "%s", crm_str(buffer));		crm_free(buffer);	}		crm_debug("%s exiting normally", crm_system_name);	return -exit_code;}