MCPcopy Create free account
hub / github.com/ClusterLabs/pacemaker / get_last_sequence

Function get_last_sequence

lib/common/utils.c:1117–1176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1115}
1116
1117int
1118get_last_sequence(const char *directory, const char *series)
1119{
1120 FILE *file_strm = NULL;
1121 int start = 0, length = 0, read_len = 0;
1122 char *series_file = NULL;
1123 char *buffer = NULL;
1124 int seq = 0;
1125 int len = 36;
1126
1127 CRM_CHECK(directory != NULL, return 0);
1128 CRM_CHECK(series != NULL, return 0);
1129
1130 len += strlen(directory);
1131 len += strlen(series);
1132 series_file = calloc(1, len);
1133 CRM_CHECK(series_file != NULL, return 0);
1134 sprintf(series_file, "%s/%s.last", directory, series);
1135
1136 file_strm = fopen(series_file, "r");
1137 if (file_strm == NULL) {
1138 crm_debug("Series file %s does not exist", series_file);
1139 free(series_file);
1140 return 0;
1141 }
1142
1143 /* see how big the file is */
1144 start = ftell(file_strm);
1145 fseek(file_strm, 0L, SEEK_END);
1146 length = ftell(file_strm);
1147 fseek(file_strm, 0L, start);
1148
1149 CRM_ASSERT(length >= 0);
1150 CRM_ASSERT(start == ftell(file_strm));
1151
1152 if (length <= 0) {
1153 crm_info("%s was not valid", series_file);
1154 free(buffer);
1155 buffer = NULL;
1156
1157 } else {
1158 crm_trace("Reading %d bytes from file", length);
1159 buffer = calloc(1, (length + 1));
1160 read_len = fread(buffer, 1, length, file_strm);
1161 if (read_len != length) {
1162 crm_err("Calculated and read bytes differ: %d vs. %d", length, read_len);
1163 free(buffer);
1164 buffer = NULL;
1165 }
1166 }
1167
1168 seq = crm_parse_int(buffer, "0");
1169 fclose(file_strm);
1170
1171 crm_trace("Found %d in %s", seq, series_file);
1172
1173 free(series_file);
1174 free(buffer);

Callers 3

readCibXmlFileFunction · 0.85
write_cib_contentsFunction · 0.85
process_pe_messageFunction · 0.85

Calls 1

crm_parse_intFunction · 0.85

Tested by

no test coverage detected