| 1033 | } |
| 1034 | |
| 1035 | static void |
| 1036 | setup_input(const char *input, const char *output) |
| 1037 | { |
| 1038 | int rc = pcmk_ok; |
| 1039 | cib_t *cib_conn = NULL; |
| 1040 | xmlNode *cib_object = NULL; |
| 1041 | char *local_output = NULL; |
| 1042 | |
| 1043 | if (input == NULL) { |
| 1044 | /* Use live CIB */ |
| 1045 | cib_conn = cib_new(); |
| 1046 | rc = cib_conn->cmds->signon(cib_conn, crm_system_name, cib_command); |
| 1047 | |
| 1048 | if (rc == pcmk_ok) { |
| 1049 | cib_object = get_cib_copy(cib_conn); |
| 1050 | } |
| 1051 | |
| 1052 | cib_conn->cmds->signoff(cib_conn); |
| 1053 | cib_delete(cib_conn); |
| 1054 | cib_conn = NULL; |
| 1055 | |
| 1056 | if (cib_object == NULL) { |
| 1057 | fprintf(stderr, "Live CIB query failed: empty result\n"); |
| 1058 | crm_exit(3); |
| 1059 | } |
| 1060 | |
| 1061 | } else if (safe_str_eq(input, "-")) { |
| 1062 | cib_object = filename2xml(NULL); |
| 1063 | |
| 1064 | } else { |
| 1065 | cib_object = filename2xml(input); |
| 1066 | } |
| 1067 | |
| 1068 | if (get_object_root(XML_CIB_TAG_STATUS, cib_object) == NULL) { |
| 1069 | create_xml_node(cib_object, XML_CIB_TAG_STATUS); |
| 1070 | } |
| 1071 | |
| 1072 | if (cli_config_update(&cib_object, NULL, FALSE) == FALSE) { |
| 1073 | free_xml(cib_object); |
| 1074 | crm_exit(-ENOKEY); |
| 1075 | } |
| 1076 | |
| 1077 | if (validate_xml(cib_object, NULL, FALSE) != TRUE) { |
| 1078 | free_xml(cib_object); |
| 1079 | crm_exit(-pcmk_err_dtd_validation); |
| 1080 | } |
| 1081 | |
| 1082 | if (output == NULL) { |
| 1083 | char *pid = crm_itoa(getpid()); |
| 1084 | |
| 1085 | local_output = get_shadow_file(pid); |
| 1086 | output = local_output; |
| 1087 | free(pid); |
| 1088 | } |
| 1089 | |
| 1090 | rc = write_xml_file(cib_object, output, FALSE); |
| 1091 | free_xml(cib_object); |
| 1092 | cib_object = NULL; |
no test coverage detected