Changeset 122


Ignore:
Timestamp:
Nov 15, 2005, 12:01:12 AM (14 years ago)
Author:
bcornec
Message:

memory management going on (libmondo-verify.c, libmondo-devices.c, libmondo-string.c, libmondo-stream.c)

Location:
trunk/mondo/mondo/common
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/common/X-specific.h

    r89 r122  
    11/* X-specific.h */
    2 
    3 #include <config.h>
    42
    53#ifdef __cplusplus
  • trunk/mondo/mondo/common/libmondo-devices.c

    r89 r122  
    18291829    malloc_string(command);
    18301830    malloc_string(comment);
    1831     malloc_string(prompt);
    18321831    assert(bkpinfo != NULL);
    18331832    sz_size[0] = '\0';
  • trunk/mondo/mondo/common/libmondo-stream.c

    r59 r122  
    1 /* libmondo-stream.c
    2    $Id$
     1/* $Id$
    32
    43...tools for talking to tapes, Monitas streams, etc.
    5 
    6 
    7 07/10
    8 - added ACL and XATTR support
    9 
    10 04/17
    11 - added bkpinfo->internal_tape_block_size
    12 - fixed bug in set_tape_block_size_with_mt()
    13 
    14 03/25
    15 - call 'mt' when opening tape in/out, to set block size to 32K
    16 
    17 02/06/2004
    18 - only eject_device() at end of closein_tape() --- not closeout_tape()
    19 
    20 10/26/2003
    21 - call eject_device() at end of closein_tape() and closeout_tape()
    22  
    23 09/25
    24 - added docu-header to each subroutine
    25 
    26 09/20
    27 - working on multi-tape code
    28 - friendlier message in insist_on_this_tape_number()
    29 - delay is now 5s
    30 
    31 09/10
    32 - adding multi-tape support
    33 - adding 'back catalog' of previous archives, so that we may resume
    34   from point of end-of-tape (approx.)
    35 
    36 09/08
    37 - cleaned up insist_on_this_tape_number() --- 10s delay for same tape now
    38 
    39 08/27
    40 - improved find_tape_device_and_size() --- tries /dev/osst*
    41 
    42 05/05
    43 - added Joshua Oreman's FreeBSD patches
    44 
    45 04/24
    46 - added lots of assert()'s and log_OS_error()'s
    47 
    48 04/06/2003
    49 - use find_home_of_exe() instead of which
    50 
    51 12/13/2002
    52 - cdrecord -scanbus call was missing 2> /dev/null
    53 
    54 11/24
    55 - disabled fatal_error("Bad marker")
    56 
    57 10/29
    58 - replaced convoluted grep wih wc (KP)
    59 
    60 09/07
    61 - removed g_end_of_tape_reached
    62 - lots of multitape-related fixes
    63 
    64 08/01 - 08/31
    65 - write 16MB of zeroes to end of tape when closing(out)
    66 - compensate for 'buffer' and its distortion of speed of writing/reading
    67   when writing/reading data disks at start of tape
    68 - rewrote lots of multitape stuff
    69 - wrote workaround to allow >2GB of archives w/buffering
    70 - do not close/reopen tape when starting to read/write from
    71   new tape: no need! 'buffer' handles all that; we're writing
    72   to/reading from a FIFO, so no need to close/reopen when new tape
    73 - write 8MB of zeroes at end of tape, just in case
    74 - re-enable various calls to *_evalcall_form
    75 - added g_end_of_tape_reached
    76 - fixed bugs in start_to_[read|write]_[to|from]_next_tape
    77 - added internal buffering, replacing the external 'buffer' exe
    78 - wait 10 seconds (after user inserts new tape), to
    79   let tape stabilize in drive
    80 - added insist_on_this_tape_number()
    81 - worked on find_tape_device_and_size()
    82 - cleaned up some log_it() calls
    83 - added find_tape_device_and_size()
    84 - replaced using_cdstream with backup_media_type
    85 - replace *_from_tape with *_from_stream
    86 - replace *_to_stream with *_to_stream
    87 
    88 07/01 - 07/31
    89 - leave 32MB at end of tape, to avoid overrunning
    90 - started [07/24/2002]
    914*/
    925
    93 
    94 /**
     6/*
     7 *
    958 * @file
    969 * Functions for writing data to/reading data from streams (tape, CD stream, etc.)
     
    18598    int ctrl_chr = '\0';
    18699
    187     /*@ buffers ***************************************************** */
    188     char fname[MAX_STR_LEN];
    189 
    190100    /*@ long long's ************************************************* */
    191101    long long size;
     
    196106
    197107    log_it("closein_tape() -- entering");
    198     res = read_header_block_from_stream(&size, fname, &ctrl_chr);
     108    res = read_header_block_from_stream(&size, NULL, &ctrl_chr);
    199109    retval += res;
    200110    if (ctrl_chr != BLK_END_OF_BACKUP) {
    201111        wrong_marker(BLK_END_OF_BACKUP, ctrl_chr);
    202112    }
    203     res = read_header_block_from_stream(&size, fname, &ctrl_chr);
     113    res = read_header_block_from_stream(&size, NULL, &ctrl_chr);
    204114    retval += res;
    205115    if (ctrl_chr != BLK_END_OF_TAPE) {
     
    214124    paranoid_pclose(g_tape_stream);
    215125    log_it("closein_tape() -- leaving");
    216 /*
    217   for(i=0; i < g_tapecatalog->entries; i++)
    218     {
    219       log_it("i=%d type=%s num=%d aux=%ld", i, (g_tapecatalog->el[i].type==fileset)?"fileset":"bigslice", g_tapecatalog->el[i].number, g_tapecatalog->el[i].aux);
    220     }
    221 */
    222126    if (!bkpinfo->please_dont_eject) {
    223127        eject_device(bkpinfo->media_device);
     
    241145    /*@ int's ******************************************************* */
    242146    int retval = 0;
    243 //  int res = 0;
    244 //  int ctrl_chr = '\0';
    245 
    246     /*@ buffers ***************************************************** */
    247 //  char fname[MAX_STR_LEN];
    248147
    249148    /*@ long long's ************************************************* */
    250 //  long long size;
    251149    int i;
    252150    char *blk;
     
    262160                                     BLK_END_OF_BACKUP);
    263161    retval += write_header_block_to_stream(0, "end-of-tape", BLK_END_OF_TAPE);  /* just in case */
    264 /* write 1MB of crap */
     162    /* write 1MB of crap */
    265163    for (i = 0; i < 256 * 1024; i++) {
    266164        blk[i] = (int) (random() & 0xFF);
     
    273171        }
    274172    }
    275 /* write 1MB of zeroes */
    276 /*
    277     for (i = 0; i < 256*1024; i++)
    278       {
    279         blk[i] = 0;
    280       }
    281     for (i = 0; i < 4; i++)
    282       {
    283         fwrite (blk, 1, 256*1024, g_tape_stream);
    284         if (should_we_write_to_next_tape (bkpinfo->media_size[g_current_media_number], 256*1024))
    285           {
    286             start_to_write_to_next_tape (bkpinfo);
    287           }
    288       }
    289 */
    290173    sleep(2);
    291174    paranoid_pclose(g_tape_stream);
     
    298181               g_tapecatalog->el[i].tape_posK);
    299182    }
    300     //  if (!bkpinfo->please_dont_eject)
    301     //    { eject_device(bkpinfo->media_device); }
    302183    paranoid_free(blk);
    303184    paranoid_free(g_tapecatalog);
     
    312193    int res;
    313194
    314     malloc_string(command);
    315     sprintf(command, "mt -f %s status", dev);
     195    asprintf(&command, "mt -f %s status", dev);
    316196    res = run_program_and_log_output(command, 1);
    317197    paranoid_free(command);
     
    334214int find_tape_device_and_size(char *dev, char *siz)
    335215{
    336     char tmp[MAX_STR_LEN];
    337     char command[MAX_STR_LEN * 2];
    338     char cdr_exe[MAX_STR_LEN];
    339 //  char tape_description_[MAX_STR_LEN];
    340 //  char tape_manufacturer_cdr[MAX_STR_LEN];
    341 //  FILE*fin;
     216    char *tmp;
     217    char *command;
     218    char *cdr_exe;
    342219    int res;
    343220
     
    345222    dev[0] = siz[0] = '\0';
    346223    if (find_home_of_exe("cdrecord")) {
    347         strcpy(cdr_exe, "cdrecord");
    348     } else {
    349         strcpy(cdr_exe, "dvdrecord");
    350     }
    351     sprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l",
     224        asprintf(&cdr_exe, "cdrecord");
     225    } else {
     226        asprintf(&cdr_exe, "dvdrecord");
     227    }
     228    asprintf(&command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l",
    352229            cdr_exe);
    353     strcpy(tmp, call_program_and_get_last_line_of_output(command));
     230    asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     231    paranoid_free(command);
     232
    354233    if (atoi(tmp) != 1) {
    355234        log_it
     
    358237        return 1;
    359238    }
    360     sprintf(command,
     239    paranoid_free(tmp);
     240
     241    asprintf(&command,
    361242            "%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",
    362243            cdr_exe);
    363     strcpy(tmp, call_program_and_get_last_line_of_output(command));
     244    asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     245    paranoid_free(command);
    364246    if (strlen(tmp) < 2) {
    365247        log_it("Could not find tape device");
    366248        return 1;
    367249    }
    368     sprintf(command,
     250    paranoid_free(tmp);
     251
     252    asprintf(&command,
    369253            "%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",
    370254            cdr_exe);
    371     strcpy(tmp, call_program_and_get_last_line_of_output(command));
     255    paranoid_free(cdr_exe);
     256
     257    asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     258    paranoid_free(command);
    372259    strcpy(dev, VANILLA_SCSI_TAPE);
    373260    dev[strlen(dev) - 1] = '\0';
    374261    strcat(dev, tmp);           // e.g. '/dev/st0' becomes '/dev/stN'
     262    paranoid_free(tmp);
     263
    375264    res = 0;
    376265    if (!mt_says_tape_exists(dev)) {
     
    393282    log_it("At this point, dev = %s and res = %d", dev, res);
    394283
    395     strcpy(tmp, call_program_and_get_last_line_of_output("\
     284    asprintf(&tmp, call_program_and_get_last_line_of_output("\
    396285cdrecord -scanbus 2> /dev/null | tr -s '\t' ' ' | \
    397286grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | \
     
    402291    } else {
    403292        log_it("Turning %s", dev);
    404         strcpy(tmp, (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev);
     293        paranoid_free(tmp);
     294        asprintf(&tmp, (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev);
    405295        sprintf(dev, "/dev/os%s", tmp);
    406296        log_it("...into %s", dev);
     
    427317        return (0);
    428318    }
    429 }
    430 
    431 
    432 
    433 
    434 
     319    paranoid_free(tmp);
     320}
    435321
    436322int read_EXAT_files_from_tape(struct s_bkpinfo *bkpinfo,
     
    441327    int res = 0;
    442328    int retval = 0;
     329    char *fname = &res;     /* Should NOT be NULL */
    443330
    444331// xattr
    445     res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
     332    res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr);
    446333    if (*pctrl_chr != BLK_START_EXAT_FILE) {
    447334        wrong_marker(BLK_START_EXAT_FILE, *pctrl_chr);
    448335    }
    449     if (!strstr(tmp_fname, "xattr")) {
     336    if (!strstr(fname, "xattr")) {
    450337        fatal_error("Wrong order, sunshine.");
    451338    }
     339    paranoid_free(fname);
     340    fname = &res;
    452341    read_file_from_stream_to_file(bkpinfo, xattr_fname, *ptmp_size);
    453     res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
     342    res = read_header_block_from_stream(ptmp_size, NULL, pctrl_chr);
    454343    if (*pctrl_chr != BLK_STOP_EXAT_FILE) {
    455344        wrong_marker(BLK_STOP_EXAT_FILE, *pctrl_chr);
    456345    }
    457 // acl
    458     res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
    459     if (!strstr(tmp_fname, "acl")) {
     346    // acl
     347    res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr);
     348    if (!strstr(fname, "acl")) {
    460349        fatal_error("Wrong order, sunshine.");
    461350    }
     351    paranoid_free(fname);
     352    fname = &res;
    462353    if (*pctrl_chr != BLK_START_EXAT_FILE) {
    463354        wrong_marker(BLK_START_EXAT_FILE, *pctrl_chr);
    464355    }
    465356    read_file_from_stream_to_file(bkpinfo, acl_fname, *ptmp_size);
    466     res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
     357    res = read_header_block_from_stream(ptmp_size, NULL, pctrl_chr);
    467358    if (*pctrl_chr != BLK_STOP_EXAT_FILE) {
    468359        wrong_marker(BLK_STOP_EXAT_FILE, *pctrl_chr);
    469360    }
    470     res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
     361    res = read_header_block_from_stream(ptmp_size, NULL, pctrl_chr);
    471362    if (*pctrl_chr != BLK_STOP_EXTENDED_ATTRIBUTES) {
    472363        wrong_marker(BLK_STOP_EXTENDED_ATTRIBUTES, *pctrl_chr);
    473364    }
    474 // tarball itself
    475     res = read_header_block_from_stream(ptmp_size, tmp_fname, pctrl_chr);
     365    // tarball itself
     366    res = read_header_block_from_stream(ptmp_size, fname, pctrl_chr);
    476367    log_msg(1, "Got xattr and acl; now looking for afioball");
     368    tmp_fname = fname;
    477369    return (retval);
    478370}
     
    483375{
    484376    int res = 0;
    485 // EXATs
     377    // EXATs
    486378    write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname,
    487379                                 BLK_START_EXTENDED_ATTRIBUTES);
    488 // xattr
     380    // xattr
    489381    write_header_block_to_stream(length_of_file(xattr_fname), xattr_fname,
    490382                                 BLK_START_EXAT_FILE);
     
    513405{
    514406    int i;
    515     char tmp[MAX_STR_LEN];
     407    char *tmp;
    516408
    517409    log_it("Insisting on tape #%d", tapeno);
    518410    if (g_current_media_number != tapeno) {
    519411        //      log_it("g_current_media_number = %d", g_current_media_number);
    520         sprintf(tmp,
     412        asprintf(&tmp,
    521413                "When the tape drive goes quiet, please insert volume %d in this series.",
    522414                tapeno);
    523415        popup_and_OK(tmp);
     416        paranoid_free(tmp);
    524417        open_evalcall_form("Waiting while the tape drive settles");
    525418    } else {
     
    540433
    541434
    542 
    543 
    544435/**
    545436 * Debugging aid - log the offset we're at on the tape (reading or writing).
     
    547438void log_tape_pos(void)
    548439{
    549     /*@ buffers ***************************************************** */
    550 
    551 
    552     /*@ end vars *************************************************** */
    553 
    554440    log_it("Tape position -- %ld KB (%ld MB)", (long) g_tape_posK,
    555441           (long) g_tape_posK >> 10);
     
    576462    int last, curr, i;
    577463    t_archtype type = other;
    578     char command[MAX_STR_LEN];
    579     char tmpdir[MAX_STR_LEN];
    580     char old_fname[MAX_STR_LEN];
     464    char *command;
     465    char *tmpdir;
     466    char *old_fname;
    581467    char *p;
     468    /* BERLIOS: useless
    582469    char suffix[16];
     470    */
    583471
    584472    bufsize_K = (long long) (1024LL * (1 + g_tape_buffer_size_MB));
    585     sprintf(tmpdir, "%s/tmpfs/backcatalog", td);
     473    asprintf(&tmpdir, "%s/tmpfs/backcatalog", td);
     474    /* BERLIOS: useless
    586475    if ((p = strrchr(latest_fname, '.'))) {
    587476        strcpy(suffix, ++p);
     
    589478        suffix[0] = '\0';
    590479    }
     480    */
    591481    if (strstr(latest_fname, ".afio.") || strstr(latest_fname, ".star.")) {
    592482        type = fileset;
     
    599489    }
    600490    mkdir(tmpdir, 0x700);
    601     sprintf(command, "cp -f %s %s", latest_fname, tmpdir);
     491    asprintf(&command, "cp -f %s %s", latest_fname, tmpdir);
    602492    if (run_program_and_log_output(command, 6)) {
    603493        log_it("Warning - failed to copy %s to backcatalog at %s",
    604494               latest_fname, tmpdir);
    605495    }
     496    paranoid_free(command);
     497
    606498    last = g_tapecatalog->entries - 1;
    607499    if (last <= 0) {
     
    626518
    627519    for (i = curr - 1; i >= 0 && curr - i < 10; i--) {
    628         sprintf(old_fname, "%s/%s", tmpdir, g_tapecatalog->el[i].fname);
     520        asprintf(&old_fname, "%s/%s", tmpdir, g_tapecatalog->el[i].fname);
    629521        unlink(old_fname);
    630     }
     522        paranoid_free(old_fname);
     523    }
     524    paranoid_free(tmpdir);
    631525    return (0);
    632526}
    633 
    634 
    635527
    636528
     
    646538}
    647539
     540
    648541/**
    649542 * FIFO used to read/write to the tape device.
     
    651544 */
    652545char g_tape_fifo[MAX_STR_LEN];
    653 
    654 
    655546
    656547int set_tape_block_size_with_mt(char *tapedev,
     
    665556        return (0);
    666557    }
    667     malloc_string(tmp);
    668     sprintf(tmp, "mt -f %s setblk %ld", tapedev, internal_tape_block_size);
     558    asprintf(&tmp, "mt -f %s setblk %ld", tapedev, internal_tape_block_size);
    669559    res = run_program_and_log_output(tmp, 3);
    670560    paranoid_free(tmp);
    671561    return (res);
    672562}
    673 
    674563
    675564
     
    685574{
    686575    /*@ buffer ***************************************************** */
    687     char fname[MAX_STR_LEN];
    688576    char *datablock;
    689     char tmp[MAX_STR_LEN];
     577    char *tmp;
    690578    char old_cwd[MAX_STR_LEN];
    691     char outfname[MAX_STR_LEN];
     579    char *outfname;
    692580    /*@ int ******************************************************* */
    693581    int i;
     
    718606    }
    719607    insist_on_this_tape_number(1);
    720     sprintf(outfname, "%s/tmp/all.tar.gz", bkpinfo->tmpdir);
     608    asprintf(&outfname, "%s/tmp/all.tar.gz", bkpinfo->tmpdir);
    721609    make_hole_for_file(outfname);
    722610
     
    765653    paranoid_fclose(fout);
    766654    paranoid_free(datablock);
    767 /* find initial blocks */
    768     res = read_header_block_from_stream(&size, fname, &ctrl_chr);
     655    /* find initial blocks */
     656    res = read_header_block_from_stream(&size, NULL, &ctrl_chr);
    769657    retval += res;
    770658    if (ctrl_chr != BLK_START_OF_TAPE) {
    771659        wrong_marker(BLK_START_OF_TAPE, ctrl_chr);
    772660    }
    773     res = read_header_block_from_stream(&size, fname, &ctrl_chr);
     661    res = read_header_block_from_stream(&size, NULL, &ctrl_chr);
    774662    retval += res;
    775663    if (ctrl_chr != BLK_START_OF_BACKUP) {
     
    780668    (void) getcwd(old_cwd, MAX_STR_LEN);
    781669    chdir(bkpinfo->tmpdir);
    782     sprintf(tmp, "tar -zxf %s tmp/mondo-restore.cfg 2> /dev/null",
     670    asprintf(&tmp, "tar -zxf %s tmp/mondo-restore.cfg 2> /dev/null",
    783671            outfname);
    784672    paranoid_system(tmp);
     673    paranoid_free(tmp);
    785674    paranoid_system("cp -f tmp/mondo-restore.cfg . 2> /dev/null");
    786675    chdir(old_cwd);
    787676    unlink(outfname);
     677    paranoid_free(outfname);
    788678    return (retval);
    789679}
     
    800690{
    801691    /*@ buffers ***************************************************** */
    802     char command[MAX_STR_LEN * 2];
     692    char command;
    803693
    804694    /*@ end vars *************************************************** */
    805695
    806 /*  add 'dummy' if testing */
    807     sprintf(command,
     696    /*  add 'dummy' if testing */
     697    asprintf(&command,
    808698            "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s",
    809699            cddev, speed, MONDO_LOGFILE, MONDO_LOGFILE);
    810 /*  initialise the catalog */
     700    /*  initialise the catalog */
    811701    g_current_media_number = 1;
    812702    if (!(g_tapecatalog = malloc(sizeof(struct s_tapecatalog)))) {
     
    814704    }
    815705    g_tapecatalog->entries = 0;
    816 /* log stuff */
     706    /* log stuff */
    817707    log_it("Opening OUT cdstream with the command");
    818708    log_it(command);
    819 /*  log_it("Let's see what happens, shall we?"); */
     709    /*  log_it("Let's see what happens, shall we?"); */
    820710    g_tape_stream = popen(command, "w");
     711    paranoid_free(command);
    821712    if (g_tape_stream) {
    822713        return (0);
     
    827718}
    828719
     720
    829721/**
    830722 * Start writing to a tape device for the backup.
     
    836728int openout_tape(char *tapedev, long internal_tape_block_size)
    837729{
    838 //  char sz_call_to_buffer[MAX_STR_LEN];
    839 
    840730    g_current_media_number = 1;
    841731    if (g_tape_stream) {
     
    862752
    863753
    864 
    865 
    866754/**
    867755 * Copy a file from the opened stream (CD or tape) to @p outfile.
     
    885773    return (res);
    886774}
    887 
    888775
    889776
     
    907794
    908795    res = read_file_from_stream_FULL(bkpinfo, NULL, fout, size);
    909 /*  fflush(g_tape_stream);
    910   fflush(fout);*/
    911796    return (res);
    912797}
    913 
    914798
    915799
     
    933817    char *tmp;
    934818    char *datablock;
    935     char *temp_fname;
    936     char *temp_cksum;
     819    char *temp_fname = bkpinfo;     /* Should NOT be NULL */
     820    char *temp_cksum = bkpinfo;     /* Should NOT be NULL */
    937821    char *actual_cksum;
    938 //  char *pA, *pB;
    939822
    940823    /*@ int ********************************************************* */
     
    950833
    951834    /*@ long    ***************************************************** */
    952     long bytes_to_write = 0 /*,i */ ;
    953 //  long bytes_successfully_read_in_this_time = 0;
     835    long bytes_to_write = 0;
    954836
    955837    /*@ long long *************************************************** */
     
    959841    long long where_I_was_before_tape_change = 0;
    960842    /*@ unsigned int ************************************************ */
    961     /*  unsigned int ch; */
    962843    unsigned int crc16;
    963844    unsigned int crctt;
     
    966847
    967848    /*@ init  ******************************************************* */
    968     malloc_string(tmp);
    969     malloc_string(temp_fname);
    970     malloc_string(temp_cksum);
    971     malloc_string(actual_cksum);
    972849    datablock = malloc(TAPE_BLOCK_SIZE);
    973850    crc16 = 0;
     
    979856    res = read_header_block_from_stream(&temp_size, temp_fname, &ctrl_chr);
    980857    if (orig_size != temp_size && orig_size != -1) {
    981         sprintf(tmp,
     858        asprintf(&tmp,
    982859                "output file's size should be %ld K but is apparently %ld K",
    983860                (long) size >> 10, (long) temp_size >> 10);
    984861        log_to_screen(tmp);
     862        paranoid_free(tmp);
    985863    }
    986864    if (ctrl_chr != BLK_START_FILE) {
     
    988866        return (1);
    989867    }
    990     sprintf(tmp, "Reading file from tape; writing to '%s'; %ld KB",
     868    asprintf(&tmp, "Reading file from tape; writing to '%s'; %ld KB",
    991869            outfname, (long) size >> 10);
     870    log_to_screen(tmp);
     871    paranoid_free(tmp);
    992872
    993873    if (foutstream) {
     
    1045925    log_msg(6, ".......................... Should be %lld", orig_size);
    1046926    g_tape_posK += total_read_from_tape_for_this_file / 1024;
    1047     sprintf(actual_cksum, "%04x%04x", crc16, crctt);
     927    asprintf(&actual_cksum, "%04x%04x", crc16, crctt);
    1048928    if (foutstream) {           /*log_it("Finished writing to foutstream"); */
    1049929    } else {
     
    1056936    }
    1057937    if (strcmp(temp_cksum, actual_cksum)) {
    1058         sprintf(tmp, "actual cksum=%s; recorded cksum=%s", actual_cksum,
     938        asprintf(&tmp, "actual cksum=%s; recorded cksum=%s", actual_cksum,
    1059939                temp_cksum);
    1060940        log_to_screen(tmp);
    1061         sprintf(tmp, "%s (%ld K) is corrupt on tape", temp_fname,
     941        paranoid_free(tmp);
     942
     943        asprintf(&tmp, "%s (%ld K) is corrupt on tape", temp_fname,
    1062944                (long) orig_size >> 10);
    1063945        log_to_screen(tmp);
     946        paranoid_free(tmp);
    1064947        retval++;
    1065     } else {
    1066         sprintf(tmp, "%s is GOOD on tape", temp_fname);
    1067         /*      log_it(tmp); */
    1068     }
     948    }
     949    paranoid_free(actual_cksum);
    1069950    paranoid_free(datablock);
    1070     paranoid_free(tmp);
    1071951    paranoid_free(temp_fname);
    1072952    paranoid_free(temp_cksum);
    1073     paranoid_free(actual_cksum);
    1074953    return (retval);
    1075954}
    1076 
    1077955
    1078956
     
    1110988                  g_tape_stream) / 1024;
    1111989    }
    1112 /*  memcpy((char*)plength_of_incoming_file,(char*)tempblock+7001,sizeof(long long)); */
    1113 /*  for(*plen=0,i=7;i>=0;i--) {*plen<<=8; *plen |= tempblock[7001+i];} */
    1114990    memcpy((char *) plen, tempblock + 7001, sizeof(long long));
    1115991    if (strcmp(tempblock + 6000 + *pcontrol_char, "Mondolicious, baby")) {
    1116992        log_it("Bad header block at %ld K", (long) g_tape_posK);
    1117993    }
    1118     strcpy(filename, tempblock + 1000);
    1119 /*  strcpy(cksum,tempblock+5555);*/
    1120 /*  log_it( "%s  (reading) fname=%s, filesize=%ld K",
    1121        marker_to_string (*pcontrol_char), filename,
    1122        (long) ((*plen) >> 10));
    1123 */
     994    /* the caller manages whether we should allocate or not
     995     * by setting the value to NULL (do not allocate) or
     996     * something (allocate) */
     997    if (filename != NULL) {
     998        asprintf(&filename, tempblock + 1000);
     999    }
    11241000    if (*pcontrol_char == BLK_ABORTED_BACKUP) {
    11251001        log_to_screen("I can't verify an aborted backup.");
     
    11401016    return (retval);
    11411017}
    1142 
    11431018
    11441019
     
    11861061
    11871062
    1188 
    1189 
    11901063/**
    11911064 * Decide whether we should start a new tape. This is TRUE if we've run out of tape
     
    12371110    int res;
    12381111    int ctrl_chr;
    1239     char *temp_fname;
     1112    char *temp_fname = &res;        /* should NOT be NULL */
    12401113    char *datablock;
    12411114    long long temp_size, size;
     
    12431116
    12441117    datablock = malloc(TAPE_BLOCK_SIZE);
    1245     malloc_string(temp_fname);
    12461118    pB = strrchr(the_file_I_was_reading, '/');
    12471119    if (pB) {
     
    12631135        wrong_marker(BLK_START_AN_AFIO_OR_SLICE, ctrl_chr);
    12641136        log_msg(3, "Still trying to re-sync w/ tape");
     1137        paranoid_free(temp_fname);
     1138        temp_fname = &res;
    12651139    }
    12661140    while (ctrl_chr != BLK_START_FILE) {
     
    12741148        wrong_marker(BLK_START_FILE, ctrl_chr);
    12751149        log_msg(3, "Still trying to re-sync w/ tape");
     1150        /* Do not desallocate when the while condition is met */
     1151        if (ctrl_chr != BLK_START_FILE) {
     1152            paranoid_free(temp_fname);
     1153            temp_fname = &res;
     1154        }
    12761155    }
    12771156    pA = strrchr(temp_fname, '/');
     
    12961175            fread(datablock, 1, (size_t) TAPE_BLOCK_SIZE, g_tape_stream);
    12971176        }
     1177       
     1178        paranoid_free(temp_fname);
     1179        temp_fname = &res;
    12981180        res =
    1299             read_header_block_from_stream(&temp_size, temp_fname,
     1181            read_header_block_from_stream(&temp_size, NULL,
    13001182                                          &ctrl_chr);
    13011183        if (ctrl_chr != BLK_STOP_FILE) {
     
    13031185        }
    13041186        res =
    1305             read_header_block_from_stream(&temp_size, temp_fname,
     1187            read_header_block_from_stream(&temp_size, NULL,
    13061188                                          &ctrl_chr);
    13071189        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
     
    13091191        }
    13101192        res =
    1311             read_header_block_from_stream(&temp_size, temp_fname,
     1193            read_header_block_from_stream(&temp_size, NULL,
    13121194                                          &ctrl_chr);
    13131195        if (ctrl_chr != BLK_START_AN_AFIO_OR_SLICE) {
     
    13261208            pA = temp_fname;
    13271209        }
     1210        /* BERLIOS: useless ?
    13281211        pB = strrchr(the_file_I_was_reading, '/');
    13291212        if (pB) {
     
    13321215            pB = the_file_I_was_reading;
    13331216        }
     1217        */
    13341218    }
    13351219    log_msg(2, "Reading %s (it matches %s)", temp_fname,
     
    13501234    /*@ int ********************************************************* */
    13511235    int res = 0;
    1352     char *sz_msg;
    13531236    int ctrlchr;
    13541237    long long temp_size;
    1355     malloc_string(sz_msg);
    13561238    /*@ end vars *************************************************** */
    13571239
     
    13731255    g_tape_posK = 0;
    13741256    g_sigpipe = FALSE;
    1375     res += read_header_block_from_stream(&temp_size, sz_msg, &ctrlchr); /* just in case */
     1257    res += read_header_block_from_stream(&temp_size, NULL, &ctrlchr);   /* just in case */
    13761258    if (ctrlchr != BLK_START_OF_TAPE) {
    13771259        wrong_marker(BLK_START_OF_TAPE, ctrlchr);
    13781260    }
    1379     res += read_header_block_from_stream(&temp_size, sz_msg, &ctrlchr); /* just in case */
     1261    res += read_header_block_from_stream(&temp_size, NULL, &ctrlchr);   /* just in case */
    13801262    if (ctrlchr != BLK_START_OF_BACKUP) {
    13811263        wrong_marker(BLK_START_OF_BACKUP, ctrlchr);
     
    13831265        log_msg(3, "Next tape opened OK. Whoopee!");
    13841266    }
    1385     paranoid_free(sz_msg);
    13861267    return (res);
    13871268}
    1388 
    13891269
    13901270
     
    13971277{
    13981278    int res = 0;
    1399     char command[MAX_STR_LEN * 2];
     1279    char *command;
     1280
    14001281    paranoid_pclose(g_tape_stream);
    14011282    system("sync");
     
    14091290    }
    14101291    if (bkpinfo->backup_media_type == cdstream) {
    1411         sprintf(command,
     1292        asprintf(&command,
    14121293                "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s",
    14131294                bkpinfo->media_device, bkpinfo->cdrw_speed, MONDO_LOGFILE,
     
    14171298        log_it("Let's see what happens, shall we?");
    14181299        g_tape_stream = popen(command, "w");
     1300        paranoid_free(command);
    14191301        if (!g_tape_stream) {
    14201302            log_to_screen("Failed to openout to cdstream (fifo)");
     
    14381320    return (res);
    14391321}
    1440 
    1441 
    14421322
    14431323
     
    14601340
    14611341    log_msg(2, "I am now writing back catalog to tape");
    1462     malloc_string(fname);
    14631342    last = g_tapecatalog->entries - 1;
    14641343    for (i = 0; i <= last; i++) {
    1465         sprintf(fname, "%s/tmpfs/backcatalog/%s", bkpinfo->tmpdir,
     1344        asprintf(&fname, "%s/tmpfs/backcatalog/%s", bkpinfo->tmpdir,
    14661345                g_tapecatalog->el[i].fname);
    14671346        if (!does_file_exist(fname)) {
     
    14821361            }
    14831362        }
    1484     }
    1485     paranoid_free(fname);
     1363        paranoid_free(fname);
     1364    }
    14861365    log_msg(2, "Finished writing back catalog to tape");
    14871366    return (res);
     
    14891368
    14901369
    1491 
    14921370/**
    14931371 * Write all.tar.gz (produced by Mindi) to the first 32M of the first tape.
     
    14991377    /*@ pointers *************************************************** */
    15001378    FILE *fin;
    1501     char tmp[MAX_STR_LEN];
     1379    char *tmp;
    15021380
    15031381    /*@ long ******************************************************* */
     
    15171395    log_it("Data disks = %s", fname);
    15181396    if (!does_file_exist(fname)) {
    1519         sprintf(tmp, "Cannot find %s", fname);
     1397        asprintf(&tmp, "Cannot find %s", fname);
    15201398        log_to_screen(tmp);
     1399        paranoid_free(tmp);
    15211400        return (1);
    15221401    }
     
    15501429
    15511430
    1552 
    1553 
    15541431/**
    15551432 * Copy @p infile to the opened stream (CD or tape).
     
    15611438{
    15621439    /*@ buffers **************************************************** */
    1563     char tmp[MAX_STR_LEN];
     1440    char *tmp;
    15641441    char datablock[TAPE_BLOCK_SIZE];
    1565     char checksum[MAX_STR_LEN];
     1442    char *checksum;
    15661443    char *infile_basename;
    15671444
     
    15921469    crc16 = 0;
    15931470    crctt = 0;
    1594 
    1595 
    15961471
    15971472    /*@ end vars *************************************************** */
     
    16151490        p++;
    16161491    }
    1617     sprintf(tmp, "Writing file '%s' to tape (%ld KB)", p,
     1492    asprintf(&tmp, "Writing file '%s' to tape (%ld KB)", p,
    16181493            (long) filesize >> 10);
    16191494    log_it(tmp);
     1495    paranoid_free(tmp);
     1496
    16201497    write_header_block_to_stream(filesize, infile_basename,
    16211498                                 BLK_START_FILE);
     
    16561533    }
    16571534    paranoid_fclose(fin);
    1658     sprintf(checksum, "%04x%04x", crc16, crctt);
     1535    asprintf(&checksum, "%04x%04x", crc16, crctt);
    16591536    write_header_block_to_stream(g_current_media_number, checksum,
    16601537                                 BLK_STOP_FILE);
     1538    paranoid_free(checksum);
    16611539//  log_it("File '%s' written to tape.", infile);
    16621540    return (retval);
    16631541}
    1664 
    1665 
    1666 
    16671542
    16681543
     
    16841559    /*@ buffers **************************************************** */
    16851560    char tempblock[TAPE_BLOCK_SIZE];
    1686     char tmp[MAX_STR_LEN];
     1561    char *tmp;
    16871562    char *p;
    16881563
     
    17131588    sprintf(tempblock + 6000 + control_char, "Mondolicious, baby");
    17141589    tempblock[7000] = control_char;
    1715 /*  for(i=0;i<8;i++) {tempblock[7001+i]=olen&0xff; olen>>=8;} */
    17161590    memcpy(tempblock + 7001, (char *) &olen, sizeof(long long));
    1717 /*  if (length_of_incoming_file) {memcpy(tempblock+7001,(char*)&length_of_incoming_file,sizeof(long long));} */
    17181591    strcpy(tempblock + 1000, filename);
    1719 /*  strcpy(tempblock+5555,cksum); */
    17201592    g_tape_posK +=
    17211593        fwrite(tempblock, 1, (size_t) TAPE_BLOCK_SIZE,
    17221594               g_tape_stream) / 1024;
    1723     sprintf(tmp, "%s (fname=%s, size=%ld K)",
     1595    asprintf(&tmp, "%s (fname=%s, size=%ld K)",
    17241596            marker_to_string(control_char), p,
    17251597            (long) length_of_incoming_file >> 10);
    17261598    log_msg(6, tmp);
    1727 /*  log_tape_pos(); */
     1599    paranoid_free(tmp);
    17281600    return (0);
    17291601}
    1730 
    1731 
    1732 
    1733 
    1734 
    1735 
    1736 
    1737 
    17381602
    17391603
     
    17461610{
    17471611    /*@ buffer ***************************************************** */
    1748     char tmp[MAX_STR_LEN];
     1612    char *tmp;
    17491613
    17501614
    17511615    /*@ end vars *************************************************** */
    1752     sprintf(tmp, "Wrong marker! (Should be %s, ",
    1753             marker_to_string(should_be));
    1754     sprintf(tmp + strlen(tmp), "is actually %s)", marker_to_string(it_is));
     1616    asprintf(&tmp, "Wrong marker! (Should be %s, is actually %s)",
     1617            marker_to_string(should_be), marker_to_string(it_is));
    17551618    log_to_screen(tmp);
     1619    paranoid_free(tmp);
    17561620}
    17571621
  • trunk/mondo/mondo/common/libmondo-string.c

    r121 r122  
    10621062
    10631063    /* BERLIOS There is a bug here I can't solve for the moment. If you
    1064      * replace %% in the asprintf below by 'percent' it just works, but
     1064     * replace %% in the format below by 'percent' it just works, but
    10651065     * like this it creates a huge number. Memory pb somewhere */
    10661066    /*
  • trunk/mondo/mondo/common/libmondo-verify.c

    r120 r122  
    608608    char *orig_cksum;
    609609    char *tmp;
    610     char *slice_fnam;
     610    char *slice_fnam = (char *)&res;
    611611
    612612    /*@ pointers ******************************************************** */
     
    616616    long long slice_siz;
    617617
    618     malloc_string(slice_fnam);
    619618    assert(bkpinfo != NULL);
    620619    assert_string_is_neither_NULL_nor_zerolength(biggie_fname);
     
    627626    }
    628627    asprintf(&test_file, "%s/temporary-%s", bkpinfo->tmpdir, p);
    629     /* BERLIOS: useless
    630        asprintf(&tmp,
    631        "Temporarily copying biggiefile %s's slices from tape to '%s'",
    632        p, test_file);
    633        log_it(tmp);
    634        paranoid_free(tmp);
    635      */
     628    asprintf(&tmp,
     629    "Temporarily copying biggiefile %s's slices from tape to '%s'",
     630    p, test_file);
     631    log_it(tmp);
     632    paranoid_free(tmp);
    636633    for (res =
    637634         read_header_block_from_stream(&slice_siz, slice_fnam, &ctrl_chr);
     
    645642        res = read_file_from_stream_to_file(bkpinfo, test_file, slice_siz);
    646643        unlink(test_file);
     644        paranoid_free(slice_fnam);
     645        slice_fnam = (char *)&res;
    647646        res =
    648647            read_header_block_from_stream(&slice_siz, slice_fnam,
     
    654653        current_slice_number++;
    655654        retval += res;
     655        paranoid_free(slice_fnam);
     656        slice_fnam = (char *)&res;
    656657    }
    657658    paranoid_free(test_file);
     
    705706    /*@ buffers ***************************************************** */
    706707    char *tmp;
    707     char *fname;
     708    char *fname = (char *)&res;             /* Should NOT be NULL */
    708709    char *curr_xattr_list_fname;
    709710    char *curr_acl_list_fname;
     
    713714
    714715    assert(bkpinfo != NULL);
    715     malloc_string(fname);
    716716
    717717    asprintf(&curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ,
     
    725725                       "Please wait. This may take a couple of hours.", "",
    726726                       total_afioballs);
    727     res = read_header_block_from_stream(&size, fname, &ctrl_chr);
     727    res = read_header_block_from_stream(&size, NULL, &ctrl_chr);
    728728    if (ctrl_chr != BLK_START_AFIOBALLS) {
    729729        iamhere("YOU SHOULD NOT GET HERE");
     
    731731        if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
    732732            res =
    733                 read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr,
     733                read_EXAT_files_from_tape(bkpinfo, &size, NULL, &ctrl_chr,
    734734                                          curr_xattr_list_fname,
    735735                                          curr_acl_list_fname);
     
    744744    for (res = read_header_block_from_stream(&size, fname, &ctrl_chr);
    745745         ctrl_chr != BLK_STOP_AFIOBALLS;
    746          res = read_header_block_from_stream(&size, fname, &ctrl_chr)) {
     746         res =
     747         read_header_block_from_stream(&size, fname, &ctrl_chr)) {
    747748        asprintf(&curr_xattr_list_fname, XATTR_LIST_FNAME_RAW_SZ,
    748749                 bkpinfo->tmpdir, current_afioball_number);
     
    751752        if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
    752753            iamhere("Reading EXAT files from tape");
     754            paranoid_free(fname);
     755            fname = (char *)&res;
    753756            res =
    754757                read_EXAT_files_from_tape(bkpinfo, &size, fname, &ctrl_chr,
     
    777780        current_afioball_number++;
    778781        g_current_progress++;
     782        paranoid_free(fname);
     783        fname = (char *)&res;
    779784        res = read_header_block_from_stream(&size, fname, &ctrl_chr);
    780785        if (ctrl_chr != BLK_STOP_AN_AFIO_OR_SLICE) {
    781786            wrong_marker(BLK_STOP_AN_AFIO_OR_SLICE, ctrl_chr);
    782787        }
     788        paranoid_free(fname);
     789        fname = (char *)&res;
    783790    }
    784791    log_msg(1, "All done with afioballs");
     
    810817
    811818    /*@ buffers ******************************************************** */
    812     char *orig_fname, *logical_fname;
     819    char *orig_fname = (char *)&ctrl_chr;   /* Should NOT be NULL */
     820    char *logical_fname;
    813821    char *comment;
    814822    char *curr_xattr_list_fname;
     
    821829
    822830    assert(bkpinfo != NULL);
    823     malloc_string(orig_fname);
    824831
    825832    asprintf(&curr_xattr_list_fname, XATTR_BIGGLST_FNAME_RAW_SZ,
     
    829836    asprintf(&comment, "Verifying all bigfiles.");
    830837    log_to_screen(comment);
    831     /*
    832        asprintf(&tmp, "%s/biggielist.txt", bkpinfo->tmpdir);
    833        noof_biggiefiles = count_lines_in_file (tmp); // pointless
    834        paranoid_free(tmp);
    835      */
    836838    res = read_header_block_from_stream(&size, orig_fname, &ctrl_chr);
    837839    if (ctrl_chr != BLK_START_BIGGIEFILES) {
    838840        if (ctrl_chr == BLK_START_EXTENDED_ATTRIBUTES) {
    839841            iamhere("Grabbing the EXAT biggiefiles");
     842            paranoid_free(orig_fname);
     843            orig_fname = (char *)&ctrl_chr;
    840844            res =
    841845                read_EXAT_files_from_tape(bkpinfo, &size, orig_fname,
     
    846850    paranoid_free(curr_xattr_list_fname);
    847851    paranoid_free(curr_acl_list_fname);
     852    paranoid_free(orig_fname);
     853    orig_fname = (char *)&ctrl_chr;
    848854
    849855    if (ctrl_chr != BLK_START_BIGGIEFILES) {
     
    884890        current_biggiefile_number++;
    885891        g_current_progress++;
     892        paranoid_free(orig_fname);
     893        orig_fname = (char *)&ctrl_chr;
    886894    }
    887895    close_progress_form();
    888     paranoid_free(orig_fname);
    889896    return (retval);
    890897}
  • trunk/mondo/mondo/common/mondostructures.h

    r59 r122  
    1818
    1919
    20 /**
     20/*
    2121 * @file
    2222 * The header file defining all of Mondo's structures.
     
    2424
    2525
    26 /** @def MAX_NOOF_MEDIA The maximum number of media that can be used in any one backup. */
    27 
    28 ///* So we can override it in config.h: */
     26/* @def MAX_NOOF_MEDIA The maximum number of media that can be used in any one backup. */
     27
     28/* So we can override it in config.h: */
    2929//#ifndef MAX_NOOF_MEDIA
    3030#define MAX_NOOF_MEDIA 50
  • trunk/mondo/mondo/common/my-stuff.h

    r89 r122  
    1717#define _MY_STUFF_H_
    1818
    19 /* Required for the use of asprintf */
     19/* Required for the use of getline, ... */
    2020#define __USE_GNU
    2121
Note: See TracChangeset for help on using the changeset viewer.