Changeset 3193 in MondoRescue
- Timestamp:
- Sep 29, 2013, 9:31:34 AM (7 years ago)
- Location:
- branches
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.1/mondo/src/include/mr_str.h
r2421 r3193 16 16 17 17 extern char *mr_strtok(char *instr, const char *delims, int *lastpos); 18 extern char *mr_stresc(char *instr, char *toesc, const char escchr );19 extern char *mr_date(void);18 extern char *mr_stresc(char *instr, char *toesc, const char escchr, const char specialchr); 19 extern inline char *mr_date(void); 20 20 extern void mr_strip_spaces(char *in_out); 21 21 extern void mr_strip_char(char *in_out, char *caracs); -
branches/3.1/mondo/src/include/my-stuff.h
r3147 r3193 339 339 #define ARCH_THREADS 2 ///< The number of simultaneous threads running afio in the background. 340 340 #define ARCH_BUFFER_NUM (ARCH_THREADS*4) // Number of permissible queued afio files 341 #define FORTY_SPACES " " ///< 40 spaces. 341 342 #define DO_MBR_PLEASE "/tmp/DO-MBR-PLEASE" 342 343 #define MONDO_MNTLISTCHG "/tmp/mountlist.changed" -
branches/3.1/mondo/src/lib/mr_str.c
r3147 r3193 12 12 13 13 #include "mr_mem.h" 14 15 // to get bool type 16 #define _MY_STUFF_H_ 17 #include "my-stuff.h" 14 18 15 19 /** … … 66 70 * @note this function allocates memory that needs to be freed by caller 67 71 **/ 68 char *mr_stresc(char *instr, char *toesc, const char escchr ) {72 char *mr_stresc(char *instr, char *toesc, const char escchr, const char specialchr) { 69 73 char *inptr = NULL; 70 74 char *retstr = NULL; … … 72 76 char *escptr = NULL; 73 77 int cnt = 0; 78 bool found = FALSE; 74 79 75 80 inptr = instr; 76 77 81 // Count how many characters need escaping. 78 82 while (*inptr != '\0') { … … 82 86 // Found it, skip the rest. 83 87 cnt++; 88 // if specialchar (' or ") then replace it with '\'' or "\"" so adds 2 chars 89 if (*inptr == specialchr) { 90 cnt += 2; 91 } 84 92 break; 85 93 } … … 88 96 inptr++; 89 97 } 98 90 99 inptr = instr; 91 92 100 retstr = (char *) mr_malloc(strlen(inptr) + cnt + 1); 93 101 retptr = retstr; … … 99 107 if (*inptr == *escptr) { 100 108 // Found it, skip the rest. 101 *retptr = escchr; 102 retptr++; 109 // if specialchar (' or ") then replace it with '\'' or "\"" so adds 2 chars 110 if (*inptr == specialchr) { 111 *retptr = specialchr; 112 retptr++; 113 *retptr = escchr; 114 retptr++; 115 found = TRUE; 116 } else { 117 *retptr = escchr; 118 retptr++; 119 } 103 120 break; 104 121 } … … 108 125 retptr++; 109 126 inptr++; 127 if (found) { 128 // finish to put the remaining specialchr 129 *retptr = specialchr; 130 retptr++; 131 found = FALSE; 132 } 110 133 } 111 134 *retptr = '\0'; … … 114 137 } 115 138 116 /** 117 * Remove all characters in caracs from begining and end of string @p in_out 118 * @param in_out The string to strip char characters from (modified). 139 /* Return a string containing the date */ 140 char *mr_date(void) { 141 142 time_t tcurr; 143 144 tcurr = time(NULL); 145 return(ctime(&tcurr)); 146 } 147 148 /* Return an allocated string containing the date 149 char *mr_date(void) { 150 151 time_t tcurr; 152 char *tmp = NULL; 153 154 tcurr = time(NULL); 155 mr_asprintf(tmp, "%s", ctime(&tcurr)); 156 mr_chomp(tmp); 157 return(tmp); 158 } 119 159 */ 120 void mr_strip_char(char *in_out, char *caracs) {121 int i = 0;122 int j = 0;123 int length = 0;124 125 if (caracs == NULL) {126 return;127 }128 if (in_out == NULL) {129 return;130 }131 length = (int)strlen(in_out);132 133 /* Skip initial caracs */134 for (i = 0; index(caracs, in_out[i]) != NULL && i < length ; i++);135 136 /* Shift the string to the begining if needed */137 if (i != 0) {138 for (j = 0; i < length ; i++, j++) {139 in_out[j] = in_out[i];140 }141 /* Erase the end of the string if needed */142 j++;143 in_out[j] = '\0';144 }145 146 /* Skip final spaces and special chars */147 for (i = (int)strlen(in_out) - 1; i >= 0 && index(caracs, in_out[i]) != NULL; i--);148 149 /* The string now ends after that char */150 i++;151 in_out[i] = '\0';152 }153 160 154 161 /** … … 158 165 */ 159 166 void mr_strip_spaces(char *in_out) { 160 161 int i; 162 char *tmp = NULL; 163 164 mr_asprintf(tmp, ""); 165 166 /* Build the string of char to avoid: ctrl char up to space*/ 167 for (i = 0; i <= ' '; i++) { 168 mr_strcat(tmp, "%c", i); 169 } 170 171 mr_strip_char(in_out, tmp); 172 mr_free(tmp); 173 } 167 int i = 0; 168 int j = 0; 169 size_t length; 170 171 if (in_out == NULL) { 172 return; 173 } 174 length = strlen(in_out); 175 176 /* Skip initial spaces and special chars */ 177 for (i = 0; in_out[i] <= ' ' && i < (int)length ; i++); 178 /* Shift the string to the begining if needed */ 179 if (i != 0) { 180 for (j = 0; i < (int)length ; i++, j++) { 181 in_out[j] = in_out[i]; 182 } 183 /* Erase the end of the string if needed */ 184 j++; 185 in_out[j] = '\0'; 186 } 187 188 /* Skip final spaces and special chars */ 189 for (i = (int)strlen(in_out) - 1; i >= 0 && in_out[i] <= ' '; i--); 190 191 /* The string now ends after that char */ 192 i++; 193 in_out[i] = '\0'; 194 } 195 174 196 175 197 /* 176 198 * Remove '\n' char from both sides of @p in_out. 177 199 * @param in_out The string to strip characters from (modified). 178 */ 200 179 201 void mr_chomp(char *in_out) { 180 202 181 203 mr_strip_char(in_out, "\n"); 182 204 } 183 184 /* Return an allocated string containing the date */ 185 char *mr_date(void) { 186 187 time_t tcurr; 188 char *tmp = NULL; 189 190 tcurr = time(NULL); 191 mr_asprintf(tmp, "%s", ctime(&tcurr)); 192 mr_chomp(tmp); 193 return(tmp); 194 } 195 196 205 */ 206 207 /** 208 * Remove all characters in caracs from begining and end of string @p in_out 209 * @param in_out The string to strip char characters from (modified). 210 211 void mr_strip_char(char *in_out, char *caracs) { 212 int i = 0; 213 int j = 0; 214 size_t length = 0; 215 216 if (caracs == NULL) { 217 return; 218 } 219 if (in_out == NULL) { 220 return; 221 } 222 length = strlen(in_out); 223 224 /* Skip initial caracs */ 225 for (i = 0; index(caracs, in_out[i]) != NULL && i < (int)length ; i++); 226 227 /* Shift the string to the begining if needed */ 228 if (i != 0) { 229 for (j = 0; i < (int)length ; i++, j++) { 230 in_out[j] = in_out[i]; 231 } 232 /* Erase the end of the string if needed */ 233 j++; 234 in_out[j] = '\0'; 235 } 236 237 /* Skip final caracs */ 238 for (i = (int)strlen(in_out) - 1; i >= 0 && index(caracs, in_out[i]) != NULL; i--); 239 240 /* The string now ends after that char */ 241 i++; 242 in_out[i] = '\0'; 243 } 244 */ 245 -
branches/3.1/mondo/src/mondoarchive/mondoarchive.c
r3148 r3193 37 37 extern t_bkptype g_backup_media_type; 38 38 extern int g_loglevel; 39 39 40 extern char *g_magicdev_command; 40 41 … … 101 102 log_msg(7, "Seven..."); 102 103 log_msg(8, "Eight..."); 104 printf("See %s for details of backup run.\n", MONDO_LOGFILE); 103 105 } 104 106 … … 164 166 FILE *fin = NULL; 165 167 168 /* Make sure I'm root; abort if not */ 169 if (getuid() != 0) { 170 fprintf(stderr, "Please run as root.\r\n"); 171 exit(127); 172 } 173 174 /* If -V, -v or --version then echo version no. and quit */ 175 if (argc == 2 && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V") || !strcmp(argv[argc - 1], "--version"))) { 176 printf("mondoarchive v%s\nSee man page for help\n", PACKAGE_VERSION); 177 exit(0); 178 } 179 180 /* Initialize variables */ 181 166 182 printf("Initializing...\n"); 183 184 init_bkpinfo(); 185 186 /* Memory allocation is done in those functions */ 187 malloc_libmondo_global_strings(); 167 188 168 189 /* initialize log file with time stamp */ 169 190 unlink(MONDO_LOGFILE); 170 tmp = mr_date(); 171 log_msg(0, "Time started: %s", tmp); 172 mr_free(tmp); 173 174 init_bkpinfo(); 175 176 /* Memory allocation is done in those functions */ 177 malloc_libmondo_global_strings(); 191 log_msg(0, "Time started: %s", mr_date()); 192 178 193 if (argc == 1) { 179 194 g_text_mode = FALSE; … … 188 203 } 189 204 setup_newt_stuff(); 190 191 /* Make sure I'm root; abort if not */192 if (getuid() != 0) {193 fatal_error("Please run as root.\n");194 }195 196 /* If -V, -v or --version then echo version no. and quit */197 if (argc == 2 && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V") || !strcmp(argv[argc - 1], "--version"))) {198 printf("mondoarchive v%s\nSee man page for help\n", PACKAGE_VERSION);199 finish(0);200 }201 202 205 203 206 /* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */ … … 449 452 450 453 /* finalize log file with time stamp */ 451 tmp = mr_date(); 452 log_msg(0, "Time finished: %s", tmp); 453 mr_free(tmp); 454 log_msg(0, "Time finished: %s", mr_date()); 454 455 455 456 if (chdir("/tmp")) { -
branches/3.1/mondo/src/mondorestore/mondo-prep.c
r3161 r3193 43 43 extern char *MONDO_LOGFILE; 44 44 45 // FIXME: is it really usefull - maps to /tmp/prep.sh ?? 45 46 FILE *g_fprep = NULL; 46 47 extern char *g_mondo_cfg_file; // where m*ndo-restore.cfg (the config file) is stored … … 108 109 sync(); 109 110 sync(); 110 popup_and_OK 111 ("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine."); 111 popup_and_OK("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine."); 112 112 paranoid_system("reboot"); 113 113 } 114 114 } 115 // Still here? Cool!115 // Still here? Cool! 116 116 log_msg(1, "Cool. I didn't have to wipe anything."); 117 117 } … … 218 218 } 219 219 220 // TODO: FIXME 220 221 command = malloc(1024); 221 222 … … 390 391 } 391 392 mr_asprintf(tmp1, "echo \"%s\" >> /tmp/out.sh", command); 392 if (system(tmp1)) { 393 //FIXME 394 } 393 paranoid_system(tmp1); 395 394 mr_free(tmp1); 396 395 sleep(1); … … 515 514 } 516 515 } 517 paranoid_free(incoming);518 516 519 517 return (0); … … 539 537 char *level = NULL; 540 538 char *program = NULL; 541 char *strtmp = NULL;542 539 char *oldmd = NULL; 543 540 544 // leave straight away if raidlist is initial or has no entries 545 if (!raidlist || raidlist->entries == 0) { 546 log_msg(1, "No RAID arrays found."); 547 return 1; 548 } else { 549 log_msg(1, "%d RAID arrays found.", raidlist->entries); 550 } 551 // find raidlist entry for requested device 552 for (i = 0; i < raidlist->entries; i++) { 553 if (!strcmp(raidlist->el[i].raid_device, device)) break; 554 } 555 // check whether RAID device was found in raidlist 556 if (i == raidlist->entries) { 557 log_msg(1, "RAID device %s not found in list.", device); 558 return 1; 559 } 560 // create device list from normal disks followed by spare ones 561 mr_asprintf(devices, "%s", raidlist->el[i].data_disks.el[0].device); 562 for (j = 1; j < raidlist->el[i].data_disks.entries; j++) { 563 mr_asprintf(strtmp, "%s", devices); 564 mr_free(devices); 565 mr_asprintf(devices, "%s %s", strtmp, raidlist->el[i].data_disks.el[j].device); 566 mr_free(strtmp); 567 } 568 for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) { 569 mr_asprintf(strtmp, "%s", devices); 570 mr_free(devices); 571 mr_asprintf(devices, "%s %s", strtmp, raidlist->el[i].spare_disks.el[j].device); 572 mr_free(strtmp); 573 } 574 // translate RAID level 575 if (raidlist->el[i].raid_level == -2) { 576 mr_asprintf(level, "multipath"); 577 } else if (raidlist->el[i].raid_level == -1) { 578 mr_asprintf(level, "linear"); 579 } else { 580 mr_asprintf(level, "raid%d", raidlist->el[i].raid_level); 581 } 582 // create RAID device: 583 // - RAID device, number of devices and devices mandatory 584 // - parity algorithm, chunk size and spare devices optional 585 // - faulty devices ignored 586 // - persistent superblock always used as this is recommended 587 588 mr_asprintf(program, "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d %s", raidlist->el[i].raid_device, level, raidlist->el[i].data_disks.entries, oldmd); 589 mr_free(oldmd); 590 if (raidlist->el[i].parity != -1) { 591 mr_asprintf(strtmp, "%s", program); 592 mr_free(program); 593 switch(raidlist->el[i].parity) { 594 case 0: 595 mr_asprintf(program, "%s --parity=%s", strtmp, "la"); 596 break; 597 case 1: 598 mr_asprintf(program, "%s --parity=%s", strtmp, "ra"); 599 break; 600 case 2: 601 mr_asprintf(program, "%s --parity=%s", strtmp, "ls"); 602 break; 603 case 3: 604 mr_asprintf(program, "%s --parity=%s", strtmp, "rs"); 605 break; 606 default: 607 fatal_error("Unknown RAID parity algorithm."); 608 break; 609 } 610 mr_free(strtmp); 611 } 612 if (raidlist->el[i].chunk_size != -1) { 613 mr_asprintf(strtmp, "%s", program); 614 mr_free(program); 615 mr_asprintf(program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size); 616 mr_free(strtmp); 617 } 618 if (raidlist->el[i].spare_disks.entries > 0) { 619 mr_asprintf(strtmp, "%s", program); 620 mr_free(program); 621 mr_asprintf(program, "%s --spare-devices=%d", strtmp, raidlist->el[i].spare_disks.entries); 622 mr_free(strtmp); 623 } 624 mr_asprintf(strtmp, "%s", program); 625 mr_free(program); 626 mr_asprintf(program, "%s %s", strtmp, devices); 627 mr_free(strtmp); 628 res = run_program_and_log_output(program, 1); 629 mr_free(devices); 630 mr_free(level); 631 mr_free(program); 632 return res; 541 // leave straight away if raidlist is initial or has no entries 542 if (!raidlist || raidlist->entries == 0) { 543 log_msg(1, "No RAID arrays found."); 544 return 1; 545 } else { 546 log_msg(1, "%d RAID arrays found.", raidlist->entries); 547 } 548 // find raidlist entry for requested device 549 for (i = 0; i < raidlist->entries; i++) { 550 if (!strcmp(raidlist->el[i].raid_device, device)) break; 551 } 552 // check whether RAID device was found in raidlist 553 if (i == raidlist->entries) { 554 log_msg(1, "RAID device %s not found in list.", device); 555 return 1; 556 } else { 557 log_msg(1, "RAID device %s found in list (%d).", device, i); 558 } 559 560 // create device list from normal disks followed by spare ones 561 if (raidlist->el[i].data_disks.el[0].device != NULL) { 562 mr_asprintf(devices, "%s", raidlist->el[i].data_disks.el[0].device); 563 log_msg(4, "Adding device %s to list", raidlist->el[i].data_disks.el[0].device); 564 } else { 565 log_msg(1, "Strange, there are entries but no device"); 566 } 567 for (j = 1; j < raidlist->el[i].data_disks.entries; j++) { 568 mr_strcat(devices, " %s", raidlist->el[i].data_disks.el[j].device); 569 log_msg(4, "Adding device %s to list", raidlist->el[i].data_disks.el[j].device); 570 } 571 for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) { 572 mr_strcat(devices, " %s", raidlist->el[i].spare_disks.el[j].device); 573 log_msg(4, "Adding spare device %s to list", raidlist->el[i].spare_disks.el[j].device); 574 } 575 log_msg(4, "RAID devices: %s", devices); 576 // translate RAID level 577 if (raidlist->el[i].raid_level == -2) { 578 mr_asprintf(level, "multipath"); 579 } else if (raidlist->el[i].raid_level == -1) { 580 mr_asprintf(level, "linear"); 581 } else { 582 mr_asprintf(level, "raid%d", raidlist->el[i].raid_level); 583 } 584 // create RAID device: 585 // - RAID device, number of devices and devices mandatory 586 // - parity algorithm, chunk size and spare devices optional 587 // - faulty devices ignored 588 // - persistent superblock always used as this is recommended 589 590 mr_asprintf(program, "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d", raidlist->el[i].raid_device, level, raidlist->el[i].data_disks.entries); 591 mr_free(level); 592 log_msg(4, "cmd built: %s", program); 593 // Restoring the UUID and Version stored at backup time of present 594 for (v = 0; v < raidlist->el[i].additional_vars.entries ; v++ ) { 595 log_msg(4,"Working on additional param #%d (Label: %s)",v,raidlist->el[i].additional_vars.el[v].label); 596 if ((raidlist->el[i].additional_vars.el[v].label != NULL) && (strcmp(raidlist->el[i].additional_vars.el[v].label,"UUID") == 0)) { 597 // We have a UUID to handle 598 if (raidlist->el[i].additional_vars.el[v].value != NULL) { 599 // force its restoration in order to avoid modifying all conf files using it 600 log_it("Managing previous UUID %s", raidlist->el[i].additional_vars.el[v].value); 601 mr_strcat(program, " --uuid %s",raidlist->el[i].additional_vars.el[v].value); 602 continue; 603 } else { 604 log_msg(1,"Unable to manage previous NULL UUID"); 605 } 606 } 607 if ((raidlist->el[i].additional_vars.el[v].label != NULL) && (strcmp(raidlist->el[i].additional_vars.el[v].label,"Version") == 0)) { 608 // We have a Version to handle 609 if (raidlist->el[i].additional_vars.el[v].value != NULL) { 610 // force its restoration in order to support all complex boot loader + md format cases 611 // Also see bug #473 612 log_it("Managing previous Version %s", raidlist->el[i].additional_vars.el[v].value); 613 mr_strcat(program, " -e %s",raidlist->el[i].additional_vars.el[v].value); 614 continue; 615 } else { 616 log_msg(1,"Unable to manage previous NULL Version"); 617 } 618 } 619 } 620 log_msg(4, "cmd built: %s", program); 621 if (raidlist->el[i].parity != -1) { 622 switch(raidlist->el[i].parity) { 623 case 0: 624 mr_strcat(program, " --parity=%s", "la"); 625 break; 626 case 1: 627 mr_strcat(program, " --parity=%s", "ra"); 628 break; 629 case 2: 630 mr_strcat(program, " --parity=%s", "ls"); 631 break; 632 case 3: 633 mr_strcat(program, " --parity=%s", "rs"); 634 break; 635 default: 636 fatal_error("Unknown RAID parity algorithm."); 637 break; 638 } 639 } 640 log_msg(4, "cmd built: %s", program); 641 if (raidlist->el[i].chunk_size != -1) { 642 mr_strcat(program, " --chunk=%d", raidlist->el[i].chunk_size); 643 } 644 if (raidlist->el[i].spare_disks.entries > 0) { 645 mr_strcat(program, " --spare-devices=%d", raidlist->el[i].spare_disks.entries); 646 } 647 log_msg(4, "cmd built: %s", program); 648 mr_strcat(program, " %s", devices); 649 log_msg(2, "RAID device re-created with the following command:\n%s\n", program); 650 if (test == TRUE) { 651 res = run_program_and_log_output(program, 1); 652 } else { 653 // test mode, always returns TRUE without executing the mdadm command 654 res = TRUE; 655 } 656 // free memory 657 mr_free(devices); 658 mr_free(program); 659 return res; 633 660 } 634 661 … … 759 786 sync(); 760 787 sleep(1); 788 if (g_fprep) { 789 fprintf(g_fprep, "%s\n", program); 790 } 761 791 762 792 log_msg(1, "Making %s", device); … … 845 875 return (retval); 846 876 } 847 848 849 850 877 851 878 … … 1006 1033 if (g_partition_table_locked_up > 0) { 1007 1034 if (retval > 0 && !interactively) { 1008 //123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567891035 //123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1009 1036 log_to_screen("Partition table locked up %d times. At least one 'mkfs' (format) command", g_partition_table_locked_up); 1010 1037 log_to_screen("failed. I think these two events are related. Sometimes, fdisk's ioctl() call"); … … 1015 1042 sync(); 1016 1043 sync(); 1017 if (system("reboot")) { 1018 // FIXME 1019 } 1044 paranoid_system("reboot"); 1020 1045 } 1021 1046 } else { … … 1558 1583 1559 1584 if (pout_to_fdisk) { 1560 // mark relevant partition as bootable1561 tmp1 = call_program_and_get_last_line_of_output ("make-me-bootable "MINDI_CACHE"/mountlist.txt dummy",TRUE);1562 mr_asprintf(tmp, "a\n%s\n", tmp1);1563 mr_free(tmp1);1564 1565 fput_string_one_char_at_a_time(pout_to_fdisk, tmp);1566 mr_free(tmp);1567 1568 1585 // close fdisk 1586 fput_string_one_char_at_a_time(pout_to_fdisk, "p\n"); 1569 1587 fput_string_one_char_at_a_time(pout_to_fdisk, "w\n"); 1570 sync();1571 1588 paranoid_pclose(pout_to_fdisk); 1572 1589 sync(); 1573 1590 log_msg(0,"------------------- fdisk.log looks like this ------------------"); 1574 1591 mr_asprintf(tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE); 1575 if (system(tmp)) { 1576 // FIXME 1577 } 1592 paranoid_system(tmp); 1578 1593 mr_free(tmp); 1579 1594 1580 log_msg(0, 1581 "------------------- end of fdisk.log... word! ------------------"); 1595 // mark relevant partition as bootable 1596 mr_asprintf(tmp1,"make-me-bootable /tmp/mountlist.txt %s",drivename); 1597 call_program_and_get_last_line_of_output(tmp1); 1598 mr_free(tmp1); 1599 log_msg(0,"------------------- end of fdisk.log... ------------------"); 1600 sync(); 1601 1582 1602 mr_asprintf(tmp, "tail -n6 %s | grep -F \"16: \"", FDISK_LOG); 1583 1603 if (!run_program_and_log_output(tmp, 5)) { … … 1947 1967 #endif 1948 1968 } 1949 log_msg(1, tmp,"Setting %s's type to %s (%s)", partition, format, partcode);1969 log_msg(1, "Setting %s's type to %s (%s)", partition, format, partcode); 1950 1970 mr_free(partition); 1951 1971 … … 2009 2029 } 2010 2030 } 2011 2012 2031 mr_free(partcode); 2032 2013 2033 return (res); 2014 2034 } … … 2080 2100 mr_asprintf(program, "vinum stop -f %s", raid_device); 2081 2101 #else 2082 2083 2102 // use raidstop if it exists, otherwise use mdadm 2103 if (run_program_and_log_output("which raidstop", FALSE)) { 2084 2104 mr_asprintf(program, "mdadm -S %s", raid_device); 2085 2105 } else { … … 2201 2221 * @return 0 for success, nonzero for failure. 2202 2222 */ 2203 char *which_format_command_do_i_need(char *format)2223 static char *which_format_command_do_i_need(char *format) 2204 2224 { 2205 2225 /** buffers *********************************************************/ … … 2229 2249 } else if (strcmp(format, "ext4") == 0) { 2230 2250 mr_asprintf(program, "mkfs -t ext4 -F -q"); 2231 } else if (strcmp(format, "btrfs") == 0) {2232 strcpy(program, "mkfs.btrfs");2233 2251 } else if (strcmp(format, "btrfs") == 0) { 2234 2252 strcpy(program, "mkfs.btrfs"); -
branches/3.1/mondo/src/mondorestore/mondo-rstr-compare.c
r3161 r3193 76 76 paranoid_fclose(fin); 77 77 78 79 mr_asprintf(bigfile_fname, "%s", biggiestruct.filename); 80 log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename); 78 81 mr_asprintf(checksum, "%s", biggiestruct.checksum); 79 mr_asprintf(bigfile_fname, "%s", biggiestruct.filename);80 81 log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename);82 82 log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum); 83 83 … … 85 85 mr_asprintf(tmp, "Comparing %s", bigfile_fname); 86 86 newtDrawRootText(0, 22, tmp); 87 paranoid_free(tmp);87 mr_free(tmp); 88 88 newtRefresh(); 89 89 } 90 if ( !checksum[0]) {90 if (checksum == NULL]) { 91 91 log_msg(2, "Warning - %s has no checksum", bigfile_fname); 92 92 } 93 93 if (!strncmp(bigfile_fname, "/dev/", 5)) { 94 94 log_msg(2, "IGNORING %s as begining with /dev", bigfile_fname); 95 mr_free(checksum); 95 96 mr_free(bigfile_fname); 96 97 return (1); … … 104 105 mr_asprintf(tmp, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE); 105 106 paranoid_system(tmp); 106 paranoid_free(tmp);107 mr_free(tmp); 107 108 108 109 if (i) { 109 110 log_OS_error("Warning - command failed"); 111 mr_free(checksum); 112 mr_free(bigfile_fname); 110 113 return (1); 111 114 } else { 112 115 if (!(fin = fopen("/tmp/md5sum.txt", "r"))) { 113 log_msg(2, 114 "Unable to open /tmp/md5sum.txt; can't get live checksum");116 log_msg(2, "Unable to open /tmp/md5sum.txt; can't get live checksum"); 117 mr_free(checksum); 115 118 mr_free(bigfile_fname); 116 119 return (1); … … 135 138 136 139 log_msg(1, tmp); 137 paranoid_free(tmp);140 mr_free(tmp); 138 141 139 142 if (retval) { … … 270 273 } else { 271 274 // afio 275 mr_asprintf(tmp, "%s", compressor_exe); 272 276 mr_free(compressor_exe); 273 mr_asprintf(tmp, "%s", compressor_exe);274 277 mr_asprintf(compressor_exe, "-P %s -Z", tmp); 275 278 mr_free(tmp); … … 291 294 } 292 295 mr_free(compressor_exe); 293 paranoid_free(archiver_exe);296 mr_free(archiver_exe); 294 297 295 298 #undef BUFSIZE … … 474 477 noof_changed_files = count_lines_in_file(MONDO_CACHE"/changed.txt"); 475 478 if (noof_changed_files) { 476 mr_asprintf(tmp, "%ld files do not match the backup ", noof_changed_files); 477 log_to_screen(tmp); 478 mr_free(tmp); 479 log_to_screen("%ld files do not match the backup ", noof_changed_files); 479 480 480 481 mr_asprintf(command, "cat "MONDO_CACHE"/changed.txt >> %s", MONDO_LOGFILE); … … 525 526 526 527 /************************************************************************** 527 * also deletes tmp/filelist.full & biggielist.txt _and_ tries to *528 * also deletes tmp/filelist.full & tmp/biggielist.txt _and_ tries to * 528 529 * restore them from start of tape, if available * 529 530 **************************************************************************/ … … 653 654 } 654 655 655 mvaddstr_and_log_it(g_currentY, 656 0, "Verifying archives against filesystem"); 656 mvaddstr_and_log_it(g_currentY, 0, "Verifying archives against filesystem"); 657 657 658 658 mr_free(bkpinfo->media_device); … … 711 711 } 712 712 713 mvaddstr_and_log_it(g_currentY, 714 0, "Verifying archives against filesystem"); 713 mvaddstr_and_log_it(g_currentY, 0, "Verifying archives against filesystem"); 715 714 res = verify_tape_backups(); 716 715 if (chdir(dir)) { -
branches/3.1/mondo/src/mondorestore/mondo-rstr-newt.c
r3161 r3193 212 212 mr_strip_spaces(size_str); 213 213 214 strip_spaces(device_str);214 mr_strip_spaces(device_str); 215 215 if (b_res == bOK) { 216 216 if (device_str[strlen(device_str) - 1] == '/') { … … 480 480 mr_free(tmp); 481 481 mr_free(prompt); 482 mr_free(prompt);483 482 return; 484 483 } … … 530 529 531 530 assert(raidrec != NULL); 532 533 if (system("grep Pers /proc/mdstat > /tmp/raid-personalities.txt 2> /dev/null")) { 534 // FIXME 535 } 531 paranoid_system("grep Pers /proc/mdstat > /tmp/raid-personalities.txt 2> /dev/null"); 536 532 personalities = last_line_of_file("/tmp/raid-personalities.txt"); 537 533 mr_asprintf(prompt, "Please enter the RAID level you want. %s", personalities); … … 583 579 mr_free(tmp); 584 580 mr_free(prompt); 581 585 582 raidrec->raid_level = out; 586 583 #endif … … 607 604 int pos = 0; 608 605 609 /** buffers ***********************************************************/610 606 assert(mountlist != NULL); 611 607 assert(raidlist != NULL); … … 931 927 strcpy(g_strings_of_flist_window[i - 1], tmp1); 932 928 mr_free(tmp1); 929 933 930 dummybool = g_is_path_selected[i]; 934 931 g_is_path_selected[i] = g_is_path_selected[i - 1]; … … 1683 1680 1684 1681 /** buffers ***********************************************************/ 1685 char title_of_editraidForm_window[MAX_STR_LEN];1682 char *title_of_editraidForm_window = NULL; 1686 1683 1687 1684 /** newt **************************************************************/ … … 1713 1710 memcpy((void *) &bkp_raidrec, (void *) raidrec, 1714 1711 sizeof(struct vinum_plex)); 1715 sprintf(title_of_editraidForm_window, "%s.p%i", 1716 raidlist->el[currline].volname, currline2); 1712 mr_asprintf(title_of_editraidForm_window, "%s.p%i", raidlist->el[currline].volname, currline2); 1717 1713 newtPushHelpLine 1718 1714 (" Please select a subdisk to edit, or edit this plex's parameters"); 1719 1715 newtOpenWindow(13, 3, 54, 18, title_of_editraidForm_window); 1716 mr_free(title_of_editraidForm_window); 1717 1720 1718 for (;;) { 1721 1719 int i; … … 1888 1886 strcpy(raidrec->additional_vars.el[lino].value, p); 1889 1887 } 1888 mr_free(header); 1889 mr_free(comment); 1890 1890 mr_free(p); 1891 1891 } … … 1953 1953 mr_asprintf(tmp, "%-24s %-24s %-8s %s", "Device", "Mountpoint", "Format", "Size (MB)"); 1954 1954 headerMsg = newtLabel(2, 1, tmp); 1955 mr_free(tmp); 1956 1955 1957 flawsLabelA = newtLabel(2, 13, " "); 1956 1958 flawsLabelB = newtLabel(2, 14, " "); … … 2044 2046 } 2045 2047 newtFormDestroy(myForm); 2046 2047 mr_free(flaws_str_A);2048 mr_free(flaws_str_B);2049 mr_free(flaws_str_C);2050 mr_free(tmp);2051 2052 2048 newtPopWindow(); 2053 2049 newtPopHelpLine(); … … 2829 2825 disklist->el[currline].index = atoi(sz_res); 2830 2826 } 2827 2831 2828 redraw_disklist(disklist, keylist, partitionsListbox); 2832 2829 mr_free(sz_res); -
branches/3.1/mondo/src/mondorestore/mondo-rstr-tools.c
r3161 r3193 90 90 fatal_error("Cannot openin outfname"); 91 91 } 92 for (mr_getline(incoming, fin); !feof(fin) ; mr_getline(incoming, fin)) {92 for (mr_getline(incoming, fin); !feof(fin) && (incoming != NULL); mr_getline(incoming, fin)) { 93 93 mr_strip_spaces(incoming); 94 94 … … 140 140 } 141 141 if (file[0] == '/' && file[1] == '/') { 142 mr_asprintf(tmp, "%s", file); 143 mr_free(file); 142 tmp = file; 144 143 145 144 mr_asprintf(file, "%s", tmp + 1); … … 174 173 * @return 0 for success, nonzero for failure. 175 174 */ 176 int iso_fiddly_bits(bool nuke_me_please) 177 { 178 179 180 181 182 175 int iso_fiddly_bits(bool nuke_me_please) { 176 177 char *mount_isodir_command = NULL; 178 char *command = NULL; 179 char *mds = NULL; 180 int retval = 0, i; 181 char *isodir_format = NULL; 183 182 184 183 g_ISO_restore_mode = TRUE; … … 305 304 mr_strcat(additional_parameters, "-o ro"); 306 305 } 306 mr_free(tmp); 307 307 308 tmp = find_home_of_exe("setfattr"); 308 309 if (tmp) { … … 374 375 mr_free(mountpoint); 375 376 376 377 return (res); 377 378 } 378 379 /************************************************************************** … … 418 419 mr_free(tmp); 419 420 res = mount_device(mountlist->el[lino].device, mountlist->el[lino].mountpoint, mountlist->el[lino].format, writeable); 420 421 421 retval += res; 422 422 if (res) { … … 660 660 assert(bkpinfo != NULL); 661 661 assert(cfgf != NULL); 662 log_it("Entering read_cfg_file_into_bkpinfo"); 662 663 663 664 media_specified_by_user = bkpinfo->backup_media_type; // or 'none', if not specified … … 676 677 bkpinfo->please_dont_eject = TRUE; 677 678 } else if (!strcmp(value, "iso")) { 678 // Patch by Conor Daly - 2004/07/12679 679 bkpinfo->backup_media_type = iso; 680 680 if (am_I_in_disaster_recovery_mode()) { … … 687 687 bkpinfo->backup_media_type = cdr; 688 688 run_program_and_log_output("umount -d "MNT_CDROM, 1); 689 log_it 690 ("Re-jigging configuration AGAIN. CD-R, not ISO."); 689 log_it("Re-jigging configuration AGAIN. CD-R, not ISO."); 691 690 } 692 691 } … … 698 697 mr_asprintf(bkpinfo->prefix, "%s", STD_PREFIX); 699 698 } 699 log_it("Setting Prefix to %s", bkpinfo->prefix); 700 700 } else if ((!strcmp(value, "netfs")) || (!strcmp(value, "nfs"))) { 701 701 /* Stay compatible with previous versions by allowing nfs as an entry here */ … … 727 727 tmp = call_program_and_get_last_line_of_output("cat " CMDLINE,TRUE); 728 728 if (strstr(tmp, "pxe")) { 729 /* We need to override prefix value in PXE mode as it's 729 /* We need to override prefix value in PXE mode as it's 730 730 * already done in start-netfs */ 731 731 envtmp1 = getenv("imgname"); … … 754 754 mr_free(bkpinfo->media_device); 755 755 mr_asprintf(bkpinfo->media_device, "/dev/cdrom"); 756 bkpinfo->media_size[0] = 1999 * 1024; 757 bkpinfo->media_size[1] = 650; /* good guess */ 756 bkpinfo->media_size = 650; /* good guess */ 758 757 } else if (bkpinfo->backup_media_type == usb) { 759 758 envtmp1 = getenv("MRUSBDEV"); … … 778 777 value = read_cfg_var(cfg_file, "media-size"); 779 778 if (value != NULL) { 780 bkpinfo->media_size [1]= atol(value);779 bkpinfo->media_size = atol(value); 781 780 mr_free(value); 782 781 } else { 783 bkpinfo->media_size [1]= 0L;782 bkpinfo->media_size = 0L; 784 783 } 785 784 log_msg(2, "Backup medium is TAPE --- dev=%s", bkpinfo->media_device); … … 787 786 mr_free(bkpinfo->media_device); 788 787 mr_asprintf(bkpinfo->media_device, "/dev/cdrom"); /* we don't really need this var */ 789 bkpinfo->media_size[0] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */ 790 bkpinfo->media_size[1] = 1999 * 1024; /* 650, probably, but we don't need this var anyway */ 791 log_msg(2, "Backup medium is CD-R[W]"); 788 bkpinfo->media_size = 1999 * 1024; /* 650, probably, but we don't need this var anyway */ 789 log_msg(2, "Backup medium is similar to CD-R[W]"); 792 790 } 793 791 } else { … … 968 966 mr_free(tmp1); 969 967 } 970 971 968 } else if (bkpinfo->backup_media_type == iso) { 972 969 /* Patch by Conor Daly 23-june-2004 … … 1044 1041 if (! bkpinfo->disaster_recovery) { 1045 1042 if (bkpinfo->backup_media_type != media_specified_by_user) { 1046 log_msg(2, 1047 "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)"); 1043 log_msg(2, "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)"); 1048 1044 interactively_obtain_media_parameters_from_user(FALSE); 1049 1045 media_specified_by_user = bkpinfo->backup_media_type; … … 1086 1082 int res = 0; 1087 1083 pid_t pid; 1084 bool extract_mountlist_stub = FALSE; 1088 1085 1089 1086 assert(bkpinfo != NULL); … … 1234 1231 popup_and_OK("You'll now be chrooted under your future / partition.\nEdit /etc/mkinitcpio.conf if needed and rebuild your initrd with the kernel preset name e.g.\nmkinitcpio -p kernel26\nThen type exit to finish.\n"); 1235 1232 } else { 1236 popup_and_OK("You'll now be chrooted under your future / partition.\nGo under /boot and rebuild your init rd with\nmkinitrd -f -v initrd-2.x.y.img 2.x.y e.g.\nThen type exit to finish.");1233 popup_and_OK("You'll now be chrooted under your future / partition.\nGo under /boot and rebuild your init(rd|ramfs) with\nmkinitrd -f -v initrd-2.x.y.img 2.x.y e.g.\nor initramfs, dracut, ... Then type exit to finish."); 1237 1234 } 1238 1235 mvaddstr_and_log_it(g_currentY, 0, "Modifying initrd..."); … … 1435 1432 1436 1433 if ((res) || (mntlistchg)) { 1437 popup_and_OK("GRUB installation failed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install"); 1438 } else { 1439 popup_and_OK("The mountlist was changed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install"); 1440 } 1441 if (!g_text_mode) { 1442 newtSuspend(); 1443 } 1444 mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor); 1445 paranoid_system(tmp); 1446 mr_free(tmp); 1447 1448 mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor); 1449 paranoid_system(tmp); 1450 mr_free(tmp); 1451 1452 if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) { 1453 mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor); 1454 } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) { 1455 mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor); 1456 } else if (does_file_exist(MNT_RESTORING"/boot/grub2/grub.cfg")) { 1457 mr_asprintf(tmp, "chroot %s %s /boot/grub2/grub.cfg", MNT_RESTORING, editor); 1458 } 1459 paranoid_system(tmp); 1460 mr_free(tmp); 1461 1462 if (does_file_exist(MNT_RESTORING"/boot/grub/device.map")) { 1434 if (res) { 1435 popup_and_OK("GRUB installation failed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install"); 1436 } else { 1437 popup_and_OK("The mountlist was changed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install"); 1438 } 1439 if (!g_text_mode) { 1440 newtSuspend(); 1441 } 1442 mr_asprintf(editor, "%s", find_my_editor()); 1443 mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor); 1444 paranoid_system(tmp); 1445 mr_free(tmp); 1446 1447 mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor); 1448 paranoid_system(tmp); 1449 mr_free(tmp); 1450 1451 if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) { 1452 mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor); 1453 } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) { 1454 mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor); 1455 } else if (does_file_exist(MNT_RESTORING"/boot/grub2/grub.cfg")) { 1456 mr_asprintf(tmp, "chroot %s %s /boot/grub2/grub.cfg", MNT_RESTORING, editor); 1457 } 1458 paranoid_system(tmp); 1459 mr_free(tmp); 1460 1461 if (does_file_exist(MNT_RESTORING"/boot/grub/device.map")) { 1462 mr_asprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor); 1463 } else if (does_file_exist(MNT_RESTORING"/boot/grub2/device.map")) { 1464 mr_asprintf(tmp, "chroot %s %s /boot/grub2/device.map", MNT_RESTORING, editor); 1465 } 1466 paranoid_system(tmp); 1467 mr_free(tmp); 1468 1469 if (!g_text_mode) { 1470 newtResume(); 1471 } 1472 mr_asprintf(command, "stabgrub-me %s", boot_device); 1473 res = run_program_and_log_output(command, 1); 1474 mr_free(command); 1475 1476 if (res) { 1477 popup_and_OK("GRUB installation failed. Please fix the conf files so that a manual install using 'grub-install' or similar command works. You are now chroot()'ed to your restored system. Please type 'exit' when you are done."); 1478 newtSuspend(); 1479 paranoid_system("chroot " MNT_RESTORING); 1480 newtResume(); 1481 popup_and_OK("Thank you."); 1482 } else { 1483 popup_and_OK("GRUB is now installed correctly"); 1484 done = TRUE; 1485 } 1486 popup_and_OK("You will now edit fstab, mtab, device.map and menu.lst/grub.cfg"); 1487 if (!g_text_mode) { 1488 newtSuspend(); 1489 } 1490 1491 mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor); 1492 paranoid_system(tmp); 1493 mr_free(tmp); 1494 1495 mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor); 1496 paranoid_system(tmp); 1497 mr_free(tmp); 1498 1499 if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) { 1500 mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor); 1501 } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) { 1502 mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor); 1503 } 1504 paranoid_system(tmp); 1505 mr_free(tmp); 1506 1463 1507 mr_asprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor); 1464 } else if (does_file_exist(MNT_RESTORING"/boot/grub2/device.map")) { 1465 mr_asprintf(tmp, "chroot %s %s /boot/grub2/device.map", MNT_RESTORING, editor); 1466 } 1467 paranoid_system(tmp); 1468 mr_free(tmp); 1469 1470 if (!g_text_mode) { 1471 newtResume(); 1472 } 1473 mr_asprintf(command, "stabgrub-me %s", boot_device); 1474 res = run_program_and_log_output(command, 1); 1475 mr_free(command); 1476 if (res) { 1477 popup_and_OK("GRUB installation failed. Please fix the conf files so that a manual install using 'grub-install' or similar command works. You are now chroot()'ed to your restored system. Please type 'exit' when you are done."); 1478 newtSuspend(); 1479 paranoid_system("chroot " MNT_RESTORING); 1480 newtResume(); 1481 popup_and_OK("Thank you."); 1482 } else { 1483 popup_and_OK("GRUB is now installed correctly"); 1484 done = TRUE; 1485 } 1486 popup_and_OK("You will now edit fstab, mtab, device.map and menu.lst/grub.cfg"); 1487 if (!g_text_mode) { 1488 newtSuspend(); 1489 } 1490 mr_asprintf(editor, "%s", find_my_editor()); 1491 1492 mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor); 1493 paranoid_system(tmp); 1494 mr_free(tmp); 1495 1496 mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor); 1497 paranoid_system(tmp); 1498 mr_free(tmp); 1499 1500 if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) { 1501 mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor); 1502 } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) { 1503 mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor); 1504 } 1505 paranoid_system(tmp); 1506 mr_free(tmp); 1507 1508 mr_asprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor); 1509 paranoid_system(tmp); 1510 mr_free(tmp); 1511 mr_free(editor); 1512 1513 if (!g_text_mode) { 1514 newtResume(); 1508 paranoid_system(tmp); 1509 mr_free(tmp); 1510 mr_free(editor); 1511 1512 if (!g_text_mode) { 1513 newtResume(); 1514 } 1515 1515 } 1516 1516 } … … 1525 1525 log_msg(1, "WARNING - grub-MR not found; using grub-install"); 1526 1526 } 1527 mvaddstr_and_log_it(g_currentY, 1528 0, 1529 "Running GRUB... "); 1527 mvaddstr_and_log_it(g_currentY, 0, "Running GRUB... "); 1530 1528 log_it("%s",command); 1531 1529 res = run_program_and_log_output(command, 1); … … 1611 1609 paranoid_system(tmp); 1612 1610 mr_free(tmp); 1613 1614 1611 mr_free(editor); 1615 1612 … … 1688 1685 paranoid_system(tmp); 1689 1686 mr_free(tmp); 1690 1691 1687 mr_free(editor); 1692 1688 … … 2114 2110 paranoid_free(raidlist); 2115 2111 } 2116 2117 -
branches/3.1/mondo/src/mondorestore/mondoprep.h
r3147 r3193 69 69 int partition_everything(struct mountlist_itself *); 70 70 int do_my_funky_lvm_stuff(bool, bool); 71 char *which_format_command_do_i_need(char *);72 71 int make_dummy_partitions(FILE *, char *, int); 73 72 int make_list_of_drives(struct mountlist_itself *, -
branches/3.1/mondo/src/mondorestore/mondorestore.c
r3161 r3193 582 582 log_msg(1, "Restoring subset"); 583 583 retval += restore_everything(filelist); 584 free_filelist(filelist); 584 585 } else { 585 586 mr_free(bkpinfo->restore_path); … … 839 840 "Using tune2fs/tune4fs to identify your ext2,3,4 partitions"); 840 841 841 mr_asprintf(tmp , "label-partitions-as-necessary %s < /tmp/fstab >> %s 2>> %s", MINDI_CACHE"/mountlist.txt", MONDO_LOGFILE, MONDO_LOGFILE);842 mr_asprintf(tmp1, "label-partitions-as-necessary %s < /tmp/fstab >> %s 2>> %s", MINDI_CACHE"/mountlist.txt", MONDO_LOGFILE, MONDO_LOGFILE); 842 843 res = run_program_and_log_output(tmp, TRUE); 843 mr_free(tmp );844 mr_free(tmp1); 844 845 if (res) { 845 846 log_to_screen("label-partitions-as-necessary returned an error"); … … 2045 2046 int res; 2046 2047 int attempts; 2047 long current_tarball_number = 0 ;2048 long current_tarball_number = 0L; 2048 2049 long max_val; 2049 2050 /**malloc ***/ … … 2620 2621 mr_free(tmp1); 2621 2622 2623 mountlist = (struct mountlist_itself *)mr_malloc(sizeof(struct mountlist_itself)); 2624 raidlist = (struct raidlist_itself *)mr_malloc(sizeof(struct raidlist_itself)); 2625 2626 2627 2622 2628 /* Init GUI */ 2623 2629 setup_newt_stuff(); /* call newtInit and setup screen log */ … … 2666 2672 2667 2673 log_it("what time is it"); 2668 2669 mountlist = (struct mountlist_itself *)mr_malloc(sizeof(struct mountlist_itself));2670 raidlist = (struct raidlist_itself *)mr_malloc(sizeof(struct raidlist_itself));2671 2674 2672 2675 /* Process command-line parameters */ … … 2799 2802 mount_boot_if_necessary(); /* for Gentoo users */ 2800 2803 log_msg(2, "Still here."); 2801 /* Adding an initialisation in order to avoid to h ndle NULL pointer later */2804 /* Adding an initialisation in order to avoid to handle NULL pointer later */ 2802 2805 mr_free(bkpinfo->restore_path); 2803 2806 mr_asprintf(bkpinfo->restore_path, "%s", "/tmp"); -
branches/3.2/mondo/src/include/mr_str.h
r3171 r3193 19 19 extern inline char *mr_date(void); 20 20 extern void mr_strip_spaces(char *in_out); 21 /* 22 extern void mr_strip_char(char *in_out, char *caracs); 23 extern void mr_chomp(char *in_out); 24 */ 21 25 22 26 #endif /* MR_STR_H */ -
branches/3.2/mondo/src/include/my-stuff.h
r3191 r3193 8 8 // Extra info for ACLs and SELINUX users 9 9 #define STAR_ACL_SZ "-xattr -acl" 10 //#define STAR_ACL_SZ "-xfflags"11 //#define STAR_ACL_SZ ""12 // Enable the first line and disable the second if you are a Fedora Core 2 user13 10 14 11 /** … … 230 227 */ 231 228 #define MAX_TAPECAT_FNAME_LEN 32 232 233 //#define strcpy(y,x) strncpy(y, x, sizeof(y)-1)234 235 229 236 230 /** … … 346 340 #define ARCH_BUFFER_NUM (ARCH_THREADS*4) // Number of permissible queued afio files 347 341 #define FORTY_SPACES " " ///< 40 spaces. 348 ///< Size of the tmpfs, in megabytes, to attempt to mount (to speed up Mondo).349 /*350 #define PPCFG_RAMDISK_SIZE 350351 */352 353 342 #define DO_MBR_PLEASE "/tmp/DO-MBR-PLEASE" 354 343 #define MONDO_MNTLISTCHG "/tmp/mountlist.changed" -
branches/3.2/mondo/src/lib/mr_str.c
r3171 r3193 146 146 } 147 147 148 /* Return an allocated string containing the date 149 char *mr_date(void) { 150 151 time_t tcurr; 152 char *tmp = NULL; 153 154 tcurr = time(NULL); 155 mr_asprintf(tmp, "%s", ctime(&tcurr)); 156 mr_chomp(tmp); 157 return(tmp); 158 } 159 */ 148 160 149 161 /** … … 181 193 in_out[i] = '\0'; 182 194 } 195 196 197 /* 198 * Remove '\n' char from both sides of @p in_out. 199 * @param in_out The string to strip characters from (modified). 200 201 void mr_chomp(char *in_out) { 202 203 mr_strip_char(in_out, "\n"); 204 } 205 */ 206 207 /** 208 * Remove all characters in caracs from begining and end of string @p in_out 209 * @param in_out The string to strip char characters from (modified). 210 211 void mr_strip_char(char *in_out, char *caracs) { 212 int i = 0; 213 int j = 0; 214 size_t length = 0; 215 216 if (caracs == NULL) { 217 return; 218 } 219 if (in_out == NULL) { 220 return; 221 } 222 length = strlen(in_out); 223 224 /* Skip initial caracs */ 225 for (i = 0; index(caracs, in_out[i]) != NULL && i < (int)length ; i++); 226 227 /* Shift the string to the begining if needed */ 228 if (i != 0) { 229 for (j = 0; i < (int)length ; i++, j++) { 230 in_out[j] = in_out[i]; 231 } 232 /* Erase the end of the string if needed */ 233 j++; 234 in_out[j] = '\0'; 235 } 236 237 /* Skip final caracs */ 238 for (i = (int)strlen(in_out) - 1; i >= 0 && index(caracs, in_out[i]) != NULL; i--); 239 240 /* The string now ends after that char */ 241 i++; 242 in_out[i] = '\0'; 243 } 244 */ 245 -
branches/3.2/mondo/src/mondoarchive/mondoarchive.c
r3185 r3193 10 10 #include "my-stuff.h" 11 11 #include "mr_mem.h" 12 #include "mr_str.h" 12 13 #include "../common/mondostructures.h" 13 14 #include "../common/libmondo.h" … … 32 33 33 34 /***************** global vars, used only by main.c ******************/ 34 long diffs ;35 long diffs = 0L; 35 36 36 37 extern t_bkptype g_backup_media_type; 37 38 extern int g_loglevel; 39 40 extern char *g_magicdev_command; 38 41 39 42 /** … … 74 77 char *tmp = NULL; 75 78 76 log_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org", 77 PACKAGE_VERSION); 79 log_msg(0, "Mondo Archive v%s --- http://www.mondorescue.org", PACKAGE_VERSION); 78 80 log_msg(0, "running %s binaries", get_architecture()); 79 81 tmp = get_uname_m(); 80 82 log_msg(0, "running on %s architecture", tmp); 81 83 mr_free(tmp); 82 log_msg(0, 83 "-----------------------------------------------------------"); 84 log_msg(0, 85 "NB: Mondo logs almost everything, so don't panic if you see"); 86 log_msg(0, 87 "some error messages. Please read them carefully before you"); 88 log_msg(0, 89 "decide to break out in a cold sweat. Despite (or perhaps"); 90 log_msg(0, 91 "because of) the wealth of messages. some users are inclined"); 92 log_msg(0, 93 "to stop reading this log. If Mondo stopped for some reason,"); 94 log_msg(0, 95 "chances are it's detailed here. More than likely there's a"); 96 log_msg(0, 97 "message at the very end of this log that will tell you what"); 98 log_msg(0, 99 "is wrong. Please read it! -Devteam"); 100 log_msg(0, 101 "-----------------------------------------------------------"); 84 log_msg(0, "-----------------------------------------------------------"); 85 log_msg(0, "NB: Mondo logs almost everything, so don't panic if you see"); 86 log_msg(0, "some error messages. Please read them carefully before you"); 87 log_msg(0, "decide to break out in a cold sweat. Despite (or perhaps"); 88 log_msg(0, "because of) the wealth of messages. some users are inclined"); 89 log_msg(0, "to stop reading this log. If Mondo stopped for some reason,"); 90 log_msg(0, "chances are it's detailed here. More than likely there's a"); 91 log_msg(0, "message at the very end of this log that will tell you what"); 92 log_msg(0, "is wrong. Please read it! -Devteam"); 93 log_msg(0, "-----------------------------------------------------------"); 102 94 103 95 log_msg(0, "Zero..."); … … 113 105 } 114 106 115 116 extern char *g_magicdev_command;117 107 118 108 /** … … 170 160 char *tmp = NULL; 171 161 char *tmp1 = NULL; 172 int res, retval; 162 int res = 0; 163 int i = 0; 164 int retval = 0; 173 165 char *say_at_end = NULL; 174 166 FILE *fin = NULL; … … 181 173 182 174 /* If -V, -v or --version then echo version no. and quit */ 183 if (argc == 2 184 && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V") 185 || !strcmp(argv[argc - 1], "--version"))) { 175 if (argc == 2 && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V") || !strcmp(argv[argc - 1], "--version"))) { 186 176 printf("mondoarchive v%s\nSee man page for help\n", PACKAGE_VERSION); 187 177 exit(0); … … 196 186 reset_bkpinfo(); 197 187 198 res = 0; 199 retval = 0; 200 diffs = 0; 188 /* Memory allocation is done in those functions */ 201 189 malloc_libmondo_global_strings(); 202 190 … … 208 196 mr_asprintf(tmp1,"%s:/sbin:/usr/sbin:/usr/local/sbin",getenv("PATH")); 209 197 setenv("PATH", tmp1, 1); 210 paranoid_free(tmp1);198 mr_free(tmp1); 211 199 212 200 /* Add the ARCH environment variable for ia64 purposes */ 213 201 mr_asprintf(tmp1,"%s",get_architecture()); 214 202 setenv("ARCH", tmp1, 1); 215 paranoid_free(tmp1);203 mr_free(tmp1); 216 204 217 205 /* Add MONDO_SHARE environment variable for mindi */ … … 255 243 g_text_mode = TRUE; 256 244 setup_newt_stuff(); 257 malloc_string(tmp); 258 turn_wildcard_chars_into_literal_chars(tmp, argv[2]); 259 printf("in=%s; out=%s\n", argv[2], tmp); 260 paranoid_free(tmp); 245 tmp1 = mr_stresc(argv[2], "[]*?", '\\'); 246 printf("in=%s; out=%s\n", argv[2], tmp1); 247 mr_free(tmp1); 261 248 finish(1); 262 249 } … … 311 298 printf("CD-ROM is at %s\n", tmp); 312 299 } 313 paranoid_free(tmp);300 mr_free(tmp); 314 301 finish(0); 315 302 } … … 325 312 printf("DVD is at %s\n", tmp); 326 313 } 327 paranoid_free(tmp);314 mr_free(tmp); 328 315 finish(0); 329 316 } … … 343 330 344 331 if (pre_param_configuration()) { 345 fatal_error 346 ("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting..."); 347 } 348 349 /* Process command line, if there is one. If not, ask user for info. */ 332 fatal_error("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting..."); 333 } 334 335 /* Process command line, if there is one. If not, ask user for info. */ 350 336 if (argc == 1) { 351 337 g_text_mode = FALSE; … … 353 339 res = interactively_obtain_media_parameters_from_user(TRUE); /* yes, archiving */ 354 340 if (res) { 355 fatal_error 356 ("Syntax error. Please review the parameters you have supplied and try again."); 341 fatal_error("Syntax error. Please review the parameters you have supplied and try again."); 357 342 } 358 343 } else { 359 344 res = handle_incoming_parameters(argc, argv); 360 345 if (res) { 361 printf 362 ("Errors were detected in the command line you supplied.\n"); 346 printf("Errors were detected in the command line you supplied.\n"); 363 347 printf("Please review the log file - %s\n", MONDO_LOGFILE ); 364 348 log_msg(1, "Mondoarchive will now exit."); … … 370 354 /* Finish configuring global structures */ 371 355 if (post_param_configuration()) { 372 fatal_error 373 ("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting..."); 374 } 375 376 log_to_screen 377 ("BusyBox's sources are available from http://www.busybox.net"); 356 fatal_error("Post-param initialization phase failed. Perhaps bad parameters were supplied to mondoarchive? Please review the documentation, error messages and logs. Exiting..."); 357 } 378 358 379 359 /* If we're meant to backup then backup */ … … 392 372 res = verify_data(); 393 373 if (res < 0) { 394 mr_asprintf(tmp, "%d difference%c found.", -res, 395 (-res != 1) ? 's' : ' '); 374 mr_asprintf(tmp, "%d difference%c found.", -res, (-res != 1) ? 's' : ' '); 396 375 mr_asprintf(say_at_end, "%s", tmp); 397 376 log_to_screen(tmp); … … 430 409 if (say_at_end != NULL) { 431 410 log_to_screen(say_at_end); 432 paranoid_free(say_at_end);411 mr_free(say_at_end); 433 412 } 434 413 mr_asprintf(tmp, "umount %s/tmpfs", bkpinfo->tmpdir); … … 437 416 if (bkpinfo->backup_media_type == usb) { 438 417 log_msg(1, "Unmounting USB device."); 418 if (bkpinfo->media_device == NULL) { 419 fatal_error("USB device set to NULL"); 420 } 439 421 mr_asprintf(tmp, "umount %s1", bkpinfo->media_device); 440 422 run_program_and_log_output(tmp, TRUE); … … 471 453 472 454 if (!g_text_mode) { 473 popup_and_OK 474 ("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt."); 455 popup_and_OK("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt."); 475 456 log_to_screen("See %s for details of backup run.", MONDO_LOGFILE); 476 457 } else { -
branches/3.2/mondo/src/mondoarchive/mondoarchive.h
r3141 r3193 9 9 */ 10 10 char *MONDO_LOGFILE = "/var/log/mondoarchive.log"; 11 char *MONDO_OPTIONS = "0123456789A:B:C:DE:FGHI:J:K:LM:NOP:QRS:T:UVW b:c:d:ef:gik:l:mn:op:rs:tuw:x:z";11 char *MONDO_OPTIONS = "0123456789A:B:C:DE:FGHI:J:K:LM:NOP:QRS:T:UVWYb:c:d:ef:gik:l:mn:op:rs:tuw:x:z"; 12 12 13 13 /* No restriction on ps options */ -
branches/3.2/mondo/src/mondorestore/mondo-rstr-compare.c
r3185 r3193 43 43 44 44 /** needs malloc *******/ 45 char *checksum_ptr; 46 char *original_cksum_ptr; 47 char *bigfile_fname_ptr; 48 char *tmp_ptr = NULL; 49 char *command_ptr; 50 51 char *checksum, *original_cksum, *bigfile_fname, *tmp, *command; 45 char *checksum = NULL; 46 char *original_cksum = NULL; 47 char *bigfile_fname = NULL; 48 char *tmp = NULL; 49 char *command = NULL; 52 50 53 51 char *p; … … 56 54 57 55 struct s_filename_and_lstat_info biggiestruct; 58 59 malloc_string(checksum);60 malloc_string(original_cksum);61 malloc_string(bigfile_fname);62 malloc_string(tmp);63 malloc_string(command);64 malloc_string(checksum_ptr);65 malloc_string(original_cksum_ptr);66 malloc_string(bigfile_fname_ptr);67 malloc_string(command_ptr);68 56 69 57 /********************************************************************* … … 71 59 *********************************************************************/ 72 60 assert(bkpinfo != NULL); 73 memset(checksum_ptr, '\0', sizeof(checksum));74 memset(original_cksum_ptr, '\0', sizeof(original_cksum));75 memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname));76 memset(command_ptr, '\0', sizeof(command));77 61 /** end **/ 78 62 … … 81 65 insist_on_this_cd_number((++g_current_media_number)); 82 66 } else { 83 mr_asprintf(tmp_ptr, "No CD's left. No biggiefiles left. No prob, Bob."); 84 log_msg(2, tmp_ptr); 85 paranoid_free(tmp_ptr); 67 log_msg(2, "No CD's left. No biggiefiles left. No prob, Bob."); 86 68 return (0); 87 69 } 88 70 } 89 71 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) { 90 mr_asprintf(tmp_ptr, "Cannot open bigfile %ld (%s)'s info file", bigfileno + 1, bigfile_fname_ptr); 91 log_to_screen(tmp_ptr); 92 paranoid_free(tmp_ptr); 72 log_to_screen("Cannot open bigfile %ld (NULL)'s info file", bigfileno + 1); 93 73 return (1); 94 74 } … … 98 78 paranoid_fclose(fin); 99 79 100 strcpy(checksum_ptr, biggiestruct.checksum); 101 strcpy(bigfile_fname_ptr, biggiestruct.filename); 102 80 81 mr_asprintf(bigfile_fname, "%s", biggiestruct.filename); 103 82 log_msg(2, "biggiestruct.filename = %s", biggiestruct.filename); 83 mr_asprintf(checksum, "%s", biggiestruct.checksum); 104 84 log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum); 105 85 106 86 if (!g_text_mode) { 107 mr_asprintf(tmp _ptr, "Comparing %s", bigfile_fname_ptr);108 newtDrawRootText(0, 22, tmp _ptr);109 paranoid_free(tmp_ptr);87 mr_asprintf(tmp, "Comparing %s", bigfile_fname); 88 newtDrawRootText(0, 22, tmp); 89 mr_free(tmp); 110 90 newtRefresh(); 111 91 } 112 if (!checksum[0]) { 113 log_msg(2, "Warning - %s has no checksum", bigfile_fname_ptr); 114 } 115 if (!strncmp(bigfile_fname_ptr, "/dev/", 5)) { 116 strcpy(original_cksum_ptr, "IGNORE"); 117 } else { 118 sprintf(command_ptr, 119 "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors", 120 MNT_RESTORING, bigfile_fname_ptr); 121 } 122 log_msg(2, command_ptr); 123 mr_asprintf(tmp_ptr, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE); 124 paranoid_system(tmp_ptr); 125 paranoid_free(tmp_ptr); 126 127 if (system(command_ptr)) { 92 if (checksum == NULL]) { 93 log_msg(2, "Warning - %s has no checksum", bigfile_fname); 94 } 95 if (!strncmp(bigfile_fname, "/dev/", 5)) { 96 log_msg(2, "IGNORING %s as begining with /dev", bigfile_fname); 97 mr_free(checksum); 98 mr_free(bigfile_fname); 99 return (1); 100 } 101 102 mr_asprintf(command, "md5sum \"%s%s\" > /tmp/md5sum.txt 2> /tmp/errors", MNT_RESTORING, bigfile_fname); 103 log_msg(2, command); 104 i = system(command); 105 mr_free(command); 106 107 mr_asprintf(tmp, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE); 108 paranoid_system(tmp); 109 mr_free(tmp); 110 111 if (i) { 128 112 log_OS_error("Warning - command failed"); 129 original_cksum[0] = '\0'; 113 mr_free(checksum); 114 mr_free(bigfile_fname); 130 115 return (1); 131 116 } else { 132 117 if (!(fin = fopen("/tmp/md5sum.txt", "r"))) { 133 log_msg(2, 134 "Unable to open /tmp/md5sum.txt; can't get live checksum");135 original_cksum[0] = '\0';118 log_msg(2, "Unable to open /tmp/md5sum.txt; can't get live checksum"); 119 mr_free(checksum); 120 mr_free(bigfile_fname); 136 121 return (1); 137 122 } else { 138 if (fgets(original_cksum_ptr, MAX_STR_LEN - 1, fin)) { 139 // FIXME 140 } 123 mr_getline(original_cksum, fin); 141 124 paranoid_fclose(fin); 142 for (i = strlen(original_cksum _ptr);125 for (i = strlen(original_cksum); 143 126 i > 0 && original_cksum[i - 1] < 32; i--); 144 127 original_cksum[i] = '\0'; 145 p = (char *) strchr(original_cksum_ptr, ' ');128 p = strchr(original_cksum, ' '); 146 129 if (p) { 147 130 *p = '\0'; … … 149 132 } 150 133 } 151 mr_asprintf(tmp _ptr, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname_ptr);152 if ( !strcmp(checksum_ptr, original_cksum_ptr) != 0) {153 mr_strcat(tmp _ptr, " ... OK");154 } else { 155 mr_strcat(tmp _ptr, "... changed");134 mr_asprintf(tmp, "bigfile #%ld ('%s') ", bigfileno + 1, bigfile_fname); 135 if ((original_cksum != NULL) && (strcmp(checksum, original_cksum) == 0)) { 136 mr_strcat(tmp, " ... OK"); 137 } else { 138 mr_strcat(tmp, "... changed"); 156 139 retval++; 157 140 } 158 log_msg(1, tmp_ptr); 159 paranoid_free(tmp_ptr); 141 mr_free(checksum); 142 mr_free(original_cksum); 143 144 log_msg(1, tmp); 145 mr_free(tmp); 160 146 161 147 if (retval) { … … 163 149 fatal_error("Cannot openout changed.txt"); 164 150 } 165 fprintf(fout, "%s\n", bigfile_fname _ptr);151 fprintf(fout, "%s\n", bigfile_fname); 166 152 paranoid_fclose(fout); 167 153 } 168 169 paranoid_free(original_cksum_ptr); 170 paranoid_free(original_cksum); 171 paranoid_free(bigfile_fname_ptr); 172 paranoid_free(bigfile_fname); 173 paranoid_free(checksum_ptr); 174 paranoid_free(checksum); 175 paranoid_free(command_ptr); 176 paranoid_free(command); 177 paranoid_free(tmp); 154 mr_free(bigfile_fname); 178 155 179 156 return (retval); … … 194 171 int res; 195 172 long noof_biggiefiles, bigfileno = 0; 196 char tmp[MAX_STR_LEN];173 char *tmp = NULL; 197 174 198 175 log_msg(1, "Comparing biggiefiles"); … … 215 192 noof_biggiefiles); 216 193 for (bigfileno = 0; bigfileno < noof_biggiefiles; bigfileno++) { 217 sprintf(tmp, "Comparing big file #%ld", bigfileno + 1);194 mr_asprintf(tmp, "Comparing big file #%ld", bigfileno + 1); 218 195 log_msg(1, tmp); 219 196 update_progress_form(tmp); 197 mr_free(tmp); 198 220 199 res = compare_a_biggiefile(bigfileno); 221 200 retval += res; … … 253 232 254 233 /*** needs malloc *********/ 255 char *command , *tmp, *filelist_name, *logfile,256 *compressor_exe;234 char *command = NULL; 235 char *tmp = NULL; 257 236 char *archiver_exe = NULL; 258 259 malloc_string(command); 260 malloc_string(tmp); 261 malloc_string(filelist_name); 262 malloc_string(logfile); 263 malloc_string(compressor_exe); 237 char *tmp1 = NULL; 238 char *logfile = NULL; 239 char *compressor_exe = NULL; 264 240 265 241 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 266 242 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 267 sprintf(logfile, "/tmp/afio.log.%d", current_tarball_number); 268 sprintf(filelist_name, MNT_CDROM "/archives/filelist.%d", 269 current_tarball_number); 243 mr_asprintf(filelist_name, MNT_CDROM "/archives/filelist.%d", current_tarball_number); 270 244 271 245 if (strstr(tarball_fname, ".bz2")) { 272 strcpy(compressor_exe, "bzip2"); 246 mr_asprintf(compressor_exe, "bzip2"); 247 } else if (strstr(tarball_fname, ".lzma")) { 248 mr_asprintf(compressor_exe, "lzma"); 273 249 } else if (strstr(tarball_fname, ".gz")) { 274 strcpy(compressor_exe, "gzip");250 mr_asprintf(compressor_exe, "gzip"); 275 251 } else if (strstr(tarball_fname, ".lzo")) { 276 strcpy(compressor_exe, "lzop"); 277 } else { 278 compressor_exe[0] = '\0'; 252 mr_asprintf(compressor_exe, "lzop"); 279 253 } 280 254 … … 285 259 } 286 260 287 if (compressor_exe [0]) {288 strcpy(tmp, compressor_exe);261 if (compressor_exe) { 262 mr_asprintf(tmp, "%s", compressor_exe); 289 263 if (!find_home_of_exe(tmp)) { 264 mr_free(tmp); 265 mr_free(compressor_exe); 266 mr_free(archiver_exe); 290 267 fatal_error("(compare_a_tarball) Compression program missing"); 291 268 } 292 if (use_star) // star 293 { 269 mr_free(tmp); 270 271 if (use_star) { 294 272 if (!strcmp(compressor_exe, "bzip2")) { 295 273 mr_strcat(archiver_exe, " -bz"); 296 274 } else { 297 fatal_error 298 ("(compare_a_tarball) Please use only bzip2 with star"); 275 mr_free(compressor_exe); 276 mr_free(archiver_exe); 277 fatal_error("(compare_a_tarball) Please use only bzip2 with star"); 299 278 } 300 } else // afio 301 { 302 sprintf(compressor_exe, "-P %s -Z", tmp); 303 } 304 } 305 // star -diff H=star -bz file=.... 279 } else { 280 // afio 281 mr_asprintf(tmp, "%s", compressor_exe); 282 mr_free(compressor_exe); 283 mr_asprintf(compressor_exe, "-P %s -Z", tmp); 284 mr_free(tmp); 285 } 286 } 306 287 307 288 #ifdef __FreeBSD__ … … 310 291 #define BUFSIZE (1024L*1024L)/TAPE_BLOCK_SIZE 311 292 #endif 312 if (use_star) // doesn't use compressor_exe 313 { 314 sprintf(command, 315 "%s -sparse -diff H=exustar file=%s >> %s 2>> %s", 316 archiver_exe, tarball_fname, logfile, logfile); 317 } else { 318 sprintf(command, 319 "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s", 320 archiver_exe, 321 TAPE_BLOCK_SIZE, 322 BUFSIZE, compressor_exe, tarball_fname, logfile, logfile); 323 } 324 paranoid_free(archiver_exe); 293 mr_asprintf(logfile, "/tmp/afio.log.%d", current_tarball_number); 294 295 if (use_star) { 296 // doesn't use compressor_exe 297 mr_asprintf(command, "%s -sparse -diff H=exustar file=%s >> %s 2>> %s", archiver_exe, tarball_fname, logfile, logfile); 298 } else { 299 mr_asprintf(command, "%s -r -b %ld -M 16m -c %ld %s %s >> %s 2>> %s", archiver_exe, TAPE_BLOCK_SIZE, BUFSIZE, compressor_exe, tarball_fname, logfile, logfile); 300 } 301 mr_free(compressor_exe); 302 mr_free(archiver_exe); 325 303 326 304 #undef BUFSIZE … … 330 308 if (res) { 331 309 log_OS_error(command); 332 sprintf(tmp, "Warning - afio returned error = %d", res); 333 log_msg(2, tmp); 334 } 310 log_msg(2, "Warning - afio returned error = %d", res); 311 } 312 mr_free(command); 313 335 314 if (length_of_file(logfile) > 5) { 336 sprintf(command, 337 "sed s/': \\\"'/\\|/ %s | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort -u | grep -vE \"^dev/.*\" >> "MONDO_CACHE"/changed.txt", 338 logfile); 315 mr_asprintf(command, "sed s/': \\\"'/\\|/ %s | sed s/'\\\": '/\\|/ | cut -d'|' -f2 | sort -u | grep -vE \"^dev/.*\" >> "MONDO_CACHE"/changed.txt", logfile); 339 316 paranoid_system(command); 317 mr_free(command); 318 340 319 archiver_errors = count_lines_in_file(logfile); 341 320 } else { 342 321 archiver_errors = 0; 343 322 } 344 sprintf(tmp, "%ld difference%c in fileset #%d ",345 archiver_errors, (archiver_errors != 1) ? 's' : ' ',346 current_tarball_number);347 323 if (archiver_errors) { 348 sprintf(tmp, 349 "Differences found while processing fileset #%d ", 350 current_tarball_number); 351 log_msg(1, tmp); 324 log_msg(1, "%ld difference%c in fileset #%d ", archiver_errors, (archiver_errors != 1) ? 's' : ' ', current_tarball_number); 352 325 } 353 326 unlink(logfile); 354 paranoid_free(command); 355 paranoid_free(tmp); 356 paranoid_free(filelist_name); 357 paranoid_free(logfile); 358 paranoid_free(compressor_exe); 327 mr_free(logfile); 328 359 329 return (retval); 360 330 } … … 377 347 /** needs malloc **********/ 378 348 379 char *tarball_fname, *progress_str, *tmp; 349 char *tarball_fname = NULL; 350 char *progress_str = NULL; 351 char *tmp = NULL; 380 352 char *mds = NULL; 381 353 long max_val; 382 354 383 malloc_string(tarball_fname);384 malloc_string(progress_str);385 355 malloc_string(tmp); 386 387 356 assert(bkpinfo != NULL); 388 357 mvaddstr_and_log_it(g_currentY, 0, "Comparing archives"); 389 358 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 390 391 359 max_val = atol(tmp); 360 paranoid_free(tmp); 361 392 362 mds = media_descriptor_string(bkpinfo->backup_media_type); 393 sprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number);363 mr_asprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number); 394 364 395 365 open_progress_form("Comparing files", … … 403 373 insist_on_this_cd_number(g_current_media_number); 404 374 update_progress_form(progress_str); 405 sprintf(tarball_fname, 406 MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number); 375 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.bz2", current_tarball_number); 407 376 408 377 if (!does_file_exist(tarball_fname)) { 409 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo",410 378 mr_free(tarball_fname); 379 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzo", current_tarball_number); 411 380 } 412 381 if (!does_file_exist(tarball_fname)) { 413 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.gz",414 382 mr_free(tarball_fname); 383 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.lzma", current_tarball_number); 415 384 } 416 385 if (!does_file_exist(tarball_fname)) { 417 sprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.",418 386 mr_free(tarball_fname); 387 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.gz", current_tarball_number); 419 388 } 420 389 if (!does_file_exist(tarball_fname)) { 421 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2",422 390 mr_free(tarball_fname); 391 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.afio.", current_tarball_number); 423 392 } 424 393 if (!does_file_exist(tarball_fname)) { 425 sprintf(tarball_fname, MNT_CDROM "/archives/%d.star.", 426 current_tarball_number); 394 mr_free(tarball_fname); 395 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.star.bz2", current_tarball_number); 396 } 397 if (!does_file_exist(tarball_fname)) { 398 mr_free(tarball_fname); 399 mr_asprintf(tarball_fname, MNT_CDROM "/archives/%d.star.", current_tarball_number); 427 400 } 428 401 if (!does_file_exist(tarball_fname)) { … … 432 405 == 0) { 433 406 log_msg(2, "OK, I think I'm done with tarballs..."); 407 mr_free(tarball_fname); 434 408 break; 435 409 } 436 410 log_msg(2, "OK, I think it's time for another CD..."); 437 411 g_current_media_number++; 438 sprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number); 412 413 mr_free(progress_str); 414 mr_asprintf(progress_str, "Comparing with %s #%d ", mds, g_current_media_number); 439 415 log_to_screen(progress_str); 440 416 } else { … … 444 420 current_tarball_number++; 445 421 } 446 } 422 mr_free(tarball_fname); 423 } 424 mr_free(progress_str); 447 425 mr_free(mds); 448 426 … … 453 431 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 454 432 } 455 paranoid_free(tarball_fname);456 paranoid_free(progress_str);457 paranoid_free(tmp);458 433 return (retval); 459 434 } … … 478 453 { 479 454 /** needs malloc *********/ 480 char *tmp, *cwd, *new, *command; 455 char *tmp = NULL; 456 char *cwd, *new; 457 char *command = NULL; 481 458 int resA = 0; 482 459 int resB = 0; … … 486 463 malloc_string(cwd); 487 464 malloc_string(new); 488 malloc_string(command);489 465 490 466 assert(bkpinfo != NULL); … … 509 485 noof_changed_files = count_lines_in_file(MONDO_CACHE"/changed.txt"); 510 486 if (noof_changed_files) { 511 sprintf(tmp, "%ld files do not match the backup ", 512 noof_changed_files); 513 // mvaddstr_and_log_it( g_currentY++, 0, tmp ); 514 log_to_screen(tmp); 515 sprintf(command, "cat "MONDO_CACHE"/changed.txt >> %s", MONDO_LOGFILE); 487 log_to_screen("%ld files do not match the backup ", noof_changed_files); 488 489 mr_asprintf(command, "cat "MONDO_CACHE"/changed.txt >> %s", MONDO_LOGFILE); 516 490 paranoid_system(command); 517 } else { 518 sprintf(tmp, "All files match the backup "); 491 mr_free(command); 492 } else { 493 mr_asprintf(tmp, "All files match the backup "); 519 494 mvaddstr_and_log_it(g_currentY++, 0, tmp); 520 495 log_to_screen(tmp); 521 }522 523 paranoid_free(tmp); 496 mr_free(tmp); 497 } 498 524 499 paranoid_free(cwd); 525 500 paranoid_free(new); 526 paranoid_free(command);527 501 528 502 return (resA + resB); … … 552 526 int res = 0; 553 527 long q; 554 char *tmp ;528 char *tmp = NULL; 555 529 char *new; 556 530 char *cwd; 557 531 558 malloc_string(tmp);559 532 malloc_string(new); 560 533 malloc_string(cwd); … … 630 603 } else { 631 604 q = count_lines_in_file(MONDO_CACHE"/changed.files"); 632 sprintf(tmp, "%ld significant difference%s found.", q, 633 (q != 1) ? "s" : ""); 605 mr_asprintf(tmp, "%ld significant difference%s found.", q, (q != 1) ? "s" : ""); 634 606 mvaddstr_and_log_it(g_currentY++, 0, tmp); 635 607 log_to_screen(tmp); 636 637 strcpy(tmp, 638 608 mr_free(tmp); 609 610 mr_asprintf(tmp, "Type 'less /tmp/changed.files' for a list of non-matching files"); 639 611 mvaddstr_and_log_it(g_currentY++, 0, tmp); 640 612 log_to_screen(tmp); 613 mr_free(tmp); 641 614 642 615 log_msg(2, "calling popup_changelist_from_file()"); … … 663 636 664 637 kill_petris(); 665 paranoid_free(tmp);666 638 paranoid_free(new); 667 639 paranoid_free(cwd); … … 686 658 687 659 /** needs malloc **/ 688 char *dir, *command; 660 char *dir; 661 char *command = NULL; 689 662 690 663 assert(bkpinfo != NULL); 691 664 malloc_string(dir); 692 malloc_string(command);693 665 if (getcwd(dir, MAX_STR_LEN)) { 694 666 // FIXME … … 698 670 } 699 671 700 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", 701 bkpinfo->restore_path); 672 mr_asprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path); 702 673 run_program_and_log_output(command, FALSE); 703 m vaddstr_and_log_it(g_currentY,704 674 mr_free(command); 675 mvaddstr_and_log_it(g_currentY, 0, "Verifying archives against filesystem"); 705 676 706 677 if (bkpinfo->disaster_recovery … … 726 697 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 727 698 paranoid_free(dir); 728 paranoid_free(command);729 699 return (res); 730 700 } … … 749 719 { 750 720 int res; 751 char *dir, *command; 721 char *dir; 722 char *command = NULL; 752 723 753 724 assert(bkpinfo != NULL); 754 725 malloc_string(dir); 755 malloc_string(command);756 726 757 727 if (getcwd(dir, MAX_STR_LEN)) { … … 761 731 // FIXME 762 732 } 763 sprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", 764 bkpinfo->restore_path); 733 mr_asprintf(command, "cp -f /tmp/LAST-FILELIST-NUMBER %s/tmp", bkpinfo->restore_path); 765 734 run_program_and_log_output(command, FALSE); 766 mvaddstr_and_log_it(g_currentY, 767 0, "Verifying archives against filesystem"); 735 mr_free(command); 736 737 mvaddstr_and_log_it(g_currentY, 0, "Verifying archives against filesystem"); 768 738 res = verify_tape_backups(); 769 739 if (chdir(dir)) { … … 776 746 } 777 747 paranoid_free(dir); 778 paranoid_free(command);779 748 return (res); 780 749 } -
branches/3.2/mondo/src/mondorestore/mondo-rstr-newt.c
r3185 r3193 12 12 #include "mondo-rstr-newt.h" 13 13 #include "mr_mem.h" 14 #include "mr_str.h" 14 15 15 16 //static char cvsid[] = "$Id$"; … … 52 53 { 53 54 /** buffers ***********************************************************/ 54 char tmp[MAX_STR_LEN];55 char *tmp = NULL; 55 56 56 57 /** newt **************************************************************/ … … 78 79 newtPushHelpLine 79 80 (" Add one of the following unallocated RAID partitions to this RAID device."); 80 sprintf(tmp, "%-26s %s", "Device", "Size");81 mr_asprintf(tmp, "%-26s %s", "Device", "Size"); 81 82 headerMsg = newtLabel(1, 1, tmp); 82 83 partitionsListbox = … … 104 105 105 106 items = disklist->entries; 106 strcpy(disklist->el[items].device, 107 unallocated_raid_partitions->el[currline].device); 107 strcpy(disklist->el[items].device, unallocated_raid_partitions->el[currline].device); 108 108 disklist->el[items].index = index; 109 109 disklist->entries = ++items; … … 112 112 } 113 113 newtFormDestroy(myForm); 114 mr_free(tmp); 114 115 newtPopWindow(); 115 116 newtPopHelpLine(); … … 152 153 153 154 /** buffers **********************************************************/ 154 char drive_to_add[MAX_STR_LEN];155 char mountpoint_str[MAX_STR_LEN];156 char size_str[MAX_STR_LEN];157 char device_str[MAX_STR_LEN];158 char format_str[MAX_STR_LEN];155 char *drive_to_add = NULL; 156 char *mountpoint_str = NULL; 157 char *size_str = NULL; 158 char *device_str = NULL; 159 char *format_str = NULL; 159 160 160 161 /** pointers *********************************************************/ … … 169 170 assert(keylist != NULL); 170 171 171 strcpy(device_str, "/dev/"); 172 strcpy(mountpoint_str, "/"); 172 mr_asprintf(device_str, "/dev/"); 173 mr_asprintf(mountpoint_str, "/"); 174 mr_asprintf(size_str, ""); 173 175 #ifdef __FreeBSD__ 174 strcpy(format_str, "ufs");176 mr_asprintf(format_str, "ufs"); 175 177 #else 176 strcpy(format_str, "ext3");178 mr_asprintf(format_str, "ext3"); 177 179 #endif 178 size_str[0] = '\0';179 /* sprintf(size_str,""); */180 180 newtOpenWindow(20, 5, 48, 10, "Add entry"); 181 181 label0 = newtLabel(2, 1, "Device: "); … … 183 183 label2 = newtLabel(2, 3, "Size (MB): "); 184 184 label3 = newtLabel(2, 4, "Format: "); 185 deviceComp = 186 newtEntry(14, 1, device_str, 30, (void *) &device_here, 0); 187 mountpointComp = 188 newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0); 189 formatComp = 190 newtEntry(14, 4, format_str, 15, (void *) &format_here, 0); 185 deviceComp = newtEntry(14, 1, device_str, 30, (void *) &device_here, 0); 186 mountpointComp = newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0); 187 formatComp = newtEntry(14, 4, format_str, 15, (void *) &format_here, 0); 191 188 sizeComp = newtEntry(14, 3, size_str, 10, (void *) &size_here, 0); 192 189 bOK = newtButton(5, 6, " OK "); … … 200 197 for (b_res = NULL; b_res != bOK && b_res != bCancel;) { 201 198 b_res = newtRunForm(myForm); 202 strcpy(device_str, device_here); 203 strcpy(mountpoint_str, mountpoint_here); 204 strcpy(format_str, format_here); 205 strcpy(size_str, size_here); 206 // log_it ("Originals = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str); 207 strip_spaces(device_str); 208 strip_spaces(mountpoint_str); 209 strip_spaces(format_str); 210 strip_spaces(size_str); 211 // log_it ("Modified = %s,%s,%s,%s", device_str, mountpoint_str, format_str, size_str); 199 mr_free(device_str); 200 mr_asprintf(device_str, "%s", device_here); 201 202 mr_free(mountpoint_str); 203 mr_asprintf(mountpoint_str, "%s", mountpoint_here); 204 mr_strip_spaces(mountpoint_str); 205 206 mr_free(format_str); 207 mr_asprintf(format_str, "%s", format_here); 208 mr_strip_spaces(format_str); 209 210 mr_free(size_str); 211 mr_asprintf(size_str, "%s", size_here); 212 mr_strip_spaces(size_str); 213 214 mr_strip_spaces(device_str); 212 215 if (b_res == bOK) { 213 216 if (device_str[strlen(device_str) - 1] == '/') { … … 215 218 b_res = NULL; 216 219 } 217 if (size_of_specific_device_in_mountlist(mountlist, device_str) 218 >= 0) { 220 if (size_of_specific_device_in_mountlist(mountlist, device_str) >= 0) { 219 221 popup_and_OK("Can't add this - you've got one already!"); 220 222 b_res = NULL; … … 228 230 return; 229 231 } 230 strcpy(drive_to_add, device_str);232 mr_asprintf(drive_to_add, "%s", device_str); 231 233 for (i = strlen(drive_to_add); isdigit(drive_to_add[i - 1]); i--); 232 drive_to_add[i] = '\0'; 234 mr_free(drive_to_add); 235 233 236 currline = mountlist->entries; 234 237 strcpy(mountlist->el[currline].device, device_str); 235 238 strcpy(mountlist->el[currline].mountpoint, mountpoint_str); 239 mr_free(mountpoint_str); 240 236 241 strcpy(mountlist->el[currline].format, format_str); 242 mr_free(format_str); 243 237 244 mountlist->el[currline].size = atol(size_str) * 1024L; 245 mr_free(size_str); 246 238 247 mountlist->entries++; 239 248 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) { 240 initiate_new_raidlist_entry(raidlist, mountlist, currline, 241 device_str); 242 } 249 initiate_new_raidlist_entry(raidlist, mountlist, currline, device_str); 250 } 251 mr_free(device_str); 252 243 253 redraw_mountlist(mountlist, keylist, listbox); 244 254 } … … 315 325 316 326 /** buffers ***********************************************************/ 317 char tmp[MAX_STR_LEN]; 318 319 320 327 char tmp = NULL; 328 char *devname = NULL; 321 329 322 330 for (i = 0; … … 324 332 && strcmp(raidlist->el[i].volname, basename(raid_device)); i++); 325 333 if (i == raidlist->entries) { 326 sprintf(tmp, 327 "Cannot calc size of raid device %s - cannot find it in raidlist", 328 raid_device); 329 log_it(tmp); 334 log_it("Cannot calc size of raid device %s - cannot find it in raidlist", raid_device); 330 335 return (0); // Isn't this more sensible than 999999999? If the raid dev !exists, 331 336 // then it has no size, right? … … 339 344 int k = 0, l = 0; 340 345 for (k = 0; k < raidrec->plex[j].subdisks; ++k) { 341 char devname[64]; 342 strcpy(devname, raidrec->plex[j].sd[k].which_device); 346 mr_asprintf(devname, "%s", raidrec->plex[j].sd[k].which_device); 343 347 for (l = 0; l < raidlist->disks.entries; ++l) { 344 348 if (!strcmp(devname, raidlist->disks.el[l].name)) { … … 368 372 } 369 373 } 374 mr_free(devname); 370 375 } 371 376 … … 388 393 } 389 394 390 sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device, 391 (long) smallest_plex); 392 log_it(tmp); 395 log_it("I have calculated %s's real size to be %ld", raid_device, (long) smallest_plex); 393 396 return (smallest_plex); 394 397 #else … … 407 410 long sp = 0; 408 411 409 /** buffers ***********************************************************/410 char tmp[MAX_STR_LEN];411 412 412 assert(mountlist != NULL); 413 413 assert(raidlist != NULL); … … 418 418 && strcmp(raidlist->el[i].raid_device, raid_device); i++); 419 419 if (i == raidlist->entries) { 420 sprintf(tmp, 421 "Cannot calc size of raid device %s - cannot find it in raidlist", 422 raid_device); 423 log_it(tmp); 420 log_it("Cannot calc size of raid device %s - cannot find it in raidlist", raid_device); 424 421 return (999999999); 425 422 } … … 444 441 total_size = smallest_partition * (noof_partitions - 1); 445 442 } 446 sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device, 447 (long) total_size); 448 log_it(tmp); 443 log_it("I have calculated %s's real size to be %ld", raid_device, (long) total_size); 449 444 return (total_size); 450 445 #endif … … 470 465 /** buffers ***********************************************************/ 471 466 char tmp[MAX_STR_LEN]; 472 char prompt[MAX_STR_LEN];467 char *prompt = NULL; 473 468 char sz[MAX_STR_LEN]; 474 469 475 sprintf(prompt, 476 "Please enter the RAID level you want. (concat, striped, raid5)"); 470 mr_asprintf(prompt, "Please enter the RAID level you want. (concat, striped, raid5)"); 477 471 if (raidrec->raidlevel == -1) { 478 472 strcpy(tmp, "concat"); … … 485 479 res = popup_and_get_string("Specify RAID level", prompt, tmp, 10); 486 480 if (!res) { 481 mr_free(prompt); 487 482 return; 488 483 } … … 502 497 log_it(tmp); 503 498 if (is_this_raid_personality_registered(out)) { 504 log_it 505 ("Groovy. You've picked a RAID personality which is registered."); 499 log_it("Groovy. You've picked a RAID personality which is registered."); 506 500 } else { 507 if (ask_me_yes_or_no 508 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 501 if (ask_me_yes_or_no("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 509 502 { 510 503 out = 999; … … 512 505 } 513 506 } 507 mr_free(prompt); 508 514 509 raidrec->raidlevel = out; 515 510 #else 516 511 /** buffers ***********************************************************/ 517 512 char tmp[MAX_STR_LEN]; 518 char personalities[MAX_STR_LEN];519 char prompt[MAX_STR_LEN];513 char *personalities = NULL; 514 char *prompt = NULL; 520 515 char sz[MAX_STR_LEN]; 521 int out = 0, res = 0; 516 int out = 0; 517 int res = 0; 522 518 523 519 524 520 assert(raidrec != NULL); 525 521 paranoid_system("grep Pers /proc/mdstat > /tmp/raid-personalities.txt 2> /dev/null"); 526 strcpy(personalities,527 last_line_of_file("/tmp/raid-personalities.txt"));528 sprintf(prompt, "Please enter the RAID level you want. %s",529 personalities); 522 mr_asprintf(personalities, "%s", last_line_of_file("/tmp/raid-personalities.txt")); 523 mr_asprintf(prompt, "Please enter the RAID level you want. %s", personalities); 524 mr_free(personalities); 525 530 526 if (raidrec->raid_level == -1) { 531 527 strcpy(tmp, "linear"); … … 555 551 log_it(tmp); 556 552 if (is_this_raid_personality_registered(out)) { 557 log_it 558 ("Groovy. You've picked a RAID personality which is registered."); 553 log_it("Groovy. You've picked a RAID personality which is registered."); 559 554 } else { 560 if (ask_me_yes_or_no 561 ("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) 562 { 555 if (ask_me_yes_or_no("You have chosen a RAID personality which is not registered with the kernel. Make another selection?")) { 563 556 out = 999; 564 557 } 565 558 } 566 559 } 560 mr_free(prompt); 561 567 562 raidrec->raid_level = out; 568 563 #endif … … 589 584 int pos = 0; 590 585 591 /** buffers ***********************************************************/592 char tmp[MAX_STR_LEN];593 594 586 assert(mountlist != NULL); 595 587 assert(raidlist != NULL); … … 602 594 pos++); 603 595 if (pos < mountlist->entries) { 604 sprintf(tmp, 605 "Deleting partition %s cos it was part of a now-defunct RAID", 606 mountlist->el[pos].device); 607 log_it(tmp); 596 log_it("Deleting partition %s cos it was part of a now-defunct RAID", mountlist->el[pos].device); 597 608 598 memcpy((void *) &mountlist->el[pos], 609 599 (void *) &mountlist->el[mountlist->entries - 1], … … 631 621 /** int ***************************************************************/ 632 622 int pos = 0; 623 int res = 0; 633 624 634 625 /** buffers ***********************************************************/ 635 char tmp[MAX_STR_LEN];626 char *tmp = NULL; 636 627 637 628 assert(disklist != NULL); 638 629 assert_string_is_neither_NULL_nor_zerolength(raid_device); 639 630 640 sprintf(tmp, "Delete %s from RAID device %s - are you sure?", 641 disklist->el[currline].device, raid_device); 642 if (!ask_me_yes_or_no(tmp)) { 631 mr_asprintf(tmp, "Delete %s from RAID device %s - are you sure?", disklist->el[currline].device, raid_device); 632 res = ask_me_yes_or_no(tmp); 633 mr_free(tmp); 634 635 if (!res) { 643 636 return; 644 637 } 645 638 for (pos = currline; pos < disklist->entries - 1; pos++) { 646 /* memcpy((void*)&disklist->el[pos], (void*)&disklist->el[pos+1], sizeof(struct s_disk)); */647 639 strcpy(disklist->el[pos].device, disklist->el[pos + 1].device); 648 640 } … … 670 662 /** int ***************************************************************/ 671 663 int pos = 0; 664 int res = 0; 672 665 673 666 /** buffers ***********************************************************/ 674 char tmp[MAX_STR_LEN];675 char device[MAX_STR_LEN];667 char *tmp = NULL; 668 char *device = NULL; 676 669 677 670 … … 681 674 assert(keylist != NULL); 682 675 683 pos = 684 which_raid_device_is_using_this_partition(raidlist, 685 mountlist->el[currline]. 686 device); 676 pos = which_raid_device_is_using_this_partition(raidlist, mountlist->el[currline].device); 687 677 if (pos >= 0) { 688 sprintf(tmp, "Cannot delete %s: it is in use by RAID device %s", 689 mountlist->el[currline].device, 690 raidlist->el[pos].OSSWAP(raid_device, volname)); 678 mr_asprintf(tmp, "Cannot delete %s: it is in use by RAID device %s", mountlist->el[currline].device, raidlist->el[pos].OSSWAP(raid_device, volname)); 691 679 popup_and_OK(tmp); 680 mr_free(tmp); 692 681 return; 693 682 } 694 sprintf(tmp, "Delete %s - are you sure?", 695 mountlist->el[currline].device); 696 if (!ask_me_yes_or_no(tmp)) { 683 mr_asprintf(tmp, "Delete %s - are you sure?", mountlist->el[currline].device); 684 res = ask_me_yes_or_no(tmp); 685 mr_free(tmp); 686 687 if (!res) { 697 688 return; 698 689 } 699 690 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) { 700 strcpy(device, mountlist->el[currline].device);691 mr_asprintf(device, "%s", mountlist->el[currline].device); 701 692 delete_raidlist_entry(mountlist, raidlist, device); 702 693 for (currline = 0; … … 704 695 && strcmp(mountlist->el[currline].device, device); 705 696 currline++); 697 mr_free(device); 698 706 699 if (currline == mountlist->entries) { 707 700 log_it("Dev is gone. I can't delete it. Ho-hum"); … … 737 730 738 731 /** buffers ***********************************************************/ 739 char tmp[MAX_STR_LEN];732 char *tmp = NULL; 740 733 741 734 assert(mountlist != NULL); … … 747 740 return; 748 741 } 749 sprintf(tmp, "Do you want me to delete %s's partitions, too?", device);742 mr_asprintf(tmp, "Do you want me to delete %s's partitions, too?", device); 750 743 delete_partitions_too = ask_me_yes_or_no(tmp); 751 744 if (delete_partitions_too) { … … 760 753 if (!strcmp(raidlist->el[i].plex[x].sd[y].which_device, 761 754 raidlist->disks.el[z].name)) { 762 strcpy(d.el[d.entries].name, 763 raidlist->disks.el[z].name); 764 strcpy(d.el[d.entries++].device, 765 raidlist->disks.el[z].device); 755 strcpy(d.el[d.entries].name, raidlist->disks.el[z].name); 756 strcpy(d.el[d.entries++].device, raidlist->disks.el[z].device); 766 757 } 767 758 } … … 791 782 items--; 792 783 } 784 mr_free(tmp); 793 785 raidlist->entries = items; 794 786 } … … 806 798 807 799 /** buffers ************************************************************/ 808 char tmp[MAX_STR_LEN]; 800 char *tmp = NULL; 801 int res = 0; 809 802 810 803 /** structures *********************************************************/ … … 814 807 815 808 av = &raidrec->additional_vars; 816 sprintf(tmp, "Delete %s - are you sure?", av->el[lino].label); 817 if (ask_me_yes_or_no(tmp)) { 809 mr_asprintf(tmp, "Delete %s - are you sure?", av->el[lino].label); 810 res = ask_me_yes_or_no(tmp); 811 mr_free(tmp); 812 813 if (res) { 818 814 if (!strcmp(av->el[lino].label, "persistent-superblock") 819 815 || !strcmp(av->el[lino].label, "chunk-size")) { 820 sprintf(tmp, "%s must not be deleted. It would be bad.", 821 av->el[lino].label); 816 mr_asprintf(tmp, "%s must not be deleted. It would be bad.", av->el[lino].label); 822 817 popup_and_OK(tmp); 818 mr_free(tmp); 823 819 } else { 824 820 memcpy((void *) &av->el[lino], (void *) &av->el[av->entries--], … … 856 852 static char current_filename[MAX_STR_LEN]; 857 853 char tmp[MAX_STR_LEN + 2]; 854 char *tmp1 = NULL; 858 855 859 856 /** bool *************************************************************/ … … 886 883 if (!warned_already) { 887 884 warned_already = TRUE; 888 sprintf(tmp, 889 "Too many lines. Displaying first %d entries only. Close a directory to see more.", 890 ARBITRARY_MAXIMUM); 891 popup_and_OK(tmp); 885 mr_asprintf(tmp1, "Too many lines. Displaying first %d entries only. Close a directory to see more.", ARBITRARY_MAXIMUM); 886 popup_and_OK(tmp1); 887 mr_free(tmp1); 892 888 } 893 889 } else { 894 strcpy(g_strings_of_flist_window[lines_in_flist_window], 895 current_filename); 890 strcpy(g_strings_of_flist_window[lines_in_flist_window], current_filename); 896 891 g_is_path_selected[lines_in_flist_window] = node->selected; 897 892 lines_in_flist_window++; … … 908 903 (g_strings_of_flist_window[i], 909 904 g_strings_of_flist_window[i - 1]) < 0) { 910 strcpy(tmp, g_strings_of_flist_window[i]); 911 strcpy(g_strings_of_flist_window[i], 912 g_strings_of_flist_window[i - 1]); 913 strcpy(g_strings_of_flist_window[i - 1], tmp); 905 mr_asprintf(tmp1, "%s", g_strings_of_flist_window[i]); 906 strcpy(g_strings_of_flist_window[i], g_strings_of_flist_window[i - 1]); 907 strcpy(g_strings_of_flist_window[i - 1], tmp1); 908 mr_free(tmp1); 909 914 910 dummybool = g_is_path_selected[i]; 915 911 g_is_path_selected[i] = g_is_path_selected[i - 1]; … … 1014 1010 void *curr_choice; 1015 1011 void *keylist[ARBITRARY_MAXIMUM]; 1016 1017 /** buffers ***********************************************************/1018 char tmp[MAX_STR_LEN];1019 1012 1020 1013 /** bool **************************************************************/ … … 1064 1057 indexno = 0; 1065 1058 } 1066 sprintf(tmp, "You selected '%s'", 1067 g_strings_of_flist_window[indexno]); 1068 log_it(tmp); 1059 log_it("You selected '%s'", g_strings_of_flist_window[indexno]); 1060 1069 1061 if (b_res == bMore) { 1070 1062 g_is_path_expanded[indexno] = TRUE; … … 1158 1150 1159 1151 /** buffers ***********************************************************/ 1160 char device_str[MAX_STR_LEN];1161 char mountpoint_str[MAX_STR_LEN];1162 char size_str[MAX_STR_LEN];1163 char format_str[MAX_STR_LEN];1164 char tmp[MAX_STR_LEN];1165 char device_used_to_be[MAX_STR_LEN];1166 char mountpt_used_to_be[MAX_STR_LEN];1152 char *device_str = NULL; 1153 char *mountpoint_str = NULL; 1154 char *size_str = NULL; 1155 char *format_str = NULL; 1156 char *tmp = NULL; 1157 char *device_used_to_be = NULL; 1158 char *mountpt_used_to_be = NULL; 1167 1159 1168 1160 /** pointers **********************************************************/ … … 1182 1174 memcpy((void *) &bkp_raidlist, (void *) raidlist, 1183 1175 sizeof(struct raidlist_itself)); 1184 strcpy(device_str, mountlist->el[currline].device);1185 strcpy(device_used_to_be, mountlist->el[currline].device);1186 strcpy(mountpoint_str, mountlist->el[currline].mountpoint);1187 strcpy(mountpt_used_to_be, mountlist->el[currline].mountpoint);1188 strcpy(format_str, mountlist->el[currline].format);1189 sprintf(size_str, "%lld", mountlist->el[currline].size / 1024L);1176 mr_asprintf(device_str, "%s", mountlist->el[currline].device); 1177 mr_asprintf(device_used_to_be, "%s", mountlist->el[currline].device); 1178 mr_asprintf(mountpoint_str, "%s", mountlist->el[currline].mountpoint); 1179 mr_asprintf(mountpt_used_to_be, "%s", mountlist->el[currline].mountpoint); 1180 mr_asprintf(format_str, "%s", mountlist->el[currline].format); 1181 mr_asprintf(size_str, "%lld", mountlist->el[currline].size / 1024L); 1190 1182 newtOpenWindow(20, 5, 48, 10, "Edit entry"); 1191 1183 label0 = newtLabel(2, 1, "Device:"); … … 1193 1185 label2 = newtLabel(2, 3, "Size (MB): "); 1194 1186 label3 = newtLabel(2, 4, "Format: "); 1195 deviceComp = 1196 newtEntry(14, 1, device_str, 30, (void *) &device_here, 0); 1197 mountpointComp = 1198 newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0); 1199 formatComp = 1200 newtEntry(14, 4, format_str, 15, (void *) &format_here, 0); 1187 deviceComp = newtEntry(14, 1, device_str, 30, (void *) &device_here, 0); 1188 mountpointComp = newtEntry(14, 2, mountpoint_str, 30, (void *) &mountpoint_here, 0); 1189 formatComp = newtEntry(14, 4, format_str, 15, (void *) &format_here, 0); 1201 1190 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1202 1191 || !strcmp(mountlist->el[currline].mountpoint, "image")) { … … 1218 1207 for (b_res = NULL; b_res != bOK && b_res != bCancel;) { 1219 1208 b_res = newtRunForm(myForm); 1220 strcpy(device_str, device_here); 1221 strip_spaces(device_str); 1222 strcpy(mountpoint_str, mountpoint_here); 1223 strip_spaces(mountpoint_str); 1224 strcpy(format_str, format_here); 1225 strip_spaces(format_str); 1209 mr_free(device_str); 1210 mr_asprintf(device_str, "%s", device_here); 1211 mr_strip_spaces(device_str); 1212 1213 mr_free(mountpoint_str); 1214 mr_asprintf(mountpoint_str, "%s", mountpoint_here); 1215 mr_strip_spaces(mountpoint_str); 1216 1217 mr_free(format_str); 1218 mr_asprintf(format_str, "%s", format_here); 1219 mr_strip_spaces(format_str); 1220 1226 1221 if (b_res == bOK && strstr(device_str, RAID_DEVICE_STUB) 1227 1222 && strstr(device_used_to_be, RAID_DEVICE_STUB) … … 1238 1233 if (!strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1239 1234 && strcmp(mountlist->el[currline].mountpoint, "image")) { 1240 strcpy(size_str, size_here); 1241 strip_spaces(size_str); 1235 mr_free(size_str); 1236 mr_asprintf(size_str, "%s", size_here); 1237 mr_strip_spaces(size_str); 1242 1238 } else { 1243 sprintf(size_str, "%ld", 1244 calculate_raid_device_size(mountlist, raidlist, 1245 mountlist->el[currline]. 1246 device) / 1024); 1239 mr_asprintf(size_str, "%ld", calculate_raid_device_size(mountlist, raidlist, mountlist->el[currline].device) / 1024); 1247 1240 newtLabelSetText(sizeComp, size_str); 1248 1241 } … … 1261 1254 device); 1262 1255 if (j < 0) { 1263 sprintf(tmp, 1264 "/etc/raidtab does not have an entry for %s; please delete it and add it again", 1265 mountlist->el[currline].device); 1256 mr_asprintf(tmp, "/etc/raidtab does not have an entry for %s; please delete it and add it again", mountlist->el[currline].device); 1266 1257 popup_and_OK(tmp); 1258 mr_free(tmp); 1267 1259 } else { 1268 1260 log_it("edit_raidlist_entry - calling"); … … 1276 1268 newtPopHelpLine(); 1277 1269 newtPopWindow(); 1270 mr_free(mountpt_used_to_be); 1271 1278 1272 if (b_res == bCancel) { 1279 1273 memcpy((void *) raidlist, (void *) &bkp_raidlist, 1280 1274 sizeof(struct raidlist_itself)); 1275 mr_free(device_str); 1276 mr_free(device_used_to_be); 1277 mr_free(format_str); 1278 mr_free(size_str); 1281 1279 return; 1282 1280 } 1283 1281 strcpy(mountlist->el[currline].device, device_str); 1284 1282 strcpy(mountlist->el[currline].mountpoint, mountpoint_str); 1283 mr_free(mountpoint_str); 1284 1285 1285 strcpy(mountlist->el[currline].format, format_str); 1286 mr_free(format_str); 1287 1286 1288 if (strcmp(mountlist->el[currline].mountpoint, "image")) { 1287 1289 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)) { … … 1293 1295 } 1294 1296 } 1297 mr_free(size_str); 1295 1298 newtListboxSetEntry(listbox, (long) keylist[currline], 1296 1299 mountlist_entry_to_string(mountlist, currline)); … … 1298 1301 if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB) 1299 1302 && !strstr(device_used_to_be, RAID_DEVICE_STUB)) { 1300 initiate_new_raidlist_entry(raidlist, mountlist, currline, 1301 device_str); 1303 initiate_new_raidlist_entry(raidlist, mountlist, currline, device_str); 1302 1304 } 1303 1305 /* if moving from RAID to non-RAID then do funky stuff */ … … 1316 1318 #ifndef __FreeBSD__ /* It works fine under FBSD. */ 1317 1319 else if (strcmp(device_used_to_be, device_str)) { 1318 popup_and_OK 1319 ("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it."); 1320 popup_and_OK("You are renaming a RAID device as another RAID device. I don't like it but I'll allow it."); 1320 1321 } 1321 1322 #endif 1323 mr_free(device_str); 1324 mr_free(device_used_to_be); 1325 1322 1326 redraw_mountlist(mountlist, keylist, listbox); 1323 1327 } … … 1342 1346 for (i = 0; i < raidlist->disks.entries; ++i) { 1343 1347 if (!strcmp(raidlist->disks.el[i].device, temp)) { 1344 strcpy(raidrec->sd[raidrec->subdisks].which_device, 1345 raidlist->disks.el[i].name); 1348 strcpy(raidrec->sd[raidrec->subdisks].which_device, raidlist->disks.el[i].name); 1346 1349 found = TRUE; 1347 1350 } 1348 1351 } 1349 1352 if (!found) { 1350 sprintf(raidlist->disks.el[raidlist->disks.entries].name, 1351 "drive%i", raidlist->disks.entries); 1352 sprintf(raidrec->sd[raidrec->subdisks].which_device, "drive%i", 1353 raidlist->disks.entries); 1353 sprintf(raidlist->disks.el[raidlist->disks.entries].name, "drive%i", raidlist->disks.entries); 1354 sprintf(raidrec->sd[raidrec->subdisks].which_device, "drive%i", raidlist->disks.entries); 1354 1355 strcpy(raidlist->disks.el[raidlist->disks.entries++].device, temp); 1355 1356 } … … 1424 1425 void *keylist[10]; 1425 1426 void *curr_choice; 1427 char *raidlevel = NULL; 1428 char *chunksize = NULL; 1429 char *msg = NULL; 1426 1430 1427 1431 int currline2 = 0; 1432 int res = 0; 1428 1433 1429 1434 log_it("Started edit_raidlist_entry"); … … 1455 1460 keylist[i] = (void *) i; 1456 1461 if (i < raidrec->plexes) { 1457 char pname[64], entry[MAX_STR_LEN], raidlevel[64], 1458 chunksize[64]; 1462 char pname[64], entry[MAX_STR_LEN]; 1459 1463 switch (raidrec->plex[i].raidlevel) { 1460 1464 case -1: 1461 strcpy(raidlevel, "concat");1465 mr_asprintf(raidlevel, "concat"); 1462 1466 break; 1463 1467 case 0: 1464 strcpy(raidlevel, "striped");1468 mr_asprintf(raidlevel, "striped"); 1465 1469 break; 1466 1470 case 5: 1467 strcpy(raidlevel, "raid5");1471 mr_asprintf(raidlevel, "raid5"); 1468 1472 break; 1469 1473 default: 1470 sprintf(raidlevel, "raid%i", 1471 raidrec->plex[i].raidlevel); 1474 mr_asprintf(raidlevel, "raid%i", raidrec->plex[i].raidlevel); 1472 1475 break; 1473 1476 } 1474 1477 1475 1478 if (raidrec->plex[i].raidlevel == -1) { 1476 strcpy(chunksize, "N/A");1479 mr_asprintf(chunksize, "N/A"); 1477 1480 } else { 1478 sprintf(chunksize, "%dk", raidrec->plex[i].stripesize);1481 mr_asprintf(chunksize, "%dk", raidrec->plex[i].stripesize); 1479 1482 } 1480 1483 snprintf(pname, 64, "%s.p%i", raidrec->volname, i); … … 1482 1485 pname, raidlevel, chunksize, 1483 1486 raidrec->plex[i].subdisks); 1487 mr_free(raidlevel); 1488 mr_free(chunksize); 1489 1484 1490 newtListboxAppendEntry(plexesListbox, entry, keylist[i]); 1485 1491 } … … 1503 1509 1504 1510 if (b_res == bDelete) { 1505 char msg[MAX_STR_LEN]; 1506 sprintf(msg, "Are you sure you want to delete %s.p%i?", 1507 raidrec->volname, currline2); 1508 if (ask_me_yes_or_no(msg)) { 1511 mr_asprintf(msg, "Are you sure you want to delete %s.p%i?", raidrec->volname, currline2); 1512 res = ask_me_yes_or_no(msg); 1513 mr_free(msg); 1514 1515 if (res) { 1509 1516 log_it("Deleting RAID plex"); 1510 1517 memcpy((void *) &raidrec->plex[currline2], … … 1540 1547 /** buffers ***********************************************************/ 1541 1548 char *title_of_editraidForm_window; 1542 char *sz_raid_level ;1543 char *sz_data_disks ;1544 char *sz_spare_disks ;1545 char *sz_parity_disks ;1546 char *sz_failed_disks ;1549 char *sz_raid_level = NULL; 1550 char *sz_data_disks = NULL; 1551 char *sz_spare_disks = NULL; 1552 char *sz_parity_disks = NULL; 1553 char *sz_failed_disks = NULL; 1547 1554 1548 1555 /** newt **************************************************************/ … … 1562 1569 assert(raidrec != NULL); 1563 1570 1564 malloc_string(title_of_editraidForm_window); 1565 malloc_string(sz_raid_level); 1566 malloc_string(sz_data_disks); 1567 malloc_string(sz_spare_disks); 1568 malloc_string(sz_parity_disks); 1569 malloc_string(sz_failed_disks); 1570 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) { 1571 fatal_error("Cannot malloc space for raidrec"); 1572 } 1573 1571 bkp_raidrec = mr_malloc(sizeof(struct raid_device_record)); 1574 1572 log_it("Started edit_raidlist_entry"); 1575 1573 1576 memcpy((void *) bkp_raidrec, (void *) raidrec, 1577 sizeof(struct raid_device_record)); 1578 sprintf(title_of_editraidForm_window, "%s", raidrec->raid_device); 1574 memcpy((void *) bkp_raidrec, (void *) raidrec, sizeof(struct raid_device_record)); 1575 mr_asprintf(title_of_editraidForm_window, "%s", raidrec->raid_device); 1579 1576 log_msg(2, "Opening newt window"); 1580 1577 newtOpenWindow(20, 5, 40, 14, title_of_editraidForm_window); 1581 1578 for (;;) { 1582 1579 log_msg(2, "Main loop"); 1583 sprintf(title_of_editraidForm_window, "Edit %s", 1584 raidrec->raid_device); 1585 strcpy(sz_raid_level, 1586 turn_raid_level_number_to_string(raidrec->raid_level)); 1587 strcpy(sz_data_disks, 1588 number_of_disks_as_string(raidrec->data_disks.entries, 1589 "data")); 1590 strcpy(sz_spare_disks, 1591 number_of_disks_as_string(raidrec->spare_disks.entries, 1592 "spare")); 1593 strcpy(sz_parity_disks, 1594 number_of_disks_as_string(raidrec->parity_disks.entries, 1595 "parity")); 1596 strcpy(sz_failed_disks, 1597 number_of_disks_as_string(raidrec->failed_disks.entries, 1598 "failed")); 1580 mr_free(title_of_editraidForm_window); 1581 mr_asprintf(title_of_editraidForm_window, "Edit %s", raidrec->raid_device); 1582 mr_asprintf(sz_raid_level, "%s", turn_raid_level_number_to_string(raidrec->raid_level)); 1583 mr_asprintf(sz_data_disks, "%s", number_of_disks_as_string(raidrec->data_disks.entries, "data")); 1584 mr_asprintf(sz_spare_disks, "%s", number_of_disks_as_string(raidrec->spare_disks.entries, "spare")); 1585 mr_asprintf(sz_parity_disks, "%s", number_of_disks_as_string(raidrec->parity_disks.entries, "parity")); 1586 mr_asprintf(sz_failed_disks, "%s", number_of_disks_as_string(raidrec->failed_disks.entries, "failed")); 1599 1587 bSelectData = newtButton(1, 1, sz_data_disks); 1600 1588 bSelectSpare = newtButton(20, 1, sz_spare_disks); … … 1617 1605 choose_raid_level(raidrec); 1618 1606 } else if (b_res == bSelectData) { 1619 select_raid_disks(mountlist, raidlist, raidrec, "data", 1620 &raidrec->data_disks); 1607 select_raid_disks(mountlist, raidlist, raidrec, "data", &raidrec->data_disks); 1621 1608 } else if (b_res == bSelectSpare) { 1622 select_raid_disks(mountlist, raidlist, raidrec, "spare", 1623 &raidrec->spare_disks); 1609 select_raid_disks(mountlist, raidlist, raidrec, "spare", &raidrec->spare_disks); 1624 1610 } else if (b_res == bSelectParity) { 1625 select_raid_disks(mountlist, raidlist, raidrec, "parity", 1626 &raidrec->parity_disks); 1611 select_raid_disks(mountlist, raidlist, raidrec, "parity", &raidrec->parity_disks); 1627 1612 } else if (b_res == bSelectFailed) { 1628 select_raid_disks(mountlist, raidlist, raidrec, "failed", 1629 &raidrec->failed_disks); 1613 select_raid_disks(mountlist, raidlist, raidrec, "failed", &raidrec->failed_disks); 1630 1614 } else if (b_res == bAdditional) { 1631 1615 edit_raidrec_additional_vars(raidrec); … … 1635 1619 break; 1636 1620 } 1621 mr_free(sz_data_disks); 1622 mr_free(sz_spare_disks); 1623 mr_free(sz_parity_disks); 1624 mr_free(sz_failed_disks); 1637 1625 } 1638 1626 if (b_res == bCancel) { 1639 memcpy((void *) raidrec, (void *) bkp_raidrec, 1640 sizeof(struct raid_device_record)); 1627 memcpy((void *) raidrec, (void *) bkp_raidrec, sizeof(struct raid_device_record)); 1641 1628 } 1642 1629 newtPopHelpLine(); 1643 1630 newtPopWindow(); 1644 mountlist->el[currline].size = 1645 calculate_raid_device_size(mountlist, raidlist, 1646 raidrec->raid_device); 1647 paranoid_free(title_of_editraidForm_window); 1648 paranoid_free(sz_raid_level); 1649 paranoid_free(sz_data_disks); 1650 paranoid_free(sz_spare_disks); 1651 paranoid_free(sz_parity_disks); 1652 paranoid_free(sz_failed_disks); 1631 mountlist->el[currline].size = calculate_raid_device_size(mountlist, raidlist, raidrec->raid_device); 1632 mr_free(title_of_editraidForm_window); 1633 mr_free(sz_raid_level); 1653 1634 paranoid_free(bkp_raidrec); 1654 1635 #endif … … 1678 1659 1679 1660 /** buffers ***********************************************************/ 1680 char title_of_editraidForm_window[MAX_STR_LEN];1661 char *title_of_editraidForm_window = NULL; 1681 1662 1682 1663 /** newt **************************************************************/ … … 1697 1678 int currline_a, currline_u; 1698 1679 1680 char *p = NULL; 1681 char *tmp = NULL; 1682 char *entry = NULL; 1683 1699 1684 struct mountlist_itself *unallocparts; 1700 1685 … … 1704 1689 memcpy((void *) &bkp_raidrec, (void *) raidrec, 1705 1690 sizeof(struct vinum_plex)); 1706 sprintf(title_of_editraidForm_window, "%s.p%i", 1707 raidlist->el[currline].volname, currline2); 1691 mr_asprintf(title_of_editraidForm_window, "%s.p%i", raidlist->el[currline].volname, currline2); 1708 1692 newtPushHelpLine 1709 1693 (" Please select a subdisk to edit, or edit this plex's parameters"); 1710 1694 newtOpenWindow(13, 3, 54, 18, title_of_editraidForm_window); 1695 mr_free(title_of_editraidForm_window); 1696 1711 1697 for (;;) { 1712 1698 int i; 1713 char headerstr[MAX_STR_LEN];1714 char tmp[64];1715 snprintf(headerstr, MAX_STR_LEN, "%-24s %s", "Subdisk", "Device");1716 1717 1699 1718 1700 switch (raidrec->raidlevel) { 1719 1701 case -1: 1720 strcpy(tmp, "concat");1702 mr_asprintf(tmp, "concat"); 1721 1703 break; 1722 1704 case 0: 1723 strcpy(tmp, "striped");1705 mr_asprintf(tmp, "striped"); 1724 1706 break; 1725 1707 case 5: 1726 strcpy(tmp, "raid5");1708 mr_asprintf(tmp, "raid5"); 1727 1709 break; 1728 1710 default: 1729 sprintf(tmp, "unknown (%i)", raidrec->raidlevel);1711 mr_asprintf(tmp, "unknown (%i)", raidrec->raidlevel); 1730 1712 break; 1731 1713 } 1732 1714 bLevel = newtCompactButton(2, 2, " RAID level "); 1733 1715 sLevel = newtLabel(19, 2, tmp); 1716 mr_free(tmp); 1734 1717 1735 1718 if (raidrec->raidlevel >= 0) { 1736 sprintf(tmp, "%ik", raidrec->stripesize);1719 mr_asprintf(tmp, "%ik", raidrec->stripesize); 1737 1720 bStripeSize = newtCompactButton(2, 4, " Stripe size "); 1738 1721 } else { 1739 strcpy(tmp, "N/A");1722 mr_asprintf(tmp, "N/A"); 1740 1723 bStripeSize = newtLabel(2, 4, "Stripe size:"); 1741 1724 } 1742 1725 sStripeSize = newtLabel(19, 4, tmp); 1726 mr_free(tmp); 1743 1727 1744 1728 bOK = newtCompactButton(2, 16, " OK "); … … 1749 1733 1750 1734 1751 // plexesListbox = newtListbox (2, 7, 9, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT);1752 // plexesHeader = newtLabel (2, 6, headerstr);1753 1735 unallocListbox = 1754 1736 newtListbox(2, 7, 7, NEWT_FLAG_SCROLL | NEWT_FLAG_RETURNEXIT); … … 1766 1748 raidlist); 1767 1749 for (i = 0; i < ARBITRARY_MAXIMUM; ++i) { 1768 char entry[MAX_STR_LEN];1769 1750 keylist[i] = (void *) i; 1770 1751 if (i < raidrec->subdisks) { 1771 snprintf(entry, MAX_STR_LEN, "%-17s", 1772 find_dev_entry_for_raid_device_name(raidlist, 1773 raidrec-> 1774 sd[i]. 1775 which_device)); 1752 mr_asprintf(entry, "%-17s", find_dev_entry_for_raid_device_name(raidlist, raidrec->sd[i].which_device)); 1776 1753 newtListboxAppendEntry(allocListbox, entry, keylist[i]); 1754 mr_free(entry); 1777 1755 } 1778 1756 if (i < unallocparts->entries) { 1779 snprintf(entry, MAX_STR_LEN, "%-17s", 1780 unallocparts->el[i].device); 1757 mr_asprintf(entry, "%-17s", unallocparts->el[i].device); 1781 1758 newtListboxAppendEntry(unallocListbox, entry, keylist[i]); 1759 mr_free(entry); 1782 1760 } 1783 1761 } … … 1830 1808 choose_raid_level(raidrec); 1831 1809 } else if (b_res == bStripeSize) { 1832 char tmp [64];1833 sprintf(tmp , "%i", raidrec->stripesize);1810 char tmp1[64]; 1811 sprintf(tmp1, "%i", raidrec->stripesize); 1834 1812 if (popup_and_get_string 1835 1813 ("Stripe size", 1836 "Please enter the stripe size in kilobytes.", tmp , 20)) {1837 raidrec->stripesize = atoi(tmp );1814 "Please enter the stripe size in kilobytes.", tmp1, 20)) { 1815 raidrec->stripesize = atoi(tmp1); 1838 1816 } 1839 1817 } else if ((b_res == bAlloc) || (b_res == unallocListbox)) { … … 1849 1827 } 1850 1828 } 1851 #if 01852 } else {1853 edit_raid_subdisk(raidlist, raidrec, &raidrec->sd[currline3],1854 currline3);1855 }1856 #endif1857 1829 newtFormDestroy(editraidForm); 1858 1830 newtRefresh(); … … 1860 1832 1861 1833 if (b_res == bCancel) { 1862 memcpy((void *) raidrec, (void *) &bkp_raidrec, 1863 sizeof(struct vinum_plex)); 1834 memcpy((void *) raidrec, (void *) &bkp_raidrec, sizeof(struct vinum_plex)); 1864 1835 } 1865 1836 newtPopWindow(); … … 1877 1848 1878 1849 /** buffers ***********************************************************/ 1879 char header[MAX_STR_LEN];1880 char comment[MAX_STR_LEN];1850 char *header = NULL; 1851 char *comment = NULL; 1881 1852 char sz_out[MAX_STR_LEN]; 1882 1853 … … 1885 1856 1886 1857 strcpy(sz_out, raidrec->additional_vars.el[lino].value); 1887 sprintf(header, "Edit %s", raidrec->additional_vars.el[lino].label); 1888 sprintf(comment, "Please set %s's value (currently '%s')", 1889 raidrec->additional_vars.el[lino].label, sz_out); 1858 mr_asprintf(header, "Edit %s", raidrec->additional_vars.el[lino].label); 1859 mr_asprintf(comment, "Please set %s's value (currently '%s')", raidrec->additional_vars.el[lino].label, sz_out); 1890 1860 if (popup_and_get_string(header, comment, sz_out, MAX_STR_LEN)) { 1891 1861 strip_spaces(sz_out); 1892 1862 strcpy(raidrec->additional_vars.el[lino].value, sz_out); 1893 1863 } 1894 } 1895 1896 1897 /* I'm not racist against white people. I just don't like people who think Liberia is near Spain. - Hugo, 09/01/2001 */ 1864 mr_free(header); 1865 mr_free(comment); 1866 } 1898 1867 1899 1868 #endif … … 1936 1905 1937 1906 /** buffers **********************************************************/ 1938 char tmp[MAX_STR_LEN];1907 char *tmp = NULL; 1939 1908 char *flaws_str = NULL; 1940 1909 char *flaws_str_A = NULL; … … 1957 1926 bCancel = newtCompactButton(i += 12, 17, "Cancel"); 1958 1927 bOK = newtCompactButton(i += 12, 17, " OK "); 1959 sprintf(tmp, "%-24s %-24s %-8s %s", "Device", "Mountpoint", "Format", "Size (MB)");1928 mr_asprintf(tmp, "%-24s %-24s %-8s %s", "Device", "Mountpoint", "Format", "Size (MB)"); 1960 1929 headerMsg = newtLabel(2, 1, tmp); 1930 mr_free(tmp); 1931 1961 1932 flawsLabelA = newtLabel(2, 13, " "); 1962 1933 flawsLabelB = newtLabel(2, 14, " "); … … 2015 1986 } else if (b_res == bReload) { 2016 1987 if (ask_me_yes_or_no("Reload original mountlist?")) { 2017 /*2018 This would be really dumb. RAIDTAB_FNAME is #define'd. --- Hugo, 2003/04/242019 if (!RAIDTAB_FNAME[0])2020 {2021 strcpy(RAIDTAB_FNAME, "/etc/raidtab");2022 log_it("Warning - raidtab_fname is blank. Assuming %s", g_raidtab_fname);2023 }2024 */2025 1988 load_mountlist(mountlist, mountlist_fname); 2026 1989 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); … … 2237 2200 int i = 0; 2238 2201 #ifdef __FreeBSD__ 2239 char vdev[64]; 2202 char *vdev = NULL; 2203 int res = 0; 2240 2204 #else 2241 2205 // Linux … … 2247 2211 #ifdef __FreeBSD__ 2248 2212 for (i = 0; i < raidlist->entries; i++) { 2249 sprintf(vdev, "/dev/vinum/%s", raidlist->el[i].volname); 2250 if (!strcmp(device, vdev)) 2213 mr_asprintf(vdev, "/dev/vinum/%s", raidlist->el[i].volname); 2214 res = strcmp(device, vdev); 2215 mr_free(vdev); 2216 2217 if (!res) 2251 2218 break; 2252 2219 } … … 2298 2265 raidrec = &raidlist->el[pos_in_raidlist]; 2299 2266 initialize_raidrec(raidrec); 2300 strcpy(raidrec->OSSWAP(raid_device, volname), 2301 OSSWAP(device, basename(device))); 2267 strcpy(raidrec->OSSWAP(raid_device, volname), OSSWAP(device, basename(device))); 2302 2268 #ifndef __FreeBSD__ 2303 2269 choose_raid_level(raidrec); … … 2549 2515 char *new_dev) 2550 2516 { 2551 /** buffers ********************************************************/2552 char tmp[MAX_STR_LEN];2553 2554 2517 /** int ************************************************************/ 2555 2518 int pos = 0; … … 2562 2525 pos = which_raid_device_is_using_this_partition(raidlist, old_dev); 2563 2526 if (pos < 0) { 2564 sprintf(tmp, "No need to rejig %s in raidlist: it's not listed.", 2565 old_dev); 2566 log_it(tmp); 2527 log_it("No need to rejig %s in raidlist: it's not listed.", old_dev); 2567 2528 } else { 2568 2529 if ((j = … … 2570 2531 OSSWAP(el[pos].data_disks, disks), 2571 2532 old_dev)) >= 0) { 2572 strcpy(raidlist->OSSWAP(el[pos].data_disks, disks).el[j]. 2573 device, new_dev); 2533 strcpy(raidlist->OSSWAP(el[pos].data_disks, disks).el[j].device, new_dev); 2574 2534 } else 2575 2535 if ((j = … … 2578 2538 spares), 2579 2539 old_dev)) >= 0) { 2580 strcpy(raidlist->OSSWAP(el[pos].spare_disks, spares).el[j]. 2581 device, new_dev); 2540 strcpy(raidlist->OSSWAP(el[pos].spare_disks, spares).el[j].device, new_dev); 2582 2541 } 2583 2542 #ifndef __FreeBSD__ … … 2596 2555 #endif 2597 2556 else { 2598 sprintf(tmp, 2599 "%s is supposed to be listed in this raid dev but it's not...", 2600 old_dev); 2601 log_it(tmp); 2557 log_it("%s is supposed to be listed in this raid dev but it's not...", old_dev); 2602 2558 } 2603 2559 } … … 2671 2627 /** buffers **********************************************************/ 2672 2628 void *keylist[ARBITRARY_MAXIMUM]; 2673 char *tmp; 2674 char *help_text; 2675 char *title_of_window; 2676 char *sz_res; 2677 char *header_text; 2629 char *tmp = NULL; 2630 char *help_text = NULL; 2631 char *title_of_window = NULL; 2632 char sz_res[MAX_STR_LEN]; 2633 char *header_text = NULL; 2634 char *p = NULL; 2678 2635 2679 2636 /** int **************************************************************/ … … 2688 2645 2689 2646 log_it("malloc'ing"); 2690 malloc_string(tmp); 2691 malloc_string(help_text); 2692 malloc_string(title_of_window); 2693 malloc_string(sz_res); 2694 malloc_string(header_text); 2695 if (!(bkp_raidrec = malloc(sizeof(struct raid_device_record)))) { 2696 fatal_error("Cannot malloc space for raidrec"); 2697 } 2698 if (!(bkp_disklist = malloc(sizeof(struct list_of_disks)))) { 2699 fatal_error("Cannot malloc space for disklist"); 2700 } 2701 if (!(bkp_raidlist = malloc(sizeof(struct raidlist_itself)))) { 2702 fatal_error("Cannot malloc space for raidlist"); 2703 } 2704 if (! 2705 (unallocated_raid_partitions = 2706 malloc(sizeof(struct mountlist_itself)))) { 2707 fatal_error("Cannot malloc space for unallocated_raid_partitions"); 2708 } 2709 2710 memcpy((void *) bkp_raidlist, (void *) raidlist, 2711 sizeof(struct raidlist_itself)); 2712 memcpy((void *) bkp_raidrec, (void *) raidrec, 2713 sizeof(struct raid_device_record)); 2714 memcpy((void *) bkp_disklist, (void *) disklist, 2715 sizeof(struct list_of_disks)); 2647 bkp_raidrec = mr_malloc(sizeof(struct raid_device_record)); 2648 bkp_disklist = mr_malloc(sizeof(struct list_of_disks)); 2649 bkp_raidlist = mr_malloc(sizeof(struct raidlist_itself)); 2650 unallocated_raid_partitions = mr_malloc(sizeof(struct mountlist_itself)); 2651 2652 memcpy((void *) bkp_raidlist, (void *) raidlist, sizeof(struct raidlist_itself)); 2653 memcpy((void *) bkp_raidrec, (void *) raidrec, sizeof(struct raid_device_record)); 2654 memcpy((void *) bkp_disklist, (void *) disklist, sizeof(struct list_of_disks)); 2716 2655 2717 2656 log_it("Post-malloc"); 2718 strcpy(help_text, 2719 " Edit this RAID device's list of partitions. Choose OK or Cancel when done."); 2720 sprintf(header_text, "%-24s %s", "Device", "Index"); 2721 sprintf(title_of_window, "%s contains...", raidrec->raid_device); 2657 mr_asprintf(help_text, " Edit this RAID device's list of partitions. Choose OK or Cancel when done."); 2658 mr_asprintf(header_text, "%-24s %s", "Device", "Index"); 2659 mr_asprintf(title_of_window, "%s contains...", raidrec->raid_device); 2722 2660 newtPushHelpLine(help_text); 2723 2661 for (b_res = (newtComponent) 12345; b_res != bOK && b_res != bCancel;) { … … 2774 2712 redraw_disklist(disklist, keylist, partitionsListbox); 2775 2713 } else { 2776 sprintf(tmp, "%s's index is %d. What should it be?", 2777 raidrec->raid_device, 2778 disklist->el[currline].index); 2714 mr_asprintf(tmp, "%s's index is %d. What should it be?", raidrec->raid_device, disklist->el[currline].index); 2779 2715 sprintf(sz_res, "%d", disklist->el[currline].index); 2780 2716 if (popup_and_get_string("Set index", tmp, sz_res, 10)) { 2781 2717 disklist->el[currline].index = atoi(sz_res); 2782 2718 } 2719 mr_free(tmp); 2720 2783 2721 redraw_disklist(disklist, keylist, partitionsListbox); 2784 2722 } … … 2789 2727 } 2790 2728 newtPopHelpLine(); 2729 mr_free(help_text); 2730 mr_free(header_text); 2731 mr_free(title_of_window); 2732 2791 2733 if (b_res == bCancel) { 2792 memcpy((void *) raidlist, (void *) bkp_raidlist, 2793 sizeof(struct raidlist_itself)); 2794 memcpy((void *) raidrec, (void *) bkp_raidrec, 2795 sizeof(struct raid_device_record)); 2796 memcpy((void *) disklist, (void *) bkp_disklist, 2797 sizeof(struct list_of_disks)); 2798 } 2799 paranoid_free(tmp); 2800 paranoid_free(help_text); 2801 paranoid_free(title_of_window); 2734 memcpy((void *) raidlist, (void *) bkp_raidlist, sizeof(struct raidlist_itself)); 2735 memcpy((void *) raidrec, (void *) bkp_raidrec, sizeof(struct raid_device_record)); 2736 memcpy((void *) disklist, (void *) bkp_disklist, sizeof(struct list_of_disks)); 2737 } 2802 2738 paranoid_free(sz_res); 2803 paranoid_free(header_text); 2804 paranoid_free(bkp_raidrec); 2805 paranoid_free(bkp_disklist); 2806 paranoid_free(bkp_raidlist); 2807 paranoid_free(unallocated_raid_partitions); 2739 mr_free(bkp_raidrec); 2740 mr_free(bkp_disklist); 2741 mr_free(bkp_raidlist); 2742 mr_free(unallocated_raid_partitions); 2808 2743 } 2809 2744 #endif … … 2821 2756 /** char *************************************************************/ 2822 2757 char output = '\0'; 2823 char tmp[MAX_STR_LEN];2758 char *tmp = NULL; 2824 2759 2825 2760 /** newt *************************************************************/ … … 2833 2768 2834 2769 if (g_text_mode) { 2835 for (output = 'z'; !strchr("AICE", output); output = tmp[0]) { 2836 printf 2837 ("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> "); 2838 if (fgets(tmp, MAX_STR_LEN - 1, stdin)) { 2839 // FIXME 2840 } 2770 while (!strchr("AICE", output)) { 2771 printf("Which mode - (A)utomatic, (I)nteractive, \n(C)ompare only, or (E)xit to shell?\n--> "); 2772 mr_getline(tmp, stdin); 2773 output = tmp[0]; 2774 mr_free(tmp); 2841 2775 } 2842 2776 return (output); 2843 2777 } 2844 2778 2845 newtPushHelpLine 2846 (" Do you want to 'nuke' your system, restore interactively, or just compare?"); 2779 newtPushHelpLine(" Do you want to 'nuke' your system, restore interactively, or just compare?"); 2847 2780 newtOpenWindow(24, 3, 32, 17, "How should I restore?"); 2848 2781 b1 = newtButton(7, 1, "Automatically"); -
branches/3.2/mondo/src/mondorestore/mondo-rstr-tools.c
r3185 r3193 7 7 #include "my-stuff.h" 8 8 #include "mr_mem.h" 9 #include "mr_str.h" 9 10 #include "../common/mondostructures.h" 10 11 #include "../common/libmondo.h" … … 120 121 * @ingroup restoreUtilityGroup 121 122 */ 122 void ask_about_these_imagedevs(char *infname, char *outfname) 123 { 123 void ask_about_these_imagedevs(char *infname, char *outfname) { 124 124 125 FILE *fin; 125 126 FILE *fout; 126 /************************************************************************ 127 * allocate memory regions. test and set -sab 16 feb 2003 * 128 ************************************************************************/ 129 char *incoming_ptr; 130 char *question_ptr; 131 char *q; 132 133 char incoming[MAX_STR_LEN] = "\0"; 134 char question[MAX_STR_LEN]; 127 char *incoming = NULL; 128 char *question = NULL; 135 129 136 130 assert_string_is_neither_NULL_nor_zerolength(infname); 137 131 assert_string_is_neither_NULL_nor_zerolength(outfname); 138 132 139 incoming_ptr = malloc(sizeof(incoming));140 if (incoming_ptr == NULL) {141 fprintf(stderr, "Out of Memory\n");142 exit(EXIT_FAILURE);143 }144 145 question_ptr = malloc(sizeof(question));146 if (question_ptr == NULL) {147 fprintf(stderr, "Out of Memory\n");148 exit(EXIT_FAILURE);149 }150 151 memset(incoming_ptr, '\0', sizeof(incoming));152 memset(question_ptr, '\0', sizeof(question));153 154 155 156 133 if (!(fin = fopen(infname, "r"))) { 157 134 fatal_error("Cannot openin infname"); … … 160 137 fatal_error("Cannot openin outfname"); 161 138 } 162 for ( q = fgets(incoming_ptr, MAX_STR_LEN, fin); !feof(fin) && (q != NULL); q = fgets(incoming_ptr, MAX_STR_LEN, fin)) {163 strip_spaces(incoming_ptr);139 for (mr_getline(incoming, fin); !feof(fin) && (incoming != NULL); mr_getline(incoming, fin)) { 140 mr_strip_spaces(incoming); 164 141 165 142 if (incoming[0] == '\0') { 143 mr_free(incoming); 166 144 continue; 167 145 } 168 146 169 sprintf(question_ptr, "Should I restore the image of %s ?", incoming_ptr); 170 171 if (ask_me_yes_or_no(question_ptr)) { 172 fprintf(fout, "%s\n", incoming_ptr); 173 } 174 } 175 176 /*** free memory ***********/ 177 paranoid_free(incoming_ptr); 178 incoming_ptr = NULL; 179 paranoid_free(question_ptr); 180 question_ptr = NULL; 181 182 147 mr_asprintf(question, "Should I restore the image of %s ?", incoming); 148 149 if (ask_me_yes_or_no(question)) { 150 fprintf(fout, "%s\n", incoming); 151 } 152 mr_free(incoming); 153 } 154 mr_free(incoming); 155 mr_free(question); 183 156 paranoid_fclose(fout); 184 157 paranoid_fclose(fin); … … 232 205 { 233 206 234 /** needs malloc **/ 235 char *command; 236 char *file; 237 char *tmp; 207 char *command = NULL; 208 char *file = NULL; 209 char *tmp = NULL; 238 210 int res; 239 211 240 malloc_string(command);241 malloc_string(file);242 malloc_string(tmp);243 212 assert_string_is_neither_NULL_nor_zerolength(f); 244 213 assert_string_is_neither_NULL_nor_zerolength(list_fname); … … 246 215 247 216 if (strncmp(preamble, f, strlen(preamble)) == 0) { 248 strcpy(file, f + strlen(preamble));217 mr_asprintf(file, "%s", f + strlen(preamble)); 249 218 } else { 250 strcpy(file, f);219 mr_asprintf(file, "%s", f); 251 220 } 252 221 if (file[0] == '/' && file[1] == '/') { 253 strcpy(tmp, file); 254 strcpy(file, tmp + 1); 255 } 256 sprintf(tmp, 257 "Checking to see if f=%s, file=%s, is in the list of biggiefiles", 258 f, file); 259 log_msg(2, tmp); 260 sprintf(command, "grep -E '^%s$' %s", file, list_fname); 222 tmp = file; 223 224 mr_asprintf(file, "%s", tmp + 1); 225 mr_free(tmp); 226 } 227 log_msg(2, "Checking to see if f=%s, file=%s, is in the list of biggiefiles", f, file); 228 mr_asprintf(command, "grep -E '^%s$' %s", file, list_fname); 229 mr_free(file); 230 261 231 res = run_program_and_log_output(command, FALSE); 262 paranoid_free(command); 263 paranoid_free(file); 264 paranoid_free(tmp); 232 mr_free(command); 265 233 if (res) { 266 return (FALSE);234 return (FALSE); 267 235 } else { 268 return (TRUE);236 return (TRUE); 269 237 } 270 238 } … … 351 319 * @return 0 for success, nonzero for failure. 352 320 */ 353 int iso_fiddly_bits(bool nuke_me_please) 354 { 321 int iso_fiddly_bits(bool nuke_me_please) { 322 355 323 char *mount_isodir_command = NULL; 356 char * tmp, *command;324 char *command = NULL; 357 325 char *mds = NULL; 358 326 int retval = 0, i; 359 327 360 assert(bkpinfo != NULL);361 malloc_string(tmp);362 malloc_string(command);363 328 g_ISO_restore_mode = TRUE; 364 329 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device); … … 370 335 } 371 336 /* End patch */ 372 sprintf(command, "mkdir -p %s", bkpinfo->isodir);337 mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir); 373 338 run_program_and_log_output(command, 5); 339 mr_free(command); 374 340 log_msg(2, "Setting isodir to %s", bkpinfo->isodir); 375 341 } … … 387 353 mr_strcat(mount_isodir_command, " -t %s", g_isodir_format); 388 354 } 355 389 356 mr_strcat(mount_isodir_command, " -o ro %s", bkpinfo->isodir); 390 run_program_and_log_output("df -m", FALSE); 391 sprintf(tmp, 392 "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", 393 mount_isodir_command); 394 log_msg(1, tmp); 357 run_program_and_log_output("df -m -P", FALSE); 358 log_msg(1, "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", mount_isodir_command); 395 359 if (run_program_and_log_output(mount_isodir_command, FALSE)) { 396 360 popup_and_OK … … 407 371 i = what_number_cd_is_this(); /* has the side-effect of calling mount_media() */ 408 372 mds = media_descriptor_string(bkpinfo->backup_media_type); 409 sprintf(tmp, "%s #%d has been mounted via loopback mount", mds, i);410 373 mr_free(mds); 411 374 412 log_msg(1, tmp);375 log_msg(1, "%s #%d has been mounted via loopback mount", mds, i); 413 376 if (i < 0) { 414 popup_and_OK 415 ("Cannot find ISO images in the directory you specified."); 416 retval = 1; 417 } 418 log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__, 419 bkpinfo->isodir); 420 paranoid_free(tmp); 421 paranoid_free(command); 377 popup_and_OK("Cannot find ISO images in the directory you specified."); 378 retval = 1; 379 } 380 log_msg(2, "bkpinfo->isodir is now %s", bkpinfo->isodir); 422 381 return (retval); 423 382 } … … 451 410 452 411 /** malloc **/ 453 char *tmp, *command, *mountdir, *mountpoint; 412 char *tmp = NULL; 413 char *command = NULL; 414 char *mountdir = NULL; 415 char *mountpoint = NULL; 454 416 char *additional_parameters = NULL; 455 417 … … 457 419 assert_string_is_neither_NULL_nor_zerolength(mpt); 458 420 assert(format != NULL); 459 malloc_string(tmp);460 malloc_string(command);461 malloc_string(mountdir);462 malloc_string(mountpoint);463 421 464 422 if (!strcmp(mpt, "/1")) { 465 strcpy(mountpoint, "/");423 mr_asprintf(mountpoint, "/"); 466 424 log_msg(3, "Mommm! SME is being a dildo!"); 467 425 } else { 468 strcpy(mountpoint, mpt);426 mr_asprintf(mountpoint, "%s", mpt); 469 427 } 470 428 … … 475 433 return (0); 476 434 } 477 sprintf(tmp, "Mounting device %s ", device);435 mr_asprintf(tmp, "Mounting device %s ", device); 478 436 log_msg(1, tmp); 479 437 /* Deal with additional params only if not /proc or /sys */ … … 494 452 495 453 if (!strcmp(mountpoint, "swap")) { 496 sprintf(command, "swapon %s", device); 454 mr_asprintf(command, "swapon %s", device); 455 mr_asprintf(mountdir, "swap"); 497 456 } else { 498 457 if (!strcmp(mountpoint, "/")) { 499 strcpy(mountdir, MNT_RESTORING);458 mr_asprintf(mountdir, "%s", MNT_RESTORING); 500 459 } else { 501 sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);502 } 503 sprintf(command, "mkdir -p %s", mountdir);460 mr_asprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint); 461 } 462 mr_asprintf(command, "mkdir -p %s", mountdir); 504 463 run_program_and_log_output(command, FALSE); 505 sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device, 506 additional_parameters, mountdir, MONDO_LOGFILE); 464 mr_free(command); 465 466 mr_asprintf(command, "mount -t %s %s %s %s 2>> %s", format, device, additional_parameters, mountdir, MONDO_LOGFILE); 507 467 log_msg(2, "command='%s'", command); 508 468 } 509 paranoid_free(additional_parameters);469 mr_free(additional_parameters); 510 470 511 471 res = run_program_and_log_output(command, TRUE); 512 472 if (res && (strstr(command, "xattr") || strstr(command, "acl"))) { 513 473 log_msg(1, "Re-trying without the fancy extra parameters"); 514 sprintf(command, "mount -t %s %s %s 2>> %s", format, device,515 474 mr_free(command); 475 mr_asprintf(command, "mount -t %s %s %s 2>> %s", format, device, mountdir, MONDO_LOGFILE); 516 476 res = run_program_and_log_output(command, TRUE); 517 477 } 518 478 if (res) { 519 log_msg(1, "Unable to mount device %s (type %s) at %s", device, 520 format, mountdir); 479 log_msg(1, "Unable to mount device %s (type %s) at %s", device, format, mountdir); 521 480 log_msg(1, "command was '%s'", command); 522 481 if (!strcmp(mountpoint, "swap")) { … … 524 483 } else { 525 484 log_msg(2, "Retrying w/o the '-t' switch"); 526 sprintf(command, "mount %s %s 2>> %s", device, mountdir,527 485 mr_free(command); 486 mr_asprintf(command, "mount %s %s 2>> %s", device, mountdir, MONDO_LOGFILE); 528 487 log_msg(2, "2nd command = '%s'", command); 529 488 res = run_program_and_log_output(command, TRUE); … … 543 502 } 544 503 545 paranoid_free(tmp);546 paranoid_free(command);547 paranoid_free(mountdir);548 paranoid_free(mountpoint);549 550 504 mr_free(tmp); 505 mr_free(command); 506 mr_free(mountdir); 507 mr_free(mountpoint); 508 509 return (res); 551 510 } 552 511 /************************************************************************** … … 561 520 * @return The number of errors encountered (0 for success). 562 521 */ 563 int mount_all_devices(struct mountlist_itself 564 *p_external_copy_of_mountlist, bool writeable) 522 int mount_all_devices(struct mountlist_itself *p_external_copy_of_mountlist, bool writeable) 565 523 { 566 524 int retval = 0, lino, res; 567 char *tmp ;525 char *tmp = NULL; 568 526 char *these_failed = NULL; 569 char *format;570 527 struct mountlist_itself *mountlist = NULL; 571 572 malloc_string(tmp);573 malloc_string(format);574 528 575 529 assert(p_external_copy_of_mountlist != NULL); … … 581 535 582 536 mvaddstr_and_log_it(g_currentY, 0, "Mounting devices "); 583 open_progress_form("Mounting devices", 584 "I am now mounting all the drives.", 585 "This should not take long.", 586 "", mountlist->entries); 537 open_progress_form("Mounting devices", "I am now mounting all the drives.", "This should not take long.", "", mountlist->entries); 587 538 588 539 mr_asprintf(these_failed, ""); 589 540 for (lino = 0; lino < mountlist->entries; lino++) { 590 541 if (!strcmp(mountlist->el[lino].device, "/proc")) { 591 log_msg(1, 592 "Again with the /proc - why is this in your mountlist?"); 542 log_msg(1, "Again with the /proc - why is this in your mountlist?"); 593 543 } else if (is_this_device_mounted(mountlist->el[lino].device)) { 594 sprintf(tmp, "%s is already mounted", 595 mountlist->el[lino].device); 596 log_to_screen(tmp); 544 log_to_screen("%s is already mounted", mountlist->el[lino].device); 597 545 } else if (strcmp(mountlist->el[lino].mountpoint, "none") 598 546 && strcmp(mountlist->el[lino].mountpoint, "lvm") 599 547 && strcmp(mountlist->el[lino].mountpoint, "raid") 600 548 && strcmp(mountlist->el[lino].mountpoint, "image")) { 601 sprintf(tmp, "Mounting %s", mountlist->el[lino].device);549 mr_asprintf(tmp, "Mounting %s", mountlist->el[lino].device); 602 550 update_progress_form(tmp); 603 strcpy(format, mountlist->el[lino].format); 604 res = mount_device(mountlist->el[lino].device, 605 mountlist->el[lino].mountpoint, 606 format, writeable); 551 mr_free(tmp); 552 res = mount_device(mountlist->el[lino].device, mountlist->el[lino].mountpoint, mountlist->el[lino].format, writeable); 607 553 retval += res; 608 554 if (res) { … … 615 561 if (retval) { 616 562 if (g_partition_table_locked_up > 0) { 617 log_to_screen 618 ("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to"); 619 log_to_screen 620 ("lock up the partition table. You might have to reboot and use Interactive Mode to"); 621 log_to_screen 622 ("format and restore *without* partitioning first. Sorry for the inconvenience."); 623 } 624 sprintf(tmp, "Could not mount device(s) %s- shall I abort?", these_failed); 563 log_to_screen("fdisk's ictol() call to refresh its copy of the partition table causes the kernel to"); 564 log_to_screen("lock up the partition table. You might have to reboot and use Interactive Mode to"); 565 log_to_screen("format and restore *without* partitioning first. Sorry for the inconvenience."); 566 } 567 mr_asprintf(tmp, "Could not mount device(s) %s- shall I abort?", these_failed); 625 568 626 569 if (!ask_me_yes_or_no(tmp)) { 627 570 retval = 0; 628 log_to_screen 629 ("Continuing, although some device(s) failed to be mounted"); 571 log_to_screen("Continuing, although some device(s) failed to be mounted"); 630 572 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 631 573 } else { 632 574 mvaddstr_and_log_it(g_currentY++, 74, "Failed."); 633 log_to_screen 634 ("Unable to mount some or all of your partitions.");635 }575 log_to_screen("Unable to mount some or all of your partitions."); 576 } 577 mr_free(tmp); 636 578 } else { 637 579 log_to_screen("All partitions were mounted OK."); … … 643 585 (void)mount_device("/proc","/proc","proc",TRUE); 644 586 (void)mount_device("/sys","/sys","sysfs",TRUE); 645 run_program_and_log_output("df -m ", 3);587 run_program_and_log_output("df -m -P", 3); 646 588 paranoid_free(mountlist); 647 paranoid_free(tmp);648 paranoid_free(format);649 589 return (retval); 650 590 } … … 652 592 *END_MOUNT_ALL_DEVICES * 653 593 **************************************************************************/ 654 655 656 594 657 595 … … 700 638 { 701 639 /** add mallocs **/ 702 char *value = NULL;640 char value[MAX_STR_LEN]; 703 641 char *tmp = NULL; 642 char *tmp1 = NULL; 704 643 char *envtmp1 = NULL; 705 644 char *envtmp2 = NULL; 706 645 char *command = NULL; 707 char *iso_mnt = NULL;708 char *iso_path = NULL;646 char iso_mnt[MAX_STR_LEN]; 647 char iso_path[MAX_STR_LEN]; 709 648 char *old_isodir = NULL; 710 char cfg_file[100];649 char *cfg_file = NULL; 711 650 t_bkptype media_specified_by_user; 712 651 713 malloc_string(command);714 malloc_string(iso_mnt);715 malloc_string(iso_path);716 malloc_string(old_isodir);717 malloc_string(value);718 malloc_string(tmp);719 652 // assert_string_is_neither_NULL_nor_zerolength(cfg_file); 720 653 assert(bkpinfo != NULL); 654 assert(cfgf != NULL); 721 655 log_it("Entering read_cfg_file_into_bkpinfo"); 722 656 … … 730 664 731 665 if (0 == read_cfg_var(cfg_file, "backup-media-type", value)) { 732 if (!strcmp(value, "cdstream")) { 733 bkpinfo->backup_media_type = cdstream; 734 } else if (!strcmp(value, "cdr")) { 735 bkpinfo->backup_media_type = cdr; 736 } else if (!strcmp(value, "cdrw")) { 737 bkpinfo->backup_media_type = cdrw; 738 } else if (!strcmp(value, "dvd")) { 739 bkpinfo->backup_media_type = dvd; 740 } else if (!strcmp(value, "usb")) { 741 bkpinfo->backup_media_type = usb; 742 bkpinfo->please_dont_eject = TRUE; 743 } else if (!strcmp(value, "iso")) { 744 bkpinfo->backup_media_type = iso; 745 if (am_I_in_disaster_recovery_mode()) { 746 /* Check to see if CD is already mounted before mounting it... */ 747 if (!is_this_device_mounted("/dev/cdrom")) { 748 log_msg(2, "NB: CDROM device not mounted, mounting..."); 749 run_program_and_log_output("mount /dev/cdrom " MNT_CDROM, 1); 750 } 751 if (does_file_exist(MNT_CDROM "/archives/filelist.0")) { 752 bkpinfo->backup_media_type = cdr; 753 run_program_and_log_output("umount -d " MNT_CDROM, 1); 754 log_it("Re-jigging configuration AGAIN. CD-R, not ISO."); 755 } 756 } 757 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) { 758 strcpy(bkpinfo->prefix,value); 666 if (!strcmp(value, "cdstream")) { 667 bkpinfo->backup_media_type = cdstream; 668 } else if (!strcmp(value, "cdr")) { 669 bkpinfo->backup_media_type = cdr; 670 } else if (!strcmp(value, "cdrw")) { 671 bkpinfo->backup_media_type = cdrw; 672 } else if (!strcmp(value, "dvd")) { 673 bkpinfo->backup_media_type = dvd; 674 } else if (!strcmp(value, "usb")) { 675 bkpinfo->backup_media_type = usb; 676 bkpinfo->please_dont_eject = TRUE; 677 } else if (!strcmp(value, "iso")) { 678 bkpinfo->backup_media_type = iso; 679 if (am_I_in_disaster_recovery_mode()) { 680 /* Check to see if CD is already mounted before mounting it... */ 681 if (!is_this_device_mounted("/dev/cdrom")) { 682 log_msg(2, "NB: CDROM device not mounted, mounting..."); 683 run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1); 684 } 685 if (does_file_exist(MNT_CDROM"/archives/filelist.0")) { 686 bkpinfo->backup_media_type = cdr; 687 run_program_and_log_output("umount -d "MNT_CDROM, 1); 688 log_it("Re-jigging configuration AGAIN. CD-R, not ISO."); 689 } 690 } 691 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) { 692 strcpy(bkpinfo->prefix,value); 693 } else { 694 strcpy(bkpinfo->prefix,STD_PREFIX); 695 } 696 log_it("Setting Prefix to %s", bkpinfo->prefix); 697 } else if ((!strcmp(value, "netfs")) || (!strcmp(value, "nfs"))) { 698 /* Stay compatible with previous versions by allowing nfs as an entry here */ 699 bkpinfo->backup_media_type = netfs; 700 bkpinfo->please_dont_eject = TRUE; 701 if (read_cfg_var(cfg_file, "netfs-proto", value) == 0) { 702 mr_asprintf(bkpinfo->netfs_proto,"%s", value); 703 } else { 704 /* For compatibility, force protocol in old nfs case to be transparent */ 705 mr_asprintf(bkpinfo->netfs_proto, "nfs"); 706 } 707 if (read_cfg_var(cfg_file, "netfs-server-user", value) == 0) { 708 mr_asprintf(bkpinfo->netfs_user,"%s", value); 709 } 710 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) { 711 strcpy(bkpinfo->prefix,value); 712 } else { 713 strcpy(bkpinfo->prefix,STD_PREFIX); 714 } 715 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "pxe")) { 716 /* We need to override prefix value in PXE mode as it's 717 * already done in start-netfs */ 718 envtmp1 = getenv("imgname"); 719 if (envtmp1 == NULL) { 720 fatal_error("no imgname variable in environment"); 721 } 722 strcpy(bkpinfo->prefix,envtmp1); 723 } 724 } else if (!strcmp(value, "tape")) { 725 bkpinfo->backup_media_type = tape; 726 } else if (!strcmp(value, "udev")) { 727 bkpinfo->backup_media_type = udev; 759 728 } else { 760 strcpy(bkpinfo->prefix,STD_PREFIX); 761 } 762 log_it("Setting Prefix to %s", bkpinfo->prefix); 763 } else if ((!strcmp(value, "netfs")) || (!strcmp(value, "nfs"))) { 764 /* Stay compatible with previous versions by allowing nfs as an entry here */ 765 bkpinfo->backup_media_type = netfs; 766 bkpinfo->please_dont_eject = TRUE; 767 if (read_cfg_var(cfg_file, "netfs-proto", value) == 0) { 768 mr_asprintf(bkpinfo->netfs_proto,"%s", value); 769 } else { 770 /* For compatibility, force protocol in old nfs case to be transparent */ 771 mr_asprintf(bkpinfo->netfs_proto, "nfs"); 772 } 773 if (read_cfg_var(cfg_file, "netfs-server-user", value) == 0) { 774 mr_asprintf(bkpinfo->netfs_user,"%s", value); 775 } 776 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) { 777 strcpy(bkpinfo->prefix,value); 778 } else { 779 strcpy(bkpinfo->prefix,STD_PREFIX); 780 } 781 if (strstr(call_program_and_get_last_line_of_output 782 ("cat /proc/cmdline"), "pxe")) { 783 /* We need to override prefix value in PXE mode as it's 784 * already done in start-netfs */ 785 envtmp1 = getenv("imgname"); 786 if (envtmp1 == NULL) { 787 fatal_error("no imgname variable in environment"); 788 } 789 strcpy(bkpinfo->prefix,envtmp1); 790 } 791 792 } else if (!strcmp(value, "tape")) { 793 bkpinfo->backup_media_type = tape; 794 } else if (!strcmp(value, "udev")) { 795 bkpinfo->backup_media_type = udev; 729 fatal_error("UNKNOWN bkp-media-type"); 730 } 796 731 } else { 797 fatal_error("UNKNOWN bkp-media-type"); 798 } 799 } else { 800 fatal_error("backup-media-type not specified!"); 801 } 732 fatal_error("backup-media-type not specified!"); 733 } 734 802 735 if (bkpinfo->disaster_recovery) { 803 736 if (bkpinfo->backup_media_type == cdstream) { … … 814 747 } 815 748 sprintf(bkpinfo->media_device, "%s1", value); 816 sprintf(tmp, "Backup medium is USB --- dev=%s", bkpinfo->media_device); 817 log_msg(2, tmp); 818 } else if (bkpinfo->backup_media_type == tape 819 || bkpinfo->backup_media_type == udev) { 749 log_msg(2, "Backup medium is USB --- dev=%s", bkpinfo->media_device); 750 } else if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) { 820 751 if (read_cfg_var(cfg_file, "media-dev", value)) { 821 752 fatal_error("Cannot get tape device name from cfg file"); … … 824 755 read_cfg_var(cfg_file, "media-size", value); 825 756 bkpinfo->media_size = atol(value); 826 sprintf(tmp, "Backup medium is TAPE --- dev=%s", 827 bkpinfo->media_device); 828 log_msg(2, tmp); 757 log_msg(2, "Backup medium is TAPE --- dev=%s", bkpinfo->media_device); 829 758 } else { 830 759 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* we don't really need this var */ … … 833 762 } 834 763 } else { 835 log_msg(2, 836 "Not in Disaster Recovery Mode. No need to derive device name from config file."); 764 log_msg(2, "Not in Disaster Recovery Mode. No need to derive device name from config file."); 837 765 } 838 766 … … 867 795 868 796 if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) { 869 bkpinfo->internal_tape_block_size = atol(value); 870 log_msg(1, "Internal tape block size has been custom-set to %ld", 871 bkpinfo->internal_tape_block_size); 797 bkpinfo->internal_tape_block_size = atol(value); 872 798 } else { 873 bkpinfo->internal_tape_block_size = 874 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 875 log_msg(1, "Internal tape block size = default (%ld)", 876 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE); 799 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 800 } 801 log_msg(1, "Internal tape block size set to %ld", bkpinfo->internal_tape_block_size); 802 803 read_cfg_var(cfg_file, "use-lzma", value); 804 if (strstr(value, "yes")) { 805 bkpinfo->use_lzma = TRUE; 806 bkpinfo->use_lzo = FALSE; 807 bkpinfo->use_gzip = FALSE; 808 strcpy(bkpinfo->zip_exe, "lzma"); 809 strcpy(bkpinfo->zip_suffix, "lzma"); 877 810 } 878 811 879 812 read_cfg_var(cfg_file, "use-lzo", value); 880 813 if (strstr(value, "yes")) { 881 bkpinfo->use_lzo = TRUE; 882 bkpinfo->use_gzip = FALSE; 883 strcpy(bkpinfo->zip_exe, "lzop"); 884 strcpy(bkpinfo->zip_suffix, "lzo"); 885 } else { 814 bkpinfo->use_lzma = FALSE; 815 bkpinfo->use_lzo = TRUE; 816 bkpinfo->use_gzip = FALSE; 817 strcpy(bkpinfo->zip_exe, "lzop"); 818 strcpy(bkpinfo->zip_suffix, "lzo"); 819 } 820 886 821 read_cfg_var(cfg_file, "use-gzip", value); 887 822 if (strstr(value, "yes")) { 823 bkpinfo->use_lzma = FALSE; 888 824 bkpinfo->use_lzo = FALSE; 889 825 bkpinfo->use_gzip = TRUE; 890 826 strcpy(bkpinfo->zip_exe, "gzip"); 891 827 strcpy(bkpinfo->zip_suffix, "gz"); 892 } else { 893 read_cfg_var(cfg_file, "use-comp", value); 894 if (strstr(value, "yes")) { 895 bkpinfo->use_lzo = FALSE; 896 bkpinfo->use_gzip = FALSE; 897 strcpy(bkpinfo->zip_exe, "bzip2"); 898 strcpy(bkpinfo->zip_suffix, "bz2"); 899 } else { 900 bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0'; 901 } 902 } 828 } 829 830 read_cfg_var(cfg_file, "use-comp", value); 831 if (strstr(value, "yes")) { 832 bkpinfo->use_lzma = FALSE; 833 bkpinfo->use_lzo = FALSE; 834 bkpinfo->use_gzip = FALSE; 835 strcpy(bkpinfo->zip_exe, "bzip2"); 836 strcpy(bkpinfo->zip_suffix, "bz2"); 903 837 } 904 838 … … 906 840 read_cfg_var(cfg_file, "differential", value); 907 841 if (!strcmp(value, "yes") || !strcmp(value, "1")) { 908 bkpinfo->differential = TRUE;842 bkpinfo->differential = TRUE; 909 843 } 910 844 log_msg(2, "differential var = '%s'", value); 911 845 if (bkpinfo->differential) { 912 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP");846 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP"); 913 847 } else { 914 log_msg(2, "This is a regular (full) backup");915 } 916 917 read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp);918 if ( tmp[0] || strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "donteject")) {848 log_msg(2, "This is a regular (full) backup"); 849 } 850 851 read_cfg_var(g_mondo_cfg_file, "please-dont-eject", value); 852 if (value[0] || strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "donteject")) { 919 853 bkpinfo->please_dont_eject = TRUE; 920 854 log_msg(2, "Ok, I shan't eject when restoring! Groovy."); … … 923 857 if (bkpinfo->backup_media_type == netfs) { 924 858 if (!cfgf) { 925 log_msg(2, "netfs_mount remains %s", bkpinfo->netfs_mount); 926 log_msg(2, "netfs_remote_dir remains %s", 927 bkpinfo->netfs_remote_dir); 928 log_msg(2, 929 "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place"); 859 if (bkpinfo->netfs_mount) { 860 log_msg(2, "netfs_mount remains %s", bkpinfo->netfs_mount); 861 } 862 if (bkpinfo->netfs_remote_dir) { 863 log_msg(2, "netfs_remote_dir remains %s", bkpinfo->netfs_remote_dir); 864 } 865 log_msg(2, "...cos it wouldn't make sense to abandon the values that GOT ME to this config file in the first place"); 930 866 } else { 931 read_cfg_var(g_mondo_cfg_file, "netfs-server-mount", 932 bkpinfo->netfs_mount); 933 read_cfg_var(g_mondo_cfg_file, "netfs-server-path", 934 bkpinfo->netfs_remote_dir); 935 log_msg(2, "netfs_mount is %s", bkpinfo->netfs_mount); 936 log_msg(2, "netfs_proto is %s", bkpinfo->netfs_proto); 937 if (bkpinfo->netfs_user) { 867 read_cfg_var(g_mondo_cfg_file, "netfs-server-mount", value); 868 mr_free(bkpinfo->netfs_mount); 869 mr_asprintf(bkpinfo->netfs_mount, "%s", value); 870 871 read_cfg_var(g_mondo_cfg_file, "netfs-server-path", value); 872 mr_free(bkpinfo->netfs_remote_dir); 873 mr_asprintf(bkpinfo->netfs_remote_dir, "%s", value); 874 875 if (bkpinfo->netfs_mount != NULL) { 876 log_msg(2, "netfs_mount is %s", bkpinfo->netfs_mount); 877 } 878 if (bkpinfo->netfs_remote_dir != NULL) { 879 log_msg(2, "netfs_remote_dir is %s", bkpinfo->netfs_remote_dir); 880 } 881 if (bkpinfo->netfs_proto != NULL) { 882 log_msg(2, "netfs_proto is %s", bkpinfo->netfs_proto); 883 } 884 if (bkpinfo->netfs_user != NULL) { 938 885 log_msg(2, "netfs_user is %s", bkpinfo->netfs_user); 939 886 } 940 log_msg(2, "netfs_remote_dir is %s", bkpinfo->netfs_remote_dir); 941 } 942 if (strstr(call_program_and_get_last_line_of_output 943 ("cat /proc/cmdline"), "pxe")) { 887 } 888 if (strstr(call_program_and_get_last_line_of_output("cat /proc/cmdline"), "pxe")) { 944 889 /* We need to override values in PXE mode as it's 945 890 * already done in start-netfs */ … … 952 897 fatal_error("no dirimg variable in environment"); 953 898 } 954 strcpy(bkpinfo->netfs_mount,envtmp1); 955 strcpy(bkpinfo->netfs_remote_dir,envtmp2); 899 mr_free(bkpinfo->netfs_mount); 900 mr_asprintf(bkpinfo->netfs_mount, "%s", envtmp1); 901 902 mr_free(bkpinfo->netfs_remote_dir); 903 mr_asprintf(bkpinfo->netfs_remote_dir, "%s", envtmp2); 956 904 } 957 905 } else if (bkpinfo->backup_media_type == iso) { … … 960 908 * isodir in disaster recovery mode 961 909 */ 962 strcpy(old_isodir, bkpinfo->isodir);910 mr_asprintf(old_isodir, "%s", bkpinfo->isodir); 963 911 read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt); 964 912 read_cfg_var(g_mondo_cfg_file, "isodir", iso_path); … … 969 917 if ((!bkpinfo->disaster_recovery) || (g_isodir_device[0] != '\0')) { 970 918 if (strcmp(old_isodir, bkpinfo->isodir)) { 971 log_it 972 ("user nominated isodir %s differs from archive %s, keeping user's choice\n", 973 old_isodir, bkpinfo->isodir); 919 log_it("user nominated isodir %s differs from archive, keeping user's choice: %s\n", bkpinfo->isodir, old_isodir ); 974 920 strcpy(bkpinfo->isodir, old_isodir); 975 921 } … … 982 928 983 929 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, g_isodir_device); 930 984 931 if (bkpinfo->disaster_recovery) { 985 932 if (is_this_device_mounted(g_isodir_device)) { 986 933 log_msg(2, "NB: isodir is already mounted"); 987 934 /* Find out where it's mounted */ 988 sprintf(command, "mount | grep -E '^%s' | tail -n1 | cut -d' ' -f3", g_isodir_device);935 mr_asprintf(command, "mount | grep -E '^%s' | tail -n1 | cut -d' ' -f3", g_isodir_device); 989 936 log_it("command = %s", command); 990 log_it("res of it = %s", 991 call_program_and_get_last_line_of_output(command)); 992 sprintf(iso_mnt, "%s", 993 call_program_and_get_last_line_of_output(command)); 937 log_it("res of it = %s", call_program_and_get_last_line_of_output(command)); 938 mr_strcpy(iso_mnt, call_program_and_get_last_line_of_output(command)); 939 mr_free(command); 994 940 } else { 995 sprintf(iso_mnt, "/tmp/isodir"); 996 sprintf(tmp, "mkdir -p %s", iso_mnt); 997 run_program_and_log_output(tmp, 5); 998 sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt); 999 if (run_program_and_log_output(tmp, 3)) { 1000 log_msg(1, 1001 "Unable to mount isodir. Perhaps this is really a CD backup?"); 941 mr_asprintf(iso_mnt, "/tmp/isodir"); 942 mr_asprintf(tmp1, "mkdir -p %s", iso_mnt); 943 run_program_and_log_output(tmp1, 5); 944 mr_free(tmp1); 945 946 mr_asprintf(tmp1, "mount %s %s", g_isodir_device, iso_mnt); 947 if (run_program_and_log_output(tmp1, 3)) { 948 log_msg(1, "Unable to mount isodir. Perhaps this is really a CD backup?"); 1002 949 bkpinfo->backup_media_type = cdr; 1003 950 strcpy(bkpinfo->media_device, "/dev/cdrom"); /* superfluous */ 1004 951 bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0'; 1005 952 if (mount_media()) { 1006 fatal_error1007 953 mr_free(tmp1); 954 fatal_error("Unable to mount isodir. Failed to mount CD-ROM as well."); 1008 955 } else { 1009 log_msg(1, 1010 "You backed up to disk, then burned some CDs.");1011 1012 }956 log_msg(1, "You backed up to disk, then burned some CDs."); 957 } 958 } 959 mr_free(tmp1); 1013 960 } 1014 961 /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */ 1015 /* except when already done i siso_fiddly_bits */962 /* except when already done in iso_fiddly_bits */ 1016 963 if ((bkpinfo->backup_media_type == iso) && (g_isodir_device[0] == '\0')) { 1017 964 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); … … 1027 974 media_specified_by_user = bkpinfo->backup_media_type; 1028 975 get_cfg_file_from_archive(); 1029 /*1030 if (media_specified_by_user != cdr && media_specified_by_user == cdrw)1031 { g_restoring_live_from_cd = FALSE; }1032 */1033 976 } 1034 977 } … … 1037 980 g_backup_media_type = bkpinfo->backup_media_type; 1038 981 paranoid_free(value); 1039 paranoid_free(tmp);1040 paranoid_free(command);1041 982 paranoid_free(iso_mnt); 1042 983 paranoid_free(iso_path); 1043 paranoid_free(old_isodir);1044 984 return (0); 1045 985 … … 1068 1008 struct s_node *filelist; 1069 1009 1070 /** add mallocs**/ 1071 char *command; 1010 char *command = NULL; 1072 1011 char *tmp; 1073 1012 char *q; … … 1077 1016 1078 1017 assert(bkpinfo != NULL); 1079 malloc_string(command);1080 1018 malloc_string(tmp); 1081 1019 … … 1105 1043 unlink(FILELIST_FULL_STUB); 1106 1044 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1107 sprintf(command, 1108 "tar -b %ld -zxf %s ./%s ./%s ./%s ./%s ./%s", 1109 bkpinfo->internal_tape_block_size, 1110 bkpinfo->media_device, 1111 MOUNTLIST_FNAME_STUB, 1112 BIGGIELIST_TXT_STUB, 1113 FILELIST_FULL_STUB, 1114 IWANTMYLVM_STUB, 1115 MONDO_CFG_FILE_STUB); 1045 mr_asprintf(command, "tar -b %ld -zxf %s ./%s ./%s ./%s ./%s ./%s", bkpinfo->internal_tape_block_size, bkpinfo->media_device, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB); 1116 1046 log_msg(1, "tarcommand = %s", command); 1117 1047 run_program_and_log_output(command, 1); 1048 mr_free(command); 1049 1118 1050 if (!does_file_exist(FILELIST_FULL_STUB)) { 1119 1051 /* Doing that allow us to remain compatible with pre-2.2.5 versions */ 1120 1052 log_msg(2, "pre-2.2.4 compatible mode on"); 1121 sprintf(command, 1122 "tar -b %ld -zxf %s %s %s %s %s %s", 1123 bkpinfo->internal_tape_block_size, 1124 bkpinfo->media_device, 1125 MOUNTLIST_FNAME_STUB, 1126 BIGGIELIST_TXT_STUB, 1127 FILELIST_FULL_STUB, 1128 IWANTMYLVM_STUB, 1129 MONDO_CFG_FILE_STUB); 1053 mr_asprintf(command, "tar -b %ld -zxf %s %s %s %s %s %s", bkpinfo->internal_tape_block_size, bkpinfo->media_device, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB); 1130 1054 log_msg(1, "tarcommand = %s", command); 1131 1055 run_program_and_log_output(command, 1); 1056 mr_free(command); 1132 1057 } 1133 1058 } else { 1134 log_msg(2, 1135 "Calling insist_on_this_cd_number; bkpinfo->isodir=%s", 1136 bkpinfo->isodir); 1059 log_msg(2, "Calling insist_on_this_cd_number; bkpinfo->isodir=%s", bkpinfo->isodir); 1137 1060 insist_on_this_cd_number(1); 1138 1061 log_msg(2, "Back from iotcn"); 1139 1062 run_program_and_log_output("mount", 1); 1140 sprintf(command, 1141 "tar -zxf %s/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", 1142 MNT_CDROM, 1143 MOUNTLIST_FNAME_STUB, 1144 BIGGIELIST_TXT_STUB, 1145 FILELIST_FULL_STUB, 1146 IWANTMYLVM_STUB, 1147 MONDO_CFG_FILE_STUB); 1063 mr_asprintf(command, "tar -zxf %s/images/all.tar.gz ./%s ./%s ./%s ./%s ./%s", MNT_CDROM, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB); 1148 1064 1149 1065 log_msg(1, "tarcommand = %s", command); 1150 1066 run_program_and_log_output(command, 1); 1067 mr_free(command); 1068 1151 1069 if (!does_file_exist(FILELIST_FULL_STUB)) { 1152 1070 /* Doing that allow us to remain compatible with pre-2.2.5 versions */ 1153 1071 log_msg(2, "pre-2.2.4 compatible mode on"); 1154 sprintf(command, 1155 "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", 1156 MNT_CDROM, 1157 MOUNTLIST_FNAME_STUB, 1158 BIGGIELIST_TXT_STUB, 1159 FILELIST_FULL_STUB, 1160 IWANTMYLVM_STUB, 1161 MONDO_CFG_FILE_STUB); 1072 mr_asprintf(command, "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", MNT_CDROM, MOUNTLIST_FNAME_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, IWANTMYLVM_STUB, MONDO_CFG_FILE_STUB); 1162 1073 1163 1074 log_msg(1, "tarcommand = %s", command); 1164 1075 run_program_and_log_output(command, 1); 1076 mr_free(command); 1165 1077 } 1166 1078 if (!does_file_exist(BIGGIELIST_TXT_STUB)) { 1167 fatal_error 1168 ("all.tar.gz did not include " BIGGIELIST_TXT_STUB); 1079 fatal_error("all.tar.gz did not include " BIGGIELIST_TXT_STUB); 1169 1080 } 1170 1081 if (!does_file_exist(FILELIST_FULL_STUB)) { 1171 fatal_error 1172 ("all.tar.gz did not include " FILELIST_FULL_STUB); 1173 } 1174 } 1175 sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB, 1176 g_mondo_cfg_file); 1082 fatal_error("all.tar.gz did not include " FILELIST_FULL_STUB); 1083 } 1084 } 1085 mr_asprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB, g_mondo_cfg_file); 1177 1086 run_program_and_log_output(command, FALSE); 1178 1179 sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, 1180 BIGGIELIST_TXT_STUB, g_biggielist_txt);1087 mr_free(command); 1088 1089 mr_asprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, BIGGIELIST_TXT_STUB, g_biggielist_txt); 1181 1090 log_msg(1, "command = %s", command); 1182 1091 paranoid_system(command); 1183 sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, 1184 FILELIST_FULL_STUB, g_filelist_full); 1092 mr_free(command); 1093 1094 mr_asprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, FILELIST_FULL_STUB, g_filelist_full); 1185 1095 log_msg(1, "command = %s", command); 1186 1096 paranoid_system(command); 1097 mr_free(command); 1187 1098 } 1188 1099 … … 1194 1105 ask_me_yes_or_no("Do you want to retrieve the mountlist as well?")) 1195 1106 { 1196 sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB,1197 bkpinfo->tmpdir);1198 paranoid_system(command);1107 mr_asprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, bkpinfo->tmpdir); 1108 paranoid_system(command); 1109 mr_free(command); 1199 1110 } 1200 1111 … … 1209 1120 log_msg(1, "Warning - %s does not exist", g_filelist_full); 1210 1121 } 1211 // popup_and_OK("Wonderful.");1212 1122 1213 1123 log_msg(2, "Forking"); … … 1221 1131 log_to_screen("Pre-processing filelist"); 1222 1132 if (!does_file_exist(g_biggielist_txt)) { 1223 sprintf(command, "echo -n > %s", g_biggielist_txt);1133 mr_asprintf(command, "echo -n > %s", g_biggielist_txt); 1224 1134 paranoid_system(command); 1225 }1226 sprintf(command, "grep -E '^/dev/.*' %s > %s",1227 1135 mr_free(command); 1136 } 1137 mr_asprintf(command, "grep -E '^/dev/.*' %s > %s", g_biggielist_txt, g_filelist_imagedevs); 1228 1138 paranoid_system(command); 1139 mr_free(command); 1229 1140 exit(0); 1230 1141 break; … … 1247 1158 while (q == NULL) { 1248 1159 printf("Restore which directory? --> "); 1249 q = fgets(tmp, sizeof(tmp), stdin);1250 } 1251 toggle_path_selection(filelist, tmp, TRUE);1252 if (strlen( tmp) == 0) {1160 mr_getline(q, stdin); 1161 } 1162 toggle_path_selection(filelist, q, TRUE); 1163 if (strlen(q) == 0) { 1253 1164 res = 1; 1254 1165 } else { 1255 1166 res = 0; 1256 1167 } 1168 mr_free(q); 1257 1169 } else { 1258 1170 res = edit_filelist(filelist); … … 1277 1189 } 1278 1190 1279 paranoid_free(command);1280 1191 paranoid_free(tmp); 1281 1192 return (filelist); … … 1298 1209 int backup_crucial_file(char *path_root, char *filename) 1299 1210 { 1300 char *tmp ;1301 char *command ;1211 char *tmp = NULL; 1212 char *command = NULL; 1302 1213 int res; 1303 1214 1304 malloc_string(tmp);1305 malloc_string(command);1306 1215 assert(path_root != NULL); 1307 1216 assert_string_is_neither_NULL_nor_zerolength(filename); 1308 1217 1309 sprintf(tmp, "%s/%s", path_root, filename); 1310 sprintf(command, "cp -f %s %s.pristine", tmp, tmp); 1218 mr_asprintf(tmp, "%s/%s", path_root, filename); 1219 mr_asprintf(command, "cp -f %s %s.pristine", tmp, tmp); 1220 mr_free(tmp); 1311 1221 1312 1222 res = run_program_and_log_output(command, 5); 1313 paranoid_free(tmp); 1314 paranoid_free(command); 1223 mr_free(command); 1315 1224 return (res); 1316 1225 } … … 1358 1267 1359 1268 /** malloc *******/ 1360 char *device; 1361 char *tmp = NULL; 1362 char *name; 1269 char *device = NULL; 1270 char *name = NULL; 1363 1271 char *cmd = NULL; 1364 1272 … … 1385 1293 read_cfg_var(g_mondo_cfg_file, "bootloader.device", device); 1386 1294 read_cfg_var(g_mondo_cfg_file, "bootloader.name", name); 1387 mr_asprintf(tmp, "run_boot_loader: device='%s', name='%s'", device, name); 1388 log_msg(2, tmp); 1389 paranoid_free(tmp); 1390 paranoid_system("sync"); 1295 log_msg(2, "run_boot_loader: device='%s', name='%s'", device, name); 1296 sync(); 1391 1297 1392 1298 offer_to_make_initrd(); … … 1408 1314 mr_asprintf(tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device); 1409 1315 if (!system(tmp)) { 1410 paranoid_free(tmp);1316 mr_free(tmp); 1411 1317 mr_asprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device); 1412 1318 res = run_program_and_log_output(tmp, 3); 1413 1319 } else { 1414 log_msg(1, 1415 "I'm not running any boot loader. You have a DD boot drive. It's already loaded up."); 1416 } 1417 paranoid_free(tmp); 1320 log_msg(1, "I'm not running any boot loader. You have a DD boot drive. It's already loaded up."); 1321 } 1322 mr_free(tmp); 1418 1323 } 1419 1324 #else … … 1446 1351 * @note The returned string points to static storage that will be overwritten with each call. 1447 1352 */ 1448 char *find_my_editor(void) 1449 { 1353 char *find_my_editor(void) { 1354 1450 1355 static char output[MAX_STR_LEN]; 1451 1356 if (find_home_of_exe("pico")) { … … 1476 1381 { 1477 1382 /** malloc **/ 1478 char *command; 1479 char *boot_device; 1480 char *rootdev; 1481 char *rootdrive; 1482 char *conffile; 1483 char *tmp; 1484 char *editor; 1485 1383 char *command = NULL; 1384 char *boot_device = NULL; 1385 char *tmp = NULL; 1386 char *editor = NULL; 1387 1388 bool done; 1486 1389 int res = 0; /* FALSE */ 1487 int done;1488 1390 bool mntlistchg = FALSE; 1489 1391 FILE *fin = NULL; 1490 1392 1491 malloc_string(command);1492 1393 malloc_string(boot_device); 1493 malloc_string(tmp); 1494 malloc_string(editor); 1495 malloc_string(rootdev); 1496 malloc_string(rootdrive); 1497 malloc_string(conffile); 1394 1498 1395 assert_string_is_neither_NULL_nor_zerolength(bd); 1499 strcpy(editor, find_my_editor());1500 1396 strcpy(boot_device, bd); 1501 1397 1502 if (!run_program_and_log_output("which grub-MR", FALSE)) {1503 log_msg(1, "Yay! grub-MR found...");1504 sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device);1505 log_msg(1, "command = %s", command);1506 } else {1507 sprintf(command, "chroot " MNT_RESTORING " grub-install %s",1508 boot_device);1509 log_msg(1, "WARNING - grub-MR not found; using grub-install");1510 }1511 1398 if (offer_to_run_stabgrub 1512 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) 1399 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) { 1513 1400 /* interactive mode */ 1514 {1515 1401 mvaddstr_and_log_it(g_currentY, 1516 1402 0, … … 1521 1407 } 1522 1408 for (done = FALSE; !done;) { 1523 popup_and_get_string("Boot device", 1524 "Please confirm/enter the boot device. If in doubt, try /dev/hda", 1525 boot_device, MAX_STR_LEN / 4); 1409 popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/hda", boot_device, MAX_STR_LEN / 4); 1526 1410 /* Only try to adapt grub here first if the mountlist wasn't changed before */ 1527 1411 if (! mntlistchg) { 1528 sprintf(command, "stabgrub-me %s", boot_device);1412 mr_asprintf(command, "stabgrub-me %s", boot_device); 1529 1413 res = run_program_and_log_output(command, 1); 1530 } 1531 if ((res) || (mntlistchg)){ 1414 mr_free(command); 1415 } 1416 1417 if ((res) || (mntlistchg)) { 1532 1418 if (res) { 1533 1419 popup_and_OK("GRUB installation failed. You will now edit fstab, mtab, device.map and menu.lst/grub.cfg in order to fix grub install"); … … 1538 1424 newtSuspend(); 1539 1425 } 1540 sprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor); 1426 mr_asprintf(editor, "%s", find_my_editor()); 1427 mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor); 1541 1428 paranoid_system(tmp); 1542 sprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor); 1429 mr_free(tmp); 1430 1431 mr_asprintf(tmp, "chroot %s %s /etc/mtab", MNT_RESTORING, editor); 1543 1432 paranoid_system(tmp); 1433 mr_free(tmp); 1434 1544 1435 if (does_file_exist(MNT_RESTORING"/boot/grub/menu.lst")) { 1545 sprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor);1436 mr_asprintf(tmp, "chroot %s %s /boot/grub/menu.lst", MNT_RESTORING, editor); 1546 1437 } else if (does_file_exist(MNT_RESTORING"/boot/grub/grub.cfg")) { 1547 sprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor);1438 mr_asprintf(tmp, "chroot %s %s /boot/grub/grub.cfg", MNT_RESTORING, editor); 1548 1439 } else if (does_file_exist(MNT_RESTORING"/boot/grub2/grub.cfg")) { 1549 sprintf(tmp, "chroot %s %s /boot/grub2/grub.cfg", MNT_RESTORING, editor);1440 mr_asprintf(tmp, "chroot %s %s /boot/grub2/grub.cfg", MNT_RESTORING, editor); 1550 1441 } 1551 1442 paranoid_system(tmp); 1443 mr_free(tmp); 1444 1552 1445 if (does_file_exist(MNT_RESTORING"/boot/grub/device.map")) { 1553 sprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor);1446 mr_asprintf(tmp, "chroot %s %s /boot/grub/device.map", MNT_RESTORING, editor); 1554 1447 } else if (does_file_exist(MNT_RESTORING"/boot/grub2/device.map")) { 1555 sprintf(tmp, "chroot %s %s /boot/grub2/device.map", MNT_RESTORING, editor);1556 1448 mr_asprintf(tmp, "chroot %s %s /boot/grub2/device.map", MNT_RESTORING, editor); 1449 } 1557 1450 paranoid_system(tmp); 1451 mr_free(tmp); 1452 mr_free(editor); 1453 1558 1454 if (!g_text_mode) { 1559 1455 newtResume(); 1560 1456 } 1561 sprintf(command, "stabgrub-me %s", boot_device);1457 mr_asprintf(command, "stabgrub-me %s", boot_device); 1562 1458 res = run_program_and_log_output(command, 1); 1459 mr_free(command); 1460 1563 1461 if (res) { 1564 popup_and_OK 1565 ("GRUB installation failed. Please fix the conf files so that a manual install using 'grub-install' or similar command works. You are now chroot()'ed to your restored system. Please type 'exit' when you are done."); 1462 popup_and_OK("GRUB installation failed. Please fix the conf files so that a manual install using 'grub-install' or similar command works. You are now chroot()'ed to your restored system. Please type 'exit' when you are done."); 1566 1463 newtSuspend(); 1567 1464 paranoid_system("chroot " MNT_RESTORING); … … 1576 1473 } 1577 1474 } 1578 } else 1475 } else { 1579 1476 /* nuke mode */ 1580 { 1581 mvaddstr_and_log_it(g_currentY, 1582 0, 1583 "Running GRUB... "); 1477 if (!run_program_and_log_output("which grub-MR", FALSE)) { 1478 log_msg(1, "Yay! grub-MR found..."); 1479 mr_asprintf(command, "grub-MR %s "MINDI_CACHE"/mountlist.txt", boot_device); 1480 log_msg(1, "command = %s", command); 1481 } else { 1482 mr_asprintf(command, "chroot " MNT_RESTORING " grub-install %s", boot_device); 1483 log_msg(1, "WARNING - grub-MR not found; using grub-install"); 1484 } 1485 mvaddstr_and_log_it(g_currentY, 0, "Running GRUB... "); 1584 1486 log_it("%s",command); 1585 1487 res = run_program_and_log_output(command, 1); 1488 mr_free(command); 1489 1586 1490 if (res) { 1587 1491 popup_and_OK … … 1609 1513 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1610 1514 } 1611 paranoid_free(rootdev);1612 paranoid_free(rootdrive);1613 paranoid_free(conffile);1614 paranoid_free(command);1615 1515 paranoid_free(boot_device); 1616 paranoid_free(tmp);1617 paranoid_free(editor);1618 1516 1619 1517 return (res); … … 1633 1531 { 1634 1532 /** malloc **/ 1635 char *command ;1636 char *tmp ;1637 char *editor ;1533 char *command = NULL; 1534 char *tmp = NULL; 1535 char *editor = NULL; 1638 1536 1639 1537 int res; 1640 1538 int done; 1641 1539 1642 malloc_string(command);1643 malloc_string(tmp);1644 malloc_string(editor);1645 strcpy(editor, find_my_editor());1646 1540 if (offer_to_run_stabelilo 1647 1541 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) … … 1652 1546 0, 1653 1547 "Modifying fstab and elilo.conf... "); 1654 sprintf(command, "stabelilo-me");1548 mr_asprintf(command, "stabelilo-me"); 1655 1549 res = run_program_and_log_output(command, 3); 1550 mr_free(command); 1551 1656 1552 if (res) { 1657 1553 popup_and_OK … … 1661 1557 newtSuspend(); 1662 1558 } 1663 sprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor); 1559 mr_asprintf(editor, "%s", find_my_editor()); 1560 1561 mr_asprintf(tmp, "chroot %s %s /etc/fstab", MNT_RESTORING, editor); 1664 1562 paranoid_system(tmp); 1665 sprintf(tmp, "chroot %s %s /etc/elilo.conf", MNT_RESTORING, editor); 1563 mr_free(tmp); 1564 1565 mr_asprintf(tmp, "chroot %s %s /etc/elilo.conf", MNT_RESTORING, editor); 1666 1566 paranoid_system(tmp); 1567 mr_free(tmp); 1568 mr_free(editor); 1569 1667 1570 if (!g_text_mode) { 1668 1571 newtResume(); … … 1682 1585 res = TRUE; 1683 1586 } 1684 paranoid_free(command);1685 paranoid_free(tmp);1686 paranoid_free(editor);1687 1587 return (res); 1688 1588 } … … 1701 1601 { 1702 1602 /** malloc **/ 1703 char *command ;1704 char *tmp ;1705 char *editor ;1603 char *command = NULL; 1604 char *tmp = NULL; 1605 char *editor = NULL; 1706 1606 1707 1607 int res; 1708 1608 int done; 1709 1609 bool run_lilo_M = FALSE; 1710 malloc_string(command);1711 malloc_string(tmp);1712 malloc_string(editor);1713 1610 1714 1611 if (!run_program_and_log_output … … 1717 1614 } 1718 1615 1719 strcpy(editor, find_my_editor());1720 1616 if (offer_to_run_stablilo 1721 1617 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) … … 1726 1622 0, 1727 1623 "Modifying fstab and lilo.conf, and running LILO... "); 1728 sprintf(command, "stablilo-me");1624 mr_asprintf(command, "stablilo-me"); 1729 1625 res = run_program_and_log_output(command, 3); 1626 mr_free(command); 1627 1730 1628 if (res) { 1731 1629 popup_and_OK … … 1735 1633 newtSuspend(); 1736 1634 } 1737 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1635 mr_asprintf(editor, "%s", find_my_editor()); 1636 1637 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1738 1638 paranoid_system(tmp); 1739 sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor); 1639 mr_free(tmp); 1640 1641 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor); 1740 1642 paranoid_system(tmp); 1643 mr_free(tmp); 1644 mr_free(editor); 1645 1741 1646 if (!g_text_mode) { 1742 1647 newtResume(); … … 1793 1698 " lilo -M /dev/sda", 3); 1794 1699 } 1795 paranoid_free(command);1796 paranoid_free(tmp);1797 paranoid_free(editor);1798 1700 return (res); 1799 1701 } … … 1813 1715 { 1814 1716 /** malloc **/ 1815 char *command ;1816 char *boot_device ;1817 char *tmp ;1717 char *command = NULL; 1718 char *boot_device = NULL; 1719 char *tmp = NULL; 1818 1720 char *editor; 1819 1721 int res; 1820 1722 int done; 1821 1723 1822 malloc_string(command);1823 1724 malloc_string(boot_device); 1824 malloc_string(tmp);1825 malloc_string(editor);1826 1725 assert_string_is_neither_NULL_nor_zerolength(bd); 1827 1726 1828 strcpy(editor, find_my_editor());1829 1727 strcpy(boot_device, bd); 1830 sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device);1831 log_msg(2, "run_raw_mbr() --- command='%s'", command);1832 1728 1833 1729 if (offer_to_hack_scripts 1834 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) 1730 && ask_me_yes_or_no("Did you change the mountlist or cloned the system ?")) { 1835 1731 /* interactive mode */ 1836 {1837 1732 mvaddstr_and_log_it(g_currentY, 0, 1838 1733 "Modifying fstab and restoring MBR... "); … … 1843 1738 newtSuspend(); 1844 1739 } 1845 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1740 mr_asprintf(editor, "%s", find_my_editor()); 1741 mr_asprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1742 mr_free(editor); 1743 1846 1744 paranoid_system(tmp); 1745 mr_free(tmp); 1847 1746 if (!g_text_mode) { 1848 1747 newtResume(); 1849 1748 } 1850 // newtCls(); 1851 } 1852 popup_and_get_string("Boot device", 1853 "Please confirm/enter the boot device. If in doubt, try /dev/hda", 1854 boot_device, MAX_STR_LEN / 4); 1855 sprintf(command, "stabraw-me %s", boot_device); 1749 } 1750 popup_and_get_string("Boot device", "Please confirm/enter the boot device. If in doubt, try /dev/hda", boot_device, MAX_STR_LEN / 4); 1751 mr_asprintf(command, "stabraw-me %s", boot_device); 1856 1752 res = run_program_and_log_output(command, 3); 1753 mr_free(command); 1754 1857 1755 if (res) { 1858 1756 done = ask_me_yes_or_no("Modifications failed. Re-try?"); … … 1861 1759 } 1862 1760 } 1863 } else 1761 } else { 1864 1762 /* nuke mode */ 1865 { 1763 mr_asprintf(command, "raw-MR %s "MINDI_CACHE"/mountlist.txt", boot_device); 1764 log_msg(2, "run_raw_mbr() --- command='%s'", command); 1765 1866 1766 mvaddstr_and_log_it(g_currentY, 0, 1867 1767 "Restoring MBR... "); 1868 1768 res = run_program_and_log_output(command, 3); 1769 mr_free(command); 1869 1770 } 1870 1771 if (res) { … … 1875 1776 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 1876 1777 } 1877 paranoid_free(command);1878 1778 paranoid_free(boot_device); 1879 paranoid_free(tmp);1880 paranoid_free(editor);1881 1779 return (res); 1882 1780 } … … 1907 1805 malloc_string(g_mountlist_fname); 1908 1806 malloc_string(g_mondo_home); 1909 /*1910 malloc_string(g_tmpfs_mountpt);1911 */1912 1807 malloc_string(g_isodir_device); 1913 1808 malloc_string(g_isodir_format); … … 1946 1841 FILE *fin; 1947 1842 FILE *fout; 1948 /** malloc **/ 1949 char *incoming; 1950 char *q; 1843 char *incoming = NULL; 1951 1844 1952 1845 assert_string_is_neither_NULL_nor_zerolength(output_file); 1953 1846 assert_string_is_neither_NULL_nor_zerolength(input_file); 1954 malloc_string(incoming);1955 1847 1956 1848 if (!(fin = fopen(input_file, "r"))) { … … 1961 1853 fatal_error("cannot open output_file"); 1962 1854 } 1963 for (q = fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) && (q != NULL); 1964 q = fgets(incoming, MAX_STR_LEN - 1, fin)) { 1855 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) { 1965 1856 if (strncmp(incoming, "etc/adjtime", 11) 1966 1857 && strncmp(incoming, "etc/mtab", 8) … … 1971 1862 && strncmp(incoming, "var/", 4)) 1972 1863 fprintf(fout, "%s", incoming); /* don't need \n here, for some reason.. */ 1973 } 1864 mr_free(incoming); 1865 } 1866 mr_free(incoming); 1974 1867 paranoid_fclose(fout); 1975 1868 paranoid_fclose(fin); 1976 paranoid_free(incoming);1977 1869 } 1978 1870 … … 1989 1881 int i; 1990 1882 /* MALLOC * */ 1991 char *tmp; 1992 1993 malloc_string(tmp); 1883 char *tmp = NULL; 1884 1994 1885 if (does_file_exist("/tmp/NOPAUSE")) { 1995 1886 return; … … 2001 1892 for (i = 0; i < 20; i++) { 2002 1893 g_current_progress = i; 2003 sprintf(tmp, "You have %d seconds left to abort.", 20 - i);1894 mr_asprintf(tmp, "You have %d seconds left to abort.", 20 - i); 2004 1895 update_progress_form(tmp); 1896 mr_free(tmp); 2005 1897 sleep(1); 2006 1898 } 2007 1899 close_progress_form(); 2008 paranoid_free(tmp);2009 1900 } 2010 1901 … … 2024 1915 struct mountlist_itself *mountlist; 2025 1916 int retval = 0, lino, res = 0, i; 2026 char *command ;1917 char *command = NULL; 2027 1918 char *tmp = NULL; 2028 1919 2029 malloc_string(command);