Changeset 2211


Ignore:
Timestamp:
Jun 3, 2009, 7:10:19 PM (11 years ago)
Author:
Bruno Cornec
Message:

r3089@localhost: bruno | 2009-05-18 06:41:05 +0200

  • move call to asprintf to call to mr_asprintf (suppress a compiler warning)
  • remove all the most obvious bad call to strcat and replace by mr_strcat as appropriate
Location:
branches/2.2.9/mondo
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mondo/src/common/libmondo-archive.c

    r2202 r2211  
    1212
    1313#include "my-stuff.h"
     14#include "mr_mem.h"
    1415#include "mondostructures.h"
    1516#include "libmondo-string-EXT.h"
     
    192193    unsigned int res = 0;
    193194    int tries = 0;
    194     char *command;
    195     char *zipparams;
    196     char *tmp;
     195    char *command = NULL;
     196    char *tmp = NULL;
    197197    char *p;
    198198
    199     malloc_string(command);
    200     malloc_string(zipparams);
    201     malloc_string(tmp);
    202199
    203200    if (!does_file_exist(filelist)) {
    204         sprintf(tmp, "(archive_this_fileset) - filelist %s does not exist",
    205                 filelist);
     201        mr_asprintf(&tmp, "(archive_this_fileset) - filelist %s does not exist", filelist);
    206202        log_to_screen(tmp);
     203        paranoid_free(tmp);
    207204        return (1);
    208205    }
    209206
    210     sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
     207    mr_asprintf(&tmp, "echo hi > %s 2> /dev/null", fname);
    211208    if (system(tmp)) {
     209        paranoid_free(tmp);
    212210        fatal_error("Unable to write tarball to scratchdir");
    213211    }
    214 
    215     sprintf(command, "star H=star list=%s -c " STAR_ACL_SZ " file=%s",
     212    paranoid_free(tmp);
     213
     214    mr_asprintf(&command, "star H=star list=%s -c " STAR_ACL_SZ " file=%s",
    216215            filelist, fname);
    217216    if (bkpinfo->use_lzo) {
     
    219218    }
    220219    if (bkpinfo->compression_level > 0) {
    221         strcat(command, " -bz");
    222     }
    223     sprintf(command + strlen(command), " 2>> %s", MONDO_LOGFILE);
     220        mr_strcat(command, " -bz");
     221    }
     222    mr_strcat(command, " 2>> %s", MONDO_LOGFILE);
    224223    log_msg(4, "command = '%s'", command);
    225224
     
    227226        log_msg(5, "command='%s'", command);
    228227        res = system(command);
    229         strcpy(tmp, last_line_of_file(MONDO_LOGFILE));
     228        mr_asprintf(&tmp, last_line_of_file(MONDO_LOGFILE));
    230229        log_msg(1, "res=%d; tmp='%s'", res, tmp);
    231230        if (bkpinfo->use_star && (res == 254 || res == 65024)
     
    235234            res = 0;
    236235        }
     236        paranoid_free(tmp);
     237
    237238        if (res) {
    238239            log_OS_error(command);
     
    249250        }
    250251    }
     252    paranoid_free(command);
     253
    251254    retval += res;
    252255    if (retval) {
     
    256259                tries);
    257260    }
    258 
    259     paranoid_free(command);
    260     paranoid_free(zipparams);
    261     paranoid_free(tmp);
    262261    return (retval);
    263262}
     
    294293
    295294    /*@ buffers ************************************************************ */
    296     char *command;
    297     char *zipparams;
    298     char *tmp;
     295    char *command = NULL;
     296    char *zipparams = NULL;
     297    char *tmp = NULL;
    299298
    300299    assert(bkpinfo != NULL);
     
    306305    }
    307306
    308     malloc_string(command);
    309     malloc_string(zipparams);
    310     malloc_string(tmp);
    311 
    312307    if (!does_file_exist(filelist)) {
    313         sprintf(tmp, "(archive_this_fileset) - filelist %s does not exist",
     308        mr_asprintf(&tmp, "(archive_this_fileset) - filelist %s does not exist",
    314309                filelist);
    315310        log_to_screen(tmp);
     311        paranoid_free(tmp);
    316312        return (1);
    317313    }
    318     sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
     314    mr_asprintf(&tmp, "echo hi > %s 2> /dev/null", fname);
    319315    if (system(tmp)) {
     316        paranoid_free(tmp);
    320317        fatal_error("Unable to write tarball to scratchdir");
    321318    }
     319    paranoid_free(tmp);
    322320
    323321
    324322    if (bkpinfo->compression_level > 0) {
    325         sprintf(tmp, "%s/do-not-compress-these", g_mondo_home);
     323        mr_asprintf(&tmp, "%s/do-not-compress-these", g_mondo_home);
    326324        //       -b %ld, TAPE_BLOCK_SIZE
    327         sprintf(zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->zip_exe,
     325        mr_asprintf(&zipparams, "-Z -P %s -G %d -T 3k", bkpinfo->zip_exe,
    328326                bkpinfo->compression_level);
    329327        if (does_file_exist(tmp)) {
    330             strcat(zipparams, " -E ");
    331             strcat(zipparams, tmp);
     328            mr_strcat(zipparams, " -E %s",tmp);
    332329        } else {
    333330            log_msg(3, "%s not found. Cannot exclude zipfiles, etc.", tmp);
    334331        }
     332        paranoid_free(tmp);
    335333    } else {
    336         zipparams[0] = '\0';
     334        mr_asprintf(&zipparams, "");
    337335    }
    338336
     
    347345        fatal_error("scratchdir not found");
    348346    }
    349     sprintf(command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname,
     347    mr_asprintf(&command, "rm -f %s %s. %s.gz %s.%s", fname, fname, fname,
    350348            fname, bkpinfo->zip_suffix);
    351349    paranoid_system(command);
    352 
    353     sprintf(command, "afio -o -b %ld -M 16m %s %s < %s 2>> %s",
     350    paranoid_free(command);
     351
     352    mr_asprintf(&command, "afio -o -b %ld -M 16m %s %s < %s 2>> %s",
    354353            TAPE_BLOCK_SIZE, zipparams, fname, filelist, MONDO_LOGFILE);
    355 
    356     sprintf(tmp, "echo hi > %s 2> /dev/null", fname);
     354    paranoid_free(zipparams);
     355
     356    mr_asprintf(&tmp, "echo hi > %s 2> /dev/null", fname);
    357357    if (system(tmp)) {
     358        paranoid_free(tmp);
    358359        fatal_error("Unable to write tarball to scratchdir");
    359360    }
     361    paranoid_free(tmp);
    360362
    361363    for (res = 99, tries = 0; tries < 3 && res != 0; tries++) {
     
    370372        }
    371373    }
     374    paranoid_free(command);
     375
    372376    retval += res;
    373377    if (retval) {
     
    378382    }
    379383
    380     paranoid_free(command);
    381     paranoid_free(zipparams);
    382     paranoid_free(tmp);
    383384    return (retval);
    384385}
     
    511512    char *tmp2 = NULL;
    512513    char *scratchdir;
    513     char *command;
     514    char *command = NULL;
    514515    char *use_lzo_sz;
    515516    char *use_gzip_sz;
     
    541542
    542543    assert(bkpinfo != NULL);
    543     command = malloc(1200);
    544544    tmp = malloc(9*MAX_STR_LEN);
    545545    malloc_string(scratchdir);
     
    803803    }
    804804    if (bkpinfo->backup_media_type == usb) {
    805         (void)asprintf(&tmp2, "--usb %s", bkpinfo->media_device);
     805        mr_asprintf(&tmp2, "--usb %s", bkpinfo->media_device);
    806806    } else {
    807         (void)asprintf(&tmp2," ");
     807        mr_asprintf(&tmp2," ");
    808808    }
    809809
     
    828828
    829829    if (g_getfattr) {
    830         (void)asprintf(&tmp1, "%s/XATTR", bkpinfo->tmpdir);
     830        mr_asprintf(&tmp1, "%s/XATTR", bkpinfo->tmpdir);
    831831        if (write_one_liner_data_file(tmp1, "TRUE")) {
    832832            log_msg(1, "%ld: Unable to write one-liner XATTR",
     
    836836    }
    837837    if (g_getfacl) {
    838         (void)asprintf(&tmp1, "%s/ACL", bkpinfo->tmpdir);
     838        mr_asprintf(&tmp1, "%s/ACL", bkpinfo->tmpdir);
    839839        if (write_one_liner_data_file(tmp1, "TRUE")) {
    840840            log_msg(1, "%ld: Unable to write one-liner ACL",
     
    844844    }
    845845    if (bkpinfo->use_obdr) {
    846         (void)asprintf(&tmp1, "%s/OBDR", bkpinfo->tmpdir);
     846        mr_asprintf(&tmp1, "%s/OBDR", bkpinfo->tmpdir);
    847847        if (write_one_liner_data_file(tmp1, "TRUE")) {
    848848            log_msg(1, "%ld: Unable to write one-liner OBDR",
     
    855855        size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
    856856/* add nfs stuff here? */
    857     sprintf(command, "mkdir -p %s/images", bkpinfo->scratchdir);
     857    mr_asprintf(&command, "mkdir -p %s/images", bkpinfo->scratchdir);
    858858    if (system(command)) {
    859859        res++;
    860860        log_OS_error("Unable to make images directory");
    861861    }
     862    paranoid_free(command);
    862863    sprintf(tmp, "BTW, I'm telling Mindi your kernel is '%s'",
    863864            bkpinfo->kernel_path);
     
    865866    log_msg(1, "lines_in_filelist = %ld", lines_in_filelist);
    866867
    867     sprintf(command,
     868    mr_asprintf(&command,
    868869/*     "mindi --custom 2=%s 3=%s/images 4=\"%s\" 5=\"%s\" \
    8698706=\"%s\" 7=%ld 8=\"%s\" 9=\"%s\" 10=\"%s\" \
     
    891892            use_gzip_sz);       // parameter #20 (STRING)
    892893
    893 // Watch it! This next line adds a parameter...
    894894    if (bkpinfo->nonbootable_backup) {
    895         strcat(command, " NONBOOTABLE");
     895        mr_strcat(command, " NONBOOTABLE");
    896896    }
    897897    log_msg(2, command);
     
    899899//  popup_and_OK("Pausing");
    900900
    901     res =
    902         run_program_and_log_to_screen(command,
    903                                       "Generating boot+data disks");
     901    res = run_program_and_log_to_screen(command, "Generating boot+data disks");
     902    paranoid_free(command);
     903
    904904    if (bkpinfo->nonbootable_backup) {
    905905        res = 0;
     
    907907    if (!res) {
    908908        log_to_screen("Boot+data disks were created OK");
    909         sprintf(command, "cp -f %s/images/mindi.iso %s/mondorescue.iso",
     909        mr_asprintf(&command, "cp -f %s/images/mindi.iso %s/mondorescue.iso",
    910910                bkpinfo->scratchdir, MINDI_CACHE);
    911911        log_msg(2, command);
    912912        run_program_and_log_output(command, FALSE);
     913        paranoid_free(command);
     914
    913915        if (bkpinfo->nonbootable_backup) {
    914             sprintf(command, "cp -f %s/all.tar.gz %s/images",
     916            mr_asprintf(&command, "cp -f %s/all.tar.gz %s/images",
    915917                    bkpinfo->tmpdir, bkpinfo->scratchdir);
    916918            if (system(command)) {
     919                paranoid_free(command);
    917920                fatal_error("Unable to create temporary all tarball");
    918921            }
     922            paranoid_free(command);
    919923        }
    920924        /* For USB we already have everything on the key */
    921925        if (bkpinfo->backup_media_type == usb) {
    922             sprintf(command, "rm -rf %s/images", bkpinfo->scratchdir);
     926            mr_asprintf(&command, "rm -rf %s/images", bkpinfo->scratchdir);
    923927            run_program_and_log_output(command, FALSE);
     928            paranoid_free(command);
    924929        } else {
    925930            sprintf(tmp, "cp -f %s/images/all.tar.gz %s", bkpinfo->scratchdir,
     
    936941    } else {
    937942        log_to_screen("Mindi failed to create your boot+data disks.");
    938         strcpy(command, "grep 'Fatal error' /var/log/mindi.log");
     943        mr_asprintf(&command, "grep 'Fatal error' /var/log/mindi.log");
    939944        strcpy(tmp, call_program_and_get_last_line_of_output(command));
     945        paranoid_free(command);
     946
    940947        if (strlen(tmp) > 1) {
    941948            popup_and_OK(tmp);
     
    957964    paranoid_free(value);
    958965    paranoid_free(bootdev);
    959     paranoid_free(command);
    960966    paranoid_free(use_star_sz);
    961967    return (res);
     
    13451351    char *storing_filelist_fname;
    13461352    char *storing_afioball_fname;
    1347     char *tmp;
     1353    char *tmp = NULL;
    13481354    char *media_usage_comment;
    13491355    pthread_t archival_thread[ARCH_THREADS];
     
    13601366    log_msg(8, "here");
    13611367    assert(bkpinfo != NULL);
    1362     tmp = malloc(MAX_STR_LEN * 2);
    13631368    malloc_string(result_str);
    13641369    malloc_string(curr_xattr_list_fname);
     
    13821387    *p_last_set_archived = -1;
    13831388    *p_next_set_to_archive = 0;
    1384     sprintf(tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
    13851389    log_to_screen("Archiving regular files");
    13861390    log_msg(5, "Go, Shorty. It's your birthday.");
     
    15001504            update_progress_form(media_usage_comment);
    15011505            if (res) {
    1502                 sprintf(tmp,
     1506                mr_asprintf(&tmp,
    15031507                        "Failed to add archive %ld's files to CD dir\n",
    15041508                        storing_set_no);
    15051509                log_to_screen(tmp);
     1510                paranoid_free(tmp);
    15061511                fatal_error
    15071512                    ("Is your hard disk full? If not, please send the author the logfile.");
     
    15131518    close_progress_form();
    15141519
    1515     sprintf(tmp, "Your regular files have been archived ");
     1520    mr_asprintf(&tmp, "Your regular files have been archived ");
    15161521    log_msg(2, "Joining background threads to foreground thread");
    15171522    for (i = 0; i < noof_threads; i++) {
     
    15221527    log_msg(2, "Done.");
    15231528    if (retval) {
    1524         strcat(tmp, "(with errors).");
     1529        mr_strcat(tmp, "(with errors).");
    15251530    } else {
    1526         strcat(tmp, "successfully.");
     1531        mr_strcat(tmp, "successfully.");
    15271532    }
    15281533    log_to_screen(tmp);
     1534    paranoid_free(tmp);
     1535
    15291536    paranoid_free(transfer_block);
    15301537    paranoid_free(result_str);
     
    15811588    log_msg(2, "make_usb_fs --- scratchdir=%s", bkpinfo->scratchdir);
    15821589    (void) getcwd(old_pwd, MAX_STR_LEN - 1);
    1583     (void)asprintf(&tmp, "chmod 755 %s", bkpinfo->scratchdir);
     1590    mr_asprintf(&tmp, "chmod 755 %s", bkpinfo->scratchdir);
    15841591    run_program_and_log_output(tmp, FALSE);
    15851592    paranoid_free(tmp);
    15861593    (void)chdir(bkpinfo->scratchdir);
    15871594
    1588     (void)asprintf(&message_to_screen, "Copying data to make %s #%d",
     1595    mr_asprintf(&message_to_screen, "Copying data to make %s #%d",
    15891596                media_descriptor_string(bkpinfo->backup_media_type),
    15901597                g_current_media_number);
    15911598    log_msg(1, message_to_screen);
    15921599
    1593     (void)asprintf(&tmp1, "%s1", bkpinfo->media_device);
     1600    mr_asprintf(&tmp1, "%s1", bkpinfo->media_device);
    15941601    if (is_this_device_mounted(tmp1)) {
    15951602        log_msg(1, "USB device mounted. Remounting it at the right place");
    1596         (void)asprintf(&tmp, "umount %s", tmp1);
     1603        mr_asprintf(&tmp, "umount %s", tmp1);
    15971604        run_program_and_log_output(tmp, FALSE);
    15981605        paranoid_free(tmp);
     
    16011608
    16021609    log_msg(1, "Mounting USB device.");
    1603     (void)asprintf(&tmp1, "%s/usb", bkpinfo->tmpdir);
    1604     (void)asprintf(&tmp, "mkdir -p %s", tmp1);
     1610    mr_asprintf(&tmp1, "%s/usb", bkpinfo->tmpdir);
     1611    mr_asprintf(&tmp, "mkdir -p %s", tmp1);
    16051612    run_program_and_log_output(tmp, FALSE);
    16061613    paranoid_free(tmp);
    16071614    /* Mindi always create one single parition on the USB dev */
    1608     (void)asprintf(&tmp, "mount %s1 %s", bkpinfo->media_device, tmp1);
     1615    mr_asprintf(&tmp, "mount %s1 %s", bkpinfo->media_device, tmp1);
    16091616    run_program_and_log_output(tmp, FALSE);
    16101617    paranoid_free(tmp);
     
    16161623
    16171624        /* Command to execute */
    1618         (void)asprintf(&tmp,"mv %s/* %s", bkpinfo->scratchdir, tmp1);
     1625        mr_asprintf(&tmp,"mv %s/* %s", bkpinfo->scratchdir, tmp1);
    16191626        res = eval_call_to_make_USB(tmp, message_to_screen);
    16201627        if (res) {
    1621             (void)asprintf(&result_sz, "%s ...failed",tmp);
     1628            mr_asprintf(&result_sz, "%s ...failed",tmp);
    16221629        } else {
    1623             (void)asprintf(&result_sz, "%s ...OK",tmp);
     1630            mr_asprintf(&result_sz, "%s ...OK",tmp);
    16241631        }
    16251632        log_to_screen(result_sz);
     
    16321639
    16331640    if (is_this_device_mounted(bkpinfo->media_device)) {
    1634         (void)asprintf(&tmp, "umount %s1", bkpinfo->media_device);
     1641        mr_asprintf(&tmp, "umount %s1", bkpinfo->media_device);
    16351642        run_program_and_log_output(tmp, FALSE);
    16361643        paranoid_free(tmp);
     
    16721679    char *tmp;
    16731680    char *old_pwd;
    1674     char *result_sz;
    1675     char *message_to_screen;
     1681    char *result_sz = NULL;
     1682    char *message_to_screen = NULL;
    16761683    char *sz_blank_disk;
    16771684    char *fnam;
     
    16811688
    16821689    malloc_string(old_pwd);
    1683     malloc_string(result_sz);
    1684     malloc_string(message_to_screen);
    16851690    malloc_string(sz_blank_disk);
    16861691    malloc_string(fnam);
     
    17171722
    17181723    if (bkpinfo->call_before_iso[0] != '\0') {
    1719         sprintf(message_to_screen, "Running pre-ISO call for CD#%d",
     1724        mr_asprintf(&message_to_screen, "Running pre-ISO call for CD#%d",
    17201725                g_current_media_number);
    17211726        res =
     
    17241729                                  MONDO_LOGFILE, message_to_screen);
    17251730        if (res) {
    1726             strcat(message_to_screen, "...failed");
     1731            mr_strcat(message_to_screen, "...failed");
    17271732        } else {
    1728             strcat(message_to_screen, "...OK");
     1733            mr_strcat(message_to_screen, "...OK");
    17291734        }
    17301735        log_to_screen(message_to_screen);
     1736        paranoid_free(message_to_screen);
     1737
    17311738        retval += res;
    17321739    }
     
    17351742        log_msg(2, "bkpinfo->call_make_iso = %s", bkpinfo->call_make_iso);
    17361743        sprintf(tmp, "%s/archives/NOT-THE-LAST", bkpinfo->scratchdir);
    1737         sprintf(message_to_screen, "Making an ISO (%s #%d)",
     1744        mr_asprintf(&message_to_screen, "Making an ISO (%s #%d)",
    17381745                media_descriptor_string(bkpinfo->backup_media_type),
    17391746                g_current_media_number);
     
    18301837            }
    18311838        }
     1839        paranoid_free(message_to_screen);
    18321840    } else {
    1833         sprintf(message_to_screen, "Running mkisofs to make %s #%d",
     1841        mr_asprintf(&message_to_screen, "Running mkisofs to make %s #%d",
    18341842                media_descriptor_string(bkpinfo->backup_media_type),
    18351843                g_current_media_number);
    18361844        log_msg(1, message_to_screen);
    1837         sprintf(result_sz, "Call to mkisofs to make ISO (%s #%d) ",
     1845        mr_asprintf(&result_sz, "Call to mkisofs to make ISO (%s #%d) ",
    18381846                media_descriptor_string(bkpinfo->backup_media_type),
    18391847                g_current_media_number);
     
    18881896            }
    18891897        }
     1898        paranoid_free(message_to_screen);
     1899
    18901900        if (res) {
    1891             strcat(result_sz, "...failed");
     1901            mr_strcat(result_sz, "...failed");
    18921902        } else {
    1893             strcat(result_sz, "...OK");
     1903            mr_strcat(result_sz, "...OK");
    18941904        }
    18951905        log_to_screen(result_sz);
     1906        paranoid_free(result_sz);
    18961907        retval += res;
    18971908    }
     
    19101921    if (bkpinfo->call_burn_iso[0] != '\0') {
    19111922        log_msg(2, "bkpinfo->call_burn_iso = %s", bkpinfo->call_burn_iso);
    1912         sprintf(message_to_screen, "Burning %s #%d",
     1923        mr_asprintf(&message_to_screen, "Burning %s #%d",
    19131924                media_descriptor_string(bkpinfo->backup_media_type),
    19141925                g_current_media_number);
     
    19191930                                  MONDO_LOGFILE, message_to_screen);
    19201931        if (res) {
    1921             strcat(message_to_screen, "...failed");
     1932            mr_strcat(message_to_screen, "...failed");
    19221933        } else {
    1923             strcat(message_to_screen, "...OK");
     1934            mr_strcat(message_to_screen, "...OK");
    19241935        }
    19251936        log_to_screen(message_to_screen);
     1937        paranoid_free(message_to_screen);
     1938
    19261939        retval += res;
    19271940    }
    19281941
    19291942    if (bkpinfo->call_after_iso[0] != '\0') {
    1930         sprintf(message_to_screen, "Running post-ISO call (%s #%d)",
     1943        mr_asprintf(&message_to_screen, "Running post-ISO call (%s #%d)",
    19311944                media_descriptor_string(bkpinfo->backup_media_type),
    19321945                g_current_media_number);
     
    19361949                                  MONDO_LOGFILE, message_to_screen);
    19371950        if (res) {
    1938             strcat(message_to_screen, "...failed");
     1951            mr_strcat(message_to_screen, "...failed");
    19391952        } else {
    1940             strcat(message_to_screen, "...OK");
     1953            mr_strcat(message_to_screen, "...OK");
    19411954        }
    19421955        log_to_screen(message_to_screen);
     1956        paranoid_free(message_to_screen);
     1957
    19431958        retval += res;
    19441959    }
     
    19491964    }
    19501965    paranoid_free(old_pwd);
    1951     paranoid_free(result_sz);
    1952     paranoid_free(message_to_screen);
    19531966    paranoid_free(sz_blank_disk);
    19541967    paranoid_free(fnam);
     
    20102023
    20112024    /*@ buffers ******************************************** */
    2012     char *tmp;
     2025    char *tmp = NULL;
    20132026    char *bigfile_fname;
    20142027    char *sz_devfile;
     
    20312044    assert_string_is_neither_NULL_nor_zerolength(biggielist_fname);
    20322045
    2033     malloc_string(tmp);
    20342046    malloc_string(bigfile_fname);
    20352047    malloc_string(sz_devfile);
     
    20472059        return (0);
    20482060    }
    2049     sprintf(tmp, "I am now backing up all large files.");
     2061    mr_asprintf(&tmp, "I am now backing up all large files.");
    20502062    log_to_screen(tmp);
    20512063    noof_biggie_files = count_lines_in_file(biggielist_fname);
     
    20532065                       "Please wait. This may take some time.", "",
    20542066                       estimated_total_noof_slices);
     2067    paranoid_free(tmp);
     2068
    20552069    if (!(fin = fopen(biggielist_fname, "r"))) {
    20562070        log_OS_error("Unable to openin biggielist");
     
    21092123                }
    21102124            }
    2111 // Otherwise, use good old 'dd' and 'bzip2'
     2125            // Otherwise, use good old 'dd' and 'bzip2'
    21122126            else {
    21132127                sz_devfile[0] = '\0';
     
    21152129            }
    21162130
    2117 // Whether partition or biggiefile, just do your thang :-)
    2118             sprintf(tmp, "Bigfile #%ld is '%s' (%ld KB)",
    2119                     biggie_file_number + 1, bigfile_fname,
    2120                     (long) biggie_fsize >> 10);
     2131            // Whether partition or biggiefile, just do your thang :-)
    21212132            if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    21222133                write_header_block_to_stream(biggie_fsize, bigfile_fname,
     
    21422153                p = bigfile_fname;
    21432154            }
    2144             sprintf(tmp, "Archiving %s ... ", bigfile_fname);
     2155            mr_asprintf(&tmp, "Archiving %s ... ", bigfile_fname);
    21452156            if (res) {
    2146                 strcat(tmp, "Failed!");
     2157                mr_strcat(tmp, "Failed!");
    21472158            } else {
    2148                 strcat(tmp, "OK");
     2159                mr_strcat(tmp, "OK");
    21492160            }
    21502161            if (delete_when_done) {
     
    21592170        }
    21602171#endif
     2172        paranoid_free(tmp);
    21612173    }
    21622174    log_msg(1, "Finished backing up bigfiles");
     
    21652177    close_progress_form();
    21662178    paranoid_fclose(fin);
    2167     paranoid_free(tmp);
    21682179    paranoid_free(bigfile_fname);
    21692180    paranoid_free(sz_devfile);
     
    21912202    char *curr_xattr_list_fname;
    21922203    char *curr_acl_list_fname;
    2193     char *tmp;
     2204    char *tmp = NULL;
    21942205    char *media_usage_comment;
    21952206
     
    21992210    malloc_string(curr_xattr_list_fname);
    22002211    malloc_string(curr_acl_list_fname);
    2201 
    2202     tmp = malloc(MAX_STR_LEN * 2);
    2203 
    2204     sprintf(tmp, "%s/archives/filelist.full", bkpinfo->scratchdir);
    22052212
    22062213    log_to_screen("Archiving regular files");
     
    22422249        retval += res;
    22432250        if (res) {
    2244             sprintf(tmp,
     2251            mr_asprintf(&tmp,
    22452252                    "Errors occurred while archiving set %ld. Perhaps your live filesystem changed?",
    22462253                    curr_set_no);
    22472254            log_to_screen(tmp);
     2255            paranoid_free(tmp);
    22482256        }
    22492257
     
    22882296
    22892297        if (res) {
    2290             sprintf(tmp, "Failed to add archive %ld's files to CD dir\n",
     2298            mr_asprintf(&tmp, "Failed to add archive %ld's files to CD dir\n",
    22912299                    curr_set_no);
    22922300            log_to_screen(tmp);
     2301            paranoid_free(tmp);
    22932302            fatal_error
    22942303                ("Is your hard disk is full? If not, please send the author the logfile.");
     
    22962305    }
    22972306    close_progress_form();
    2298     sprintf(tmp, "Your regular files have been archived ");
     2307    mr_asprintf(&tmp, "Your regular files have been archived ");
    22992308    if (retval) {
    2300         strcat(tmp, "(with errors).");
     2309        mr_strcat(tmp, "(with errors).");
    23012310    } else {
    2302         strcat(tmp, "successfully.");
     2311        mr_strcat(tmp, "successfully.");
    23032312    }
    23042313    log_to_screen(tmp);
     
    23982407    }
    23992408
    2400     (void)asprintf(&command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir,
     2409    mr_asprintf(&command, "cp %s/biggielist.txt %s", bkpinfo->tmpdir,
    24012410            biggielist);
    24022411    paranoid_system(command);
    24032412    paranoid_free(command);
    24042413
    2405     (void)asprintf(&blah, "biggielist = %s", biggielist);
     2414    mr_asprintf(&blah, "biggielist = %s", biggielist);
    24062415    log_msg(2, blah);
    24072416    paranoid_free(blah);
     
    24132422    if (g_getfattr) {
    24142423        get_fattr_list(biggielist, xattr_fname);
    2415         (void)asprintf(&command, "cp %s %s/archives/", xattr_fname,
     2424        mr_asprintf(&command, "cp %s %s/archives/", xattr_fname,
    24162425            bkpinfo->scratchdir);
    24172426        paranoid_system(command);
     
    24202429    if (g_getfacl) {
    24212430        get_acl_list(biggielist, acl_fname);
    2422         (void)asprintf(&command, "cp %s %s/archives/", acl_fname,
     2431        mr_asprintf(&command, "cp %s %s/archives/", acl_fname,
    24232432             bkpinfo->scratchdir);
    24242433        paranoid_system(command);
     
    24282437    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    24292438        res += write_EXAT_files_to_tape(xattr_fname, acl_fname);
    2430         (void)asprintf(&blah, "%ld", count_lines_in_file(biggielist));
     2439        mr_asprintf(&blah, "%ld", count_lines_in_file(biggielist));
    24312440        write_header_block_to_stream((off_t)0, blah, BLK_START_BIGGIEFILES);
    24322441        paranoid_free(blah);
     
    29542963
    29552964    /*@ buffers ************************************************** */
    2956     char *tmp, *checksum_line, *command;
     2965    char *tmp = NULL;
     2966    char *checksum_line, *command;
    29572967    char *tempblock;
    29582968    char *curr_slice_fname_uncompressed;
     
    29903000    assert(bkpinfo != NULL);
    29913001    assert_string_is_neither_NULL_nor_zerolength(biggie_filename);
    2992     malloc_string(tmp);
    29933002    malloc_string(checksum_line);
    29943003    malloc_string(curr_slice_fname_uncompressed);
     
    30283037        sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", biggie_filename);
    30293038        log_it("command = %s", command);
    3030         strcpy (tmp, call_program_and_get_last_line_of_output(command));
     3039        mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command));
    30313040        log_it("res of it = %s", tmp);
    30323041        totallength = (off_t)atoll(tmp);
     3042        paranoid_free(tmp);
    30333043    } else {
    30343044        file_to_openin = biggie_filename;
     
    30573067    strcpy(biggiestruct.checksum, checksum_line);
    30583068
    3059     strcpy(tmp, slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""));
     3069    mr_asprintf(&tmp, slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""));
    30603070    fout = fopen(tmp, "w");
    30613071    if (fout == NULL) {
     
    30653075        return (1);
    30663076    }
     3077    paranoid_free(tmp);
    30673078
    30683079    (void) fwrite((void *) &biggiestruct, 1, sizeof(biggiestruct), fout);
     
    30753086    if (!(fin = fopen(file_to_openin, "r"))) {
    30763087        log_OS_error("Unable to openin biggie_filename");
    3077         sprintf(tmp, "Cannot archive bigfile '%s': not found",
    3078                 biggie_filename);
     3088        mr_asprintf(&tmp, "Cannot archive bigfile '%s': not found", biggie_filename);
    30793089        log_to_screen(tmp);
     3090        paranoid_free(tmp);
     3091
    30803092        paranoid_free(tempblock);
    3081         paranoid_free(tmp);
    30823093        paranoid_free(checksum_line);
    30833094        paranoid_free(command);
     
    31023113                           suffix));
    31033114
    3104         strcpy(tmp, percent_media_full_comment());
     3115        mr_asprintf(&tmp, percent_media_full_comment());
    31053116        update_progress_form(tmp);
     3117        paranoid_free(tmp);
     3118
    31063119        if (!(fout = fopen(curr_slice_fname_uncompressed, "w"))) {
    31073120            log_OS_error(curr_slice_fname_uncompressed);
     
    31563169            }
    31573170            if (res) {
    3158                 sprintf(tmp, "Problem with slice # %ld", slice_num);
     3171                mr_asprintf(&tmp, "Problem with slice # %ld", slice_num);
    31593172            } else {
    3160                 sprintf(tmp,
     3173                mr_asprintf(&tmp,
    31613174                        "%s - Bigfile #%ld, slice #%ld compressed OK          ",
    31623175                        biggie_filename, biggie_file_number + 1,
     
    31733186            log_msg(2, tmp);
    31743187#endif
     3188            paranoid_free(tmp);
     3189
    31753190            strcpy(file_to_archive, curr_slice_fname_compressed);
    31763191            g_current_progress++;
     
    31953210        retval += res;
    31963211        if (res) {
    3197             sprintf(tmp,
     3212            mr_asprintf(&tmp,
    31983213                    "Failed to add slice %ld of bigfile %ld to scratchdir",
    31993214                    slice_num, biggie_file_number + 1);
    32003215            log_to_screen(tmp);
     3216            paranoid_free(tmp);
    32013217            fatal_error
    32023218                ("Hard disk full. You should have bought a bigger one.");
     
    32043220    }
    32053221    paranoid_fclose(fin);
    3206     sprintf(tmp, "Sliced bigfile #%ld", biggie_file_number + 1);
     3222    mr_asprintf(&tmp, "Sliced bigfile #%ld", biggie_file_number + 1);
    32073223    if (retval) {
    3208         strcat(tmp, "...FAILED");
     3224        mr_strcat(tmp, "...FAILED");
    32093225    } else {
    3210         strcat(tmp, "...OK!");
     3226        mr_strcat(tmp, "...OK!");
    32113227    }
    32123228    log_msg(1, tmp);
     3229    paranoid_free(tmp);
     3230
    32133231    paranoid_free(tempblock);
    3214     paranoid_free(tmp);
    32153232    paranoid_free(checksum_line);
    32163233    paranoid_free(command);
  • branches/2.2.9/mondo/src/common/libmondo-cli.c

    r2202 r2211  
    1212#include <pthread.h>
    1313#include "my-stuff.h"
     14#include "mr_mem.h"
     15#include "mr_string.h"
    1416#include "mondostructures.h"
    1517#include "libmondo-cli-EXT.h"
    1618#include "libmondo.h"
    17 #include "mr_string.h"
    1819
    1920extern int g_loglevel;
     
    278279    ********/
    279280    /* Get the number of mounted file systems ((those that start with "/dev/" */
    280     asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l");
     281    mr_asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l");
    281282    log_msg(5, "Running: %s", command);
    282     asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
     283    mr_asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
    283284    paranoid_free(command);
    284285
     
    288289
    289290    for (i=mount_cnt; i > 0; i--) {
    290         asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i);
     291        mr_asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i);
    291292        log_msg(5, "Running: %s", command);
    292         asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
     293        mr_asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
    293294        paranoid_free(command);
    294295
     
    366367    log_msg(5, "  %s looks like a device special file", dsf);
    367368    /* Verify that the dsf exists */
    368     asprintf(&command, "ls -al %s 2>/dev/null | wc -l", dsf);
     369    mr_asprintf(&command, "ls -al %s 2>/dev/null | wc -l", dsf);
    369370    log_msg(5, "  Executing: %s", command);
    370     asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     371    mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    371372    paranoid_free(command);
    372373
     
    392393    * Either way, it's an error.
    393394    ********/
    394     asprintf(&command,
     395    mr_asprintf(&command,
    395396      "fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf);
    396397    log_msg(4, "Executing: %s", command);
    397     asprintf(&partition_list, "%s", call_program_and_get_last_line_of_output(command));
     398    mr_asprintf(&partition_list, "%s", call_program_and_get_last_line_of_output(command));
    398399    paranoid_free(command);
    399400    log_msg(4, "Partition list for %s: %s", dsf, partition_list);
     
    445446        log_msg(4, "Processing partition: %s", partitions[i]);
    446447        /* See if it's swap. If it is, ignore it. */
    447         asprintf(&command,
     448        mr_asprintf(&command,
    448449          "fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'",
    449450          dsf, partitions[i]);
    450451        log_msg(4, "  Running: %s", command);
    451         asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     452        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    452453        paranoid_free(command);
    453454        log_msg(4, "  Return value: %s", tmp);
     
    459460        }
    460461        /* It's not swap. See if we can find the mount point from the mount command. */
    461         asprintf(&command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
    462         asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     462        mr_asprintf(&command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
     463        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    463464        paranoid_free(command);
    464465        if (strlen(tmp)) {
     
    477478        log_msg(4, "  It's not mounted. Checking to see if it's LVM...");
    478479        /* Get the partition ID; 8e for LVM */
    479         asprintf(&command, "fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf, partitions[i]);
     480        mr_asprintf(&command, "fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf, partitions[i]);
    480481        log_msg(4, "  Running: %s", command);
    481         asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     482        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    482483        paranoid_free(command);
    483484        if (strlen(tmp)) {
     
    486487                /* It's LVM: Find the VG it's in */
    487488                log_msg(4, "  It's LVM: Find the VG it's in...");
    488                 asprintf(&command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
     489                mr_asprintf(&command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
    489490                log_msg(4, "  Running: %s", command);
    490491                strcpy(VG, call_program_and_get_last_line_of_output(command));
     
    494495                    /* Found the Volume Group. Now find all of the VG's mount points */
    495496                    log_msg(4, "  Found the Volume Group. Now find all of the VG's mount points");
    496                     asprintf(&command,
     497                    mr_asprintf(&command,
    497498                      "mount 2>/dev/null|grep -E \"/dev/mapper/%s-|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'",
    498499                      VG, VG);
    499500                    log_msg(4, "  Running: %s", command);
    500                     asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
     501                    mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
    501502                    paranoid_free(command);
    502503                    log_msg(4, "  VG %s mount_list: %s", VG, mount_list);
     
    516517                     *******/
    517518                    paranoid_free(mount_list);
    518                     asprintf(&command, "%s",
     519                    mr_asprintf(&command, "%s",
    519520                        "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    520521                    log_msg (5, "Running: %s", command);
    521                     asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
     522                    mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
    522523                    paranoid_free(command);
    523524                    log_msg(4, "  Software raid device list: %s", mount_list);   
    524525                    lastpos = 0;
    525526                    while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
    526                         asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
     527                        mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
    527528                        log_msg (5, "Running: %s", command);
    528529                        paranoid_free(tmp);
    529                         asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     530                        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    530531                        paranoid_free(command);
    531532                        log_msg(4, "Number of Software raid device: %s", tmp);
     
    557558         ********/
    558559        log_msg (5, "It's not swap, mounted, or LVM. See if it's used in a software raid device.");
    559         asprintf(&command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);
     560        mr_asprintf(&command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);
    560561        log_msg(4, "  Running: %s", command);
    561         asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     562        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    562563        paranoid_free(command);
    563564        if (!strlen(tmp)) {
     
    568569        log_msg (5, "  UUID: %s", tmp);
    569570        /* Get the Software raid device list */
    570         asprintf(&command, "%s",
     571        mr_asprintf(&command, "%s",
    571572         "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    572573        log_msg (5, "  Running: %s", command);
    573         asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
     574        mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
    574575        paranoid_free(command);
    575576        log_msg(4, "  Software raid device list: %s", mount_list);   
     
    577578        lastpos = 0;
    578579        while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) {
    579             asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);
     580            mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);
    580581            log_msg(4, "  Running: %s", command);
    581582            paranoid_free(tmp);
    582             asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     583            mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    583584            paranoid_free(command);
    584585            if (!atoi(tmp)) {
     
    756757        }
    757758       
    758         asprintf(&tmp1, "%s", flag_val['I']);
     759        mr_asprintf(&tmp1, "%s", flag_val['I']);
    759760        p = tmp1;
    760761        q = tmp1;
     
    10351036    if (flag_set['z']) {
    10361037        if (find_home_of_exe("getfattr")) {
    1037             asprintf(&g_getfattr,"getfattr");
     1038            mr_asprintf(&g_getfattr,"getfattr");
    10381039        }
    10391040        if (find_home_of_exe("getfacl")) {
    1040             asprintf(&g_getfacl,"getfacl");
     1041            mr_asprintf(&g_getfacl,"getfacl");
    10411042        }
    10421043    }
     
    10551056            strcat(bkpinfo->exclude_paths, " ");
    10561057        }
    1057         asprintf(&tmp1, "%s", flag_val['E']);
     1058        mr_asprintf(&tmp1, "%s", flag_val['E']);
    10581059
    10591060        p = tmp1;
     
    12111212
    12121213    if ((flag_set['n']) && (! bkpinfo->restore_data)) {
    1213         asprintf(&tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->nfs_remote_dir);
     1214        mr_asprintf(&tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->nfs_remote_dir);
    12141215        sprintf(tmp, "echo hi > %s", tmp1);
    12151216        if (run_program_and_log_output(tmp, 2)) {
     
    14671468            if (flag_set[optopt]) {
    14681469                bad_switches = TRUE;
    1469                 (void) asprintf(&tmp, "Switch -%c previously defined as %s\n", opt,
     1470                mr_asprintf(&tmp, "Switch -%c previously defined as %s\n", opt,
    14701471                        flag_val[i]);
    14711472                log_to_screen(tmp);
     
    14841485                        if (strchr(flag_val[opt], '/')
    14851486                            && flag_val[opt][0] != '/') {
    1486                             (void)asprintf(&tmp,
     1487                            mr_asprintf(&tmp,
    14871488                                    "-%c flag --- must be absolute path --- '%s' isn't absolute",
    14881489                                    opt, flag_val[opt]);
     
    14991500    for (i = optind; i < argc; i++) {
    15001501        bad_switches = TRUE;
    1501         (void)asprintf(&tmp, "Invalid arg -- %s\n", argv[i]);
     1502        mr_asprintf(&tmp, "Invalid arg -- %s\n", argv[i]);
    15021503        log_to_screen(tmp);
    15031504        paranoid_free(tmp);
     
    15251526void terminate_daemon(int sig)
    15261527{
    1527     char tmp[64];
    1528     char tmp2[MAX_STR_LEN];
    1529     //  char command[512];
    1530     //  pid_t pid;
     1528    char *tmp = NULL;
     1529    char *tmp2 = NULL;
    15311530
    15321531    switch (sig) {
    15331532    case SIGINT:
    1534         sprintf(tmp, "SIGINT");
    1535         strcpy(tmp2, "You interrupted me :-)");
     1533        mr_asprintf(&tmp, "SIGINT");
     1534        mr_asprintf(&tmp2, "You interrupted me :-)");
    15361535        break;
    15371536    case SIGKILL:
    1538         sprintf(tmp, "SIGKILL");
    1539         strcpy(tmp2,
     1537        mr_asprintf(&tmp, "SIGKILL");
     1538        mr_asprintf(&tmp2,
    15401539               "I seriously have no clue how this signal even got to me. Something's wrong with your system.");
    15411540        break;
    15421541    case SIGTERM:
    1543         sprintf(tmp, "SIGTERM");
    1544         strcpy(tmp2, "Got terminate signal");
     1542        mr_asprintf(&tmp, "SIGTERM");
     1543        mr_asprintf(&tmp2, "Got terminate signal");
    15451544        break;
    15461545    case SIGHUP:
    1547         sprintf(tmp, "SIGHUP");
    1548         strcpy(tmp2, "Hangup on line");
     1546        mr_asprintf(&tmp, "SIGHUP");
     1547        mr_asprintf(&tmp2, "Hangup on line");
    15491548        break;
    15501549    case SIGSEGV:
    1551         sprintf(tmp, "SIGSEGV");
    1552         strcpy(tmp2,
     1550        mr_asprintf(&tmp, "SIGSEGV");
     1551        mr_asprintf(&tmp2,
    15531552               "Internal programming error. Please send a backtrace as well as your log.");
    15541553        break;
    15551554    case SIGPIPE:
    1556         sprintf(tmp, "SIGPIPE");
    1557         strcpy(tmp2, "Pipe was broken");
     1555        mr_asprintf(&tmp, "SIGPIPE");
     1556        mr_asprintf(&tmp2, "Pipe was broken");
    15581557        break;
    15591558    case SIGABRT:
    1560         sprintf(tmp, "SIGABRT");
    1561         sprintf(tmp2,
     1559        mr_asprintf(&tmp, "SIGABRT");
     1560        mr_asprintf(&tmp2,
    15621561                "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message.");
    15631562        break;
    15641563    default:
    1565         sprintf(tmp, "(Unknown)");
    1566     }
    1567 
    1568     strcat(tmp, " signal received from OS");
     1564        mr_asprintf(&tmp, "(Unknown)");
     1565        mr_asprintf(&tmp2, "(Unknown)");
     1566    }
     1567
     1568    mr_strcat(tmp, " signal received from OS");
    15691569    log_to_screen(tmp);
     1570    paranoid_free(tmp);
     1571
    15701572    log_to_screen(tmp2);
     1573    paranoid_free(tmp2);
    15711574    if (sig == SIGABRT) {
    15721575        sleep(10);
  • branches/2.2.9/mondo/src/common/libmondo-devices.c

    r2205 r2211  
    99
    1010#include "my-stuff.h"
     11#include "mr_mem.h"
    1112#include "mondostructures.h"
    1213#include "libmondo-files-EXT.h"
     
    327328    char *program;
    328329    char *incoming;
    329     char *searchstr;
     330    char *searchstr = NULL;
    330331    char *tmp;
    331332
     
    10401041bool is_this_a_valid_disk_format(char *format)
    10411042{
    1042     char *good_formats;
     1043    char *good_formats = NULL;
    10431044    char *command;
    10441045    char *format_sz;
     
    12881289{
    12891290    /*@ buffer ****************************************************** */
    1290     char *command;
    1291     char *dev;
    1292     char *options;
     1291    char *command = NULL;
    12931292    int retval;
    12941293
    1295     malloc_string(command);
    1296     malloc_string(dev);
    1297     malloc_string(options);
    12981294    assert_string_is_neither_NULL_nor_zerolength(device);
    12991295    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    13001296
    13011297    make_hole_for_dir(mountpoint);
    1302     strcpy(options, "ro");
     1298
     1299#ifndef __FreeBSD__
     1300    char *dev = NULL;
     1301    char *options = NULL;
     1302    mr_asprintf(&options, "ro");
     1303#endif
     1304
    13031305    if (isdigit(device[0])) {
    13041306        find_cdrom_device(device, FALSE);
    1305     } else {
    1306         strcpy(dev, device);
    13071307    }
    13081308    if (g_ISO_restore_mode) {
    13091309
    13101310#ifdef __FreeBSD__
    1311         strcpy(dev, make_vn(device));
     1311        mr_asprintf(&dev, make_vn(device));
    13121312        if (!dev) {
    1313             sprintf(command, "Unable to mount ISO (make_vn(%s) failed)",
    1314                     device);
     1313            mr_asprintf(&command, "Unable to mount ISO (make_vn(%s) failed)", device);
    13151314            fatal_error(command);
    13161315        }
    13171316        strcpy(device, dev);
     1317        paranoid_free(dev);
    13181318#else
    1319         strcat(options, ",loop");
     1319        mr_strcat(options, ",loop");
    13201320#endif
    13211321
     
    13261326
    13271327#ifdef __FreeBSD__
    1328     sprintf(command, "mount_cd9660 -r %s %s 2>> %s",
     1328    mr_asprintf(&command, "mount_cd9660 -r %s %s 2>> %s",
    13291329            device, mountpoint, MONDO_LOGFILE);
    13301330
    13311331#else
    1332     sprintf(command, "mount %s -o %s -t iso9660 %s 2>> %s",
     1332    mr_asprintf(&command, "mount %s -o %s -t iso9660 %s 2>> %s",
    13331333            device, options, mountpoint, MONDO_LOGFILE);
     1334    paranoid_free(options);
    13341335#endif
    13351336
     
    13401341    retval = system(command);
    13411342    log_msg(1, "system(%s) returned %d", command, retval);
    1342 
    13431343    paranoid_free(command);
    1344     paranoid_free(dev);
    1345     paranoid_free(options);
     1344
    13461345    return (retval);
    13471346}
     
    21832182void sensibly_set_tmpdir_and_scratchdir()
    21842183{
    2185     char *tmp, *command, *sz;
    2186 
    2187     malloc_string(tmp);
     2184    char *tmp = NULL;
     2185    char *command, *sz;
     2186
    21882187    malloc_string(command);
    21892188    malloc_string(sz);
     
    21912190
    21922191#ifdef __FreeBSD__
    2193     strcpy(tmp,
     2192    mr_asprintf(&tmp,
    21942193           call_program_and_get_last_line_of_output
    21952194           ("LANGUAGE=C df -m -P -t nonfs,msdosfs,ntfs,ntfs-3g,smbfs,smb,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | tr -s '\t' ' ' | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
    21962195#else
    2197     strcpy(tmp,
     2196    mr_asprintf(&tmp,
    21982197           call_program_and_get_last_line_of_output
    21992198           ("LANGUAGE=C df -m -P -x nfs -x nfs4 -x vfat -x ntfs -x ntfs-3g -x smbfs -x smb -x cifs -x afs -x gfs -x ocfs -x ocfs2 -x mvfs -x nsspool -x nssvol -x iso9660| sed 's/                  /devdev/' | tr -s '\t' ' ' | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
     
    22022201    if (tmp[0] != '/') {
    22032202        strcpy(sz, tmp);
    2204         strcpy(tmp, "/");
    2205         strcat(tmp, sz);
     2203        paranoid_free(tmp);
     2204        mr_asprintf(&tmp, "/%s", sz);
    22062205    }
    22072206    if (!tmp[0]) {
     
    22162215
    22172216    sprintf(command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp);
     2217    paranoid_free(tmp);
     2218
    22182219    paranoid_system(command);
    2219     paranoid_free(tmp);
    22202220    paranoid_free(command);
    22212221    paranoid_free(sz);
     
    22822282{
    22832283    int cd_number = -1;
    2284     char *mountdev;
    2285     char *tmp;
    2286 
    2287     malloc_string(mountdev);
    2288     malloc_string(tmp);
     2284    char *mountdev = NULL;
     2285    char *tmp = NULL;
     2286
    22892287    assert(bkpinfo != NULL);
    22902288//  log_it("Asking what_number_cd_is_this");
    22912289    if (g_ISO_restore_mode) {
    2292         sprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'");
    2293 //      log_it("tmp = %s", tmp);
    2294 
    2295         strcpy(mountdev, call_program_and_get_last_line_of_output(tmp));
    2296         strcat(mountdev, "/archives/THIS-CD-NUMBER");
    2297 //      log_it("mountdev = %s", mountdev);
     2290        mr_asprintf(&tmp, "mount | grep iso9660 | awk '{print $3;}'");
     2291
     2292        mr_asprintf(&mountdev, "%s%s", call_program_and_get_last_line_of_output(tmp), "/archives/THIS-CD-NUMBER");
    22982293        cd_number = atoi(last_line_of_file(mountdev));
    2299 //      log_it("cd_number = %d", cd_number);
    23002294        paranoid_free(mountdev);
    23012295        paranoid_free(tmp);
     2296
    23022297        return (cd_number);
    23032298    }
    23042299
    2305     strcpy(mountdev, bkpinfo->media_device);
     2300    mr_asprintf(&mountdev, bkpinfo->media_device);
    23062301    if (!mountdev[0]) {
    23072302        log_it
     
    23162311        }
    23172312    }
    2318     cd_number =
    2319         atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"));
    2320 //  log_it("cd_number..later.. = %d", cd_number);
    23212313    paranoid_free(mountdev);
    2322     paranoid_free(tmp);
     2314
     2315    cd_number = atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"));
    23232316    return (cd_number);
    23242317}
  • branches/2.2.9/mondo/src/common/libmondo-filelist.c

    r2206 r2211  
    1818#include "libmondo-tools-EXT.h"
    1919#include "mr_string.h"
     20#include "mr_mem.h"
    2021
    2122#include <time.h>
     
    484485        log_msg(8, "Analyzing %s", file_to_analyze);
    485486        tmp = mr_stresc(file_to_analyze, "`$\\\"(){}[]'*?&|!#~", '\\');
    486         (void)asprintf(&strtmp, syscall_sprintf, tmp);
     487        mr_asprintf(&strtmp, syscall_sprintf, tmp);
    487488        paranoid_free(tmp);
    488         (void)asprintf(&syscall, "%s 2>> /dev/null", strtmp);   // " MONDO_LOGFILE);
     489        mr_asprintf(&syscall, "%s 2>> /dev/null", strtmp);  // " MONDO_LOGFILE);
    489490        paranoid_free(strtmp);
    490491        call_exe_and_pipe_output_to_fd(syscall, pout);
     
    13891390        malloc_string(name_of_evalcall_form);
    13901391        malloc_string(find_skeleton_marker);
    1391         (void)asprintf(&find_excludes, " ");
     1392        mr_asprintf(&find_excludes, " ");
    13921393        while((token = mr_strtok (sth, delims, &lastpos))) {
    1393           (void)asprintf(&strtmp,"%s", find_excludes);
     1394          mr_asprintf(&strtmp,"%s", find_excludes);
    13941395          paranoid_free(find_excludes);
    1395           (void)asprintf(&find_excludes,"%s -path %s -prune -o", strtmp, token);
     1396          mr_asprintf(&find_excludes,"%s -path %s -prune -o", strtmp, token);
    13961397          paranoid_free(strtmp);
    13971398          paranoid_free(token);
     
    13991400#if linux
    14001401        // 2.6 has /sys as a proc-type thing -- must be excluded
    1401         (void)asprintf(&strtmp,
     1402        mr_asprintf(&strtmp,
    14021403             "find '%s' -fstype mvfs -prune -o -fstype devpts -prune -o -fstype tmpfs -prune -o -fstype proc -prune -o -fstype sysfs -prune -o %s -type d -print > %s 2> /dev/null",
    14031404             dir, find_excludes, g_skeleton_filelist);
    14041405#else
    14051406        // On BSD, for example, /sys is the kernel sources -- don't exclude
    1406         (void)asprintf(&strtmp,
     1407        mr_asprintf(&strtmp,
    14071408             "find '%s' -fstype mvfs -prune -o -path /proc -prune -o %s -type d -print > %s 2> /dev/null",
    14081409                dir, find_excludes, g_skeleton_filelist);
     
    14121413        (void)system(strtmp);
    14131414        paranoid_free(strtmp);
    1414         (void)asprintf(&tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist);
     1415        mr_asprintf(&tmp, "wc -l %s | awk '{print $1;}'", g_skeleton_filelist);
    14151416        g_skeleton_entries =
    14161417            1 + atol(call_program_and_get_last_line_of_output(tmp));
     
    14421443#ifndef _XWIN
    14431444                if (!g_text_mode) {
    1444                     (void)asprintf(&tmp, "Reading %-68s", dir);
     1445                    mr_asprintf(&tmp, "Reading %-68s", dir);
    14451446                    newtDrawRootText(0, g_noof_rows - 3, tmp);
    14461447                    paranoid_free(tmp);
     
    14561457//  log_msg(0, "Cataloguing %s", dir);
    14571458    if (sth[0] == ' ') {
    1458         (void)asprintf(&skip_these, "%s", sth);
     1459        mr_asprintf(&skip_these, "%s", sth);
    14591460    } else {
    1460         (void)asprintf(&skip_these, " %s ", sth);
    1461     }
    1462     (void)asprintf(&new_with_spaces, " %s ", dir);
     1461        mr_asprintf(&skip_these, " %s ", sth);
     1462    }
     1463    mr_asprintf(&new_with_spaces, " %s ", dir);
    14631464    if ((dip = opendir(dir)) == NULL) {
    1464         (void)asprintf(&tmp,"opendir %s", dir);
     1465        mr_asprintf(&tmp,"opendir %s", dir);
    14651466        log_OS_error(tmp);
    14661467        paranoid_free(tmp);
     
    14721473            i++;
    14731474            if (strcmp(dir, "/")) {
    1474                 (void)asprintf(&new,"%s/%s",dir,dit->d_name);
     1475                mr_asprintf(&new,"%s/%s",dir,dit->d_name);
    14751476            } else {
    1476                 (void)asprintf(&new,"%s%s",dir,dit->d_name);
     1477                mr_asprintf(&new,"%s%s",dir,dit->d_name);
    14771478            }
    14781479            paranoid_free(new_with_spaces);
    1479             (void)asprintf(&new_with_spaces, " %s ", new);
     1480            mr_asprintf(&new_with_spaces, " %s ", new);
    14801481            if (strstr(skip_these, new_with_spaces)) {
    14811482                fprintf(fout, "%s\n", new);
     
    14961497                                counter = 0;
    14971498                                uberctr++;
    1498                                 (void)asprintf(&tmp, " %c ",
     1499                                mr_asprintf(&tmp, " %c ",
    14991500                                        special_dot_char(uberctr));
    15001501#ifndef _XWIN
     
    15501551    bool in_quotes = FALSE;
    15511552
    1552     (void)asprintf(&sz_res, "%s", incoming);
     1553    mr_asprintf(&sz_res, "%s", incoming);
    15531554    p = sz_res;
    15541555    while ((*p != ' ' || in_quotes) && *p != '\0') {
     
    15981599        fatal_error("Cannot malloc exclude_paths");
    15991600    }
    1600     (void)asprintf(&sz_datefile,MONDO_CACHE"/difflevel.%d" , 0);
     1601    mr_asprintf(&sz_datefile,MONDO_CACHE"/difflevel.%d" , 0);
    16011602    if (!include_paths && !userdef_filelist) {
    16021603        fatal_error
     
    16061607    sprintf(command, "mkdir -p %s/archives", scratchdir);
    16071608    paranoid_system(command);
    1608     (void)asprintf(&sz_filelist, "%s/tmpfs/filelist.full", tmpdir);
     1609    mr_asprintf(&sz_filelist, "%s/tmpfs/filelist.full", tmpdir);
    16091610    make_hole_for_file(sz_filelist);
    16101611
     
    16461647        log_msg(2, "include_paths = '%s'", include_paths);
    16471648        log_msg(1, "Calculating filelist");
    1648         (void)asprintf(&tmp2, "%s", call_program_and_get_last_line_of_output("mount | grep -Ew 'ntfs|ntfs-3g|fat|vfat|dos' | awk '{print $3}'"));
     1649        mr_asprintf(&tmp2, "%s", call_program_and_get_last_line_of_output("mount | grep -Ew 'ntfs|ntfs-3g|fat|vfat|dos' | awk '{print $3}'"));
    16491650        if (strlen(tmp2) < 1) {
    1650             (void)asprintf(&tmp1," ");
     1651            mr_asprintf(&tmp1," ");
    16511652        } else {
    16521653            log_msg(2, "Found windows FS: %s",tmp2);
    1653             (void)asprintf(&tmp1, "find %s -name '/win386.swp' -o -name '/hiberfil.sys' -o -name '/pagefile.sys' 2> /dev/null\n",tmp2);
     1654            mr_asprintf(&tmp1, "find %s -name '/win386.swp' -o -name '/hiberfil.sys' -o -name '/pagefile.sys' 2> /dev/null\n",tmp2);
    16541655            paranoid_free(tmp2);
    1655             (void)asprintf(&tmp2, "%s", call_program_and_get_last_line_of_output(tmp1));
     1656            mr_asprintf(&tmp2, "%s", call_program_and_get_last_line_of_output(tmp1));
    16561657            log_msg(2, "Found windows files: %s",tmp2);
    16571658        }
  • branches/2.2.9/mondo/src/common/libmondo-mountlist.c

    r2209 r2211  
    7474    prev_part_no = 0;
    7575    tmp[0] = '\0';
    76     asprintf(&flaws_str, "%s", "");
     76    mr_asprintf(&flaws_str, "%s", "");
    7777
    7878
     
    363363    assert_string_is_neither_NULL_nor_zerolength(drive);
    364364    assert(mountlist != NULL);
    365     asprintf(&flaws_str, "%s", "");
     365    mr_asprintf(&flaws_str, "%s", "");
    366366
    367367    malloc_string(tmp);
     
    522522    assert(flaws_str_C != NULL);
    523523
    524     asprintf(&flaws_str, "%s", "");
     524    mr_asprintf(&flaws_str, "%s", "");
    525525
    526526    make_list_of_drives_in_mountlist(mountlist, drivelist);
     
    532532            (drivelist->el[i].device,
    533533             DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE)) {
    534             asprintf(&tmp, " Not evaluating %s (I don't know how yet)",
     534            mr_asprintf(&tmp, " Not evaluating %s (I don't know how yet)",
    535535                    drivelist->el[i].device);
    536536            log_it(tmp);
     
    606606
    607607    for (currline = 0; currline < mountlist->entries; currline++) {
    608         asprintf(&curr_mountpoint, "%s", mountlist->el[currline].mountpoint);
     608        mr_asprintf(&curr_mountpoint, "%s", mountlist->el[currline].mountpoint);
    609609        for (i = 0, copies = 0, last_copy = -1; i < mountlist->entries;
    610610             i++) {
     
    618618        if (copies > 1 && last_copy == currline
    619619            && strcmp(curr_mountpoint, "raid")) {
    620             asprintf(&tmp, " %s %s's.", number_to_text(copies),
     620            mr_asprintf(&tmp, " %s %s's.", number_to_text(copies),
    621621                    curr_mountpoint);
    622622            mr_strcat(flaws_str, "%s", tmp);
     
    657657    for (lino = 0, noof_drives = 0; lino < mountlist->entries; lino++) {
    658658
    659         asprintf(&drive, "%s", mountlist->el[lino].device);
     659        mr_asprintf(&drive, "%s", mountlist->el[lino].device);
    660660        if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
    661661            log_msg(8, "Not putting %s in list of drives: it's a virtual drive", drive);
     
    733733                       (void *) &mountlist->el[i],
    734734                       sizeof(struct mountlist_line));
    735                 asprintf(&tmp,
     735                mr_asprintf(&tmp,
    736736                         "%s is available; user may choose to add it to raid device",
    737737                         output_list->el[items - 1].device);
     
    853853            if (j < items) {
    854854                strcat(mountlist->el[items].device, "_dup");
    855                 asprintf(&tmp,
     855                mr_asprintf(&tmp,
    856856                         "Duplicate entry in mountlist - renaming to %s",
    857857                         mountlist->el[items].device);
     
    859859                paranoid_free(tmp);
    860860            }
    861             asprintf(&tmp, "%s", mountlist->el[items].device);
     861            mr_asprintf(&tmp, "%s", mountlist->el[items].device);
    862862            if (strstr(tmp, "/dev/md/")) {
    863863                log_it("format_device() --- Contracting %s", tmp);
     
    10081008    assert(b >= 0);
    10091009
    1010     asprintf(&device, "%s", mountlist->el[a].device);
    1011     asprintf(&mountpoint, "%s", mountlist->el[a].mountpoint);
    1012     asprintf(&format, "%s", mountlist->el[a].format);
     1010    mr_asprintf(&device, "%s", mountlist->el[a].device);
     1011    mr_asprintf(&mountpoint, "%s", mountlist->el[a].mountpoint);
     1012    mr_asprintf(&format, "%s", mountlist->el[a].format);
    10131013
    10141014    size = mountlist->el[a].size;
  • branches/2.2.9/mondo/src/common/libmondo-raid.c

    r2190 r2211  
    11/* libmondo-raid.c                                                subroutines for handling RAID
    22   $Id$
    3 .
    4 
    5 
    6 06/29
    7 - added create_raidtab_from_mdstat()
    8 - changed char[MAX_STR_LEN] to char*
    9 
    10 10/21/2003
    11 - get_next_raidtab_line() --- correctly handle multiple spaces
    12   between label and value
    13 
    14 07/03
    15 - line 447 - changed assert()
    16 
    17 05/08
    18 - cleaned up some FreeBSd-specific stuff
    19 
    20 05/05
    21 - added Joshua Oreman's FreeBSD patches
    22 
    23 04/25
    24 - added a bunch of RAID utilities from mondorestore/mondo-restore.c
    25 
    26 04/24/2003
    27 - added some assert()'s and log_OS_error()'s
    28 
    29 10/19/2002
    30 - added some comments
    31 
    32 07/24
    33 - created
    343*/
    354
     
    4918#include "libmondo-raid.h"
    5019#include "mr_string.h"
     20#include "mr_mem.h"
    5121
    5222#ifdef __FreeBSD__
     
    7747#else
    7848    /*@ buffer ********************************************************** */
    79     char *command;
     49    char *command = NULL;
    8050    int res;
    8151
    82     command = malloc(MAX_STR_LEN * 2);
    83     strcpy(command, "grep \"");
     52    mr_asprintf(&command, "grep \"");
    8453    if (raidno == -1) {
    85         strcat(command, "linear");
     54        mr_strcat(command, "linear");
    8655    } else {
    87         sprintf(command + strlen(command), "raid%d", raidno);
    88     }
    89     strcat(command, "\" /proc/mdstat > /dev/null 2> /dev/null");
     56        mr_strcat(command, "raid%d", raidno);
     57    }
     58    mr_strcat(command, "\" /proc/mdstat > /dev/null 2> /dev/null");
    9059    log_it("Is raid %d registered? Command = '%s'", raidno, command);
    9160    res = system(command);
    9261    paranoid_free(command);
     62
    9363    if (res) {
    9464        return (FALSE);
     
    10431013    pos = string;
    10441014    while (*pos == ' ') pos += 1;
    1045     asprintf(&strtmp, "%s", pos);
     1015    mr_asprintf(&strtmp, "%s", pos);
    10461016    strcpy(string, strtmp);
    10471017    paranoid_free(strtmp);
     
    10641034    token = mr_strtok (string, delims, &lastpos);
    10651035    // get RAID device name
    1066     asprintf(&strtmp,"%s%s", device_prefix, token);
     1036    mr_asprintf(&strtmp,"%s%s", device_prefix, token);
    10671037    strcpy(raidlist->el[raidlist->entries].raid_device, strtmp);
    10681038    paranoid_free(strtmp);
     
    11231093      case ' ': // normal data disks
    11241094        raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].index = atoi(pos + 1);
    1125         asprintf(&strtmp,"%s%s", device_prefix, token);
     1095        mr_asprintf(&strtmp,"%s%s", device_prefix, token);
    11261096        strcpy(raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].device, strtmp);
    11271097        paranoid_free(strtmp);
     
    11301100      case 'S': // spare disks
    11311101        raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].index = atoi(pos + 1);
    1132         asprintf(&strtmp,"%s%s", device_prefix, token);
     1102        mr_asprintf(&strtmp,"%s%s", device_prefix, token);
    11331103        strcpy(raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].device, strtmp);
    11341104        paranoid_free(strtmp);
     
    11371107      case 'F': // failed disks
    11381108        raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].index = atoi(pos + 1);
    1139         asprintf(&strtmp,"%s%s", device_prefix, token);
     1109        mr_asprintf(&strtmp,"%s%s", device_prefix, token);
    11401110        strcpy(raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].device, strtmp);
    11411111        paranoid_free(strtmp);
  • branches/2.2.9/mondo/src/common/libmondo-stream.c

    r2176 r2211  
    1313
    1414#include "my-stuff.h"
     15#include "mr_mem.h"
    1516#include "mondostructures.h"
    1617#include "libmondo-devices.h"
     
    369370        }
    370371        if (strstr(fname, "xattr") == NULL) {
    371             asprintf(&tmp,"Wrong order expected xattr, got %s, sunshine.", fname);
     372            mr_asprintf(&tmp,"Wrong order expected xattr, got %s, sunshine.", fname);
    372373            fatal_error(tmp);
    373374        }
     
    399400        }
    400401        if (strstr(fname, "acl") == NULL) {
    401             asprintf(&tmp,"Wrong order expected acl, got %s, sunshine.", fname);
     402            mr_asprintf(&tmp,"Wrong order expected acl, got %s, sunshine.", fname);
    402403            fatal_error(tmp);
    403404        }
     
    682683
    683684    log_it("Skipping OBDR headers");
    684     asprintf(&command, "mt -f %s rewind",bkpinfo->media_device);
     685    mr_asprintf(&command, "mt -f %s rewind",bkpinfo->media_device);
    685686    res = run_program_and_log_output(command, 1);
    686687    paranoid_free(command);
    687688
    688     asprintf(&command, "mt -f %s fsf 2",bkpinfo->media_device);
     689    mr_asprintf(&command, "mt -f %s fsf 2",bkpinfo->media_device);
    689690    res = run_program_and_log_output(command, 1);
    690691    paranoid_free(command);
     
    709710    log_it("Creating OBDR headers");
    710711    /* OBDR: First block 10 kB of zero bs = 512 */
    711     asprintf(&command, "mt -f %s compression off",bkpinfo->media_device);
     712    mr_asprintf(&command, "mt -f %s compression off",bkpinfo->media_device);
    712713    res = run_program_and_log_output(command, 1);
    713714    paranoid_free(command);
    714715
    715     asprintf(&command, "mt -f %s rewind",bkpinfo->media_device);
     716    mr_asprintf(&command, "mt -f %s rewind",bkpinfo->media_device);
    716717    res += run_program_and_log_output(command, 1);
    717718    paranoid_free(command);
     
    719720    set_tape_block_size_with_mt(512);
    720721
    721     asprintf(&command, "dd if=/dev/zero of=%s bs=512 count=20",bkpinfo->media_device);
     722    mr_asprintf(&command, "dd if=/dev/zero of=%s bs=512 count=20",bkpinfo->media_device);
    722723    res += run_program_and_log_output(command, 1);
    723724    paranoid_free(command);
     
    726727    set_tape_block_size_with_mt(2048);
    727728
    728     asprintf(&command, "dd if=%s of=%s bs=2048",MINDI_CACHE"/mondorescue.iso",bkpinfo->media_device);
     729    mr_asprintf(&command, "dd if=%s of=%s bs=2048",MINDI_CACHE"/mondorescue.iso",bkpinfo->media_device);
    729730    res += run_program_and_log_output(command, 1);
    730731    paranoid_free(command);
  • branches/2.2.9/mondo/src/common/libmondo-string.c

    r2209 r2211  
    88
    99#include "my-stuff.h"
     10#include "mr_mem.h"
    1011#include "mondostructures.h"
    1112#include "libmondo-string.h"
     
    630631    if (strlen(flaws_str) > 0) {
    631632        paranoid_free(flaws_str_A);
    632         asprintf(&flaws_str_A, "%s", flaws_str + 1);
     633        mr_asprintf(&flaws_str_A, "%s", flaws_str + 1);
    633634    }
    634635    if (strlen(flaws_str_A) >= 74) {
    635636        for (i = 74; flaws_str_A[i] != ' '; i--);
    636637        paranoid_free(flaws_str_B);
    637         asprintf(&flaws_str_B, "%s", flaws_str_A + i + 1);
     638        mr_asprintf(&flaws_str_B, "%s", flaws_str_A + i + 1);
    638639        flaws_str_A[i] = '\0';
    639640    }
     
    641642        for (i = 74; flaws_str_B[i] != ' '; i--);
    642643        paranoid_free(flaws_str_C);
    643         asprintf(&flaws_str_C, "%s", flaws_str_B + i + 1);
     644        mr_asprintf(&flaws_str_C, "%s", flaws_str_B + i + 1);
    644645        flaws_str_B[i] = '\0';
    645646    }
  • branches/2.2.9/mondo/src/common/libmondo-tools.c

    r2205 r2211  
    1010
    1111#include "my-stuff.h"
     12#include "mr_mem.h"
    1213#include "mondostructures.h"
    1314#include "lib-common-externs.h"
     
    232233
    233234    uname(&utsn);
    234     asprintf(&tmp, "%s", utsn.machine);
     235    mr_asprintf(&tmp, "%s", utsn.machine);
    235236    return (tmp);
    236237}
     
    420421int post_param_configuration()
    421422{
    422     char *extra_cdrom_params;
    423     char *mondo_mkisofs_sz;
     423    char *extra_cdrom_params = NULL;
     424    char *mondo_mkisofs_sz = NULL;
    424425    char *command;
    425426    char *mtpt;
    426     char *hostname, *ip_address;
     427    char *hostname;
     428    char *ip_address = NULL;
    427429    int retval = 0;
    428430    char *colon;
     
    440442
    441443    assert(bkpinfo != NULL);
    442     malloc_string(extra_cdrom_params);
    443     malloc_string(mondo_mkisofs_sz);
    444444    malloc_string(command);
    445445    malloc_string(mtpt);
    446446    malloc_string(hostname);
    447     malloc_string(ip_address);
    448447    malloc_string(cdr_exe);
    449448    malloc_string(tmp);
     
    497496
    498497    if (bkpinfo->backup_media_type == dvd) {
    499         extra_cdrom_params[0] = '\0';
    500         mondo_mkisofs_sz[0] = '\0';
    501498        if (find_home_of_exe("growisofs")) {
    502499            strcpy(cdr_exe, "growisofs");
     
    506503        }
    507504        if (bkpinfo->nonbootable_backup) {
    508             strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);
     505            mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);
    509506        } else if
    510507#ifdef __FreeBSD__
     
    515512#ifdef __IA64__
    516513    {
    517         strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);
     514        mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);
    518515    }
    519516#else
    520517    {
    521         strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);
     518        mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);
    522519    }
    523520#endif
    524521        else
    525522        {
    526             strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
     523            mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
    527524        }
    528525        if (bkpinfo->manual_cd_tray) {
     526            paranoid_free(mondo_mkisofs_sz);
    529527            fatal_error("Manual CD tray + DVD not supported yet.");
    530528            // -m isn't supported by growisofs, BTW...
     
    533531                    "%s %s -Z %s . 2>> _ERR_",
    534532                    mondo_mkisofs_sz,
    535                     extra_cdrom_params, bkpinfo->media_device);
     533                    "", bkpinfo->media_device);
     534            paranoid_free(mondo_mkisofs_sz);
    536535        }
    537536        if (getenv ("SUDO_COMMAND")) {
     
    549548    if (bkpinfo->backup_media_type == cdrw
    550549        || bkpinfo->backup_media_type == cdr) {
    551         extra_cdrom_params[0] = '\0';
    552550        if (!bkpinfo->manual_cd_tray) {
    553             strcat(extra_cdrom_params, "-waiti ");
     551            mr_asprintf(&extra_cdrom_params, "-waiti ");
    554552        }
    555553        if (bkpinfo->backup_media_type == cdrw) {
    556             strcat(extra_cdrom_params, "blank=fast ");
     554            mr_asprintf(&extra_cdrom_params, "blank=fast ");
    557555        }
    558556        if (find_home_of_exe("cdrecord")) {
     
    564562        }
    565563        if (bkpinfo->nonbootable_backup) {
    566             strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT);
     564            mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT);
    567565        } else if
    568566#ifdef __FreeBSD__
     
    573571#ifdef __IA64__
    574572    {
    575         strcat(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);
     573        mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);
    576574    }
    577575#else
    578576    {
    579         strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);
     577        mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);
    580578    }
    581579#endif
    582580        else
    583581        {
    584             strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);
     582            mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);
    585583        }
    586584        if (bkpinfo->manual_cd_tray) {
     
    609607                    bkpinfo->cdrw_speed);
    610608        }
     609        paranoid_free(mondo_mkisofs_sz);
     610        paranoid_free(extra_cdrom_params);
    611611    }                           // end of CD code
    612612
     
    693693                retval++;
    694694            } else {
    695                 strcpy(ip_address, inet_ntoa
     695                mr_asprintf(&ip_address, inet_ntoa
    696696                       ((struct in_addr)
    697697                        *((struct in_addr *) hent->h_addr)));
    698                 strcat(ip_address, strchr(bkpinfo->nfs_mount, ':'));
     698                mr_strcat(ip_address, strchr(bkpinfo->nfs_mount, ':'));
    699699                strcpy(bkpinfo->nfs_mount, ip_address);
     700                paranoid_free(ip_address);
    700701            }
    701702        }
     
    718719    g_backup_media_type = bkpinfo->backup_media_type;
    719720    paranoid_free(mtpt);
    720     paranoid_free(extra_cdrom_params);
    721     paranoid_free(mondo_mkisofs_sz);
    722721    paranoid_free(command);
    723722    paranoid_free(hostname);
    724     paranoid_free(ip_address);
    725723    paranoid_free(cdr_exe);
    726724    paranoid_free(tmp);
     
    758756
    759757    unlink(MONDO_TRACEFILE);
    760     asprintf(&tmp,"rm -Rf %s/changed.files*",MONDO_CACHE);
     758    mr_asprintf(&tmp,"rm -Rf %s/changed.files*",MONDO_CACHE);
    761759    run_program_and_log_output(tmp, FALSE);
    762760    paranoid_free(tmp);
     
    783781    if ((bkpinfo->tmpdir != NULL) && (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL)) {
    784782        /* purging a potential old tmpdir */
    785         asprintf(&tmp,"rm -Rf %s",bkpinfo->tmpdir);
     783        mr_asprintf(&tmp,"rm -Rf %s",bkpinfo->tmpdir);
    786784        system(tmp);
    787785        paranoid_free(tmp);
     
    789787
    790788    if (path != NULL) {
    791         asprintf(&tmp, "%s/mondo.tmp.XXXXXX", path);
     789        mr_asprintf(&tmp, "%s/mondo.tmp.XXXXXX", path);
    792790    } else if (getenv("TMPDIR")) {
    793         asprintf(&tmp, "%s/mondo.tmp.XXXXXX", getenv("TMPDIR"));
     791        mr_asprintf(&tmp, "%s/mondo.tmp.XXXXXX", getenv("TMPDIR"));
    794792    } else if (getenv("TMP")) {
    795         asprintf(&tmp, "%s/mondo.tmp.XXXXXX", getenv("TMP"));
     793        mr_asprintf(&tmp, "%s/mondo.tmp.XXXXXX", getenv("TMP"));
    796794    } else {
    797         asprintf(&tmp, "/tmp/mondo.tmp.XXXXXX");
     795        mr_asprintf(&tmp, "/tmp/mondo.tmp.XXXXXX");
    798796    }
    799797    p = mkdtemp(tmp);
  • branches/2.2.9/mondo/src/common/libmondo-verify.c

    r1747 r2211  
    11/***************************************************************************
    2 libmondo-verify.c  -  description
    3 -----------------
    4 
    5 begin: Fri Apr 19 16:40:35 EDT 2002
    6 copyright : (C) 2002 Mondo  Hugo Rabson
    7 email     : Hugo Rabson <hugorabson@msn.com>
    8 edited by : by Stan Benoit 4/2002
    9 email     : troff@nakedsoul.org
    10 cvsid     : $Id$
     2$Id$
    113***************************************************************************/
    12 
    13 /***************************************************************************
    14  *                                                                         *
    15  *   This program is free software; you can redistribute it and/or modify  *
    16  *   it under the terms of the GNU General Public License as published by  *
    17  *   the Free Software Foundation; either version 2 of the License, or     *
    18  *   (at your option) any later version.                                   *
    19  *                                                                         *
    20  ***************************************************************************/
    21 /* mondo-verify
    22 
    23 
    24 07/07
    25 - added star verify support
    26 
    27 04/04/2004
    28 - added star support
    29 
    30 10/23/2003
    31 - changed "ISO #n" to "<media descriptor> #n"
    32 
    33 10/01
    34 - working on biggiefile verification (CDs)
    35 
    36 09/16
    37 - fixed bug in CD biggie verif'n
    38 
    39 09/15
    40 - state explicitly that we do not verify disk images
    41 
    42 09/13
    43 - working on verify_all_slices_on_CD()
    44 
    45 09/01
    46 - write list of changed biggiefiles (streaming only) to changed.files
    47 
    48 05/05
    49 - exclude /dev/ * from list of changed files
    50 - add Joshua Oreman's FreeBSD patches
    51 
    52 04/24/2003
    53 - added lots of assert()'s and log_OS_error()'s
    54 
    55 09/01 - 09/30/2002
    56 - run_program_and_log_output() now takes boolean operator to specify
    57   whether it will log its activities in the event of _success_
    58 - eject_device() added
    59 - cleaned up 'changed file' feedback a little bit
    60 
    61 08/01 - 08/31
    62 - make sure to prefix bkpinfo->restore_path to local biggiefile fname when
    63   comparing it to the archived copy of biggiefile; otherwise, biggiefile
    64   not found & checksum missing & so on
    65 - exclude "incheckentry xwait()" from changed.files
    66 - cleaned up some log_it() calls
    67 
    68 07/01 - 07/31
    69 - renamed libmondo-verify.c
    70 - say 'bigfile' not 'biggiefile'
    71 - exclude /dev/ * from changed.files
    72 
    73 01/01 - 06/30
    74 - remove /tmp/changed.files.* dead files
    75 - don't pclose() tape after calling closein_tape(): the latter does it already
    76 - fixed bug in verify_cd_image()'s CD-mounting code
    77 - don't write to screen "old cksum.. curr cksum.."
    78 - changed the gawks to awks for the benefit of Debian
    79 - handles files >2GB in size
    80 - fixed bug in /tmp/changed.files-generator
    81 - re-enabled a lot of CD-verification code
    82 - afioballs are saved in %s/tmpfs/ now (%s=tmpdir)
    83 - changed some labels to make them more user-friendly
    84 - don't chdir() anywhere before verifying stuff
    85 - changed files are now detected by verify_tape_backup() and listed in
    86   /tmp/changed.files
    87 - replaced &> with > .. 2>
    88 - still implementing improved tape support
    89 
    90 
    91 Started late Dec, 2001
    92 
    93 -----------------------------------------------------------------------------
    94 */
    954
    965
     
    10110
    10211#include "my-stuff.h"
     12#include "mr_mem.h"
    10313#include "mondostructures.h"
    10414#include "libmondo-verify.h"
     
    419329                            bkpinfo->restore_path,
    420330                            biggiestruct.filename);
    421                 asprintf(&tmp, "echo \"%s/%s not found\" >> %s/biggies.changed",
     331                mr_asprintf(&tmp, "echo \"%s/%s not found\" >> %s/biggies.changed",
    422332                            bkpinfo->restore_path,
    423333                            biggiestruct.filename,
     
    1070980    assert(bkpinfo != NULL);
    1071981
    1072     asprintf(&fname, "%s1", bkpinfo->media_device);
     982    mr_asprintf(&fname, "%s1", bkpinfo->media_device);
    1073983    if (is_this_device_mounted(fname)) {
    1074984        log_msg(1, "USB device mounted. Remounting it at the right place");
    1075         asprintf(&tmp, "umount %s", fname);
     985        mr_asprintf(&tmp, "umount %s", fname);
    1076986        run_program_and_log_output(tmp, FALSE);
    1077987        paranoid_free(tmp);
     
    1080990
    1081991    log_msg(1, "Mounting USB device.");
    1082     asprintf(&mountpoint, "%s/usb", bkpinfo->tmpdir);
    1083     asprintf(&tmp, "mkdir -p %s", mountpoint);
     992    mr_asprintf(&mountpoint, "%s/usb", bkpinfo->tmpdir);
     993    mr_asprintf(&tmp, "mkdir -p %s", mountpoint);
    1084994    run_program_and_log_output(tmp, FALSE);
    1085995    paranoid_free(tmp);
    1086996    /* Mindi always create one single parition on the USB dev */
    1087     asprintf(&tmp, "mount %s1 %s", bkpinfo->media_device, mountpoint);
     997    mr_asprintf(&tmp, "mount %s1 %s", bkpinfo->media_device, mountpoint);
    1088998    ret = run_program_and_log_output(tmp, FALSE);
    1089999    paranoid_free(tmp);
     
    10951005    sync();
    10961006    log_msg(2, "OK, I've mounted the USB Disk/Key\n");
    1097     asprintf(&tmp, "%s/archives/NOT-THE-LAST", mountpoint);
     1007    mr_asprintf(&tmp, "%s/archives/NOT-THE-LAST", mountpoint);
    10981008    if (!does_file_exist(tmp)) {
    10991009        log_msg
     
    11121022    verify_all_slices_on_CD(mountpoint);
    11131023
    1114     asprintf(&tmp1, "umount %s", mountpoint);
     1024    mr_asprintf(&tmp1, "umount %s", mountpoint);
    11151025#ifdef __FreeBSD__
    11161026    ret += system(tmp1);
     
    11211031#endif
    11221032    {
    1123         asprintf(&tmp, "%s failed; unable to unmount USB device\n", tmp1);
     1033        mr_asprintf(&tmp, "%s failed; unable to unmount USB device\n", tmp1);
    11241034        log_to_screen(tmp);
    11251035        paranoid_free(tmp);
  • branches/2.2.9/mondo/src/common/newt-specific.c

    r2136 r2211  
    1919
    2020#include "my-stuff.h"
     21#include "mr_mem.h"
    2122#include "mondostructures.h"
    2223#include "newt-specific.h"
     
    263264char *tmp1 = NULL;
    264265
    265     asprintf(&tmp,"ps %s | grep \" %s \" | awk '{print %s;}' | grep -v \"grep\"", ps_options, str , ps_proc_id);
     266    mr_asprintf(&tmp,"ps %s | grep \" %s \" | awk '{print %s;}' | grep -v \"grep\"", ps_options, str , ps_proc_id);
    266267    run_program_and_log_output(tmp, TRUE);
    267268    if (strlen(tmp) > 0) {
    268         asprintf(&tmp1,"kill `%s`", tmp);
     269        mr_asprintf(&tmp1,"kill `%s`", tmp);
    269270        run_program_and_log_output(tmp1, TRUE);
    270271        paranoid_free(tmp1);
     
    386387        run_program_and_log_output("umount " MNT_CDROM, FALSE);
    387388        if (g_selfmounted_isodir) {
    388             asprintf(&command, "umount %s", g_selfmounted_isodir);
     389            mr_asprintf(&command, "umount %s", g_selfmounted_isodir);
    389390            run_program_and_log_output(command, 1);
    390391            paranoid_free(command);
    391             asprintf(&command, "rmdir %s", g_selfmounted_isodir);
     392            mr_asprintf(&command, "rmdir %s", g_selfmounted_isodir);
    392393            run_program_and_log_output(command, 1);
    393394            paranoid_free(command);
     
    405406        printf("Type 'less %s' to see the output log\n", MONDO_LOGFILE);
    406407        if (strstr(bkpinfo->tmpdir ,"mondo.tmp.") != NULL) {
    407             asprintf(&command, "rm -Rf %s %s", bkpinfo->tmpdir, bkpinfo->scratchdir);
     408            mr_asprintf(&command, "rm -Rf %s %s", bkpinfo->tmpdir, bkpinfo->scratchdir);
    408409            system(command);
    409410            paranoid_free(command);
     
    956957        /*@ buffers ********************************************************** */
    957958        char *timeline_str;
    958         char *pcline_str;
    959         char *taskprogress;
     959        char *pcline_str = NULL;
     960        char *taskprogress = NULL;
    960961
    961962        /*@ int ************************************************************** */
     
    965966
    966967        malloc_string(timeline_str);
    967         malloc_string(pcline_str);
    968         malloc_string(taskprogress);
    969968        timeline_str[0] = '\0';
    970969//  log_it("update_eval_call_form called");
     
    997996                    time_remaining % 60);
    998997            if (percentage < 3) {
    999                 sprintf(pcline_str, " Working");
     998                mr_asprintf(&pcline_str, " Working");
    1000999                for (j = 0; j < g_mysterious_dot_counter; j++) {
    1001                     strcat(pcline_str, ".");
     1000                    mr_strcat(pcline_str, ".");
    10021001                }
    10031002                for (; j < 27; j++) {
    1004                     strcat(pcline_str, " ");
     1003                    mr_strcat(pcline_str, " ");
    10051004                }
    1006                 sprintf(pcline_str + strlen(pcline_str), " %c",
    1007                         special_dot_char(g_mysterious_dot_counter));
     1005                mr_strcat(pcline_str, " %c", special_dot_char(g_mysterious_dot_counter));
    10081006            } else {
    1009                 sprintf(pcline_str, " %3d%% done              %3d%% to go",
     1007                mr_asprintf(&pcline_str, " %3d%% done              %3d%% to go",
    10101008                        percentage, 100 - percentage);
    10111009            }
    10121010            if (g_text_mode) {
    1013                 sprintf(taskprogress, "TASK:  [");
     1011                mr_asprintf(&taskprogress, "TASK:  [");
    10141012                for (i = 0; i < percentage; i += 5) {
    1015                     strcat(taskprogress, "*");
     1013                    mr_strcat(taskprogress, "*");
    10161014                }
    10171015                for (; i < 100; i += 5) {
    1018                     strcat(taskprogress, ".");
     1016                    mr_strcat(taskprogress, ".");
    10191017                }
    10201018                if (percentage >= 3) {
    1021                     sprintf(taskprogress + strlen(taskprogress),
    1022                             "] %3d%% done; %2ld:%02ld to go", percentage,
     1019                    mr_strcat(taskprogress, "] %3d%% done; %2ld:%02ld to go", percentage,
    10231020                            time_remaining / 60, time_remaining % 60);
    10241021                    printf("---evalcall---1--- %s\n",
     
    10271024                    printf("---evalcall---E---\n");
    10281025                }
     1026                paranoid_free(taskprogress);
    10291027            } else {
    10301028                newtScaleSet(g_isoform_scale,
     
    10371035                }
    10381036            }
     1037            paranoid_free(pcline_str);
    10391038        }
    10401039        if (!g_text_mode) {
     
    10431042        }
    10441043        paranoid_free(timeline_str);
    1045         paranoid_free(pcline_str);
    1046         paranoid_free(taskprogress);
    10471044    }
    10481045
     
    10991096        char *percentline_str;
    11001097        char *timeline_str;
    1101         char *taskprogress;
     1098        char *taskprogress = NULL;
    11021099        char *tmp;
    11031100
     
    11051102        percentline_str = malloc(MAX_NEWT_COMMENT_LEN);
    11061103        timeline_str = malloc(MAX_NEWT_COMMENT_LEN);
    1107         taskprogress = malloc(MAX_NEWT_COMMENT_LEN);
    11081104        malloc_string(tmp);
    11091105        if (!g_text_mode) {
     
    11591155            printf("---progress-form---3--- %s\n", blurb3);
    11601156            printf("---progress-form---E---\n");
    1161             sprintf(taskprogress, "TASK:  [");
     1157            mr_asprintf(&taskprogress, "TASK:  [");
    11621158            for (i = 0; i < percentage; i += 5) {
    1163                 strcat(taskprogress, "*");
     1159                mr_strcat(taskprogress, "*");
    11641160            }
    11651161            for (; i < 100; i += 5) {
    1166                 strcat(taskprogress, ".");
     1162                mr_strcat(taskprogress, ".");
    11671163            }
    11681164            if (percentage > 100) {
    11691165                log_msg(2, "percentage = %d", percentage);
    11701166            }
    1171             sprintf(taskprogress + strlen(taskprogress),
    1172                     "] %3d%c", percentage, '%');
    1173             sprintf(taskprogress + strlen(taskprogress),
    1174                     " done; %2ld:%02ld to go",
     1167            mr_strcat(taskprogress, "] %3d%c", percentage, '%');
     1168            mr_strcat(taskprogress, " done; %2ld:%02ld to go",
    11751169                    time_remaining / 60, time_remaining % 60);
    11761170            printf("---progress-form---4--- %s\n", taskprogress);
     1171            paranoid_free(taskprogress);
    11771172        } else {
    11781173            center_string(blurb1, 54);
     
    11991194        paranoid_free(percentline_str);
    12001195        paranoid_free(timeline_str);
    1201         paranoid_free(taskprogress);
    12021196        paranoid_free(tmp);
    12031197    }
     
    14141408        }
    14151409
    1416         asprintf(&tmp1,"%s/icantfindthesefiles.txt",bkpinfo->tmpdir);
     1410        mr_asprintf(&tmp1,"%s/icantfindthesefiles.txt",bkpinfo->tmpdir);
    14171411        if (!(fout = fopen(tmp1, "a"))) {
    14181412            log_msg(2, "Can't write to %s", tmp1);
     
    15031497    char *filelist_entry_to_string(struct s_filelist_entry *flentry) {
    15041498        static char comment[100];
    1505         char *tmp;
     1499        char *tmp = NULL;
    15061500
    15071501        iamhere("entering");
    1508         malloc_string(tmp);
    15091502        assert(flentry != NULL);
    15101503        if (flentry->severity == 0) {
    1511             strcpy(tmp, "0   ");
     1504            mr_asprintf(&tmp, "0   ");
    15121505        } else if (flentry->severity == 1) {
    1513             strcpy(tmp, "low ");
     1506            mr_asprintf(&tmp, "low ");
    15141507        } else if (flentry->severity == 2) {
    1515             strcpy(tmp, "med ");
    1516         } else {
    1517             strcpy(tmp, "high");
    1518         }
    1519         strcat(tmp, "  ");
    1520         strncat(tmp, flentry->filename, 100);
    1521         tmp[98] = '\0';
    1522         strcpy(comment, tmp);
     1508            mr_asprintf(&tmp, "med ");
     1509        } else {
     1510            mr_asprintf(&tmp, "high");
     1511        }
     1512        mr_strcat(tmp, "  ");
     1513        mr_strcat(tmp, flentry->filename);
     1514        strncpy(comment, tmp, 99);
    15231515        paranoid_free(tmp);
     1516
    15241517        iamhere("leaving");
    15251518        return (comment);
  • branches/2.2.9/mondo/src/mondoarchive/Makefile.am

    r1930 r2211  
    1111sbin_PROGRAMS        = mondoarchive
    1212mondoarchive_SOURCES = mondoarchive.c
    13 mondoarchive_LDADD   = ${top_builddir}/src/common/libmondo.a
     13mondoarchive_LDADD   = ${top_builddir}/src/common/libmondo.a ${top_builddir}/src/lib/libmr.a
  • branches/2.2.9/mondo/src/mondoarchive/mondoarchive.c

    r2113 r2211  
    11/***************************************************************************
    2                           main.c  -  description
    3                              -------------------
    4     begin                : Fri Apr 19 16:40:35 EDT 2002
    5     copyright            : (C) 2002 by Stan Benoit
    6     email                : troff@nakedsoul.org
    7     cvsid                : $Id$
    8  ***************************************************************************/
    9 
    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  * @file
    21  * The main file for mondoarchive.
    22  */
     2$Id$
     3* The main file for mondoarchive.
     4*/
    235
    246/************************* #include statements *************************/
     
    279#include <stdlib.h>
    2810#include "my-stuff.h"
     11#include "mr_mem.h"
    2912#include "../common/mondostructures.h"
    3013#include "../common/libmondo.h"
     
    7053/* Reference to global bkpinfo */
    7154struct s_bkpinfo *bkpinfo;
     55
     56/* No cleanup for the moment */
     57void (*mr_cleanup)(void) = NULL;
    7258
    7359/* To be coded */
     
    183169    char *tmp1 = NULL;
    184170    int res, retval;
    185     char *say_at_end;
     171    char *say_at_end = NULL;
    186172
    187173/* Make sure I'm root; abort if not */
     
    211197    diffs = 0;
    212198    malloc_string(tmp);
    213     malloc_string(say_at_end);
    214     say_at_end[0] = '\0';
    215199    malloc_libmondo_global_strings();
    216200
     
    220204
    221205    /* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */
    222     asprintf(&tmp1,"%s:/sbin:/usr/sbin:/usr/local/sbin",getenv("PATH"));
     206    mr_asprintf(&tmp1,"%s:/sbin:/usr/sbin:/usr/local/sbin",getenv("PATH"));
    223207    setenv("PATH", tmp1, 1);
    224208    paranoid_free(tmp1);
    225209
    226210    /* Add the ARCH environment variable for ia64 purposes */
    227     asprintf(&tmp1,"%s",get_architecture());
     211    mr_asprintf(&tmp1,"%s",get_architecture());
    228212    setenv("ARCH", tmp1, 1);
    229213    paranoid_free(tmp1);
     
    378362        retval += res;
    379363        if (res) {
    380             strcat(say_at_end,
     364            mr_asprintf(&say_at_end,
    381365                   "Data archived. Please check the logs, just as a precaution. ");
    382366        } else {
    383             strcat(say_at_end, "Data archived OK. ");
     367            mr_asprintf(&say_at_end, "Data archived OK. ");
    384368        }
    385369    }
     
    391375            sprintf(tmp, "%d difference%c found.", -res,
    392376                    (-res != 1) ? 's' : ' ');
    393             strcat(say_at_end, tmp);
     377            mr_asprintf(&say_at_end, tmp);
    394378            log_to_screen(tmp);
    395379            res = 0;
     
    424408        unlink(MONDO_CACHE"/changed.files");
    425409    }
    426     log_to_screen(say_at_end);
     410    if (say_at_end != NULL) {
     411        log_to_screen(say_at_end);
     412        paranoid_free(say_at_end);
     413    }
    427414    sprintf(tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
    428415    run_program_and_log_output(tmp, TRUE);
     
    445432
    446433    free_libmondo_global_strings();
    447     paranoid_free(say_at_end);
    448434   
    449435
  • branches/2.2.9/mondo/src/mondorestore/mondo-prep.c

    r2205 r2211  
    11/***************************************************************************
    22$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*/
    185
    196
    207#include "my-stuff.h"
     8#include "mr_mem.h"
    219#include "../common/mondostructures.h"
    2210#include "mondoprep.h"
     
    349337            log_it("%s... so I'll get creative.", tmp);
    350338            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);
    352340                strcpy(tmp, call_program_and_get_last_line_of_output(tmp1));
    353341                free(tmp1);
    354342            } 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);
    356344                strcpy(tmp, call_program_and_get_last_line_of_output(tmp1));
    357345                free(tmp1);
     
    596584  }
    597585  // 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);
    599587  for (j = 1; j < raidlist->el[i].data_disks.entries; j++) {
    600     asprintf(&strtmp, "%s", devices);
     588    mr_asprintf(&strtmp, "%s", devices);
    601589    paranoid_free(devices);
    602     asprintf(&devices, "%s %s", strtmp,
     590    mr_asprintf(&devices, "%s %s", strtmp,
    603591         raidlist->el[i].data_disks.el[j].device);
    604592    paranoid_free(strtmp);
    605593  }
    606594  for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) {
    607     asprintf(&strtmp, "%s", devices);
     595    mr_asprintf(&strtmp, "%s", devices);
    608596    paranoid_free(devices);
    609     asprintf(&devices, "%s %s", strtmp,
     597    mr_asprintf(&devices, "%s %s", strtmp,
    610598         raidlist->el[i].spare_disks.el[j].device);
    611599    paranoid_free(strtmp);
     
    613601  // translate RAID level
    614602  if (raidlist->el[i].raid_level == -2) {
    615     asprintf(&level, "multipath");
     603    mr_asprintf(&level, "multipath");
    616604  } else if (raidlist->el[i].raid_level == -1) {
    617     asprintf(&level, "linear");
     605    mr_asprintf(&level, "linear");
    618606  } else {
    619     asprintf(&level, "raid%d", raidlist->el[i].raid_level);
     607    mr_asprintf(&level, "raid%d", raidlist->el[i].raid_level);
    620608  }
    621609  // create RAID device:
     
    624612  // - faulty devices ignored
    625613  // - persistent superblock always used as this is recommended
    626   asprintf(&program,
     614  mr_asprintf(&program,
    627615       "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d",
    628616       raidlist->el[i].raid_device, level,
    629617       raidlist->el[i].data_disks.entries);
    630618  if (raidlist->el[i].parity != -1) {
    631     asprintf(&strtmp, "%s", program);
     619    mr_asprintf(&strtmp, "%s", program);
    632620    paranoid_free(program);
    633621    switch(raidlist->el[i].parity) {
    634622    case 0:
    635       asprintf(&program, "%s --parity=%s", strtmp, "la");
     623      mr_asprintf(&program, "%s --parity=%s", strtmp, "la");
    636624      break;
    637625    case 1:
    638       asprintf(&program, "%s --parity=%s", strtmp, "ra");
     626      mr_asprintf(&program, "%s --parity=%s", strtmp, "ra");
    639627      break;
    640628    case 2:
    641       asprintf(&program, "%s --parity=%s", strtmp, "ls");
     629      mr_asprintf(&program, "%s --parity=%s", strtmp, "ls");
    642630      break;
    643631    case 3:
    644       asprintf(&program, "%s --parity=%s", strtmp, "rs");
     632      mr_asprintf(&program, "%s --parity=%s", strtmp, "rs");
    645633      break;
    646634    default:
     
    651639  }
    652640  if (raidlist->el[i].chunk_size != -1) {
    653     asprintf(&strtmp, "%s", program);
     641    mr_asprintf(&strtmp, "%s", program);
    654642    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);
    656644    paranoid_free(strtmp);
    657645  }
    658646  if (raidlist->el[i].spare_disks.entries > 0) {
    659     asprintf(&strtmp, "%s", program);
     647    mr_asprintf(&strtmp, "%s", program);
    660648    paranoid_free(program);
    661     asprintf(&program, "%s --spare-devices=%d", strtmp,
     649    mr_asprintf(&program, "%s --spare-devices=%d", strtmp,
    662650         raidlist->el[i].spare_disks.entries);
    663651    paranoid_free(strtmp);
    664652  }
    665   asprintf(&strtmp, "%s", program);
     653  mr_asprintf(&strtmp, "%s", program);
    666654  paranoid_free(program);
    667   asprintf(&program, "%s %s", strtmp, devices);
     655  mr_asprintf(&program, "%s %s", strtmp, devices);
    668656  paranoid_free(strtmp);
    669657  res = run_program_and_log_output(program, 1);
     
    690678{
    691679    /** int **************************************************************/
    692     int res;
    693     int retval = 0;
    694680#ifdef __FreeBSD__
    695681    static bool vinum_started_yet = FALSE;
     
    698684    /** buffers ***********************************************************/
    699685    char *program;
    700     char *tmp;
     686    char *tmp = NULL;
     687    int res = 0;
     688    int retval = 0;
    701689
    702690    /** end ****************************************************************/
    703691
    704692    malloc_string(program);
    705     malloc_string(tmp);
    706693    assert_string_is_neither_NULL_nor_zerolength(device);
    707694    assert(format != NULL);
    708695
    709696    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);
    711698        log_it(tmp);
     699        paranoid_free(tmp);
    712700        paranoid_free(program);
    713         paranoid_free(tmp);
    714701        return (0);
    715702    }
     
    723710#endif
    724711    if (strlen(format) <= 2) {
    725         sprintf(tmp,
     712        mr_asprintf(&tmp,
    726713                "%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",
    727714                device, format);
    728715        log_it(tmp);
     716        paranoid_free(tmp);
    729717        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);
    730723        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);
    736724        paranoid_free(program);
    737         paranoid_free(tmp);
    738725        return (1);
    739726    }
     
    762749            FILE *fin;
    763750            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);
    767753            log_to_screen(tmp);
     754            paranoid_free(tmp);
     755
    768756            /* format raid partition */
    769757            //      sprintf (program, "mkraid --really-force %s", device); --- disabled -- BB, 02/12/2003
     
    780768                    *(strchr(line, '\n')) = '\0';   // get rid of the \n on the end
    781769
    782                 sprintf(tmp, "Initializing plex: %s", line);
     770                mr_asprintf(&tmp, "Initializing plex: %s", line);
    783771                open_evalcall_form(tmp);
    784                 sprintf(tmp, "vinum init %s", line);
     772                paranoid_free(tmp);
     773
     774                mr_asprintf(&tmp, "vinum init %s", line);
    785775                system(tmp);
     776                paranoid_free(tmp);
     777
    786778                while (1) {
    787                     sprintf(tmp,
     779                    mr_asprintf(&tmp,
    788780                            "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'",
    789781                            line);
    790782                    FILE *pin = popen(tmp, "r");
     783                    paranoid_free(tmp);
     784
    791785                    char status[MAX_STR_LEN / 4];
    792786                    fgets(status, MAX_STR_LEN / 4 - 1, pin);
     
    806800        }
    807801#else
    808         sprintf(tmp, "Initializing RAID device %s", device);
     802        mr_asprintf(&tmp, "Initializing RAID device %s", device);
    809803        log_to_screen(tmp);
     804        paranoid_free(tmp);
    810805
    811806// Shouldn't be necessary.
     
    856851    }
    857852    res = which_format_command_do_i_need(format, program);
    858     sprintf(tmp, "%s %s", program, device);
     853    mr_asprintf(&tmp, "%s %s", program, device);
    859854    if (strstr(program, "kludge")) {
    860         strcat(tmp, " /");
     855        mr_strcat(tmp, " /");
    861856    }
    862857    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);
    864861    update_progress_form(tmp);
     862    paranoid_free(tmp);
     863
    865864    res = run_program_and_log_output(program, FALSE);
     865    mr_asprintf(&tmp, "");
    866866    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",
    868868                format, device);
    869869#ifdef __FreeBSD__
     
    885885    retval += res;
    886886    if (retval) {
    887         strcat(tmp, "...failed");
     887        mr_strcat(tmp, "...failed");
    888888    } else {
    889         strcat(tmp, "...OK");
     889        mr_strcat(tmp, "...OK");
    890890    }
    891891
    892892    log_to_screen(tmp);
     893    paranoid_free(tmp);
     894
    893895    paranoid_free(program);
    894     paranoid_free(tmp);
    895896    system("sync");
    896897    sleep(1);
     
    17171718    char *tmp;
    17181719    char *logfile;
    1719     char *output;
     1720    char *output = NULL;
    17201721
    17211722    /** pointers **********************************************************/
     
    17301731    malloc_string(tmp);
    17311732    malloc_string(logfile);
    1732     malloc_string(output);
    17331733
    17341734    assert_string_is_neither_NULL_nor_zerolength(drive);
     
    17451745        paranoid_free(tmp);
    17461746        paranoid_free(logfile);
    1747         paranoid_free(output);
    17481747        return (0);
    17491748    }
     
    17661765        paranoid_free(tmp);
    17671766        paranoid_free(logfile);
    1768         paranoid_free(output);
    17691767        return (1);
    17701768/*
     
    17861784    /* BERLIOS: should not be called each time */
    17871785    part_table_fmt = which_partition_format(drive);
    1788     output[0] = '\0';
     1786    mr_asprintf(&output, "");
    17891787    /* make it a primary/extended/logical */
    17901788    if (partno <= 4) {
    1791         sprintf(output + strlen(output), "n\np\n%d\n", partno);
     1789        mr_strcat(output, "n\np\n%d\n", partno);
    17921790    } else {
    17931791        /* MBR needs an extended partition if more than 4 partitions */
     
    18041802                    return (1);
    18051803                } 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);
    18081805                }
    18091806            }
    1810             strcat(output + strlen(output), "n\nl\n");
     1807            mr_strcat(output, "n\nl\n");
    18111808        } else {
    18121809            /* 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 */
    18171814    if (partsize > 0) {
    18181815        if (!strcmp(format, "7")) {
     
    18201817            partsize += 512;
    18211818        }
    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");
    18251822#if 0
    18261823/*
     
    18641861        }
    18651862    } else {
    1866         strcat(output, "w\n\n");
     1863        mr_strcat(output, "w\n\n");
    18671864        if (g_fprep) {
    18681865            fprintf(g_fprep, "echo \"%s\" | %s\n", output, program);
     
    19161913        }
    19171914    }
     1915    paranoid_free(output);
     1916
    19181917    g_current_progress++;
    19191918    log_it("partition_device() --- leaving");
     
    19221921    paranoid_free(tmp);
    19231922    paranoid_free(logfile);
    1924     paranoid_free(output);
    19251923    return (retval);
    19261924}
     
    20322030    char *partition;
    20332031    char *command;
    2034     char *output;
     2032    char *output = NULL;
    20352033    char *tmp;
    20362034    char *partcode;
     
    20512049    malloc_string(partition);
    20522050    malloc_string(command);
    2053     malloc_string(output);
    20542051    malloc_string(tmp);
    20552052    malloc_string(partcode);
     
    21382135            fput_string_one_char_at_a_time(pout_to_fdisk, "p\n");
    21392136        } 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);
    21422138            sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive,
    21432139                    MONDO_LOGFILE, MONDO_LOGFILE);
     
    21542150                paranoid_pclose(fout);
    21552151            }
     2152            paranoid_free(output);
    21562153        }
    21572154        if (res) {
     
    21622159    paranoid_free(partition);
    21632160    paranoid_free(command);
    2164     paranoid_free(output);
    21652161    paranoid_free(tmp);
    21662162    paranoid_free(partcode);
  • branches/2.2.9/mondo/src/mondorestore/mondo-rstr-compare.c

    r1930 r2211  
    11/***************************************************************************
    2        mondo-compare.c  -  compares mondoarchive data
    3                              -------------------
    4     begin                : Fri Apr 25 2003
    5     copyright            : (C) 2000 by Hugo Rabson
    6     email                : Hugo Rabson <hugorabson@msn.com>
    72    cvsid                : $Id$
    83***************************************************************************/
    94
    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/2003
    27 - changed "/mnt/cdrom" to MNT_CDROM
    28 
    29 10/18
    30 - don't say unknown compressor if no compressor at all
    31 
    32 09/17
    33 - cleaned up logging & conversion-to-changed.txt
    34 - cleaned up compare_mode()
    35 
    36 09/16
    37 - fixed bad malloc(),free() pairs in compare_a_biggiefile()
    38 
    39 09/14
    40 - compare_mode() --- a couple of strings were the wrong way round,
    41   e.g. changed.txt and changed.files
    42 
    43 05/05
    44 - exclude /dev/ * from list of changed files
    45 
    46 04/30
    47 - added textonly mode
    48 
    49 04/27
    50 - improved compare_mode() to allow for ISO/cd/crazy people
    51 
    52 04/25
    53 - first incarnation
    54 */
    55 
    56 
    575#include <pthread.h>
    586#include "my-stuff.h"
     7#include "mr_mem.h"
    598#include "../common/mondostructures.h"
    609#include "../common/libmondo.h"
     
    9746    char *original_cksum_ptr;
    9847    char *bigfile_fname_ptr;
    99     char *tmp_ptr;
     48    char *tmp_ptr = NULL;
    10049    char *command_ptr;
    10150
     
    11766    malloc_string(bigfile_fname_ptr);
    11867    malloc_string(command_ptr);
    119     malloc_string(tmp_ptr);
    12068
    12169  /*********************************************************************
     
    12674    memset(original_cksum_ptr, '\0', sizeof(original_cksum));
    12775    memset(bigfile_fname_ptr, '\0', sizeof(bigfile_fname));
    128     memset(tmp_ptr, '\0', sizeof(tmp));
    12976    memset(command_ptr, '\0', sizeof(command));
    13077  /** end **/
     
    13481            insist_on_this_cd_number((++g_current_media_number));
    13582        } else {
    136             sprintf(tmp_ptr,
     83            mr_asprintf(&tmp_ptr,
    13784                    "No CD's left. No biggiefiles left. No prob, Bob.");
    13885            log_msg(2, tmp_ptr);
     86            paranoid_free(tmp_ptr);
    13987            return (0);
    14088        }
    14189    }
    14290    if (!(fin = fopen(slice_fname(bigfileno, 0, ARCHIVES_PATH, ""), "r"))) {
    143         sprintf(tmp_ptr,
     91        mr_asprintf(&tmp_ptr,
    14492                "Cannot open bigfile %ld (%s)'s info file",
    14593                bigfileno + 1, bigfile_fname_ptr);
    14694        log_to_screen(tmp_ptr);
     95        paranoid_free(tmp_ptr);
    14796        return (1);
    14897    }
     
    156105    log_msg(2, "biggiestruct.checksum = %s", biggiestruct.checksum);
    157106
    158     sprintf(tmp_ptr, "Comparing %s", bigfile_fname_ptr);
    159 
    160107    if (!g_text_mode) {
     108        mr_asprintf(&tmp_ptr, "Comparing %s", bigfile_fname_ptr);
    161109        newtDrawRootText(0, 22, tmp_ptr);
     110        paranoid_free(tmp_ptr);
    162111        newtRefresh();
    163112    }
     
    173122    }
    174123    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);
    176125    paranoid_system(tmp_ptr);
     126    paranoid_free(tmp_ptr);
     127
    177128    if (system(command_ptr)) {
    178129        log_OS_error("Warning - command failed");
     
    197148        }
    198149    }
    199     sprintf(tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1,
     150    mr_asprintf(&tmp_ptr, "bigfile #%ld ('%s') ", bigfileno + 1,
    200151            bigfile_fname_ptr);
    201152    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");
    205156        retval++;
    206157    }
    207158    log_msg(1, tmp_ptr);
     159    paranoid_free(tmp_ptr);
     160
    208161    if (retval) {
    209162        if (!(fout = fopen(MONDO_CACHE"/changed.txt", "a"))) {
     
    222175    paranoid_free(command_ptr);
    223176    paranoid_free(command);
    224     paranoid_free(tmp_ptr);
    225177    paranoid_free(tmp);
    226178
     
    302254
    303255  /***  needs malloc *********/
    304     char *command, *tmp, *filelist_name, *logfile, *archiver_exe,
     256    char *command, *tmp, *filelist_name, *logfile,
    305257        *compressor_exe;
     258    char *archiver_exe = NULL;
    306259
    307260    malloc_string(command);
     
    309262    malloc_string(filelist_name);
    310263    malloc_string(logfile);
    311     malloc_string(archiver_exe);
    312264    malloc_string(compressor_exe);
    313265
     
    331283
    332284    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");
    336288    }
    337289
     
    344296        {
    345297            if (!strcmp(compressor_exe, "bzip2")) {
    346                 strcat(archiver_exe, " -bz");
     298                mr_strcat(archiver_exe, " -bz");
    347299            } else {
    348300                fatal_error
     
    373325                BUFSIZE, compressor_exe, tarball_fname, logfile, logfile);
    374326    }
     327    paranoid_free(archiver_exe);
     328
    375329#undef BUFSIZE
    376330
     
    405359    paranoid_free(filelist_name);
    406360    paranoid_free(logfile);
    407     paranoid_free(archiver_exe);
    408361    paranoid_free(compressor_exe);
    409362    return (retval);
  • branches/2.2.9/mondo/src/mondorestore/mondo-rstr-newt.c

    r2209 r2211  
    11/***************************************************************************
    22 * $Id$
    3  */
    4 
    5 
    6 /**
    7  * @file
    83 * Functions for handling GUI interfaces in the restore.
    94 */
     
    116#ifdef __FreeBSD__
    127#define OSSWAP(linux,fbsd) fbsd
    13 //#include <libgen.h>
    148#else
    159#define OSSWAP(linux,fbsd) linux
     
    1711
    1812#include "mondo-rstr-newt.h"
     13#include "mr_mem.h"
    1914
    2015//static char cvsid[] = "$Id$";
     
    19501945    assert(raidlist != NULL);
    19511946
    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", "         ");
    19551950    if (mountlist->entries > ARBITRARY_MAXIMUM) {
    19561951        log_to_screen("Arbitrary limits suck, man!");
  • branches/2.2.9/mondo/src/mondorestore/mondo-rstr-tools.c

    r2206 r2211  
    11/***************************************************************************
    22$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 *                                                                         *
    113***************************************************************************/
    124
     
    146#include <linux/fd.h>
    157#include "my-stuff.h"
     8#include "mr_mem.h"
    169#include "../common/mondostructures.h"
    1710#include "../common/libmondo.h"
     
    284277int iso_fiddly_bits(bool nuke_me_please)
    285278{
    286 char *mount_isodir_command, *tmp, *command;
     279char *mount_isodir_command = NULL;
     280char *tmp, *command;
    287281int retval = 0, i;
    288282bool already_mounted = FALSE;
    289283
    290284assert(bkpinfo != NULL);
    291 malloc_string(mount_isodir_command);
    292285malloc_string(tmp);
    293286malloc_string(command);
     
    295288read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device);
    296289if (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
     301if (!get_isodir_info(g_isodir_device, g_isodir_format, bkpinfo->isodir, nuke_me_please)) {
     302    return (1);
    312303}
    313304paranoid_system("umount " MNT_CDROM " 2> /dev/null");   /* just in case */
    314305
    315306if (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;
    318309} 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,
    328317        "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?",
    329318        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
    337327    ("I have mounted the device where the ISO files are stored.");
    338328}
     
    351341log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__,
    352342    bkpinfo->isodir);
    353 paranoid_free(mount_isodir_command);
    354343paranoid_free(tmp);
    355344paranoid_free(command);
     
    385374
    386375/** malloc **/
    387 char *tmp, *command, *mountdir, *mountpoint, *additional_parameters;
     376char *tmp, *command, *mountdir, *mountpoint;
     377char *additional_parameters = NULL;
    388378
    389379assert_string_is_neither_NULL_nor_zerolength(device);
     
    394384malloc_string(mountdir);
    395385malloc_string(mountpoint);
    396 malloc_string(additional_parameters);
    397386
    398387    if (!strcmp(mpt, "/1")) {
     
    412401    log_msg(1, tmp);
    413402    /* Deal with additional params only if not /proc or /sys */
     403    mr_asprintf(&additional_parameters, "");
    414404    if (strcmp(format, "proc") && strcmp(format, "sys")) {
    415405        if (writeable) {
    416             strcpy(additional_parameters, "-o rw");
     406            mr_strcat(additional_parameters, "-o rw");
    417407        } else {
    418             strcpy(additional_parameters, "-o ro");
     408            mr_strcat(additional_parameters, "-o ro");
    419409        }
    420410        if (find_home_of_exe("setfattr")) {
    421             strcat(additional_parameters, ",user_xattr");
     411            mr_strcat(additional_parameters, ",user_xattr");
    422412        }
    423413        if (find_home_of_exe("setfacl")) {
    424             strcat(additional_parameters, ",acl");
     414            mr_strcat(additional_parameters, ",acl");
    425415        }
    426416    }
     
    440430        log_msg(2, "command='%s'", command);
    441431    }
     432    paranoid_free(additional_parameters);
    442433
    443434    res = run_program_and_log_output(command, TRUE);
     
    479470paranoid_free(mountdir);
    480471paranoid_free(mountpoint);
    481 paranoid_free(additional_parameters);
    482472
    483473    return (res);
     
    498488{
    499489int retval = 0, lino, res;
    500 char *tmp, *these_failed, *format;
    501     struct mountlist_itself *mountlist = NULL;
     490char *tmp;
     491char *these_failed = NULL;
     492char *format;
     493struct mountlist_itself *mountlist = NULL;
    502494
    503495malloc_string(tmp);
    504496malloc_string(format);
    505 malloc_string(these_failed);
    506 /** menset **/
    507 these_failed[0] = '\0';
    508497
    509498assert(p_external_copy_of_mountlist != NULL);
     
    520509               "", mountlist->entries);
    521510
     511    mr_asprintf(&these_failed, "");
    522512    for (lino = 0; lino < mountlist->entries; lino++) {
    523513        if (!strcmp(mountlist->el[lino].device, "/proc")) {
     
    540530            retval += res;
    541531            if (res) {
    542                 strcat(these_failed, mountlist->el[lino].device);
    543                 strcat(these_failed, " ");
     532                mr_strcat(these_failed, "%s ",mountlist->el[lino].device);
    544533            }
    545534        }
     
    556545                ("format and restore *without* partitioning first. Sorry for the inconvenience.");
    557546        }
    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);
    560548
    561549        if (!ask_me_yes_or_no(tmp)) {
     
    573561        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    574562    }
     563    paranoid_free(these_failed);
     564
    575565    /* Also mounting under MNT_RESTORING  special FS */
    576566    (void)mount_device("/proc","/proc","proc",TRUE);
     
    580570    paranoid_free(tmp);
    581571    paranoid_free(format);
    582     paranoid_free(these_failed);
    583572    return (retval);
    584573}
     
    896885read_cfg_var(cfg_file, "acl", value);
    897886if (strstr(value, "TRUE")) {
    898     asprintf(&g_getfacl,"setfacl");
     887    mr_asprintf(&g_getfacl,"setfacl");
    899888    log_msg(1, "We will restore ACLs");
    900889    if (! find_home_of_exe("setfacl")) {
     
    904893read_cfg_var(cfg_file, "xattr", value);
    905894if (strstr(value, "TRUE")) {
    906     asprintf(&g_getfattr,"setfattr");
     895    mr_asprintf(&g_getfattr,"setfattr");
    907896    log_msg(1, "We will restore XATTRs");
    908897    if (! find_home_of_exe("setfattr")) {
     
    13981387     * the current /dev location
    13991388     */
    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);
    14011390    run_program_and_log_output(cmd, 3);
    14021391    paranoid_free(cmd);
     
    14101399    read_cfg_var(g_mondo_cfg_file, "bootloader.device", device);
    14111400    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);
    14131402    log_msg(2, tmp);
    14141403    paranoid_free(tmp);
     
    14271416#ifdef __FreeBSD__
    14281417    else if (!strcmp(name, "BOOT0")) {
    1429         asprintf(&tmp, "boot0cfg -B %s", device);
     1418        mr_asprintf(&tmp, "boot0cfg -B %s", device);
    14301419        res = run_program_and_log_output(tmp, FALSE);
    14311420        paranoid_free(tmp);
    14321421    } else {
    1433         asprintf(&tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device);
     1422        mr_asprintf(&tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device);
    14341423        if (!system(tmp)) {
    14351424            paranoid_free(tmp);
    1436             asprintf(&tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
     1425            mr_asprintf(&tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);
    14371426            res = run_program_and_log_output(tmp, 3);
    14381427        } else {
     
    20192008    int retval = 0, lino, res = 0, i;
    20202009    char *command;
    2021     char *tmp;
     2010    char *tmp = NULL;
    20222011
    20232012    malloc_string(command);
    2024     malloc_string(tmp);
    20252013    assert(p_external_copy_of_mountlist != NULL);
    20262014
     
    20492037    paranoid_system("sync");
    20502038
    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);
    20522040    if (run_program_and_log_output(tmp, FALSE)) {
    20532041        log_msg(1,
    20542042                "Error. Failed to copy log to PC's /var/log dir. (Mounted read-only?)");
    20552043    }
     2044    paranoid_free(tmp);
    20562045    if (does_file_exist("/tmp/DUMBASS-GENTOO")) {
    20572046        run_program_and_log_output("mkdir -p " MNT_RESTORING
     
    20672056            continue;
    20682057        }
    2069         sprintf(tmp, "Unmounting device %s  ", mountlist->el[lino].device);
     2058        mr_asprintf(&tmp, "Unmounting device %s  ", mountlist->el[lino].device);
    20702059
    20712060        update_progress_form(tmp);
     2061
    20722062        if (is_this_device_mounted(mountlist->el[lino].device)) {
    20732063            if (!strcmp(mountlist->el[lino].mountpoint, "swap")) {
     
    20942084            res = run_program_and_log_output(command, 3);
    20952085        } else {
    2096             strcat(tmp, "...not mounted anyway :-) OK");
     2086            mr_strcat(tmp, "...not mounted anyway :-) OK");
    20972087            res = 0;
    20982088        }
    20992089        g_current_progress++;
    21002090        if (res) {
    2101             strcat(tmp, "...Failed");
     2091            mr_strcat(tmp, "...Failed");
    21022092            retval++;
    21032093            log_to_screen(tmp);
     
    21052095            log_msg(2, tmp);
    21062096        }
     2097        paranoid_free(tmp);
    21072098    }
    21082099    close_progress_form();
     
    21192110    free(mountlist);
    21202111    paranoid_free(command);
    2121     paranoid_free(tmp);
    21222112    return (retval);
    21232113}
  • branches/2.2.9/mondo/src/mondorestore/mondorestore.c

    r2209 r2211  
    22$Id$
    33restores mondoarchive data
     4The main file for mondorestore.
    45***************************************************************************/
    5 
    6 /**
    7  * @file
    8  * The main file for mondorestore.
    9  */
    106
    117/**************************************************************************
     
    1410#include <pthread.h>
    1511#include "my-stuff.h"
     12#include "mr_mem.h"
    1613#include "../common/mondostructures.h"
    1714#include "../common/libmondo.h"
     
    364361
    365362    /* 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);
    367364    (void)unlink(tmp1);
    368365    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);
    370367    (void)unlink(tmp1);
    371368    paranoid_free(tmp1);
     
    379376
    380377    /* 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);
    382379    (void)unlink(tmp1);
    383380    paranoid_free(tmp1);
    384381
    385382    /* 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);
    387384    if (does_file_exist(tmp1)) {
    388385        log_msg(2, "We may need to clean /etc/multipath.conf");
     
    394391
    395392    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);
    398395        popup_and_OK("You will now edit multipath.conf");
    399396        if (!g_text_mode) {
     
    788785    assert(raidlist != NULL);
    789786
    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", "         ");
    793790
    794791    log_msg(2, "nuke_mode --- starting");
     
    16711668
    16721669  /** malloc **/
    1673     char *command;
     1670    char *command = NULL;
    16741671    char *tmp;
    16751672    char *filelist_name;
     
    16851682
    16861683    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    1687     malloc_string(command);
    16881684    malloc_string(tmp);
    16891685    malloc_string(filelist_name);
     
    16981694    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
    16991695//  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);
    17011697    run_program_and_log_output(command, 9);
     1698    paranoid_free(command);
     1699
    17021700    sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768),
    17031701            (int) (random() % 32768));
     
    17831781//      if (strstr(tarball_fname, ".star."))
    17841782        if (use_star) {
    1785             sprintf(command,
     1783            mr_asprintf(&command,
    17861784                    "star -x -force-remove -U " STAR_ACL_SZ
    17871785                    " errctl= file=%s", tarball_fname);
    17881786            if (strstr(tarball_fname, ".bz2")) {
    1789                 strcat(command, " -bz");
     1787                mr_strcat(command, " -bz");
    17901788            }
    17911789        } else {
    17921790            if (filelist_subset_fname[0] != '\0') {
    1793                 sprintf(command,
     1791                mr_asprintf(&command,
    17941792                        "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s",
    17951793                        TAPE_BLOCK_SIZE,
     
    17981796                        tarball_fname);
    17991797            } else {
    1800                 sprintf(command,
     1798                mr_asprintf(&command,
    18011799                        "afio -i -b %ld -c %ld -M 8m %s %s",
    18021800                        TAPE_BLOCK_SIZE,
     
    18041802            }
    18051803        }
     1804
    18061805#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);
    18091807        log_msg(1, "command = '%s'", command);
    18101808        unlink(temp_log);
     
    18181816            }
    18191817        }
     1818        paranoid_free(command);
     1819
    18201820        if (res && length_of_file(temp_log) < 5) {
    18211821            res = 0;
     
    18491849        }
    18501850        if (retval) {
    1851             sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
     1851            mr_asprintf(&command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
    18521852            system(command);
     1853            paranoid_free(command);
     1854
    18531855            log_msg(2, "Errors occurred while processing fileset #%d",
    18541856                    current_tarball_number);
     
    18671869
    18681870  leave_sub:
    1869     paranoid_free(command);
    18701871    paranoid_free(tmp);
    18711872    paranoid_free(filelist_name);
     
    22492250    long max_val;
    22502251  /**malloc ***/
    2251     char *tmp;
     2252    char *tmp = NULL;
     2253    char *tmp1 = NULL;
    22522254    char *tarball_fname;
    22532255    char *progress_str;
     
    22712273    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
    22722274    max_val = atol(tmp) + 1;
     2275    paranoid_free(tmp);
     2276
    22732277    sprintf(progress_str, "Restoring from %s #%d",
    22742278            media_descriptor_string(bkpinfo->backup_media_type),
     
    23342338                                              filelist);
    23352339            }
    2336             sprintf(tmp, "%s #%d, fileset #%ld - restore ",
     2340            mr_asprintf(&tmp1, "%s #%d, fileset #%ld - restore ",
    23372341                    media_descriptor_string(bkpinfo->backup_media_type),
    23382342                    g_current_media_number, current_tarball_number);
    23392343            if (res) {
    2340                 strcat(tmp, "reported errors");
     2344                mr_strcat(tmp1, "reported errors");
    23412345            } else if (attempts > 1) {
    2342                 strcat(tmp, "succeeded");
     2346                mr_strcat(tmp1, "succeeded");
    23432347            } else {
    2344                 strcat(tmp, "succeeded");
     2348                mr_strcat(tmp1, "succeeded");
    23452349            }
    23462350            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);
    23512355            if (attempts > 1) {
    23522356                log_to_screen(comment);
     
    23642368        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    23652369    }
    2366     paranoid_free(tmp);
    23672370    paranoid_free(tarball_fname);
    23682371    paranoid_free(progress_str);
  • branches/2.2.9/mondo/test/test-mountlist.c

    r2209 r2211  
     1/*
     2 * $Id$
     3 *
     4 * Test program for mountlist management at restore time
     5 * Cn be used on host system with valgrind easier than with mondorestore
     6 */
    17#include <stdio.h>
    28#include "my-stuff.h"
     9#include "mr_mem.h"
    310#include "../common/mondostructures.h"
    411#include "../common/libmondo.h"
     
    4451    struct raidlist_itself *raidlist;
    4552
    46     asprintf(&MONDO_LOGFILE,"/tmp/mrtest-mountlist.log");
     53    mr_asprintf(&MONDO_LOGFILE,"/tmp/mrtest-mountlist.log");
    4754
    4855    /* Globals */
     
    6067
    6168setup_newt_stuff();
    62 asprintf(&g_mountlist_fname, "/tmp/mountlist.txt");
     69mr_asprintf(&g_mountlist_fname, "/tmp/mountlist.txt");
    6370log_it("before mountlist");
    6471load_mountlist(mountlist, g_mountlist_fname);
Note: See TracChangeset for help on using the changeset viewer.