Ignore:
Timestamp:
Sep 20, 2013, 2:29:57 PM (11 years ago)
Author:
Bruno Cornec
Message:

Simplify the interface of mr_getline and mr_asprintf. With 3.1 compatibility now will allow backports from this branch into 3.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/mondo/src/common/libmondo-stream.c

    r3150 r3185  
    242242    int res;
    243243
    244     mr_asprintf(&command, "mt -f %s status", dev);
     244    mr_asprintf(command, "mt -f %s status", dev);
    245245    res = run_program_and_log_output(command, 1);
    246246    mr_free(command);
     
    276276        strcpy(cdr_exe, "dvdrecord");
    277277    }
    278     mr_asprintf(&command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l",
     278    mr_asprintf(command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l",
    279279            cdr_exe);
    280280    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     
    287287        return 1;
    288288    }
    289     mr_asprintf(&command,
     289    mr_asprintf(command,
    290290            "%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",
    291291            cdr_exe);
     
    297297        return 1;
    298298    }
    299     mr_asprintf(&command,
     299    mr_asprintf(command,
    300300            "%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",
    301301            cdr_exe);
     
    383383        }
    384384        if (strstr(fname, "xattr") == NULL) {
    385             mr_asprintf(&tmp,"Wrong order expected xattr, got %s, sunshine.", fname);
     385            mr_asprintf(tmp,"Wrong order expected xattr, got %s, sunshine.", fname);
    386386            fatal_error(tmp);
    387387        }
     
    413413        }
    414414        if (strstr(fname, "acl") == NULL) {
    415             mr_asprintf(&tmp,"Wrong order expected acl, got %s, sunshine.", fname);
     415            mr_asprintf(tmp,"Wrong order expected acl, got %s, sunshine.", fname);
    416416            fatal_error(tmp);
    417417        }
     
    479479    log_it("Insisting on tape #%d", tapeno);
    480480    if (g_current_media_number != tapeno) {
    481         mr_asprintf(&tmp,
     481        mr_asprintf(tmp,
    482482                "When the tape drive goes quiet, please insert volume %d in this series.",
    483483                tapeno);
     
    549549        suffix[0] = '\0';
    550550    }
    551     mr_asprintf(&tmpdir, "%s/tmpfs/backcatalog", td);
     551    mr_asprintf(tmpdir, "%s/tmpfs/backcatalog", td);
    552552    mkdir(tmpdir, 0x700);
    553     mr_asprintf(&command, "cp -f %s %s", latest_fname, tmpdir);
     553    mr_asprintf(command, "cp -f %s %s", latest_fname, tmpdir);
    554554    if (run_program_and_log_output(command, 6)) {
    555555        log_it("Warning - failed to copy %s to backcatalog at %s",
     
    579579
    580580    for (i = curr - 1; i >= 0 && curr - i < 10; i--) {
    581         mr_asprintf(&old_fname, "%s/%s", tmpdir, g_tapecatalog->el[i].fname);
     581        mr_asprintf(old_fname, "%s/%s", tmpdir, g_tapecatalog->el[i].fname);
    582582        unlink(old_fname);
    583583        mr_free(old_fname);
     
    619619        return (0);
    620620    }
    621     mr_asprintf(&tmp, "mt -f %s setblk %ld", bkpinfo->media_device, internal_tape_block_size);
     621    mr_asprintf(tmp, "mt -f %s setblk %ld", bkpinfo->media_device, internal_tape_block_size);
    622622    res = run_program_and_log_output(tmp, 3);
    623623    mr_free(tmp);
     
    688688
    689689    log_it("Skipping OBDR headers");
    690     mr_asprintf(&command, "mt -f %s rewind",bkpinfo->media_device);
     690    mr_asprintf(command, "mt -f %s rewind",bkpinfo->media_device);
    691691    res = run_program_and_log_output(command, 1);
    692692    paranoid_free(command);
    693693
    694     mr_asprintf(&command, "mt -f %s fsf 2",bkpinfo->media_device);
     694    mr_asprintf(command, "mt -f %s fsf 2",bkpinfo->media_device);
    695695    res = run_program_and_log_output(command, 1);
    696696    paranoid_free(command);
     
    715715    log_it("Creating OBDR headers");
    716716    /* OBDR: First block 10 kB of zero bs = 512 */
    717     mr_asprintf(&command, "mt -f %s compression off",bkpinfo->media_device);
     717    mr_asprintf(command, "mt -f %s compression off",bkpinfo->media_device);
    718718    res = run_program_and_log_output(command, 1);
    719719    paranoid_free(command);
    720720
    721     mr_asprintf(&command, "mt -f %s rewind",bkpinfo->media_device);
     721    mr_asprintf(command, "mt -f %s rewind",bkpinfo->media_device);
    722722    res += run_program_and_log_output(command, 1);
    723723    paranoid_free(command);
     
    725725    set_tape_block_size_with_mt(512);
    726726
    727     mr_asprintf(&command, "dd if=/dev/zero of=%s bs=512 count=20",bkpinfo->media_device);
     727    mr_asprintf(command, "dd if=/dev/zero of=%s bs=512 count=20",bkpinfo->media_device);
    728728    res += run_program_and_log_output(command, 1);
    729729    paranoid_free(command);
     
    732732    set_tape_block_size_with_mt(2048);
    733733
    734     mr_asprintf(&command, "dd if=%s of=%s bs=2048",MINDI_CACHE"/mondorescue.iso",bkpinfo->media_device);
     734    mr_asprintf(command, "dd if=%s of=%s bs=2048",MINDI_CACHE"/mondorescue.iso",bkpinfo->media_device);
    735735    res += run_program_and_log_output(command, 1);
    736736    paranoid_free(command);
     
    739739
    740740    /* restore compression mode on */
    741     mr_asprintf(&command, "mt -f %s compression on",bkpinfo->media_device);
     741    mr_asprintf(command, "mt -f %s compression on",bkpinfo->media_device);
    742742    res = run_program_and_log_output(command, 1);
    743743    paranoid_free(command);
     
    805805
    806806    insist_on_this_tape_number(1);
    807     mr_asprintf(&outfname, "%s/tmp/all.tar.gz", bkpinfo->tmpdir);
     807    mr_asprintf(outfname, "%s/tmp/all.tar.gz", bkpinfo->tmpdir);
    808808    make_hole_for_file(outfname);
    809809
     
    874874        // FIXME
    875875    }
    876     mr_asprintf(&tmp, "tar -zxf %s ./tmp/mondo-restore.cfg 2> /dev/null",
     876    mr_asprintf(tmp, "tar -zxf %s ./tmp/mondo-restore.cfg 2> /dev/null",
    877877            outfname);
    878878    paranoid_system(tmp);
     
    904904
    905905    /*  add 'dummy' if testing */
    906     mr_asprintf(&command, "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", cddev, speed, MONDO_LOGFILE, MONDO_LOGFILE);
     906    mr_asprintf(command, "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s", cddev, speed, MONDO_LOGFILE, MONDO_LOGFILE);
    907907    /*  initialise the catalog */
    908908    g_current_media_number = 1;
     
    10781078    }
    10791079    if (orig_size != temp_size && orig_size != -1) {
    1080         mr_asprintf(&tmp, "output file's size should be %ld K but is apparently %ld K", (long) size >> 10, (long) temp_size >> 10);
     1080        mr_asprintf(tmp, "output file's size should be %ld K but is apparently %ld K", (long) size >> 10, (long) temp_size >> 10);
    10811081        log_to_screen(tmp);
    10821082        mr_free(tmp);
     
    11411141    log_msg(6, ".......................... Should be %lld", orig_size);
    11421142    g_tape_posK += total_read_from_tape_for_this_file / 1024;
    1143     mr_asprintf(&actual_cksum, "%04x%04x", crc16, crctt);
     1143    mr_asprintf(actual_cksum, "%04x%04x", crc16, crctt);
    11441144    if (foutstream) {           /*log_it("Finished writing to foutstream"); */
    11451145    } else {
     
    11511151    }
    11521152    if (strcmp(temp_cksum, actual_cksum)) {
    1153         mr_asprintf(&tmp, "actual cksum=%s; recorded cksum=%s", actual_cksum,
     1153        mr_asprintf(tmp, "actual cksum=%s; recorded cksum=%s", actual_cksum,
    11541154                temp_cksum);
    11551155        log_to_screen(tmp);
    11561156        mr_free(tmp);
    11571157
    1158         mr_asprintf(&tmp, "%s (%ld K) is corrupt on tape", temp_fname,
     1158        mr_asprintf(tmp, "%s (%ld K) is corrupt on tape", temp_fname,
    11591159                (long) orig_size >> 10);
    11601160        log_to_screen(tmp);
     
    14941494    insist_on_this_tape_number(g_current_media_number + 1); // will increment g_current_media, too
    14951495    if (bkpinfo->backup_media_type == cdstream) {
    1496         mr_asprintf(&command,
     1496        mr_asprintf(command,
    14971497                "cdrecord -eject dev=%s speed=%d fs=24m -waiti - >> %s 2>> %s",
    14981498                bkpinfo->media_device, bkpinfo->cdrw_speed, MONDO_LOGFILE,
     
    15491549    last = g_tapecatalog->entries - 1;
    15501550    for (i = 0; i <= last; i++) {
    1551         mr_asprintf(&fname, "%s/tmpfs/backcatalog/%s", bkpinfo->tmpdir, g_tapecatalog->el[i].fname);
     1551        mr_asprintf(fname, "%s/tmpfs/backcatalog/%s", bkpinfo->tmpdir, g_tapecatalog->el[i].fname);
    15521552        if (!does_file_exist(fname)) {
    15531553            log_msg(6, "Can't write %s - it doesn't exist.", fname);
     
    16021602    log_it("Data disks = %s", fname);
    16031603    if (!does_file_exist(fname)) {
    1604         mr_asprintf(&tmp, "Cannot find %s", fname);
     1604        mr_asprintf(tmp, "Cannot find %s", fname);
    16051605        log_to_screen(tmp);
    16061606        mr_free(tmp);
     
    17001700        p++;
    17011701    }
    1702     mr_asprintf(&tmp, "Writing file '%s' to tape (%ld KB)", p,
     1702    mr_asprintf(tmp, "Writing file '%s' to tape (%ld KB)", p,
    17031703            (long) filesize >> 10);
    17041704    log_it(tmp);
     
    17451745    }
    17461746    paranoid_fclose(fin);
    1747     mr_asprintf(&checksum, "%04x%04x", crc16, crctt);
     1747    mr_asprintf(checksum, "%04x%04x", crc16, crctt);
    17481748    /* BERLIOS: what does it do ??? */
    17491749    write_header_block_to_stream((off_t)g_current_media_number, checksum, BLK_STOP_FILE);
     
    18081808        fwrite(tempblock, 1, (size_t) TAPE_BLOCK_SIZE,
    18091809               g_tape_stream) / 1024;
    1810     mr_asprintf(&tmp, "%s (fname=%s, size=%ld K)",
     1810    mr_asprintf(tmp, "%s (fname=%s, size=%ld K)",
    18111811            marker_to_string(control_char), p,
    18121812            (long) length_of_incoming_file >> 10);
     
    18371837
    18381838    /*@ end vars *************************************************** */
    1839     mr_asprintf(&tmp, "Wrong marker! (Should be %s, is actually %s)", marker_to_string(should_be), marker_to_string(it_is));
     1839    mr_asprintf(tmp, "Wrong marker! (Should be %s, is actually %s)", marker_to_string(should_be), marker_to_string(it_is));
    18401840    log_to_screen(tmp);
    18411841    mr_free(tmp);
Note: See TracChangeset for help on using the changeset viewer.