Changeset 900 in MondoRescue for trunk/mondo/src/common/libmondo-fork.c


Ignore:
Timestamp:
Oct 24, 2006, 8:49:18 AM (18 years ago)
Author:
Bruno Cornec
Message:

Huge patch to introduce low level functions that will bw used everywhere (mr_free, mr_asprintf, ...)
Nearly linking now due to that.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/src/common/libmondo-fork.c

    r783 r900  
    1010#include "libmondo-files-EXT.h"
    1111#include "libmondo-tools-EXT.h"
     12#include "mr_mem.h"
    1213
    1314extern bool g_text_mode;
     
    3031
    3132    if ((fin = popen(call, "r"))) {
    32         for (getline(&result, &n, fin); !feof(fin); getline(&result, &n, fin));
     33        for (mr_getline(&result, &n, fin); !feof(fin); mr_getline(&result, &n, fin));
    3334        paranoid_pclose(fin);
    3435    } else {
     
    8990    }
    9091
    91     asprintf(&cd_number_str, "%d", cd_no);
     92    mr_asprintf(&cd_number_str, "%d", cd_no);
    9293    resolve_naff_tokens(midway_call, basic_call, isofile, "_ISO_");
    9394    resolve_naff_tokens(tmp, midway_call, cd_number_str, "_CD#_");
    94     paranoid_free(cd_number_str);
     95    mr_free(cd_number_str);
    9596
    9697    resolve_naff_tokens(ultimate_call, tmp, MONDO_LOGFILE, "_ERR_");
     
    99100    log_msg(4, "tmp = '%s'", tmp);
    100101    log_msg(4, "ultimate call = '%s'", ultimate_call);
    101     asprintf(&command, "%s >> %s", ultimate_call, MONDO_LOGFILE);
     102    mr_asprintf(&command, "%s >> %s", ultimate_call, MONDO_LOGFILE);
    102103
    103104    log_to_screen
     
    138139            (what_i_am_doing, command);
    139140    }
    140     paranoid_free(command);
    141 
    142     paranoid_free(midway_call);
    143     paranoid_free(ultimate_call);
    144     paranoid_free(tmp);
     141    mr_free(command);
     142
     143    mr_free(midway_call);
     144    mr_free(ultimate_call);
     145    mr_free(tmp);
    145146    return (retval);
    146147}
     
    181182        log_if_failure = TRUE;
    182183    }
    183     asprintf(&callstr,
     184    mr_asprintf(&callstr,
    184185            "%s > /tmp/mondo-run-prog-thing.tmp 2> /tmp/mondo-run-prog-thing.err",
    185186            program);
     
    198199                "--------------------------------start of output-----------------------------");
    199200    }
    200     paranoid_free(callstr);
     201    mr_free(callstr);
    201202
    202203    if (log_if_failure
     
    210211    fin = fopen("/tmp/mondo-run-prog-thing.tmp", "r");
    211212    if (fin) {
    212         for (getline(&incoming, &n, fin); !feof(fin);
    213              getline(&incoming, &n, fin)) {
     213        for (mr_getline(&incoming, &n, fin); !feof(fin);
     214             mr_getline(&incoming, &n, fin)) {
    214215            /* patch by Heiko Schlittermann */
    215216            p = incoming;
     
    227228            }
    228229        }
    229         paranoid_free(incoming);
     230        mr_free(incoming);
    230231        paranoid_fclose(fin);
    231232    }
     
    273274    assert_string_is_neither_NULL_nor_zerolength(basic_call);
    274275
    275     asprintf(&lockfile, "/tmp/mojo-jojo.blah.XXXXXX");
     276    mr_asprintf(&lockfile, "/tmp/mojo-jojo.blah.XXXXXX");
    276277    mkstemp(lockfile);
    277     asprintf(&command,
     278    mr_asprintf(&command,
    278279            "echo hi > %s ; %s >> %s 2>> %s; res=$?; sleep 1; rm -f %s; exit $res",
    279280            lockfile, basic_call, MONDO_LOGFILE, MONDO_LOGFILE, lockfile);
    280281    open_evalcall_form(what_i_am_doing);
    281     asprintf(&tmp, "Executing %s", basic_call);
     282    mr_asprintf(&tmp, "Executing %s", basic_call);
    282283    log_msg(2, tmp);
    283     paranoid_free(tmp);
     284    mr_free(tmp);
    284285
    285286    if (!(fin = popen(command, "r"))) {
    286287        log_OS_error("Unable to popen-in command");
    287         asprintf(&tmp, _("Failed utterly to call '%s'"), command);
     288        mr_asprintf(&tmp, _("Failed utterly to call '%s'"), command);
    288289        log_to_screen(tmp);
    289         paranoid_free(tmp);
    290         paranoid_free(lockfile);
    291         paranoid_free(command);
     290        mr_free(tmp);
     291        mr_free(lockfile);
     292        mr_free(command);
    292293        return (1);
    293294    }
    294     paranoid_free(command);
     295    mr_free(command);
    295296
    296297    if (!does_file_exist(lockfile)) {
     
    320321    close_evalcall_form();
    321322    unlink(lockfile);
    322     paranoid_free(lockfile);
     323    mr_free(lockfile);
    323324
    324325    return (retval);
     
    357358        fin = f_orig;
    358359        fout = f_archived;
    359         asprintf(&tmp, "%-64s", PIMP_START_SZ);
     360        mr_asprintf(&tmp, "%-64s", PIMP_START_SZ);
    360361        if (fwrite(tmp, 1, 64, fout) != 64) {
    361362            fatal_error("Can't write the introductory block");
    362363        }
    363         paranoid_free(tmp);
     364        mr_free(tmp);
    364365
    365366        while (1) {
     
    368369                break;
    369370            }
    370             asprintf(&tmp, "%-64ld", bytes_read_in);
     371            mr_asprintf(&tmp, "%-64ld", bytes_read_in);
    371372            if (fwrite(tmp, 1, 64, fout) != 64) {
    372373                fatal_error("Cannot write introductory block");
    373374            }
    374             paranoid_free(tmp);
     375            mr_free(tmp);
    375376
    376377            log_msg(7,
     
    378379                    subsliceno, bytes_read_in, bytes_to_be_read);
    379380            bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
    380             asprintf(&tmp, "%-64ld", subsliceno);
     381            mr_asprintf(&tmp, "%-64ld", subsliceno);
    381382            if (fwrite(tmp, 1, 64, fout) != 64) {
    382383                fatal_error("Cannot write post-thingy block");
    383384            }
    384             paranoid_free(tmp);
     385            mr_free(tmp);
    385386
    386387            log_msg(7, "Subslice #%d written OK", subsliceno);
    387388            subsliceno++;
    388389        }
    389         asprintf(&tmp, "%-64ld", 0L);
     390        mr_asprintf(&tmp, "%-64ld", 0L);
    390391        if (fwrite(tmp, 1, 64L, fout) != 64L) {
    391392            fatal_error("Cannot write final introductory block");
     
    436437
    437438    if (direction == 'w') {
    438         paranoid_free(tmp);
    439         asprintf(&tmp, "%-64s", PIMP_END_SZ);
     439        mr_free(tmp);
     440        mr_asprintf(&tmp, "%-64s", PIMP_END_SZ);
    440441        if (fwrite(tmp, 1, 64L, fout) != 64L) {
    441442            fatal_error("Can't write the final block");
    442443        }
    443         paranoid_free(tmp);
     444        mr_free(tmp);
    444445    } else {
    445446        log_msg(1, "tmpA is %s", tmp);
     
    456457                fwrite(tmp, 1, bytes_read_in, ftmp);
    457458               
    458                 paranoid_free(tmp);
     459                mr_free(tmp);
    459460                if (!(tmp = malloc(512))) {
    460461                    fatal_error("Failed to malloc() tmp");
     
    471472            }
    472473        }
    473         paranoid_free(tmp);
    474     }
    475 
    476     paranoid_free(buf);
     474        mr_free(tmp);
     475    }
     476
     477    mr_free(buf);
    477478    log_msg(3, "Successfully copied %ld bytes", bytes_written_out);
    478479    return (retval);
     
    499500        fatal_error("ntfsclone not found");
    500501    }
    501     paranoid_free(tmp);
    502 
    503     asprintf(&command, "ntfsclone --force --save-image --overwrite %s %s", output_fname, input_device);
     502    mr_free(tmp);
     503
     504    mr_asprintf(&command, "ntfsclone --force --save-image --overwrite %s %s", output_fname, input_device);
    504505    res = run_program_and_log_output(command, 5);
    505     paranoid_free(command);
     506    mr_free(command);
    506507
    507508    unlink(output_fname);
     
    526527
    527528    tempfile = call_program_and_get_last_line_of_output("mktemp -q /tmp/mondo.XXXXXXXX");
    528     asprintf(&command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
     529    mr_asprintf(&command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
    529530            tempfile);
    530531    log_msg(3, command);
     
    533534    if (!(pin = popen(command, "r"))) {
    534535        log_OS_error("fmt err");
    535         paranoid_free(command);
    536         paranoid_free(tempfile);
     536        mr_free(command);
     537        mr_free(tempfile);
    537538        return (1);
    538539    }
    539     paranoid_free(command);
     540    mr_free(command);
    540541
    541542    maxpc = 100;
     
    562563    }
    563564    unlink(tempfile);
    564     paranoid_free(tempfile);
     565    mr_free(tempfile);
    565566    return (res);
    566567}
     
    608609    *pchild_result = 999;
    609610
    610     asprintf(&command, "%s 2>> %s", cmd, MONDO_LOGFILE);
     611    mr_asprintf(&command, "%s 2>> %s", cmd, MONDO_LOGFILE);
    611612    log_msg(3, "command = '%s'", command);
    612613    if ((res =
     
    636637        update_evalcall_form(percentage);
    637638    }
    638     paranoid_free(command);
     639    mr_free(command);
    639640
    640641    log_file_end_to_screen(MONDO_LOGFILE, "");
     
    668669        fatal_error("ntfsclone not found");
    669670    }
    670     paranoid_free(tmp);
    671 
    672     asprintf(&command, "ntfsclone --force --restore-image --overwrite %s %s", output_device, input_fifo);
     671    mr_free(tmp);
     672
     673    mr_asprintf(&command, "ntfsclone --force --restore-image --overwrite %s %s", output_device, input_fifo);
    673674    res = run_program_and_log_output(command, 5);
    674     paranoid_free(command);
     675    mr_free(command);
    675676    return (res);
    676677}
Note: See TracChangeset for help on using the changeset viewer.