Changeset 2520 in MondoRescue
- Timestamp:
- Jan 4, 2010, 7:42:27 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mondo/src/common/libmondo-stream.c
r2240 r2520 233 233 bool mt_says_tape_exists(char *dev) 234 234 { 235 char *command ;235 char *command = NULL; 236 236 int res; 237 237 238 malloc_string(command); 239 sprintf(command, "mt -f %s status", dev); 238 mr_asprintf(&command, "mt -f %s status", dev); 240 239 res = run_program_and_log_output(command, 1); 241 paranoid_free(command); 240 mr_free(command); 241 242 242 if (res) { 243 243 return (FALSE); … … 259 259 { 260 260 char tmp[MAX_STR_LEN]; 261 char command[MAX_STR_LEN * 2];261 char *command = NULL; 262 262 char cdr_exe[MAX_STR_LEN]; 263 263 int res; … … 270 270 strcpy(cdr_exe, "dvdrecord"); 271 271 } 272 sprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l",272 mr_asprintf(&command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l", 273 273 cdr_exe); 274 274 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 275 mr_free(command); 276 275 277 if (atoi(tmp) != 1) { 276 278 log_it … … 279 281 return 1; 280 282 } 281 sprintf(command,283 mr_asprintf(&command, 282 284 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f2 | head -n1", 283 285 cdr_exe); 284 286 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 287 mr_free(command); 288 285 289 if (strlen(tmp) < 2) { 286 290 log_it("Could not find tape device"); 287 291 return 1; 288 292 } 289 sprintf(command,293 mr_asprintf(&command, 290 294 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f3 | cut -d')' -f1 | head -n1", 291 295 cdr_exe); 292 296 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 297 mr_free(command); 298 293 299 strcpy(dev, VANILLA_SCSI_TAPE); 294 300 dev[strlen(dev) - 1] = '\0'; … … 462 468 { 463 469 int i; 464 char tmp[MAX_STR_LEN];470 char *tmp = NULL; 465 471 466 472 log_it("Insisting on tape #%d", tapeno); 467 473 if (g_current_media_number != tapeno) { 468 // log_it("g_current_media_number = %d", g_current_media_number); 469 sprintf(tmp, 474 mr_asprintf(&tmp, 470 475 "When the tape drive goes quiet, please insert volume %d in this series.", 471 476 tapeno); 472 477 popup_and_OK(tmp); 478 mr_free(tmp); 473 479 open_evalcall_form("Waiting while the tape drive settles"); 474 480 } else { … … 525 531 int last, curr, i; 526 532 t_archtype type = other; 527 char command[MAX_STR_LEN];528 char tmpdir[MAX_STR_LEN];529 char old_fname[MAX_STR_LEN];533 char *command = NULL; 534 char *tmpdir = NULL; 535 char *old_fname = NULL; 530 536 char *p; 531 537 char suffix[16]; 532 538 533 539 bufsize_K = (long long) (1024LL * (1 + g_tape_buffer_size_MB)); 534 sprintf(tmpdir, "%s/tmpfs/backcatalog", td);535 540 if ((p = strrchr(latest_fname, '.'))) { 536 541 strcpy(suffix, ++p); … … 547 552 ("Unknown type. Internal error in maintain_collection_of_recent_archives()"); 548 553 } 554 mr_asprintf(&tmpdir, "%s/tmpfs/backcatalog", td); 549 555 mkdir(tmpdir, 0x700); 550 sprintf(command, "cp -f %s %s", latest_fname, tmpdir);556 mr_asprintf(&command, "cp -f %s %s", latest_fname, tmpdir); 551 557 if (run_program_and_log_output(command, 6)) { 552 558 log_it("Warning - failed to copy %s to backcatalog at %s", 553 559 latest_fname, tmpdir); 554 560 } 561 mr_free(command); 562 555 563 last = g_tapecatalog->entries - 1; 556 564 if (last <= 0) { 557 565 log_it("Too early to start deleting from collection."); 566 mr_free(tmpdir); 558 567 return (0); 559 568 } … … 569 578 if (curr < 0) { 570 579 log_it("Not far enough into tape to start deleting old archives from collection."); 580 mr_free(tmpdir); 571 581 return (0); 572 582 } 573 // log_it( "There are %lld KB (more than %d KB) in my backcatalog", final_alleged_writeK - final_actually_certain_writeK, bufsize_K);574 583 575 584 for (i = curr - 1; i >= 0 && curr - i < 10; i--) { 576 sprintf(old_fname, "%s/%s", tmpdir, g_tapecatalog->el[i].fname);585 mr_asprintf(&old_fname, "%s/%s", tmpdir, g_tapecatalog->el[i].fname); 577 586 unlink(old_fname); 578 } 587 mr_free(old_fname); 588 } 589 mr_free(tmpdir); 579 590 return (0); 580 591 } … … 604 615 int set_tape_block_size_with_mt(long internal_tape_block_size) 605 616 { 606 char *tmp ;617 char *tmp = NULL; 607 618 int res; 608 619 … … 612 623 return (0); 613 624 } 614 malloc_string(tmp); 615 sprintf(tmp, "mt -f %s setblk %ld", bkpinfo->media_device, internal_tape_block_size); 625 mr_asprintf(&tmp, "mt -f %s setblk %ld", bkpinfo->media_device, internal_tape_block_size); 616 626 res = run_program_and_log_output(tmp, 3); 617 paranoid_free(tmp);627 mr_free(tmp); 618 628 return (res); 619 629 } … … 748 758 char fname[MAX_STR_LEN]; 749 759 char *datablock; 750 char tmp[MAX_STR_LEN];760 char *tmp = NULL; 751 761 char old_cwd[MAX_STR_LEN]; 752 char outfname[MAX_STR_LEN];762 char *outfname = NULL; 753 763 /*@ int ******************************************************* */ 754 764 int i; … … 793 803 794 804 insist_on_this_tape_number(1); 795 sprintf(outfname, "%s/tmp/all.tar.gz", bkpinfo->tmpdir);805 mr_asprintf(&outfname, "%s/tmp/all.tar.gz", bkpinfo->tmpdir); 796 806 make_hole_for_file(outfname); 797 807 … … 804 814 log_OS_error(g_tape_fifo); 805 815 log_to_screen("Cannot openin stream device"); 816 mr_free(outfname); 806 817 return (1); 807 818 } … … 814 825 log_OS_error(outfname); 815 826 log_to_screen("Cannot openout datadisk all.tar.gz file"); 827 mr_free(outfname); 816 828 return (-1); 817 829 } 818 830 if (!(datablock = (char *) malloc(256 * 1024))) { 819 831 log_to_screen("Unable to malloc 256*1024"); 832 mr_free(outfname); 820 833 finish(1); 821 834 } … … 837 850 paranoid_fclose(fout); 838 851 paranoid_free(datablock); 852 839 853 /* find initial blocks */ 840 854 res = read_header_block_from_stream(&size, fname, &ctrl_chr); … … 852 866 (void) getcwd(old_cwd, MAX_STR_LEN); 853 867 chdir(bkpinfo->tmpdir); 854 sprintf(tmp, "tar -zxf %s ./tmp/mondo-restore.cfg 2> /dev/null",868 mr_asprintf(&tmp, "tar -zxf %s ./tmp/mondo-restore.cfg 2> /dev/null", 855 869 outfname); 856 870 paranoid_system(tmp); 871 mr_free(tmp); 872 857 873 paranoid_system("cp -f tmp/mondo-restore.cfg . 2> /dev/null"); 858 874 chdir(old_cwd); 859 875 unlink(outfname); 876 mr_free(outfname); 860 877 return (retval); 861 878 } … … 872 889 { 873 890 /*@ buffers ***************************************************** */ 874 char command[MAX_STR_LEN * 2];891 char *command = NULL; 875 892 876 893 /*@ end vars *************************************************** */ 877 894 878 /* add 'dummy' if testing */ 879 sprintf(command, 880 "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", 881 cddev, speed, MONDO_LOGFILE, MONDO_LOGFILE); 882 /* initialise the catalog */ 895 /* add 'dummy' if testing */ 896 mr_asprintf(&command, "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", cddev, speed, MONDO_LOGFILE, MONDO_LOGFILE); 897 /* initialise the catalog */ 883 898 g_current_media_number = 1; 884 899 if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) { … … 886 901 } 887 902 g_tapecatalog->entries = 0; 888 /* log stuff */903 /* log stuff */ 889 904 log_it("Opening OUT cdstream with the command"); 890 905 log_it(command); 891 /* log_it("Let's see what happens, shall we?"); */906 /* log_it("Let's see what happens, shall we?"); */ 892 907 g_tape_stream = popen(command, "w"); 908 mr_free(command); 909 893 910 if (g_tape_stream) { 894 911 return (0); … … 898 915 } 899 916 } 917 900 918 901 919 /** … … 1003 1021 { 1004 1022 /*@ buffers ***************************************************** */ 1005 char *tmp ;1023 char *tmp = NULL; 1006 1024 char *datablock; 1007 1025 char *temp_fname; 1008 1026 char *temp_cksum; 1009 char *actual_cksum ;1027 char *actual_cksum = NULL; 1010 1028 // char *pA, *pB; 1011 1029 … … 1038 1056 1039 1057 /*@ init ******************************************************* */ 1040 malloc_string(tmp);1041 1058 malloc_string(temp_fname); 1042 1059 malloc_string(temp_cksum); 1043 malloc_string(actual_cksum);1044 1060 datablock = malloc(TAPE_BLOCK_SIZE); 1045 1061 crc16 = 0; … … 1051 1067 res = read_header_block_from_stream(&temp_size, temp_fname, &ctrl_chr); 1052 1068 if (orig_size != temp_size && orig_size != -1) { 1053 sprintf(tmp, 1054 "output file's size should be %ld K but is apparently %ld K", 1055 (long) size >> 10, (long) temp_size >> 10); 1069 mr_asprintf(&tmp, "output file's size should be %ld K but is apparently %ld K", (long) size >> 10, (long) temp_size >> 10); 1056 1070 log_to_screen(tmp); 1071 mr_free(tmp); 1057 1072 } 1058 1073 if (ctrl_chr != BLK_START_FILE) { … … 1060 1075 return (1); 1061 1076 } 1062 /* Not used1063 sprintf(tmp, "Reading file from tape; writing to '%s'; %ld KB",1064 outfname, (long) size >> 10);1065 */1066 1077 1067 1078 if (foutstream) { … … 1119 1130 log_msg(6, ".......................... Should be %lld", orig_size); 1120 1131 g_tape_posK += total_read_from_tape_for_this_file / 1024; 1121 sprintf(actual_cksum, "%04x%04x", crc16, crctt);1132 mr_asprintf(&actual_cksum, "%04x%04x", crc16, crctt); 1122 1133 if (foutstream) { /*log_it("Finished writing to foutstream"); */ 1123 1134 } else { … … 1127 1138 if (ctrl_chr != BLK_STOP_FILE) { 1128 1139 wrong_marker(BLK_STOP_FILE, ctrl_chr); 1129 // fatal_error("Bad marker"); // return(1);1130 1140 } 1131 1141 if (strcmp(temp_cksum, actual_cksum)) { 1132 sprintf(tmp, "actual cksum=%s; recorded cksum=%s", actual_cksum,1142 mr_asprintf(&tmp, "actual cksum=%s; recorded cksum=%s", actual_cksum, 1133 1143 temp_cksum); 1134 1144 log_to_screen(tmp); 1135 sprintf(tmp, "%s (%ld K) is corrupt on tape", temp_fname, 1145 mr_free(tmp); 1146 1147 mr_asprintf(&tmp, "%s (%ld K) is corrupt on tape", temp_fname, 1136 1148 (long) orig_size >> 10); 1137 1149 log_to_screen(tmp); 1150 mr_free(tmp); 1151 1138 1152 retval++; 1139 } else { 1140 sprintf(tmp, "%s is GOOD on tape", temp_fname); 1141 /* log_it(tmp); */ 1142 } 1153 } 1154 mr_free(actual_cksum); 1155 1143 1156 paranoid_free(datablock); 1144 paranoid_free(tmp);1145 1157 paranoid_free(temp_fname); 1146 1158 paranoid_free(temp_cksum); 1147 paranoid_free(actual_cksum);1148 1159 return (retval); 1149 1160 } … … 1473 1484 { 1474 1485 int res = 0; 1475 char command[MAX_STR_LEN * 2]; 1486 char *command = NULL; 1487 1476 1488 paranoid_pclose(g_tape_stream); 1477 1489 system("sync"); … … 1485 1497 } 1486 1498 if (bkpinfo->backup_media_type == cdstream) { 1487 sprintf(command,1499 mr_asprintf(&command, 1488 1500 "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", 1489 1501 bkpinfo->media_device, bkpinfo->cdrw_speed, MONDO_LOGFILE, … … 1493 1505 log_it("Let's see what happens, shall we?"); 1494 1506 g_tape_stream = popen(command, "w"); 1507 mr_free(command); 1508 1495 1509 if (!g_tape_stream) { 1496 1510 log_to_screen("Failed to openout to cdstream (fifo)"); … … 1533 1547 { 1534 1548 int i, last, res = 0; 1535 char *fname ;1549 char *fname = NULL; 1536 1550 1537 1551 log_msg(2, "I am now writing back catalog to tape"); 1538 malloc_string(fname);1539 1552 last = g_tapecatalog->entries - 1; 1540 1553 for (i = 0; i <= last; i++) { 1541 sprintf(fname, "%s/tmpfs/backcatalog/%s", bkpinfo->tmpdir, 1542 g_tapecatalog->el[i].fname); 1554 mr_asprintf(&fname, "%s/tmpfs/backcatalog/%s", bkpinfo->tmpdir, g_tapecatalog->el[i].fname); 1543 1555 if (!does_file_exist(fname)) { 1544 1556 log_msg(6, "Can't write %s - it doesn't exist.", fname); … … 1558 1570 } 1559 1571 } 1560 }1561 paranoid_free(fname);1572 mr_free(fname); 1573 } 1562 1574 log_msg(2, "Finished writing back catalog to tape"); 1563 1575 return (res); … … 1575 1587 /*@ pointers *************************************************** */ 1576 1588 FILE *fin; 1577 char tmp[MAX_STR_LEN];1589 char *tmp = NULL; 1578 1590 1579 1591 /*@ long ******************************************************* */ … … 1593 1605 log_it("Data disks = %s", fname); 1594 1606 if (!does_file_exist(fname)) { 1595 sprintf(tmp, "Cannot find %s", fname);1607 mr_asprintf(&tmp, "Cannot find %s", fname); 1596 1608 log_to_screen(tmp); 1609 mr_free(tmp); 1597 1610 return (1); 1598 1611 } … … 1637 1650 { 1638 1651 /*@ buffers **************************************************** */ 1639 char tmp[MAX_STR_LEN];1652 char *tmp = NULL; 1640 1653 char datablock[TAPE_BLOCK_SIZE]; 1641 char checksum[MAX_STR_LEN];1654 char *checksum = NULL; 1642 1655 char *infile_basename; 1643 1656 … … 1690 1703 p++; 1691 1704 } 1692 sprintf(tmp, "Writing file '%s' to tape (%ld KB)", p,1705 mr_asprintf(&tmp, "Writing file '%s' to tape (%ld KB)", p, 1693 1706 (long) filesize >> 10); 1694 1707 log_it(tmp); 1708 mr_free(tmp); 1695 1709 write_header_block_to_stream(filesize, infile_basename, 1696 1710 BLK_START_FILE); … … 1732 1746 } 1733 1747 paranoid_fclose(fin); 1734 sprintf(checksum, "%04x%04x", crc16, crctt);1748 mr_asprintf(&checksum, "%04x%04x", crc16, crctt); 1735 1749 /* BERLIOS: what does it do ??? */ 1736 write_header_block_to_stream((off_t)g_current_media_number, checksum, 1737 BLK_STOP_FILE); 1750 write_header_block_to_stream((off_t)g_current_media_number, checksum, BLK_STOP_FILE); 1751 mr_free(checksum); 1752 1738 1753 // log_it("File '%s' written to tape.", infile); 1739 1754 return (retval); … … 1761 1776 /*@ buffers **************************************************** */ 1762 1777 char tempblock[TAPE_BLOCK_SIZE]; 1763 char tmp[MAX_STR_LEN];1778 char *tmp = NULL; 1764 1779 char *p; 1765 1780 … … 1789 1804 sprintf(tempblock + 6000 + control_char, STR_HEADER); 1790 1805 tempblock[7000] = control_char; 1791 /* for(i=0;i<8;i++) {tempblock[7001+i]=olen&0xff; olen>>=8;} */1792 1806 memcpy(tempblock + 7001, (char *) &olen, sizeof(off_t)); 1793 /* if (length_of_incoming_file) {memcpy(tempblock+7001,(char*)&length_of_incoming_file,sizeof(long long));} */1794 1807 strcpy(tempblock + 1000, filename); 1795 /* strcpy(tempblock+5555,cksum); */1796 1808 g_tape_posK += 1797 1809 fwrite(tempblock, 1, (size_t) TAPE_BLOCK_SIZE, 1798 1810 g_tape_stream) / 1024; 1799 sprintf(tmp, "%s (fname=%s, size=%ld K)",1811 mr_asprintf(&tmp, "%s (fname=%s, size=%ld K)", 1800 1812 marker_to_string(control_char), p, 1801 1813 (long) length_of_incoming_file >> 10); 1802 1814 log_msg(6, tmp); 1803 /* log_tape_pos(); */ 1815 mr_free(tmp); 1804 1816 return (0); 1805 1817 } … … 1822 1834 { 1823 1835 /*@ buffer ***************************************************** */ 1824 char tmp[MAX_STR_LEN];1836 char *tmp = NULL; 1825 1837 1826 1838 1827 1839 /*@ end vars *************************************************** */ 1828 sprintf(tmp, "Wrong marker! (Should be %s, ", 1829 marker_to_string(should_be)); 1830 sprintf(tmp + strlen(tmp), "is actually %s)", marker_to_string(it_is)); 1840 mr_asprintf(&tmp, "Wrong marker! (Should be %s, is actually %s)", marker_to_string(should_be), marker_to_string(it_is)); 1831 1841 log_to_screen(tmp); 1842 mr_free(tmp); 1832 1843 } 1833 1844
Note:
See TracChangeset
for help on using the changeset viewer.