Changeset 900 in MondoRescue for trunk/mondo/src/common/libmondo-raid.c
- Timestamp:
- Oct 24, 2006, 8:49:18 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/src/common/libmondo-raid.c
r839 r900 9 9 10 10 #include "my-stuff.h" 11 #include "mr_str ing.h"11 #include "mr_str.h" 12 12 #include "mondostructures.h" 13 13 #include "newt-specific-EXT.h" … … 16 16 #include "libmondo-string-EXT.h" 17 17 #include "libmondo-raid.h" 18 #include "mr_ string.h"18 #include "mr_mem.h" 19 19 20 20 #ifdef __FreeBSD__ … … 49 49 50 50 if (raidno == -1) { 51 asprintf(&command,51 mr_asprintf(&command, 52 52 "grep \"linear\" /proc/mdstat > /dev/null 2> /dev/null"); 53 53 } else { 54 asprintf(&command,54 mr_asprintf(&command, 55 55 "grep \"raid%d\" /proc/mdstat > /dev/null 2> /dev/null", 56 56 raidno); … … 58 58 log_it("Is raid %d registered? Command = '%s'", raidno, command); 59 59 res = system(command); 60 paranoid_free(command);60 mr_free(command); 61 61 if (res) { 62 62 return (FALSE); … … 185 185 assert(label != NULL); 186 186 187 asprintf(&sz_value, "%d", value);188 asprintf(&sz_label,label);187 mr_asprintf(&sz_value, "%d", value); 188 mr_asprintf(&sz_label,label); 189 189 raidrec->additional_vars.el[lino].value = sz_value; 190 190 raidrec->additional_vars.el[lino].label = sz_label; … … 320 320 switch (raidrec->plex[i].raidlevel) { 321 321 case -1: 322 asprintf(&org, "%s", "concat");322 mr_asprintf(&org, "%s", "concat"); 323 323 break; 324 324 case 0: 325 asprintf(&org, "%s", "striped");325 mr_asprintf(&org, "%s", "striped"); 326 326 break; 327 327 case 5: 328 asprintf(&org, "%s", "raid5");328 mr_asprintf(&org, "%s", "raid5"); 329 329 break; 330 330 } 331 331 fprintf(fout, " plex org %s", org); 332 paranoid_free(org);332 mr_free(org); 333 333 334 334 if (raidrec->plex[i].raidlevel != -1) { … … 418 418 } 419 419 420 for ( getline(&incoming, &n, fin); !feof(fin);421 getline(&incoming, &n, fin)) {420 for (mr_getline(&incoming, &n, fin); !feof(fin); 421 mr_getline(&incoming, &n, fin)) { 422 422 strip_spaces(incoming); 423 423 p = strchr(incoming, ' '); … … 433 433 return (0); 434 434 } 435 paranoid_free(incoming);435 mr_free(incoming); 436 436 return (1); 437 437 } … … 563 563 fclose(fin); 564 564 log_it("Raidtab loaded successfully."); 565 asprintf(&tmp1, "%d RAID devices in raidtab", raidlist->entries);565 mr_asprintf(&tmp1, "%d RAID devices in raidtab", raidlist->entries); 566 566 log_it(tmp1); 567 paranoid_free(tmp1);567 mr_free(tmp1); 568 568 return (0); 569 569 } … … 700 700 } 701 701 if (!disklist) { 702 asprintf(&tmp,702 mr_asprintf(&tmp, 703 703 "Ignoring '%s %s' pair of disk %s", labelB, valueB, 704 704 label); 705 705 log_it(tmp); 706 paranoid_free(tmp);706 mr_free(tmp); 707 707 } else { 708 708 index = atoi(valueB); 709 709 add_disk_to_raid_device(disklist, value, index); 710 710 } 711 paranoid_free(labelB);712 paranoid_free(valueB);711 mr_free(labelB); 712 mr_free(valueB); 713 713 } else { 714 714 v = raidrec->additional_vars.entries; … … 773 773 int lastpos = 0; 774 774 775 getline(&line, &n, f);775 mr_getline(&line, &n, f); 776 776 if (feof(f)) { 777 777 log_it("[GNVCL] Uh... I reached the EOF."); … … 933 933 934 934 FILE *fin; 935 int r es = 0, row, i, index_min;935 int row, i, index_min; 936 936 int lastpos = 0; 937 937 size_t len = 0; … … 952 952 row = 1; 953 953 // skip first output row - contains registered RAID levels 954 res =getline(&string, &len, fin);954 mr_getline(&string, &len, fin); 955 955 // parse the rest 956 956 while ( !feof_unlocked(fin) ) { 957 res = getline(&string, &len, fin); 958 if (res <= 0) break; 957 mr_getline(&string, &len, fin); 959 958 // trim leading spaces 960 959 pos = string; 961 960 while (*pos == ' ') pos++; 962 asprintf(&strtmp, pos);963 paranoid_alloc(string,strtmp);964 paranoid_free(strtmp);961 mr_asprintf(&strtmp, pos); 962 mr_allocstr(string,strtmp); 963 mr_free(strtmp); 965 964 // if we have newline after only spaces, this is a blank line, update 966 965 // counters, otherwise do normal parsing … … 981 980 token = mr_strtok (string, delims, &lastpos); 982 981 // get RAID device name 983 asprintf(&strtmp,"%s%s", device_prefix, token);982 mr_asprintf(&strtmp,"%s%s", device_prefix, token); 984 983 raidlist->el[raidlist->entries].raid_device = strtmp; 985 paranoid_free(token);984 mr_free(token); 986 985 // skip ':' and status 987 986 token = mr_strtok (string, delims, &lastpos); 988 paranoid_free(token);987 mr_free(token); 989 988 token = mr_strtok (string, delims, &lastpos); 990 989 if (!strcmp(token, "inactive")) { 991 990 log_msg(1, "RAID device '%s' inactive.\n", 992 991 raidlist->el[raidlist->entries].raid_device); 993 paranoid_free(string);994 paranoid_free(token);992 mr_free(string); 993 mr_free(token); 995 994 return 1; 996 995 } 997 paranoid_free(token);996 mr_free(token); 998 997 999 998 // get RAID level … … 1017 1016 } else { 1018 1017 log_msg(1, "Unknown RAID level '%s'.\n", token); 1019 paranoid_free(string);1020 paranoid_free(token);1018 mr_free(string); 1019 mr_free(token); 1021 1020 return 1; 1022 1021 } 1023 paranoid_free(token);1022 mr_free(token); 1024 1023 1025 1024 // get RAID devices (type, index, device) … … 1039 1038 case ' ': // normal data disks 1040 1039 raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].index = atoi(pos + 1); 1041 asprintf(&strtmp,"%s%s", device_prefix, token);1040 mr_asprintf(&strtmp,"%s%s", device_prefix, token); 1042 1041 strcpy(raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].device, strtmp); 1043 paranoid_free(strtmp);1042 mr_free(strtmp); 1044 1043 raidlist->el[raidlist->entries].data_disks.entries++; 1045 1044 break; 1046 1045 case 'S': // spare disks 1047 1046 raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].index = atoi(pos + 1); 1048 asprintf(&strtmp,"%s%s", device_prefix, token);1047 mr_asprintf(&strtmp,"%s%s", device_prefix, token); 1049 1048 strcpy(raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].device, strtmp); 1050 paranoid_free(strtmp);1049 mr_free(strtmp); 1051 1050 raidlist->el[raidlist->entries].spare_disks.entries++; 1052 1051 break; 1053 1052 case 'F': // failed disks 1054 1053 raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].index = atoi(pos + 1); 1055 asprintf(&strtmp,"%s%s", device_prefix, token);1054 mr_asprintf(&strtmp,"%s%s", device_prefix, token); 1056 1055 strcpy(raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].device, strtmp); 1057 paranoid_free(strtmp);1056 mr_free(strtmp); 1058 1057 raidlist->el[raidlist->entries].failed_disks.entries++; 1059 1058 log_it("At least one failed disk found in RAID array.\n"); … … 1061 1060 default: // error 1062 1061 log_msg(1, "Unknown device type '%c'\n", type); 1063 paranoid_free(string);1064 paranoid_free(token);1062 mr_free(string); 1063 mr_free(token); 1065 1064 return 1; 1066 1065 break; 1067 1066 } 1068 paranoid_free(token);1067 mr_free(token); 1069 1068 } 1070 1069 … … 1119 1118 if (pos < string) { 1120 1119 log_it("String underflow!\n"); 1121 paranoid_free(string);1120 mr_free(string); 1122 1121 return 1; 1123 1122 } … … 1144 1143 if (pos < string) { 1145 1144 printf("ERROR: String underflow!\n"); 1146 paranoid_free(string);1145 mr_free(string); 1147 1146 return 1; 1148 1147 } … … 1161 1160 fclose(fin); 1162 1161 // free string 1163 paranoid_free(string);1162 mr_free(string); 1164 1163 // return success 1165 1164 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.