Changeset 2211 in MondoRescue for branches/2.2.9/mondo/src/mondorestore
- Timestamp:
- Jun 3, 2009, 7:10:19 PM (15 years ago)
- Location:
- branches/2.2.9/mondo/src/mondorestore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mondo/src/mondorestore/mondo-prep.c
r2205 r2211 1 1 /*************************************************************************** 2 2 $Id$ 3 ***************************************************************************/ 4 5 /*************************************************************************** 6 * * 7 * This program is free software; you can redistribute it and/or modify * 8 * it under the terms of the GNU General Public License as published by * 9 * the Free Software Foundation; either version 2 of the License, or * 10 * (at your option) any later version. * 11 * * 12 ***************************************************************************/ 13 14 /** 15 * @file 16 * Functions for prepping hard drives: partitioning, formatting, etc. 17 */ 3 * Functions for prepping hard drives: partitioning, formatting, etc. 4 */ 18 5 19 6 20 7 #include "my-stuff.h" 8 #include "mr_mem.h" 21 9 #include "../common/mondostructures.h" 22 10 #include "mondoprep.h" … … 349 337 log_it("%s... so I'll get creative.", tmp); 350 338 if (lvmversion == 2) { 351 asprintf(&tmp1, "tail -n5 %s | grep Insufficient | tail -n1", MONDO_LOGFILE);339 mr_asprintf(&tmp1, "tail -n5 %s | grep Insufficient | tail -n1", MONDO_LOGFILE); 352 340 strcpy(tmp, call_program_and_get_last_line_of_output(tmp1)); 353 341 free(tmp1); 354 342 } else { 355 asprintf(&tmp1, "tail -n5 %s | grep lvcreate | tail -n1", MONDO_LOGFILE);343 mr_asprintf(&tmp1, "tail -n5 %s | grep lvcreate | tail -n1", MONDO_LOGFILE); 356 344 strcpy(tmp, call_program_and_get_last_line_of_output(tmp1)); 357 345 free(tmp1); … … 596 584 } 597 585 // create device list from normal disks followed by spare ones 598 asprintf(&devices, "%s", raidlist->el[i].data_disks.el[0].device);586 mr_asprintf(&devices, "%s", raidlist->el[i].data_disks.el[0].device); 599 587 for (j = 1; j < raidlist->el[i].data_disks.entries; j++) { 600 asprintf(&strtmp, "%s", devices);588 mr_asprintf(&strtmp, "%s", devices); 601 589 paranoid_free(devices); 602 asprintf(&devices, "%s %s", strtmp,590 mr_asprintf(&devices, "%s %s", strtmp, 603 591 raidlist->el[i].data_disks.el[j].device); 604 592 paranoid_free(strtmp); 605 593 } 606 594 for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) { 607 asprintf(&strtmp, "%s", devices);595 mr_asprintf(&strtmp, "%s", devices); 608 596 paranoid_free(devices); 609 asprintf(&devices, "%s %s", strtmp,597 mr_asprintf(&devices, "%s %s", strtmp, 610 598 raidlist->el[i].spare_disks.el[j].device); 611 599 paranoid_free(strtmp); … … 613 601 // translate RAID level 614 602 if (raidlist->el[i].raid_level == -2) { 615 asprintf(&level, "multipath");603 mr_asprintf(&level, "multipath"); 616 604 } else if (raidlist->el[i].raid_level == -1) { 617 asprintf(&level, "linear");605 mr_asprintf(&level, "linear"); 618 606 } else { 619 asprintf(&level, "raid%d", raidlist->el[i].raid_level);607 mr_asprintf(&level, "raid%d", raidlist->el[i].raid_level); 620 608 } 621 609 // create RAID device: … … 624 612 // - faulty devices ignored 625 613 // - persistent superblock always used as this is recommended 626 asprintf(&program,614 mr_asprintf(&program, 627 615 "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d", 628 616 raidlist->el[i].raid_device, level, 629 617 raidlist->el[i].data_disks.entries); 630 618 if (raidlist->el[i].parity != -1) { 631 asprintf(&strtmp, "%s", program);619 mr_asprintf(&strtmp, "%s", program); 632 620 paranoid_free(program); 633 621 switch(raidlist->el[i].parity) { 634 622 case 0: 635 asprintf(&program, "%s --parity=%s", strtmp, "la");623 mr_asprintf(&program, "%s --parity=%s", strtmp, "la"); 636 624 break; 637 625 case 1: 638 asprintf(&program, "%s --parity=%s", strtmp, "ra");626 mr_asprintf(&program, "%s --parity=%s", strtmp, "ra"); 639 627 break; 640 628 case 2: 641 asprintf(&program, "%s --parity=%s", strtmp, "ls");629 mr_asprintf(&program, "%s --parity=%s", strtmp, "ls"); 642 630 break; 643 631 case 3: 644 asprintf(&program, "%s --parity=%s", strtmp, "rs");632 mr_asprintf(&program, "%s --parity=%s", strtmp, "rs"); 645 633 break; 646 634 default: … … 651 639 } 652 640 if (raidlist->el[i].chunk_size != -1) { 653 asprintf(&strtmp, "%s", program);641 mr_asprintf(&strtmp, "%s", program); 654 642 paranoid_free(program); 655 asprintf(&program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size);643 mr_asprintf(&program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size); 656 644 paranoid_free(strtmp); 657 645 } 658 646 if (raidlist->el[i].spare_disks.entries > 0) { 659 asprintf(&strtmp, "%s", program);647 mr_asprintf(&strtmp, "%s", program); 660 648 paranoid_free(program); 661 asprintf(&program, "%s --spare-devices=%d", strtmp,649 mr_asprintf(&program, "%s --spare-devices=%d", strtmp, 662 650 raidlist->el[i].spare_disks.entries); 663 651 paranoid_free(strtmp); 664 652 } 665 asprintf(&strtmp, "%s", program);653 mr_asprintf(&strtmp, "%s", program); 666 654 paranoid_free(program); 667 asprintf(&program, "%s %s", strtmp, devices);655 mr_asprintf(&program, "%s %s", strtmp, devices); 668 656 paranoid_free(strtmp); 669 657 res = run_program_and_log_output(program, 1); … … 690 678 { 691 679 /** int **************************************************************/ 692 int res;693 int retval = 0;694 680 #ifdef __FreeBSD__ 695 681 static bool vinum_started_yet = FALSE; … … 698 684 /** buffers ***********************************************************/ 699 685 char *program; 700 char *tmp; 686 char *tmp = NULL; 687 int res = 0; 688 int retval = 0; 701 689 702 690 /** end ****************************************************************/ 703 691 704 692 malloc_string(program); 705 malloc_string(tmp);706 693 assert_string_is_neither_NULL_nor_zerolength(device); 707 694 assert(format != NULL); 708 695 709 696 if (strstr(format, "raid")) { // do not form RAID disks; do it to /dev/md* instead 710 sprintf(tmp, "Not formatting %s (it is a RAID disk)", device);697 mr_asprintf(&tmp, "Not formatting %s (it is a RAID disk)", device); 711 698 log_it(tmp); 699 paranoid_free(tmp); 712 700 paranoid_free(program); 713 paranoid_free(tmp);714 701 return (0); 715 702 } … … 723 710 #endif 724 711 if (strlen(format) <= 2) { 725 sprintf(tmp,712 mr_asprintf(&tmp, 726 713 "%s has a really small format type ('%s') - this is probably a hexadecimal string, which would suggest the partition is an image --- I shouldn't format it", 727 714 device, format); 728 715 log_it(tmp); 716 paranoid_free(tmp); 729 717 paranoid_free(program); 718 return (0); 719 } 720 if (is_this_device_mounted(device)) { 721 mr_asprintf(&tmp, "%s is mounted - cannot format it ", device); 722 log_to_screen(tmp); 730 723 paranoid_free(tmp); 731 return (0);732 }733 if (is_this_device_mounted(device)) {734 sprintf(tmp, "%s is mounted - cannot format it ", device);735 log_to_screen(tmp);736 724 paranoid_free(program); 737 paranoid_free(tmp);738 725 return (1); 739 726 } … … 762 749 FILE *fin; 763 750 char line[MAX_STR_LEN]; 764 sprintf(tmp, 765 "Initializing Vinum device %s (this may take a *long* time)", 766 device); 751 752 mr_asprintf(&tmp, "Initializing Vinum device %s (this may take a *long* time)", device); 767 753 log_to_screen(tmp); 754 paranoid_free(tmp); 755 768 756 /* format raid partition */ 769 757 // sprintf (program, "mkraid --really-force %s", device); --- disabled -- BB, 02/12/2003 … … 780 768 *(strchr(line, '\n')) = '\0'; // get rid of the \n on the end 781 769 782 sprintf(tmp, "Initializing plex: %s", line);770 mr_asprintf(&tmp, "Initializing plex: %s", line); 783 771 open_evalcall_form(tmp); 784 sprintf(tmp, "vinum init %s", line); 772 paranoid_free(tmp); 773 774 mr_asprintf(&tmp, "vinum init %s", line); 785 775 system(tmp); 776 paranoid_free(tmp); 777 786 778 while (1) { 787 sprintf(tmp,779 mr_asprintf(&tmp, 788 780 "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'", 789 781 line); 790 782 FILE *pin = popen(tmp, "r"); 783 paranoid_free(tmp); 784 791 785 char status[MAX_STR_LEN / 4]; 792 786 fgets(status, MAX_STR_LEN / 4 - 1, pin); … … 806 800 } 807 801 #else 808 sprintf(tmp, "Initializing RAID device %s", device);802 mr_asprintf(&tmp, "Initializing RAID device %s", device); 809 803 log_to_screen(tmp); 804 paranoid_free(tmp); 810 805 811 806 // Shouldn't be necessary. … … 856 851 } 857 852 res = which_format_command_do_i_need(format, program); 858 sprintf(tmp, "%s %s", program, device);853 mr_asprintf(&tmp, "%s %s", program, device); 859 854 if (strstr(program, "kludge")) { 860 strcat(tmp, " /");855 mr_strcat(tmp, " /"); 861 856 } 862 857 sprintf(program, "sh -c 'echo -en \"y\\ny\\ny\\n\" | %s'", tmp); 863 sprintf(tmp, "Formatting %s as %s", device, format); 858 paranoid_free(tmp); 859 860 mr_asprintf(&tmp, "Formatting %s as %s", device, format); 864 861 update_progress_form(tmp); 862 paranoid_free(tmp); 863 865 864 res = run_program_and_log_output(program, FALSE); 865 mr_asprintf(&tmp, ""); 866 866 if (res && strstr(program, "kludge")) { 867 sprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s",867 mr_strcat(tmp, "Kludge failed; using regular mkfs.%s to format %s", 868 868 format, device); 869 869 #ifdef __FreeBSD__ … … 885 885 retval += res; 886 886 if (retval) { 887 strcat(tmp, "...failed");887 mr_strcat(tmp, "...failed"); 888 888 } else { 889 strcat(tmp, "...OK");889 mr_strcat(tmp, "...OK"); 890 890 } 891 891 892 892 log_to_screen(tmp); 893 paranoid_free(tmp); 894 893 895 paranoid_free(program); 894 paranoid_free(tmp);895 896 system("sync"); 896 897 sleep(1); … … 1717 1718 char *tmp; 1718 1719 char *logfile; 1719 char *output ;1720 char *output = NULL; 1720 1721 1721 1722 /** pointers **********************************************************/ … … 1730 1731 malloc_string(tmp); 1731 1732 malloc_string(logfile); 1732 malloc_string(output);1733 1733 1734 1734 assert_string_is_neither_NULL_nor_zerolength(drive); … … 1745 1745 paranoid_free(tmp); 1746 1746 paranoid_free(logfile); 1747 paranoid_free(output);1748 1747 return (0); 1749 1748 } … … 1766 1765 paranoid_free(tmp); 1767 1766 paranoid_free(logfile); 1768 paranoid_free(output);1769 1767 return (1); 1770 1768 /* … … 1786 1784 /* BERLIOS: should not be called each time */ 1787 1785 part_table_fmt = which_partition_format(drive); 1788 output[0] = '\0';1786 mr_asprintf(&output, ""); 1789 1787 /* make it a primary/extended/logical */ 1790 1788 if (partno <= 4) { 1791 sprintf(output + strlen(output), "n\np\n%d\n", partno);1789 mr_strcat(output, "n\np\n%d\n", partno); 1792 1790 } else { 1793 1791 /* MBR needs an extended partition if more than 4 partitions */ … … 1804 1802 return (1); 1805 1803 } else { 1806 sprintf(output + strlen(output), "n\ne\n%d\n\n\n", 1807 prev_partno + 1); 1804 mr_strcat(output, "n\ne\n%d\n\n\n", prev_partno + 1); 1808 1805 } 1809 1806 } 1810 strcat(output + strlen(output), "n\nl\n");1807 mr_strcat(output, "n\nl\n"); 1811 1808 } else { 1812 1809 /* GPT allows more than 4 primary partitions */ 1813 sprintf(output + strlen(output), "n\np\n%d\n", partno);1814 } 1815 } 1816 strcat(output + strlen(output), "\n"); /*start block (ENTER for next free blk */1810 mr_strcat(output, "n\np\n%d\n", partno); 1811 } 1812 } 1813 mr_strcat(output, "\n"); /*start block (ENTER for next free blk */ 1817 1814 if (partsize > 0) { 1818 1815 if (!strcmp(format, "7")) { … … 1820 1817 partsize += 512; 1821 1818 } 1822 sprintf(output + strlen(output), "+%lldK", (long long) (partsize));1823 } 1824 strcat(output + strlen(output), "\n");1819 mr_strcat(output, "+%lldK", (long long) (partsize)); 1820 } 1821 mr_strcat(output, "\n"); 1825 1822 #if 0 1826 1823 /* … … 1864 1861 } 1865 1862 } else { 1866 strcat(output, "w\n\n");1863 mr_strcat(output, "w\n\n"); 1867 1864 if (g_fprep) { 1868 1865 fprintf(g_fprep, "echo \"%s\" | %s\n", output, program); … … 1916 1913 } 1917 1914 } 1915 paranoid_free(output); 1916 1918 1917 g_current_progress++; 1919 1918 log_it("partition_device() --- leaving"); … … 1922 1921 paranoid_free(tmp); 1923 1922 paranoid_free(logfile); 1924 paranoid_free(output);1925 1923 return (retval); 1926 1924 } … … 2032 2030 char *partition; 2033 2031 char *command; 2034 char *output ;2032 char *output = NULL; 2035 2033 char *tmp; 2036 2034 char *partcode; … … 2051 2049 malloc_string(partition); 2052 2050 malloc_string(command); 2053 malloc_string(output);2054 2051 malloc_string(tmp); 2055 2052 malloc_string(partcode); … … 2138 2135 fput_string_one_char_at_a_time(pout_to_fdisk, "p\n"); 2139 2136 } else { 2140 sprintf(output, "t\n%d\n%s\n", partno, partcode); 2141 strcat(output, "w\n"); 2137 mr_asprintf(&output, "t\n%d\n%s\nw\n", partno, partcode); 2142 2138 sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive, 2143 2139 MONDO_LOGFILE, MONDO_LOGFILE); … … 2154 2150 paranoid_pclose(fout); 2155 2151 } 2152 paranoid_free(output); 2156 2153 } 2157 2154 if (res) { … … 2162 2159 paranoid_free(partition); 2163 2160 paranoid_free(command); 2164 paranoid_free(output);2165 2161 paranoid_free(tmp); 2166 2162 paranoid_free(partcode); -
branches/2.2.9/mondo/src/mondorestore/mondo-rstr-compare.c
r1930 r2211 1 1 /*************************************************************************** 2 mondo-compare.c - compares mondoarchive data3 -------------------4 begin : Fri Apr 25 20035 copyright : (C) 2000 by Hugo Rabson6 email : Hugo Rabson <hugorabson@msn.com>7 2 cvsid : $Id$ 8 3 ***************************************************************************/ 9 4 10 /***************************************************************************11 * *12 * This program is free software; you can redistribute it and/or modify *13 * it under the terms of the GNU General Public License as published by *14 * the Free Software Foundation; either version 2 of the License, or *15 * (at your option) any later version. *16 * *17 ***************************************************************************/18 19 /***************************************************************************20 * Change Log *21 ***************************************************************************22 .23 24 25 26 10/21/200327 - changed "/mnt/cdrom" to MNT_CDROM28 29 10/1830 - don't say unknown compressor if no compressor at all31 32 09/1733 - cleaned up logging & conversion-to-changed.txt34 - cleaned up compare_mode()35 36 09/1637 - fixed bad malloc(),free() pairs in compare_a_biggiefile()38 39 09/1440 - compare_mode() --- a couple of strings were the wrong way round,41 e.g. changed.txt and changed.files42 43 05/0544 - exclude /dev/ * from list of changed files45 46 04/3047 - added textonly mode48 49 04/2750 - improved compare_mode() to allow for ISO/cd/crazy people51 52 04/2553 - first incarnation54 */55 56 57 5 #include <pthread.h> 58 6 #include "my-stuff.h" 7 #include "mr_mem.h" 59 8 #include "../common/mondostructures.h" 60 9 #include "../common/libmondo.h" … … 97 46 char *original_cksum_ptr; 98 47 char *bigfile_fname_ptr; 99 char *tmp_ptr ;48 char *tmp_ptr = NULL; 100 49 char *command_ptr; 101 50 … … 117 66 malloc_string(bigfile_fname_ptr); 118 67 malloc_string(command_ptr); 119 malloc_string(tmp_ptr);120 68 121 69 /********************************************************************* … … 126 74 memset(original_cksum_ptr, '\0', sizeof(original_cksum)); 127 75 memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname)); 128 memset(tmp_ptr, '\0', sizeof(tmp));129 76 memset(command_ptr, '\0', sizeof(command)); 130 77 /** end **/ … … 134 81 insist_on_this_cd_number((++g_current_media_number)); 135 82 } else { 136 sprintf(tmp_ptr,83 mr_asprintf(&tmp_ptr, 137 84 "No CD's left. No biggiefiles left. No prob, Bob."); 138 85 log_msg(2, tmp_ptr); 86 paranoid_free(tmp_ptr); 139 87 return (0); 140 88 } 141 89 } 142 90 if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) { 143 sprintf(tmp_ptr,91 mr_asprintf(&tmp_ptr, 144 92 "Cannot open bigfile %ld (%s)'s info file", 145 93 bigfileno + 1, bigfile_fname_ptr); 146 94 log_to_screen(tmp_ptr); 95 paranoid_free(tmp_ptr); 147 96 return (1); 148 97 } … … 156 105 log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum); 157 106 158 sprintf(tmp_ptr, "Comparing %s", bigfile_fname_ptr);159 160 107 if (!g_text_mode) { 108 mr_asprintf(&tmp_ptr, "Comparing %s", bigfile_fname_ptr); 161 109 newtDrawRootText(0, 22, tmp_ptr); 110 paranoid_free(tmp_ptr); 162 111 newtRefresh(); 163 112 } … … 173 122 } 174 123 log_msg(2, command_ptr); 175 sprintf(tmp_ptr, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE);124 mr_asprintf(&tmp_ptr, "cat /tmp/errors >> %s 2> /dev/null", MONDO_LOGFILE); 176 125 paranoid_system(tmp_ptr); 126 paranoid_free(tmp_ptr); 127 177 128 if (system(command_ptr)) { 178 129 log_OS_error("Warning - command failed"); … … 197 148 } 198 149 } 199 sprintf(tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1,150 mr_asprintf(&tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1, 200 151 bigfile_fname_ptr); 201 152 if (!strcmp(checksum_ptr, original_cksum_ptr) != 0) { 202 strcat(tmp_ptr, " ... OK");203 } else { 204 strcat(tmp_ptr, "... changed");153 mr_strcat(tmp_ptr, " ... OK"); 154 } else { 155 mr_strcat(tmp_ptr, "... changed"); 205 156 retval++; 206 157 } 207 158 log_msg(1, tmp_ptr); 159 paranoid_free(tmp_ptr); 160 208 161 if (retval) { 209 162 if (!(fout = fopen(MONDO_CACHE"/changed.txt", "a"))) { … … 222 175 paranoid_free(command_ptr); 223 176 paranoid_free(command); 224 paranoid_free(tmp_ptr);225 177 paranoid_free(tmp); 226 178 … … 302 254 303 255 /*** needs malloc *********/ 304 char *command, *tmp, *filelist_name, *logfile, *archiver_exe,256 char *command, *tmp, *filelist_name, *logfile, 305 257 *compressor_exe; 258 char *archiver_exe = NULL; 306 259 307 260 malloc_string(command); … … 309 262 malloc_string(filelist_name); 310 263 malloc_string(logfile); 311 malloc_string(archiver_exe);312 264 malloc_string(compressor_exe); 313 265 … … 331 283 332 284 if (use_star) { 333 strcpy(archiver_exe, "star");334 } else { 335 strcpy(archiver_exe, "afio");285 mr_asprintf(&archiver_exe, "star"); 286 } else { 287 mr_asprintf(&archiver_exe, "afio"); 336 288 } 337 289 … … 344 296 { 345 297 if (!strcmp(compressor_exe, "bzip2")) { 346 strcat(archiver_exe, " -bz");298 mr_strcat(archiver_exe, " -bz"); 347 299 } else { 348 300 fatal_error … … 373 325 BUFSIZE, compressor_exe, tarball_fname, logfile, logfile); 374 326 } 327 paranoid_free(archiver_exe); 328 375 329 #undef BUFSIZE 376 330 … … 405 359 paranoid_free(filelist_name); 406 360 paranoid_free(logfile); 407 paranoid_free(archiver_exe);408 361 paranoid_free(compressor_exe); 409 362 return (retval); -
branches/2.2.9/mondo/src/mondorestore/mondo-rstr-newt.c
r2209 r2211 1 1 /*************************************************************************** 2 2 * $Id$ 3 */4 5 6 /**7 * @file8 3 * Functions for handling GUI interfaces in the restore. 9 4 */ … … 11 6 #ifdef __FreeBSD__ 12 7 #define OSSWAP(linux,fbsd) fbsd 13 //#include <libgen.h>14 8 #else 15 9 #define OSSWAP(linux,fbsd) linux … … 17 11 18 12 #include "mondo-rstr-newt.h" 13 #include "mr_mem.h" 19 14 20 15 //static char cvsid[] = "$Id$"; … … 1950 1945 assert(raidlist != NULL); 1951 1946 1952 asprintf(&flaws_str_A, "%s", "xxxxxxxxx");1953 asprintf(&flaws_str_B, "%s", "xxxxxxxxx");1954 asprintf(&flaws_str_C, "%s", "xxxxxxxxx");1947 mr_asprintf(&flaws_str_A, "%s", " "); 1948 mr_asprintf(&flaws_str_B, "%s", " "); 1949 mr_asprintf(&flaws_str_C, "%s", " "); 1955 1950 if (mountlist->entries > ARBITRARY_MAXIMUM) { 1956 1951 log_to_screen("Arbitrary limits suck, man!"); -
branches/2.2.9/mondo/src/mondorestore/mondo-rstr-tools.c
r2206 r2211 1 1 /*************************************************************************** 2 2 $Id$ 3 4 ***************************************************************************5 * *6 * This program is free software; you can redistribute it and/or modify *7 * it under the terms of the GNU General Public License as published by *8 * the Free Software Foundation; either version 2 of the License, or *9 * (at your option) any later version. *10 * *11 3 ***************************************************************************/ 12 4 … … 14 6 #include <linux/fd.h> 15 7 #include "my-stuff.h" 8 #include "mr_mem.h" 16 9 #include "../common/mondostructures.h" 17 10 #include "../common/libmondo.h" … … 284 277 int iso_fiddly_bits(bool nuke_me_please) 285 278 { 286 char *mount_isodir_command, *tmp, *command; 279 char *mount_isodir_command = NULL; 280 char *tmp, *command; 287 281 int retval = 0, i; 288 282 bool already_mounted = FALSE; 289 283 290 284 assert(bkpinfo != NULL); 291 malloc_string(mount_isodir_command);292 285 malloc_string(tmp); 293 286 malloc_string(command); … … 295 288 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device); 296 289 if (bkpinfo->disaster_recovery) { 297 /* Patch Conor Daly 26-june-2004 298 * Don't let this clobber an existing bkpinfo->isodir */ 299 if (!bkpinfo->isodir[0]) { 300 strcpy(bkpinfo->isodir, "/tmp/isodir"); 301 } 302 /* End patch */ 303 sprintf(command, "mkdir -p %s", bkpinfo->isodir); 304 run_program_and_log_output(command, 5); 305 log_msg(2, "Setting isodir to %s", bkpinfo->isodir); 306 } 307 308 if (!get_isodir_info 309 (g_isodir_device, g_isodir_format, bkpinfo->isodir, 310 nuke_me_please)) { 311 return (1); 290 /* Patch Conor Daly 26-june-2004 291 * Don't let this clobber an existing bkpinfo->isodir */ 292 if (!bkpinfo->isodir[0]) { 293 strcpy(bkpinfo->isodir, "/tmp/isodir"); 294 } 295 /* End patch */ 296 sprintf(command, "mkdir -p %s", bkpinfo->isodir); 297 run_program_and_log_output(command, 5); 298 log_msg(2, "Setting isodir to %s", bkpinfo->isodir); 299 } 300 301 if (!get_isodir_info(g_isodir_device, g_isodir_format, bkpinfo->isodir, nuke_me_please)) { 302 return (1); 312 303 } 313 304 paranoid_system("umount " MNT_CDROM " 2> /dev/null"); /* just in case */ 314 305 315 306 if (is_this_device_mounted(g_isodir_device)) { 316 log_to_screen("WARNING - isodir is already mounted");317 already_mounted = TRUE;307 log_to_screen("WARNING - isodir is already mounted"); 308 already_mounted = TRUE; 318 309 } else { 319 sprintf(mount_isodir_command, "mount %s", g_isodir_device); 320 if (strlen(g_isodir_format) > 1) { 321 sprintf(mount_isodir_command + strlen(mount_isodir_command), 322 " -t %s", g_isodir_format); 323 } 324 strcat(mount_isodir_command, " -o ro "); 325 strcat(mount_isodir_command, bkpinfo->isodir); 326 run_program_and_log_output("df -m", FALSE); 327 sprintf(tmp, 310 mr_asprintf(&mount_isodir_command, "mount %s", g_isodir_device); 311 if (strlen(g_isodir_format) > 1) { 312 mr_strcat(mount_isodir_command, " -t %s", g_isodir_format); 313 } 314 mr_strcat(mount_isodir_command, " -o ro %s", bkpinfo->isodir); 315 run_program_and_log_output("df -m", FALSE); 316 sprintf(tmp, 328 317 "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", 329 318 mount_isodir_command); 330 log_msg(1, tmp); 331 if (run_program_and_log_output(mount_isodir_command, FALSE)) { 332 popup_and_OK 333 ("Cannot mount the device where the ISO files are stored."); 334 return (1); 335 } 336 log_to_screen 319 log_msg(1, tmp); 320 if (run_program_and_log_output(mount_isodir_command, FALSE)) { 321 popup_and_OK 322 ("Cannot mount the device where the ISO files are stored."); 323 return (1); 324 } 325 paranoid_free(mount_isodir_command); 326 log_to_screen 337 327 ("I have mounted the device where the ISO files are stored."); 338 328 } … … 351 341 log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__, 352 342 bkpinfo->isodir); 353 paranoid_free(mount_isodir_command);354 343 paranoid_free(tmp); 355 344 paranoid_free(command); … … 385 374 386 375 /** malloc **/ 387 char *tmp, *command, *mountdir, *mountpoint, *additional_parameters; 376 char *tmp, *command, *mountdir, *mountpoint; 377 char *additional_parameters = NULL; 388 378 389 379 assert_string_is_neither_NULL_nor_zerolength(device); … … 394 384 malloc_string(mountdir); 395 385 malloc_string(mountpoint); 396 malloc_string(additional_parameters);397 386 398 387 if (!strcmp(mpt, "/1")) { … … 412 401 log_msg(1, tmp); 413 402 /* Deal with additional params only if not /proc or /sys */ 403 mr_asprintf(&additional_parameters, ""); 414 404 if (strcmp(format, "proc") && strcmp(format, "sys")) { 415 405 if (writeable) { 416 strcpy(additional_parameters, "-o rw");406 mr_strcat(additional_parameters, "-o rw"); 417 407 } else { 418 strcpy(additional_parameters, "-o ro");408 mr_strcat(additional_parameters, "-o ro"); 419 409 } 420 410 if (find_home_of_exe("setfattr")) { 421 strcat(additional_parameters, ",user_xattr");411 mr_strcat(additional_parameters, ",user_xattr"); 422 412 } 423 413 if (find_home_of_exe("setfacl")) { 424 strcat(additional_parameters, ",acl");414 mr_strcat(additional_parameters, ",acl"); 425 415 } 426 416 } … … 440 430 log_msg(2, "command='%s'", command); 441 431 } 432 paranoid_free(additional_parameters); 442 433 443 434 res = run_program_and_log_output(command, TRUE); … … 479 470 paranoid_free(mountdir); 480 471 paranoid_free(mountpoint); 481 paranoid_free(additional_parameters);482 472 483 473 return (res); … … 498 488 { 499 489 int retval = 0, lino, res; 500 char *tmp, *these_failed, *format; 501 struct mountlist_itself *mountlist = NULL; 490 char *tmp; 491 char *these_failed = NULL; 492 char *format; 493 struct mountlist_itself *mountlist = NULL; 502 494 503 495 malloc_string(tmp); 504 496 malloc_string(format); 505 malloc_string(these_failed);506 /** menset **/507 these_failed[0] = '\0';508 497 509 498 assert(p_external_copy_of_mountlist != NULL); … … 520 509 "", mountlist->entries); 521 510 511 mr_asprintf(&these_failed, ""); 522 512 for (lino = 0; lino < mountlist->entries; lino++) { 523 513 if (!strcmp(mountlist->el[lino].device, "/proc")) { … … 540 530 retval += res; 541 531 if (res) { 542 strcat(these_failed, mountlist->el[lino].device); 543 strcat(these_failed, " "); 532 mr_strcat(these_failed, "%s ",mountlist->el[lino].device); 544 533 } 545 534 } … … 556 545 ("format and restore *without* partitioning first. Sorry for the inconvenience."); 557 546 } 558 sprintf(tmp, "Could not mount device(s) %s- shall I abort?", 559 these_failed); 547 sprintf(tmp, "Could not mount device(s) %s- shall I abort?", these_failed); 560 548 561 549 if (!ask_me_yes_or_no(tmp)) { … … 573 561 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 574 562 } 563 paranoid_free(these_failed); 564 575 565 /* Also mounting under MNT_RESTORING special FS */ 576 566 (void)mount_device("/proc","/proc","proc",TRUE); … … 580 570 paranoid_free(tmp); 581 571 paranoid_free(format); 582 paranoid_free(these_failed);583 572 return (retval); 584 573 } … … 896 885 read_cfg_var(cfg_file, "acl", value); 897 886 if (strstr(value, "TRUE")) { 898 asprintf(&g_getfacl,"setfacl");887 mr_asprintf(&g_getfacl,"setfacl"); 899 888 log_msg(1, "We will restore ACLs"); 900 889 if (! find_home_of_exe("setfacl")) { … … 904 893 read_cfg_var(cfg_file, "xattr", value); 905 894 if (strstr(value, "TRUE")) { 906 asprintf(&g_getfattr,"setfattr");895 mr_asprintf(&g_getfattr,"setfattr"); 907 896 log_msg(1, "We will restore XATTRs"); 908 897 if (! find_home_of_exe("setfattr")) { … … 1398 1387 * the current /dev location 1399 1388 */ 1400 asprintf(&cmd,"tar cf - /dev | ( cd %s ; tar xf - )",MNT_RESTORING);1389 mr_asprintf(&cmd,"tar cf - /dev | ( cd %s ; tar xf - )",MNT_RESTORING); 1401 1390 run_program_and_log_output(cmd, 3); 1402 1391 paranoid_free(cmd); … … 1410 1399 read_cfg_var(g_mondo_cfg_file, "bootloader.device", device); 1411 1400 read_cfg_var(g_mondo_cfg_file, "bootloader.name", name); 1412 asprintf(&tmp, "run_boot_loader: device='%s', name='%s'", device, name);1401 mr_asprintf(&tmp, "run_boot_loader: device='%s', name='%s'", device, name); 1413 1402 log_msg(2, tmp); 1414 1403 paranoid_free(tmp); … … 1427 1416 #ifdef __FreeBSD__ 1428 1417 else if (!strcmp(name, "BOOT0")) { 1429 asprintf(&tmp, "boot0cfg -B %s", device);1418 mr_asprintf(&tmp, "boot0cfg -B %s", device); 1430 1419 res = run_program_and_log_output(tmp, FALSE); 1431 1420 paranoid_free(tmp); 1432 1421 } else { 1433 asprintf(&tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device);1422 mr_asprintf(&tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device); 1434 1423 if (!system(tmp)) { 1435 1424 paranoid_free(tmp); 1436 asprintf(&tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);1425 mr_asprintf(&tmp, MNT_RESTORING "/sbin/fdisk -B %s", device); 1437 1426 res = run_program_and_log_output(tmp, 3); 1438 1427 } else { … … 2019 2008 int retval = 0, lino, res = 0, i; 2020 2009 char *command; 2021 char *tmp ;2010 char *tmp = NULL; 2022 2011 2023 2012 malloc_string(command); 2024 malloc_string(tmp);2025 2013 assert(p_external_copy_of_mountlist != NULL); 2026 2014 … … 2049 2037 paranoid_system("sync"); 2050 2038 2051 sprintf(tmp, "cp -f %s " MNT_RESTORING "/var/log", MONDO_LOGFILE);2039 mr_asprintf(&tmp, "cp -f %s " MNT_RESTORING "/var/log", MONDO_LOGFILE); 2052 2040 if (run_program_and_log_output(tmp, FALSE)) { 2053 2041 log_msg(1, 2054 2042 "Error. Failed to copy log to PC's /var/log dir. (Mounted read-only?)"); 2055 2043 } 2044 paranoid_free(tmp); 2056 2045 if (does_file_exist("/tmp/DUMBASS-GENTOO")) { 2057 2046 run_program_and_log_output("mkdir -p " MNT_RESTORING … … 2067 2056 continue; 2068 2057 } 2069 sprintf(tmp, "Unmounting device %s ", mountlist->el[lino].device);2058 mr_asprintf(&tmp, "Unmounting device %s ", mountlist->el[lino].device); 2070 2059 2071 2060 update_progress_form(tmp); 2061 2072 2062 if (is_this_device_mounted(mountlist->el[lino].device)) { 2073 2063 if (!strcmp(mountlist->el[lino].mountpoint, "swap")) { … … 2094 2084 res = run_program_and_log_output(command, 3); 2095 2085 } else { 2096 strcat(tmp, "...not mounted anyway :-) OK");2086 mr_strcat(tmp, "...not mounted anyway :-) OK"); 2097 2087 res = 0; 2098 2088 } 2099 2089 g_current_progress++; 2100 2090 if (res) { 2101 strcat(tmp, "...Failed");2091 mr_strcat(tmp, "...Failed"); 2102 2092 retval++; 2103 2093 log_to_screen(tmp); … … 2105 2095 log_msg(2, tmp); 2106 2096 } 2097 paranoid_free(tmp); 2107 2098 } 2108 2099 close_progress_form(); … … 2119 2110 free(mountlist); 2120 2111 paranoid_free(command); 2121 paranoid_free(tmp);2122 2112 return (retval); 2123 2113 } -
branches/2.2.9/mondo/src/mondorestore/mondorestore.c
r2209 r2211 2 2 $Id$ 3 3 restores mondoarchive data 4 The main file for mondorestore. 4 5 ***************************************************************************/ 5 6 /**7 * @file8 * The main file for mondorestore.9 */10 6 11 7 /************************************************************************** … … 14 10 #include <pthread.h> 15 11 #include "my-stuff.h" 12 #include "mr_mem.h" 16 13 #include "../common/mondostructures.h" 17 14 #include "../common/libmondo.h" … … 364 361 365 362 /* Clean up blkid cache file if they exist */ 366 asprintf(&tmp1,"%s/etc/blkid.tab",bkpinfo->restore_path);363 mr_asprintf(&tmp1,"%s/etc/blkid.tab",bkpinfo->restore_path); 367 364 (void)unlink(tmp1); 368 365 paranoid_free(tmp1); 369 asprintf(&tmp1,"%s/etc/blkid.tab.old",bkpinfo->restore_path);366 mr_asprintf(&tmp1,"%s/etc/blkid.tab.old",bkpinfo->restore_path); 370 367 (void)unlink(tmp1); 371 368 paranoid_free(tmp1); … … 379 376 380 377 /* Clean up multiconf cache file if they exist */ 381 asprintf(&tmp1,"%s/var/lib/multipath/bindings",bkpinfo->restore_path);378 mr_asprintf(&tmp1,"%s/var/lib/multipath/bindings",bkpinfo->restore_path); 382 379 (void)unlink(tmp1); 383 380 paranoid_free(tmp1); 384 381 385 382 /* Edit multipath.conf if needed to adapt wwid */ 386 asprintf(&tmp1,"%s/etc/multipath.conf", MNT_RESTORING);383 mr_asprintf(&tmp1,"%s/etc/multipath.conf", MNT_RESTORING); 387 384 if (does_file_exist(tmp1)) { 388 385 log_msg(2, "We may need to clean /etc/multipath.conf"); … … 394 391 395 392 if (bkpinfo->restore_mode != nuke) { 396 asprintf(&editor, "%s", find_my_editor());397 asprintf(&tmp1,"chroot %s %s /etc/multipath.conf", MNT_RESTORING, editor);393 mr_asprintf(&editor, "%s", find_my_editor()); 394 mr_asprintf(&tmp1,"chroot %s %s /etc/multipath.conf", MNT_RESTORING, editor); 398 395 popup_and_OK("You will now edit multipath.conf"); 399 396 if (!g_text_mode) { … … 788 785 assert(raidlist != NULL); 789 786 790 asprintf(&tmpA, "%s", "xxxxxxxxx");791 asprintf(&tmpB, "%s", "xxxxxxxxx");792 asprintf(&tmpC, "%s", "xxxxxxxxx");787 mr_asprintf(&tmpA, "%s", " "); 788 mr_asprintf(&tmpB, "%s", " "); 789 mr_asprintf(&tmpC, "%s", " "); 793 790 794 791 log_msg(2, "nuke_mode --- starting"); … … 1671 1668 1672 1669 /** malloc **/ 1673 char *command ;1670 char *command = NULL; 1674 1671 char *tmp; 1675 1672 char *filelist_name; … … 1685 1682 1686 1683 assert_string_is_neither_NULL_nor_zerolength(tarball_fname); 1687 malloc_string(command);1688 1684 malloc_string(tmp); 1689 1685 malloc_string(filelist_name); … … 1698 1694 use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE; 1699 1695 // sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random()); 1700 sprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);1696 mr_asprintf(&command, "mkdir -p %s/tmp", MNT_RESTORING); 1701 1697 run_program_and_log_output(command, 9); 1698 paranoid_free(command); 1699 1702 1700 sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768), 1703 1701 (int) (random() % 32768)); … … 1783 1781 // if (strstr(tarball_fname, ".star.")) 1784 1782 if (use_star) { 1785 sprintf(command,1783 mr_asprintf(&command, 1786 1784 "star -x -force-remove -U " STAR_ACL_SZ 1787 1785 " errctl= file=%s", tarball_fname); 1788 1786 if (strstr(tarball_fname, ".bz2")) { 1789 strcat(command, " -bz");1787 mr_strcat(command, " -bz"); 1790 1788 } 1791 1789 } else { 1792 1790 if (filelist_subset_fname[0] != '\0') { 1793 sprintf(command,1791 mr_asprintf(&command, 1794 1792 "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s", 1795 1793 TAPE_BLOCK_SIZE, … … 1798 1796 tarball_fname); 1799 1797 } else { 1800 sprintf(command,1798 mr_asprintf(&command, 1801 1799 "afio -i -b %ld -c %ld -M 8m %s %s", 1802 1800 TAPE_BLOCK_SIZE, … … 1804 1802 } 1805 1803 } 1804 1806 1805 #undef BUFSIZE 1807 sprintf(command + strlen(command), " 2>> %s >> %s", temp_log, 1808 temp_log); 1806 mr_strcat(command, " 2>> %s >> %s", temp_log, temp_log); 1809 1807 log_msg(1, "command = '%s'", command); 1810 1808 unlink(temp_log); … … 1818 1816 } 1819 1817 } 1818 paranoid_free(command); 1819 1820 1820 if (res && length_of_file(temp_log) < 5) { 1821 1821 res = 0; … … 1849 1849 } 1850 1850 if (retval) { 1851 sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);1851 mr_asprintf(&command, "cat %s >> %s", temp_log, MONDO_LOGFILE); 1852 1852 system(command); 1853 paranoid_free(command); 1854 1853 1855 log_msg(2, "Errors occurred while processing fileset #%d", 1854 1856 current_tarball_number); … … 1867 1869 1868 1870 leave_sub: 1869 paranoid_free(command);1870 1871 paranoid_free(tmp); 1871 1872 paranoid_free(filelist_name); … … 2249 2250 long max_val; 2250 2251 /**malloc ***/ 2251 char *tmp; 2252 char *tmp = NULL; 2253 char *tmp1 = NULL; 2252 2254 char *tarball_fname; 2253 2255 char *progress_str; … … 2271 2273 read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp); 2272 2274 max_val = atol(tmp) + 1; 2275 paranoid_free(tmp); 2276 2273 2277 sprintf(progress_str, "Restoring from %s #%d", 2274 2278 media_descriptor_string(bkpinfo->backup_media_type), … … 2334 2338 filelist); 2335 2339 } 2336 sprintf(tmp, "%s #%d, fileset #%ld - restore ",2340 mr_asprintf(&tmp1, "%s #%d, fileset #%ld - restore ", 2337 2341 media_descriptor_string(bkpinfo->backup_media_type), 2338 2342 g_current_media_number, current_tarball_number); 2339 2343 if (res) { 2340 strcat(tmp, "reported errors");2344 mr_strcat(tmp1, "reported errors"); 2341 2345 } else if (attempts > 1) { 2342 strcat(tmp, "succeeded");2346 mr_strcat(tmp1, "succeeded"); 2343 2347 } else { 2344 strcat(tmp, "succeeded");2348 mr_strcat(tmp1, "succeeded"); 2345 2349 } 2346 2350 if (attempts > 1) { 2347 sprintf(tmp + strlen(tmp), " (%d attempts) - review logs",2348 attempts);2349 }2350 strcpy(comment, tmp);2351 mr_strcat(tmp1, " (%d attempts) - review logs", attempts); 2352 } 2353 strcpy(comment, tmp1); 2354 paranoid_free(tmp1); 2351 2355 if (attempts > 1) { 2352 2356 log_to_screen(comment); … … 2364 2368 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 2365 2369 } 2366 paranoid_free(tmp);2367 2370 paranoid_free(tarball_fname); 2368 2371 paranoid_free(progress_str);
Note:
See TracChangeset
for help on using the changeset viewer.