crm_err("Error signing on to the CIB service: %s",
fprintf(stderr, "Error signing on to the CIB service: %s\n",
main(int argc, char **argv){	pe_working_set_t data_set;	crm_data_t *cib_xml_copy = NULL;	cib_t *	cib_conn = NULL;	enum cib_errors rc = cib_ok;		int argerr = 0;	int flag;#ifdef HAVE_GETOPT_H	int option_index = 0;	static struct option long_options[] = {		/* Top-level Options */		{"verbose", 0, 0, 'V'},		{"help",    0, 0, '?'},		{"silent",  0, 0, 'S'},		{"list",    0, 0, 'L'},		{"refresh", 0, 0, 'R'},		{"reprobe", 0, 0, 'P'},		{"query",   0, 0, 'Q'},		{"delete",  0, 0, 'D'},		{"cleanup", 0, 0, 'C'},		{"locate",  0, 0, 'W'},		{"migrate", 0, 0, 'M'},		{"un-migrate", 0, 0, 'U'},		{"resource",1, 0, 'r'},		{"host_uname", 1, 0, 'H'},		{"host_uuid",  1, 0, 'h'},		{"set-property",    1, 0, 'p'},		{"property-value",  1, 0, 'v'},		{"resource-type",  1, 0, 't'},		{0, 0, 0, 0}	};#endif	crm_system_name = basename(argv[0]);	crm_log_init(crm_system_name);	crm_log_level = LOG_ERR;	cl_log_enable_stderr(TRUE);		if(argc < 2) {		usage(crm_system_name, LSB_EXIT_EINVAL);	}		while (1) {#ifdef HAVE_GETOPT_H		flag = getopt_long(argc, argv, OPTARGS,				   long_options, &option_index);#else		flag = getopt(argc, argv, OPTARGS);#endif		if (flag == -1)			break;		switch(flag) {			case 'V':				cl_log_enable_stderr(TRUE);				alter_debug(DEBUG_INC);				break;			case '?':				usage(crm_system_name, LSB_EXIT_OK);				break;			case 'S':				BE_QUIET = TRUE;				break;			case 'L':				rsc_cmd = flag;				break;							case 'R':				rsc_cmd = flag;				break;							case 'Q':				rsc_cmd = flag;				break;							case 'D':				rsc_cmd = flag;				break;							case 'C':				rsc_cmd = flag;				break;							case 'P':				rsc_cmd = flag;				break;							case 'p':				crm_debug_2("Option %c => %s", flag, optarg);				prop_name = optarg;				rsc_cmd = flag;				break;							case 'W':				rsc_cmd = flag;				break;							case 'M':				rsc_cmd = flag;				break;							case 'U':				rsc_cmd = flag;				break;							case 'r':				crm_debug_2("Option %c => %s", flag, optarg);				rsc_id = optarg;				break;			case 'v':				crm_debug_2("Option %c => %s", flag, optarg);				prop_value = optarg;				break;			case 't':				crm_debug_2("Option %c => %s", flag, optarg);				rsc_type = optarg;				break;			case 'H':				crm_debug_2("Option %c => %s", flag, optarg);				host_uname = optarg;				break;							case 'h':				crm_debug_2("Option %c => %s", flag, optarg);				host_id = crm_strdup(optarg);				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 (argerr) {		usage(crm_system_name, LSB_EXIT_GENERIC);	}	crm_malloc0(our_pid, sizeof(char) * 11);	if(our_pid != NULL) {		snprintf(our_pid, 10, "%d", getpid());		our_pid[10] = '\0';	}	if(rc != cib_ok) {		crm_err("Error signing on to the CIB service: %s",			cib_error2string(rc));		return rc;	}	if(rsc_cmd == 'L' || rsc_cmd == 'W' || rsc_cmd == 'D' || rsc_cmd == 'Q'	   || rsc_cmd == 'p' || rsc_cmd == 'M' || rsc_cmd == 'U') {		cib_conn = cib_new();		rc = cib_conn->cmds->signon(cib_conn, crm_system_name, cib_command);		set_working_set_defaults(&data_set);		if(rsc_cmd != 'D' && rsc_cmd != 'U') {			cib_xml_copy = get_cib_copy(cib_conn);			data_set.input = cib_xml_copy;			stage0(&data_set);		}			} else if(rsc_cmd == 'R' || rsc_cmd == 'D'		  || rsc_cmd == 'C' || rsc_cmd == 'P') {		GCHSource *src = NULL;		src = init_client_ipc_comms(CRM_SYSTEM_CRMD, crmd_msg_callback,				      NULL, &crmd_channel);		send_hello_message(			crmd_channel, our_pid, crm_system_name, "0", "1");		set_IPC_Channel_dnotify(src, resource_ipc_connection_destroy);	}		if(rsc_cmd == 'L') {		do_find_resource_list(&data_set);			} else if(rsc_cmd == 'W') {		CRM_DEV_ASSERT(rsc_id != NULL);		rc = do_find_resource(rsc_id, &data_set);			} else if(rsc_cmd == 'Q') {		CRM_DEV_ASSERT(rsc_id != NULL);		rc = dump_resource(rsc_id, &data_set);	} else if(rsc_cmd == 'U') {		rc = migrate_resource(rsc_id, NULL, NULL, cib_conn);	} else if(rsc_cmd == 'M') {		resource_t *rsc = pe_find_resource(data_set.resources, rsc_id);				if(rsc == NULL) {			crm_err("Resource %s not migrated:"				" not found", rsc_id);		} else if(g_list_length(rsc->running_on) > 1) {			crm_err("Resource %s not migrated:"				" active on multiple nodes", rsc_id);					} else if(rsc->stickiness == 0 && host_uname != NULL) {			rc = migrate_resource(				rsc_id, NULL, host_uname, cib_conn);		} else if(g_list_length(rsc->running_on) == 1) {			node_t *current = rsc->running_on->data;			rc = migrate_resource(rsc_id, current->details->uname,					      host_uname, cib_conn);		} else {			crm_err("Resource %s not migrated: not-active and"				" no prefered location specified.", rsc_id);		}			} else if(rsc_cmd == 'p') {		crm_data_t *msg_data = NULL;		CRM_DEV_ASSERT(rsc_id != NULL);		CRM_DEV_ASSERT(rsc_type != NULL);		CRM_DEV_ASSERT(prop_name != NULL);		CRM_DEV_ASSERT(prop_value != NULL);		msg_data = create_xml_node(NULL, rsc_type);		crm_xml_add(msg_data, XML_ATTR_ID, rsc_id);		crm_xml_add(msg_data, prop_name, prop_value);				rc = cib_conn->cmds->modify(cib_conn, XML_CIB_TAG_RESOURCES,					    msg_data, NULL, cib_sync_call);		free_xml(msg_data);	} else if(rsc_cmd == 'P') {		HA_Message *cmd = NULL;				cmd = create_request(CRM_OP_REPROBE, NULL, host_uname,				     CRM_SYSTEM_CRMD, crm_system_name, our_pid);		send_ipc_message(crmd_channel, cmd);	} else if(rsc_cmd == 'R') {		refresh_lrm(crmd_channel, host_uname);	} else if(rsc_cmd == 'D') {		crm_data_t *msg_data = NULL;		CRM_DEV_ASSERT(rsc_type != NULL);		CRM_DEV_ASSERT(rsc_id != NULL);		msg_data = create_xml_node(NULL, rsc_type);		crm_xml_add(msg_data, XML_ATTR_ID, rsc_id);				rc = cib_conn->cmds->delete(cib_conn, XML_CIB_TAG_RESOURCES,					    msg_data, NULL, cib_sync_call);		free_xml(msg_data);	} else if(rsc_cmd == 'C') {		delete_lrm_rsc(crmd_channel, host_uname, rsc_id);		refresh_lrm(crmd_channel, host_uname);	} else {		crm_err("Unknown command: %c", rsc_cmd);	}	if(cib_conn != NULL) {		cleanup_calculations(&data_set);		cib_conn->cmds->signoff(cib_conn);	}	if(rc == cib_NOTEXISTS) {		crm_warn("Error performing operation: %s",			 cib_error2string(rc));	} else if(rc < cib_ok) {		crm_warn("Error performing operation: %s",			 cib_error2string(rc));	}		return rc;}