Changeset 900 in MondoRescue for trunk/mondo/src/mondorestore/mondo-prep.c


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/src/mondorestore/mondo-prep.c

    r783 r900  
    1919#include <math.h>
    2020#include <unistd.h>
     21#include "mr_mem.h"
    2122
    2223
     
    6364        make_list_of_drives_in_mountlist(mountlist, drivelist);
    6465        for (lino = 0; lino < drivelist->entries; lino++) {
    65             asprintf(&command,
     66            mr_asprintf(&command,
    6667                     "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"",
    6768                     drivelist->el[lino].device, MONDO_WAS_HERE);
     
    6970                log_msg(1, "Found MONDO_WAS_HERE marker on drive#%d (%s)",
    7071                        lino, drivelist->el[lino].device);
    71                 paranoid_free(command);
     72                mr_free(command);
    7273                break;
    7374            }
    74             paranoid_free(command);
     75            mr_free(command);
    7576        }
    7677
     
    8687            log_to_screen("Please hit 'Enter' to reboot.");
    8788            for (lino = 0; lino < drivelist->entries; lino++) {
    88                 asprintf(&buf, "%s\n", MONDO_WAS_HERE);
     89                mr_asprintf(&buf, "%s\n", MONDO_WAS_HERE);
    8990                fout = fopen(drivelist->el[lino].device, "w+");
    9091                if (!fout) {
     
    101102                    fclose(fout);
    102103                }
    103                 paranoid_free(buf);
     104                mr_free(buf);
    104105            }
    105106            sync();
     
    201202    if (tmp)    // found it :) cool
    202203    {
    203         asprintf(&lvscan_sz, "lvm lvscan");
    204         asprintf(&lvremove_sz, "lvm lvremove");
    205         asprintf(&vgscan_sz, "lvm vgscan");
    206         asprintf(&pvscan_sz, "lvm pvscan");
    207         asprintf(&vgchange_sz, "lvm vgchange");
    208         asprintf(&vgremove_sz, "lvm vgremove");
     204        mr_asprintf(&lvscan_sz, "lvm lvscan");
     205        mr_asprintf(&lvremove_sz, "lvm lvremove");
     206        mr_asprintf(&vgscan_sz, "lvm vgscan");
     207        mr_asprintf(&pvscan_sz, "lvm pvscan");
     208        mr_asprintf(&vgchange_sz, "lvm vgchange");
     209        mr_asprintf(&vgremove_sz, "lvm vgremove");
    209210    } else {
    210         asprintf(&lvscan_sz, "lvscan");
    211         asprintf(&lvremove_sz, "lvremove");
    212         asprintf(&vgscan_sz, "vgscan");
    213         asprintf(&pvscan_sz, "pvscan");
    214         asprintf(&vgchange_sz, "vgchange");
    215         asprintf(&vgremove_sz, "vgremove");
    216     }
    217     paranoid_free(tmp);
    218 
    219     asprintf(&command,
     211        mr_asprintf(&lvscan_sz, "lvscan");
     212        mr_asprintf(&lvremove_sz, "lvremove");
     213        mr_asprintf(&vgscan_sz, "vgscan");
     214        mr_asprintf(&pvscan_sz, "pvscan");
     215        mr_asprintf(&vgchange_sz, "vgchange");
     216        mr_asprintf(&vgremove_sz, "vgremove");
     217    }
     218    mr_free(tmp);
     219
     220    mr_asprintf(&command,
    220221            "for i in `%s | cut -d\"'\" -f2 | sort -r` ; do echo \"Shutting down lv $i\" >> "
    221222            MONDO_LOGFILE "; %s -f $i; done", lvscan_sz, lvremove_sz);
    222     paranoid_free(lvscan_sz);
    223     paranoid_free(lvremove_sz);
     223    mr_free(lvscan_sz);
     224    mr_free(lvremove_sz);
    224225
    225226    run_program_and_log_output(command, 5);
    226     paranoid_free(command);
     227    mr_free(command);
    227228
    228229    sleep(1);
    229     asprintf(&command,
     230    mr_asprintf(&command,
    230231            "for i in `%s | grep -i lvm | cut -d'\"' -f2` ; do %s -a n $i ; %s $i; echo \"Shutting down vg $i\" >> "
    231232            MONDO_LOGFILE "; done", vgscan_sz, vgchange_sz, vgremove_sz);
    232     paranoid_free(vgchange_sz);
    233     paranoid_free(vgremove_sz);
     233    mr_free(vgchange_sz);
     234    mr_free(vgremove_sz);
    234235
    235236    run_program_and_log_output(command, 5);
    236     paranoid_free(command);
     237    mr_free(command);
    237238
    238239    if (just_erase_existing_volumes) {
     
    250251    log_msg(1, "OK, rewound i-want-my-lvm. Doing funky stuff...");
    251252    rewind(fin);
    252     for (getline(&incoming, &n1, fin); !feof(fin); getline(&incoming, &n1, fin)) {
     253    for (mr_getline(&incoming, &n1, fin); !feof(fin); mr_getline(&incoming, &n1, fin)) {
    253254        fgetpos(fin, &orig_pos);
    254255        /* we want to execute lines begining with a # */
     
    264265        if ((p = strstr(incoming, "vgcreate"))) {
    265266            // include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm)
    266             for (getline(&tmp, &n, fin); !feof(fin); getline(&tmp, &n, fin)) {
     267            for (mr_getline(&tmp, &n, fin); !feof(fin); mr_getline(&tmp, &n, fin)) {
    267268                if (tmp[0] == '#') {
    268269                    fsetpos(fin, &orig_pos);
     
    270271                } else {
    271272                    fgetpos(fin, &orig_pos);
    272                     asprintf(&tmp1, "%s%s", incoming, tmp);
    273                     paranoid_free(incoming);
     273                    mr_asprintf(&tmp1, "%s%s", incoming, tmp);
     274                    mr_free(incoming);
    274275                    incoming = tmp1;
    275276                }
    276277            }
    277             paranoid_free(tmp);
     278            mr_free(tmp);
    278279
    279280            for (q = incoming; *q != '\0'; q++) {
     
    282283                }
    283284            }
    284             asprintf(&tmp1, p + strlen("vgcreate") + 1);
     285            mr_asprintf(&tmp1, p + strlen("vgcreate") + 1);
    285286            for (q = tmp1; *q > 32; q++);
    286287            *q = '\0';
    287288            log_msg(1, "Deleting old entries at /dev/%s", tmp1);
    288             asprintf(&tmp, "rm -Rf /dev/%s", tmp1);
    289             paranoid_free(tmp1);
     289            mr_asprintf(&tmp, "rm -Rf /dev/%s", tmp1);
     290            mr_free(tmp1);
    290291
    291292            run_program_and_log_output(tmp, 1);
    292             paranoid_free(tmp);
     293            mr_free(tmp);
    293294
    294295            run_program_and_log_output(vgscan_sz, 1);
     
    299300        }
    300301        for (p = incoming + 1; *p == ' '; p++);
    301         paranoid_alloc(command,p);
     302        mr_allocstr(command,p);
    302303        for (p = command; *p != '\0'; p++);
    303304        for (; *(p - 1) < 32; p--);
     
    333334            extents = atol(p);
    334335            log_msg(5, "p='%s' --> extents=%ld", p, extents);
    335             paranoid_free(tmp);
     336            mr_free(tmp);
    336337
    337338            p = strstr(command, "-L");
     
    384385            retval++;
    385386        }
    386         asprintf(&tmp, "echo \"%s\" >> /tmp/out.sh", command);
     387        mr_asprintf(&tmp, "echo \"%s\" >> /tmp/out.sh", command);
    387388        system(tmp);
    388         paranoid_free(tmp);
     389        mr_free(tmp);
    389390        sleep(1);
    390391    }
    391392    paranoid_fclose(fin);
    392     paranoid_free(vgscan_sz);
    393     paranoid_free(pvscan_sz);
    394     paranoid_free(command);
    395     paranoid_free(incoming);
     393    mr_free(vgscan_sz);
     394    mr_free(pvscan_sz);
     395    mr_free(command);
     396    mr_free(incoming);
    396397
    397398    log_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff.");
     
    460461                finish(1);
    461462            }
    462             for (getline(&incoming, &n, fin); !feof(fin)
     463            for (mr_getline(&incoming, &n, fin); !feof(fin)
    463464                 && !strstr(incoming, old_mountlist->el[lino].device);
    464                  getline(&incoming, &n, fin));
     465                 mr_getline(&incoming, &n, fin));
    465466            if (!feof(fin)) {
    466                 asprintf(&tmp, "Investigating %s",
     467                mr_asprintf(&tmp, "Investigating %s",
    467468                        old_mountlist->el[lino].device);
    468469                log_it(tmp);
    469                 paranoid_free(tmp);
    470 
    471                 for (getline(&incoming, &n, fin); !feof(fin)
     470                mr_free(tmp);
     471
     472                for (mr_getline(&incoming, &n, fin); !feof(fin)
    472473                     && !strstr(incoming, "raiddev");
    473                      getline(&incoming, &n, fin)) {
     474                     mr_getline(&incoming, &n, fin)) {
    474475                    if (strstr(incoming, OSSWAP("device", "drive"))
    475476                        && !strchr(incoming, '#')) {
     
    478479                        *p = '\0';
    479480                        for (p--; p > incoming && *(p - 1) > 32; p--);
    480                         asprintf(&tmp, "Extrapolating %s", p);
     481                        mr_asprintf(&tmp, "Extrapolating %s", p);
    481482                        log_it(tmp);
    482                         paranoid_free(tmp);
     483                        mr_free(tmp);
    483484
    484485                        for (j = 0;
     
    499500                            new_mountlist->entries++;
    500501                        } else {
    501                             asprintf(&tmp,
     502                            mr_asprintf(&tmp,
    502503                                    "Not adding %s to mountlist: it's already there", p);
    503504                            log_it(tmp);
    504                             paranoid_free(tmp);
     505                            mr_free(tmp);
    505506                        }
    506507                    }
    507508                }
    508509            }
    509             paranoid_free(incoming);
     510            mr_free(incoming);
    510511            paranoid_fclose(fin);
    511512        } else {
     
    566567    }
    567568    // create device list from normal disks followed by spare ones
    568     asprintf(&devices, raidlist->el[i].data_disks.el[0].device);
     569    mr_asprintf(&devices, raidlist->el[i].data_disks.el[0].device);
    569570    for (j = 1; j < raidlist->el[i].data_disks.entries; j++) {
    570         asprintf(&strtmp, "%s", devices);
    571         paranoid_free(devices);
    572         asprintf(&devices, "%s %s", strtmp,
     571        mr_asprintf(&strtmp, "%s", devices);
     572        mr_free(devices);
     573        mr_asprintf(&devices, "%s %s", strtmp,
    573574                 raidlist->el[i].data_disks.el[j].device);
    574         paranoid_free(strtmp);
     575        mr_free(strtmp);
    575576    }
    576577    for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) {
    577         asprintf(&strtmp, "%s", devices);
    578         paranoid_free(devices);
    579         asprintf(&devices, "%s %s", strtmp,
     578        mr_asprintf(&strtmp, "%s", devices);
     579        mr_free(devices);
     580        mr_asprintf(&devices, "%s %s", strtmp,
    580581                 raidlist->el[i].spare_disks.el[j].device);
    581         paranoid_free(strtmp);
     582        mr_free(strtmp);
    582583    }
    583584    // translate RAID level
    584585    if (raidlist->el[i].raid_level == -2) {
    585         asprintf(&level, "multipath");
     586        mr_asprintf(&level, "multipath");
    586587    } else if (raidlist->el[i].raid_level == -1) {
    587         asprintf(&level, "linear");
     588        mr_asprintf(&level, "linear");
    588589    } else {
    589         asprintf(&level, "raid%d", raidlist->el[i].raid_level);
     590        mr_asprintf(&level, "raid%d", raidlist->el[i].raid_level);
    590591    }
    591592    // create RAID device:
     
    594595    // - faulty devices ignored
    595596    // - persistent superblock always used as this is recommended
    596     asprintf(&program,
     597    mr_asprintf(&program,
    597598             "mdadm --create --force --run --auto=yes %s --level=%s --raid-devices=%d",
    598599             raidlist->el[i].raid_device, level,
    599600             raidlist->el[i].data_disks.entries);
    600601    if (raidlist->el[i].parity != -1) {
    601         asprintf(&strtmp, "%s", program);
    602         paranoid_free(program);
     602        mr_asprintf(&strtmp, "%s", program);
     603        mr_free(program);
    603604        switch (raidlist->el[i].parity) {
    604605        case 0:
    605             asprintf(&program, "%s --parity=%s", strtmp, "la");
     606            mr_asprintf(&program, "%s --parity=%s", strtmp, "la");
    606607            break;
    607608        case 1:
    608             asprintf(&program, "%s --parity=%s", strtmp, "ra");
     609            mr_asprintf(&program, "%s --parity=%s", strtmp, "ra");
    609610            break;
    610611        case 2:
    611             asprintf(&program, "%s --parity=%s", strtmp, "ls");
     612            mr_asprintf(&program, "%s --parity=%s", strtmp, "ls");
    612613            break;
    613614        case 3:
    614             asprintf(&program, "%s --parity=%s", strtmp, "rs");
     615            mr_asprintf(&program, "%s --parity=%s", strtmp, "rs");
    615616            break;
    616617        default:
     
    618619            break;
    619620        }
    620         paranoid_free(strtmp);
     621        mr_free(strtmp);
    621622    }
    622623    if (raidlist->el[i].chunk_size != -1) {
    623         asprintf(&strtmp, "%s", program);
    624         paranoid_free(program);
    625         asprintf(&program, "%s --chunk=%d", strtmp,
     624        mr_asprintf(&strtmp, "%s", program);
     625        mr_free(program);
     626        mr_asprintf(&program, "%s --chunk=%d", strtmp,
    626627                 raidlist->el[i].chunk_size);
    627         paranoid_free(strtmp);
     628        mr_free(strtmp);
    628629    }
    629630    if (raidlist->el[i].spare_disks.entries > 0) {
    630         asprintf(&strtmp, "%s", program);
    631         paranoid_free(program);
    632         asprintf(&program, "%s --spare-devices=%d", strtmp,
     631        mr_asprintf(&strtmp, "%s", program);
     632        mr_free(program);
     633        mr_asprintf(&program, "%s --spare-devices=%d", strtmp,
    633634                 raidlist->el[i].spare_disks.entries);
    634         paranoid_free(strtmp);
    635     }
    636     asprintf(&strtmp, "%s", program);
    637     paranoid_free(program);
    638     asprintf(&program, "%s %s", strtmp, devices);
    639     paranoid_free(strtmp);
     635        mr_free(strtmp);
     636    }
     637    mr_asprintf(&strtmp, "%s", program);
     638    mr_free(program);
     639    mr_asprintf(&program, "%s %s", strtmp, devices);
     640    mr_free(strtmp);
    640641    res = run_program_and_log_output(program, 1);
    641642    // free memory
    642     paranoid_free(devices);
    643     paranoid_free(level);
    644     paranoid_free(program);
     643    mr_free(devices);
     644    mr_free(level);
     645    mr_free(program);
    645646    // return to calling instance
    646647    return res;
     
    687688
    688689    if (strstr(format, "raid")) {   // do not form RAID disks; do it to /dev/md* instead
    689         asprintf(&tmp, "Not formatting %s (it is a RAID disk)", device);
     690        mr_asprintf(&tmp, "Not formatting %s (it is a RAID disk)", device);
    690691        log_it(tmp);
    691         paranoid_free(tmp);
     692        mr_free(tmp);
    692693        return (0);
    693694    }
     
    699700#endif
    700701    if (strlen(format) <= 2) {
    701         asprintf(&tmp,
     702        mr_asprintf(&tmp,
    702703                "%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",
    703704                device, format);
    704705        log_it(tmp);
    705         paranoid_free(tmp);
     706        mr_free(tmp);
    706707        return (0);
    707708    }
    708709    if (is_this_device_mounted(device)) {
    709         asprintf(&tmp, _("%s is mounted - cannot format it       "), device);
     710        mr_asprintf(&tmp, _("%s is mounted - cannot format it       "), device);
    710711        log_to_screen(tmp);
    711         paranoid_free(tmp);
     712        mr_free(tmp);
    712713        return (1);
    713714    }
     
    736737
    737738        if (vinum_started_yet) {
    738             asprintf(&tmp,
     739            mr_asprintf(&tmp,
    739740                    _
    740741                    ("Initializing Vinum device %s (this may take a *long* time)"),
    741742                    device);
    742743            log_to_screen(tmp);
    743             paranoid_free(tmp);
     744            mr_free(tmp);
    744745
    745746            /* format raid partition */
    746             asprintf(&program,
     747            mr_asprintf(&program,
    747748                    "for plex in `vinum lv -r %s | grep '^P' | tr '\t' ' ' | tr -s ' ' | cut -d' ' -f2`; do echo $plex; done > /tmp/plexes",
    748749                    basename(device));
     
    752753                fprintf(g_fprep, "%s\n", program);
    753754            }
    754             paranoid_free(program);
     755            mr_free(program);
    755756
    756757            fin = fopen("/tmp/plexes", "r");
    757             while (getline(&line, &n, fin)) {
     758            while (mr_getline(&line, &n, fin)) {
    758759                if (strchr(line, '\n'))
    759760                    *(strchr(line, '\n')) = '\0';   // get rid of the \n on the end
    760761
    761                 asprintf(&tmp, "Initializing plex: %s", line);
     762                mr_asprintf(&tmp, "Initializing plex: %s", line);
    762763                open_evalcall_form(tmp);
    763                 paranoid_free(tmp);
    764 
    765                 asprintf(&tmp, "vinum init %s", line);
     764                mr_free(tmp);
     765
     766                mr_asprintf(&tmp, "vinum init %s", line);
    766767                system(tmp);
    767                 paranoid_free(tmp);
     768                mr_free(tmp);
    768769
    769770                while (1) {
    770                     asprintf(&tmp,
     771                    mr_asprintf(&tmp,
    771772                            "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'",
    772773                            line);
    773774                    pin = popen(tmp, "r");
    774                     paranoid_free(tmp);
    775 
    776                     getline(&status, &n1, pin);
     775                    mr_free(tmp);
     776
     777                    mr_getline(&status, &n1, pin);
    777778                    pclose(pin);
    778779
     
    782783                    update_evalcall_form(atoi(status));
    783784                    usleep(250000);
    784                     paranoid_free(status);
     785                    mr_free(status);
    785786                }
    786787                close_evalcall_form();
    787788            }
    788             paranoid_free(line);
     789            mr_free(line);
    789790            fclose(fin);
    790791            unlink("/tmp/plexes");
     
    792793        }
    793794#else
    794         asprintf(&tmp, _("Initializing RAID device %s"), device);
     795        mr_asprintf(&tmp, _("Initializing RAID device %s"), device);
    795796        log_to_screen(tmp);
    796         paranoid_free(tmp);
     797        mr_free(tmp);
    797798
    798799// Shouldn't be necessary.
     
    814815                    device, res);
    815816        } else {
    816             asprintf(&program, "mkraid --really-force %s", device);
     817            mr_asprintf(&program, "mkraid --really-force %s", device);
    817818            res = run_program_and_log_output(program, 1);
    818819            log_msg(1, "%s returned %d", program, res);
     
    823824                fprintf(g_fprep, "%s\n", program);
    824825            }
    825             paranoid_free(program);
     826            mr_free(program);
    826827        }
    827828        sync();
     
    842843    res = which_format_command_do_i_need(format, program);
    843844    if (strstr(program, "kludge")) {
    844         asprintf(&tmp, "%s %s /", program, device);
     845        mr_asprintf(&tmp, "%s %s /", program, device);
    845846    } else {
    846         asprintf(&tmp, "%s %s", program, device);
    847     }
    848     paranoid_free(program);
    849 
    850     asprintf(&program, "sh -c 'echo -en \"y\\ny\\ny\\n\" | %s'", tmp);
    851     paranoid_free(tmp);
    852 
    853     asprintf(&tmp, "Formatting %s as %s", device, format);
     847        mr_asprintf(&tmp, "%s %s", program, device);
     848    }
     849    mr_free(program);
     850
     851    mr_asprintf(&program, "sh -c 'echo -en \"y\\ny\\ny\\n\" | %s'", tmp);
     852    mr_free(tmp);
     853
     854    mr_asprintf(&tmp, "Formatting %s as %s", device, format);
    854855    update_progress_form(tmp);
    855856
     
    857858    if (res && strstr(program, "kludge")) {
    858859#ifdef __FreeBSD__
    859         paranoid_free(program);
    860         asprintf(&program, "newfs_msdos -F 32 %s", device);
     860        mr_free(program);
     861        mr_asprintf(&program, "newfs_msdos -F 32 %s", device);
    861862#else
    862863#ifdef __IA64__
    863864        /* For EFI partitions take fat16
    864865         * as we want to make small ones */
    865         paranoid_free(program);
    866         asprintf(&program, "mkfs -t %s -F 16 %s", format, device);
     866        mr_free(program);
     867        mr_asprintf(&program, "mkfs -t %s -F 16 %s", format, device);
    867868#else
    868         paranoid_free(program);
    869         asprintf(&program, "mkfs -t %s -F 32 %s", format, device);
     869        mr_free(program);
     870        mr_asprintf(&program, "mkfs -t %s -F 32 %s", format, device);
    870871#endif
    871872#endif
     
    875876        }
    876877    }
    877     paranoid_free(program);
     878    mr_free(program);
    878879
    879880    retval += res;
    880881    if (retval) {
    881         asprintf(&tmp1, "%s%s",tmp, _("...failed"));
     882        mr_asprintf(&tmp1, "%s%s",tmp, _("...failed"));
    882883    } else {
    883         asprintf(&tmp1, "%s%s",tmp, _("...OK"));
    884     }
    885     paranoid_free(tmp);
     884        mr_asprintf(&tmp1, "%s%s",tmp, _("...OK"));
     885    }
     886    mr_free(tmp);
    886887
    887888    log_to_screen(tmp1);
    888     paranoid_free(tmp1);
     889    mr_free(tmp1);
    889890    sync();
    890891    sleep(1);
     
    923924
    924925    assert(mountlist != NULL);
    925     asprintf(&tmp, "format_everything (mountlist, interactively = %s",
     926    mr_asprintf(&tmp, "format_everything (mountlist, interactively = %s",
    926927            (interactively) ? "true" : "false");
    927928    log_it(tmp);
    928     paranoid_free(tmp);
     929    mr_free(tmp);
    929930
    930931    mvaddstr_and_log_it(g_currentY, 0, _("Formatting partitions     "));
     
    952953            if (interactively) {
    953954                // ask user if we should format the current device
    954                 asprintf(&tmp, "Shall I format %s (%s) ?", me->device,
     955                mr_asprintf(&tmp, "Shall I format %s (%s) ?", me->device,
    955956                        me->mountpoint);
    956957                do_it = ask_me_yes_or_no(tmp);
    957                 paranoid_free(tmp);
     958                mr_free(tmp);
    958959            } else {
    959960                do_it = TRUE;
     
    10031004        me = &mountlist->el[lino];  // the current mountlist entry
    10041005        if (!strcmp(me->mountpoint, "image")) {
    1005             asprintf(&tmp, "Not formatting %s - it's an image", me->device);
     1006            mr_asprintf(&tmp, "Not formatting %s - it's an image", me->device);
    10061007            log_it(tmp);
    1007             paranoid_free(tmp);
     1008            mr_free(tmp);
    10081009        } else if (!strcmp(me->format, "raid")) {
    1009             asprintf(&tmp, "Not formatting %s - it's a raid-let",
     1010            mr_asprintf(&tmp, "Not formatting %s - it's a raid-let",
    10101011                    me->device);
    10111012            log_it(tmp);
    1012             paranoid_free(tmp);
     1013            mr_free(tmp);
    10131014            continue;
    10141015        } else if (!strcmp(me->format, "lvm")) {
    1015             asprintf(&tmp, "Not formatting %s - it's an LVM", me->device);
     1016            mr_asprintf(&tmp, "Not formatting %s - it's an LVM", me->device);
    10161017            log_it(tmp);
    1017             paranoid_free(tmp);
     1018            mr_free(tmp);
    10181019            continue;
    10191020        } else if (!strncmp(me->device, "/dev/md", 7)) {
    1020             asprintf(&tmp, "Already formatted %s - it's a soft-RAID dev",
     1021            mr_asprintf(&tmp, "Already formatted %s - it's a soft-RAID dev",
    10211022                    me->device);
    10221023            log_it(tmp);
    1023             paranoid_free(tmp);
     1024            mr_free(tmp);
    10241025            continue;
    10251026        } else if (!does_file_exist(me->device)
    10261027                   && strncmp(me->device, "/dev/hd", 7)
    10271028                   && strncmp(me->device, "/dev/sd", 7)) {
    1028             asprintf(&tmp,
     1029            mr_asprintf(&tmp,
    10291030                    "Not formatting %s yet - doesn't exist - probably an LVM",
    10301031                    me->device);
    10311032            log_it(tmp);
    1032             paranoid_free(tmp);
     1033            mr_free(tmp);
    10331034            continue;
    10341035        } else {
    10351036            if (interactively) {
    10361037                // ask user if we should format the current device
    1037                 asprintf(&tmp, "Shall I format %s (%s) ?", me->device,
     1038                mr_asprintf(&tmp, "Shall I format %s (%s) ?", me->device,
    10381039                        me->mountpoint);
    10391040                do_it = ask_me_yes_or_no(tmp);
    1040                 paranoid_free(tmp);
     1041                mr_free(tmp);
    10411042            } else {
    10421043                do_it = TRUE;
     
    10681069    }
    10691070
    1070     asprintf(&tmp, "format_everything () - %s",
     1071    mr_asprintf(&tmp, "format_everything () - %s",
    10711072            (retval) ? "failed!" : "finished successfully");
    10721073    log_it(tmp);
    1073     paranoid_free(tmp);
     1074    mr_free(tmp);
    10741075
    10751076    if (g_partition_table_locked_up > 0) {
     
    11351136
    11361137    if (devno_we_must_allow_for >= 5) {
    1137         asprintf(&tmp, "Making dummy primary %s%d", drivename, 1);
     1138        mr_asprintf(&tmp, "Making dummy primary %s%d", drivename, 1);
    11381139        log_it(tmp);
    1139         paranoid_free(tmp);
     1140        mr_free(tmp);
    11401141
    11411142        g_maximum_progress++;
     
    11511152    }
    11521153    for (; current_devno < devno_we_must_allow_for; current_devno++) {
    1153         asprintf(&tmp, "Creating dummy partition %s%d", drivename,
     1154        mr_asprintf(&tmp, "Creating dummy partition %s%d", drivename,
    11541155                current_devno);
    11551156        log_it(tmp);
    1156         paranoid_free(tmp);
     1157        mr_free(tmp);
    11571158
    11581159        g_maximum_progress++;
     
    13011302    off_t mediasize;
    13021303
    1303     asprintf(&lnamebuf, "%s", dkname);
     1304    mr_asprintf(&lnamebuf, "%s", dkname);
    13041305    if ((f = open(lnamebuf, O_RDONLY)) == -1) {
    13051306        warn("cannot open %s", lnamebuf);
    1306         paranoid_free(lnamebuf);
     1307        mr_free(lnamebuf);
    13071308        return (NULL);
    13081309    }
    1309     paranoid_free(lnamebuf);
     1310    mr_free(lnamebuf);
    13101311
    13111312    /* New world order */
     
    13891390    for (c = 'a'; c <= 'z'; ++c) {
    13901391        int idx;
    1391         asprintf(&subdev_str, "%s%c", drivename, c);
     1392        mr_asprintf(&subdev_str, "%s%c", drivename, c);
    13921393        if ((idx = find_device_in_mountlist(mountlist, subdev_str)) < 0) {
    13931394            lp->d_partitions[c - 'a'].p_size = 0;
     
    14141415                lp->d_partitions[c - 'a'].p_fstype = FS_OTHER;
    14151416        }
    1416         paranoid_free(subdev_str);
     1417        mr_free(subdev_str);
    14171418    }
    14181419
     
    14451446    display_disklabel(ftmp, lp);
    14461447    fclose(ftmp);
    1447     asprintf(&command, "disklabel -wr %s auto", canonical_name(drivename));
     1448    mr_asprintf(&command, "disklabel -wr %s auto", canonical_name(drivename));
    14481449    retval += run_program_and_log_output(command, TRUE);
    1449     paranoid_free(command);
    1450 
    1451     asprintf(&command, "disklabel -R %s /tmp/disklabel",
     1450    mr_free(command);
     1451
     1452    mr_asprintf(&command, "disklabel -R %s /tmp/disklabel",
    14521453            canonical_name(drivename));
    14531454    retval += run_program_and_log_output(command, TRUE);
    1454     paranoid_free(command);
     1455    mr_free(command);
    14551456    if (ret)
    14561457        *ret = *lp;
     
    14951496    assert_string_is_neither_NULL_nor_zerolength(drivename);
    14961497
    1497     asprintf(&tmp, "Partitioning drive %s", drivename);
     1498    mr_asprintf(&tmp, "Partitioning drive %s", drivename);
    14981499    log_it(tmp);
    1499     paranoid_free(tmp);
     1500    mr_free(tmp);
    15001501
    15011502#if __FreeBSD__
     
    15041505#else
    15051506    make_hole_for_file(FDISK_LOG);
    1506     asprintf(&tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG,
     1507    mr_asprintf(&tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG,
    15071508            FDISK_LOG);
    15081509    pout_to_fdisk = popen(tmp, "w");
    1509     paranoid_free(tmp);
     1510    mr_free(tmp);
    15101511
    15111512    if (!pout_to_fdisk) {
     
    15311532                // try DangerouslyDedicated mode
    15321533                for (c = 'a'; c <= 'z'; c++) {
    1533                     asprintf(&subdev_str, "%s%c", drivename, c);
     1534                    mr_asprintf(&subdev_str, "%s%c", drivename, c);
    15341535                    if (find_device_in_mountlist(mountlist, subdev_str) > 0) {
    15351536                        fbsd_part = TRUE;
    15361537                    }
    1537                     paranoid_free(subdev_str);
     1538                    mr_free(subdev_str);
    15381539                }
    15391540                if (fbsd_part) {
     
    15411542                                                 drivename,
    15421543                                                 0);
    1543                     asprintf(&command, "disklabel -B %s",
     1544                    mr_asprintf(&command, "disklabel -B %s",
    15441545                            basename(drivename));
    15451546                    if (system(command)) {
     
    15481549                             ("Warning! Unable to make the drive bootable."));
    15491550                    }
    1550                     paranoid_free(command);
    1551                     paranoid_free(device_str);
     1551                    mr_free(command);
     1552                    mr_free(device_str);
    15521553
    15531554                    return r;
     
    15551556            }
    15561557            for (c = 'a'; c <= 'z'; c++) {
    1557                 asprintf(&subdev_str, "%s%c", device_str, c);
     1558                mr_asprintf(&subdev_str, "%s%c", device_str, c);
    15581559                if (find_device_in_mountlist(mountlist, subdev_str) > 0) {
    15591560                    fbsd_part = TRUE;
    15601561                }
    1561                 paranoid_free(subdev_str);
     1562                mr_free(subdev_str);
    15621563            }
    15631564            // Now we check the subpartitions of the current partition.
     
    15651566                int i, line;
    15661567
    1567                 asprintf(&format, "ufs");
     1568                mr_asprintf(&format, "ufs");
    15681569                partsize = 0;
    15691570                for (i = 'a'; i < 'z'; ++i) {
    1570                     asprintf(&subdev_str, "%s%c", device_str, i);
     1571                    mr_asprintf(&subdev_str, "%s%c", device_str, i);
    15711572                    line = find_device_in_mountlist(mountlist, subdev_str);
    1572                     paranoid_free(subdev_str);
     1573                    mr_free(subdev_str);
    15731574
    15741575                    if (line > 0) {
     
    15961597            file = open(drivename, O_WRONLY);
    15971598            if (!file) {
    1598                 asprintf(&tmp,
     1599                mr_asprintf(&tmp,
    15991600                        _("Warning - unable to open %s for wiping it's partition table"),
    16001601                        drivename);
    16011602                log_to_screen(tmp);
    1602                 paranoid_free(tmp);
     1603                mr_free(tmp);
    16031604            }
    16041605
    16051606            for (i = 0; i < 512; i++) {
    16061607                if (!write(file, "\0", 1)) {
    1607                     asprintf(&tmp, _("Warning - unable to write to %s"),
     1608                    mr_asprintf(&tmp, _("Warning - unable to write to %s"),
    16081609                            drivename);
    16091610                    log_to_screen(tmp);
    1610                     paranoid_free(tmp);
     1611                    mr_free(tmp);
    16111612                }
    16121613            }
     
    16291630#endif
    16301631
    1631             asprintf(&format, mountlist->el[lino].format);
     1632            mr_asprintf(&format, mountlist->el[lino].format);
    16321633            partsize = mountlist->el[lino].size;
    16331634
     
    16401641                (_
    16411642                 ("You must leave at least one partition spare as the Extended partition."));
    1642             paranoid_free(device_str);
    1643             paranoid_free(format);
     1643            mr_free(device_str);
     1644            mr_free(format);
    16441645
    16451646            return (1);
     
    16521653#ifdef __FreeBSD__
    16531654        if ((current_devno <= 4) && fbsd_part) {
    1654             asprintf(&tmp, "disklabel -B %s", basename(device_str));
     1655            mr_asprintf(&tmp, "disklabel -B %s", basename(device_str));
    16551656            retval += label_drive_or_slice(mountlist, device_str, 0);
    16561657            if (system(tmp)) {
     
    16581659                    (_("Warning! Unable to make the slice bootable."));
    16591660            }
    1660             paranoid_free(tmp);
     1661            mr_free(tmp);
    16611662        }
    16621663#endif
     
    16641665        previous_devno = current_devno;
    16651666    }
    1666     paranoid_free(device_str);
    1667     paranoid_free(format);
     1667    mr_free(device_str);
     1668    mr_free(format);
    16681669
    16691670    if (pout_to_fdisk) {
     
    16711672        tmp1 = call_program_and_get_last_line_of_output
    16721673                ("make-me-bootable /tmp/mountlist.txt dummy");
    1673         asprintf(&tmp, "a\n%s\n", tmp1);
    1674         paranoid_free(tmp1);
     1674        mr_asprintf(&tmp, "a\n%s\n", tmp1);
     1675        mr_free(tmp1);
    16751676
    16761677        fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    1677         paranoid_free(tmp);
     1678        mr_free(tmp);
    16781679
    16791680        // close fdisk
     
    16831684        log_msg(0,
    16841685                "------------------- fdisk.log looks like this ------------------");
    1685         asprintf(&tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE);
     1686        mr_asprintf(&tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE);
    16861687        system(tmp);
    1687         paranoid_free(tmp);
     1688        mr_free(tmp);
    16881689
    16891690        log_msg(0,
    16901691                "------------------- end of fdisk.log... word! ------------------");
    1691         asprintf(&tmp, "tail -n6 %s | grep -F \"16: \"", FDISK_LOG);
     1692        mr_asprintf(&tmp, "tail -n6 %s | grep -F \"16: \"", FDISK_LOG);
    16921693        if (!run_program_and_log_output(tmp, 5)) {
    16931694            g_partition_table_locked_up++;
     
    16961697                 ("A flaw in the Linux kernel has locked the partition table."));
    16971698        }
    1698         paranoid_free(tmp);
     1699        mr_free(tmp);
    16991700    }
    17001701    return (retval);
     
    17391740
    17401741    if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
    1741         asprintf(&tmp, "Not partitioning %s - it is a virtual drive", drive);
     1742        mr_asprintf(&tmp, "Not partitioning %s - it is a virtual drive", drive);
    17421743        log_it(tmp);
    1743         paranoid_free(tmp);
     1744        mr_free(tmp);
    17441745        return (0);
    17451746    }
    17461747    partition_name = build_partition_name(drive, partno);
    17471748    if (partsize <= 0) {
    1748         asprintf(&tmp, "Partitioning device %s (max size)", partition_name);
     1749        mr_asprintf(&tmp, "Partitioning device %s (max size)", partition_name);
    17491750    } else {
    1750         asprintf(&tmp, "Partitioning device %s (%lld MB)", partition_name,
     1751        mr_asprintf(&tmp, "Partitioning device %s (%lld MB)", partition_name,
    17511752                (long long) partsize / 1024);
    17521753    }
    17531754    update_progress_form(tmp);
    17541755    log_it(tmp);
    1755     paranoid_free(tmp);
     1756    mr_free(tmp);
    17561757
    17571758    if (is_this_device_mounted(partition_name)) {
    1758         asprintf(&tmp, _("%s is mounted, and should not be partitioned"),
     1759        mr_asprintf(&tmp, _("%s is mounted, and should not be partitioned"),
    17591760                partition_name);
    1760         paranoid_free(partition_name);
     1761        mr_free(partition_name);
    17611762
    17621763        log_to_screen(tmp);
    1763         paranoid_free(tmp);
     1764        mr_free(tmp);
    17641765        return (1);
    17651766    }
    17661767
    17671768    p = (char *) strrchr(partition_name, '/');
    1768     asprintf(&program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE,
     1769    mr_asprintf(&program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE,
    17691770            MONDO_LOGFILE);
    17701771
     
    17731774    /* make it a primary/extended/logical */
    17741775    if (partno <= 4) {
    1775         asprintf(&output,"n\np\n%d\n", partno);
     1776        mr_asprintf(&output,"n\np\n%d\n", partno);
    17761777    } else {
    17771778        /* MBR needs an extended partition if more than 4 partitions */
     
    17821783                        (_
    17831784                         ("You need to leave at least one partition free, for 'extended/logical'"));
    1784                     paranoid_free(partition_name);
    1785                     paranoid_free(program);
    1786 
    1787                     paranoid_free(output);
     1785                    mr_free(partition_name);
     1786                    mr_free(program);
     1787
     1788                    mr_free(output);
    17881789                    return (1);
    17891790                } else {
    1790                     asprintf(&output,"n\ne\n%d\n\n\n",prev_partno + 1);
     1791                    mr_asprintf(&output,"n\ne\n%d\n\n\n",prev_partno + 1);
    17911792                }
    17921793            }
    1793             asprintf(&tmp,"%sn\nl\n",output);
    1794             paranoid_free(output);
     1794            mr_asprintf(&tmp,"%sn\nl\n",output);
     1795            mr_free(output);
    17951796            output = tmp;
    17961797        } else {
    17971798            /* GPT allows more than 4 primary partitions */
    1798             asprintf(&output,"n\np\n%d\n",partno);
    1799         }
    1800     }
    1801     paranoid_free(part_table_fmt);
     1799            mr_asprintf(&output,"n\np\n%d\n",partno);
     1800        }
     1801    }
     1802    mr_free(part_table_fmt);
    18021803    /*start block (ENTER for next free blk */
    1803     asprintf(&tmp,"%s\n",output);
    1804     paranoid_free(output);
     1804    mr_asprintf(&tmp,"%s\n",output);
     1805    mr_free(output);
    18051806    output = tmp;
    18061807
     
    18101811            partsize += 512;
    18111812        }
    1812         asprintf(&tmp,"%s+%lldK", output,  (long long) (partsize));
    1813         paranoid_free(output);
     1813        mr_asprintf(&tmp,"%s+%lldK", output,  (long long) (partsize));
     1814        mr_free(output);
    18141815        output = tmp;
    18151816    }
    1816     asprintf(&tmp,"%s\n",output);
    1817     paranoid_free(output);
     1817    mr_asprintf(&tmp,"%s\n",output);
     1818    mr_free(output);
    18181819    output = tmp;
    18191820#if 0
    18201821/*
    18211822#endif
    1822     asprintf(&tmp,"PARTSIZE = +%ld",(long)partsize);
     1823    mr_asprintf(&tmp,"PARTSIZE = +%ld",(long)partsize);
    18231824    log_it(tmp);
    1824     paranoid_free(tmp);
     1825    mr_free(tmp);
    18251826
    18261827    log_it("---fdisk command---");
     
    18451846                    partno);
    18461847        }
    1847         paranoid_free(tmp);
     1848        mr_free(tmp);
    18481849
    18491850        if (!retval) {
     
    18641865        }
    18651866    } else {
    1866         asprintf(&tmp,"%sw\n\n",output);
    1867         paranoid_free(output);
     1867        mr_asprintf(&tmp,"%sw\n\n",output);
     1868        mr_free(output);
    18681869        output = tmp;
    18691870
     
    18851886                                 format, -1);
    18861887            if (res) {
    1887                 asprintf(&tmp, "Failed to vacuum-pack %s", partition_name);
     1888                mr_asprintf(&tmp, "Failed to vacuum-pack %s", partition_name);
    18881889                log_it(tmp);
    1889                 paranoid_free(tmp);
     1890                mr_free(tmp);
    18901891
    18911892                retval++;
     
    18991900                                   partsize);
    19001901            if (retval) {
    1901                 asprintf(&tmp, "Partitioned %s but failed to set its type",
     1902                mr_asprintf(&tmp, "Partitioned %s but failed to set its type",
    19021903                        partition_name);
    19031904                log_it(tmp);
    1904                 paranoid_free(tmp);
     1905                mr_free(tmp);
    19051906            } else {
    19061907                if (partsize > 0) {
    1907                     asprintf(&tmp, "Partition %s created+configured OK",
     1908                    mr_asprintf(&tmp, "Partition %s created+configured OK",
    19081909                            partition_name);
    19091910                    log_to_screen(tmp);
    1910                     paranoid_free(tmp);
     1911                    mr_free(tmp);
    19111912                } else {
    19121913                    log_it("Returning from a successful vacuum-pack");
     
    19141915            }
    19151916        } else {
    1916             asprintf(&tmp, "Failed to partition %s", partition_name);
     1917            mr_asprintf(&tmp, "Failed to partition %s", partition_name);
    19171918            if (partsize > 0) {
    19181919                log_to_screen(tmp);
     
    19201921                log_it(tmp);
    19211922            }
    1922             paranoid_free(tmp);
     1923            mr_free(tmp);
    19231924            retval++;
    19241925        }
     
    19261927    g_current_progress++;
    19271928    log_it("partition_device() --- leaving");
    1928     paranoid_free(partition_name);
    1929     paranoid_free(program);
    1930     paranoid_free(output);
     1929    mr_free(partition_name);
     1930    mr_free(program);
     1931    mr_free(output);
    19311932    return (retval);
    19321933}
     
    20142015    system("clear");
    20152016    newtResume();
    2016     paranoid_free(drivelist);
     2017    mr_free(drivelist);
    20172018    return (retval);
    20182019}
     
    20582059    p = (char *) strrchr(partition, '/');
    20592060    if (strcmp(format, "swap") == 0) {
    2060         asprintf(&partcode, "82");
     2061        mr_asprintf(&partcode, "82");
    20612062    } else if (strcmp(format, "vfat") == 0) {
    20622063        if (partsize / 1024 > 8192) {
    2063             asprintf(&partcode, "c");
     2064            mr_asprintf(&partcode, "c");
    20642065        } else {
    2065             asprintf(&partcode, "b");
     2066            mr_asprintf(&partcode, "b");
    20662067        }
    20672068    } else if (strcmp(format, "ext2") == 0
     
    20692070               || strcmp(format, "ext3") == 0 || strcmp(format, "xfs") == 0
    20702071               || strcmp(format, "jfs") == 0) {
    2071         asprintf(&partcode, "83");
     2072        mr_asprintf(&partcode, "83");
    20722073    } else if (strcmp(format, "minix") == 0) {
    2073         asprintf(&partcode, "81");
     2074        mr_asprintf(&partcode, "81");
    20742075    } else if (strcmp(format, "raid") == 0) {
    2075         asprintf(&partcode, "fd");
     2076        mr_asprintf(&partcode, "fd");
    20762077    } else if ((strcmp(format, "ufs") == 0)
    20772078               || (strcmp(format, "ffs") == 0)) {   /* raid autodetect */
    2078         asprintf(&partcode, "a5");
     2079        mr_asprintf(&partcode, "a5");
    20792080    } else if (strcmp(format, "lvm") == 0) {
    2080         asprintf(&partcode, "8e");
     2081        mr_asprintf(&partcode, "8e");
    20812082    } else if (format[0] == '\0') { /* LVM physical partition */
    2082         asprintf(&partcode, "%s", "");
     2083        mr_asprintf(&partcode, "%s", "");
    20832084    } else if (strlen(format) >= 1 && strlen(format) <= 2) {
    2084         asprintf(&partcode, format);
     2085        mr_asprintf(&partcode, format);
    20852086    } else {
    20862087        /* probably an image */
    2087         asprintf(&tmp,
     2088        mr_asprintf(&tmp,
    20882089                "Unknown format ('%s') - using supplied string anyway",
    20892090                format);
    20902091        mvaddstr_and_log_it(g_currentY++, 0, tmp);
    2091         paranoid_free(tmp);
     2092        mr_free(tmp);
    20922093#ifdef __FreeBSD__
    2093         asprintf(&partcode, format);    // was a5
     2094        mr_asprintf(&partcode, format); // was a5
    20942095#else
    2095         asprintf(&partcode, format);    // was 83
    2096 #endif
    2097     }
    2098     asprintf(&tmp, "Setting %s's type to %s (%s)", partition, format,
     2096        mr_asprintf(&partcode, format); // was 83
     2097#endif
     2098    }
     2099    mr_asprintf(&tmp, "Setting %s's type to %s (%s)", partition, format,
    20992100            partcode);
    2100     paranoid_free(partition);
     2101    mr_free(partition);
    21012102
    21022103    log_msg(1, tmp);
    2103     paranoid_free(tmp);
     2104    mr_free(tmp);
    21042105    if (partcode[0] != '\0' && strcmp(partcode, "83")) {    /* no need to set type if 83: 83 is default */
    21052106
     
    21112112                || strstr(tmp1, " (1-4)")) {
    21122113                log_msg(5, "Specifying partno (%d) - yay", partno);
    2113                 asprintf(&tmp, "%d\n", partno);
     2114                mr_asprintf(&tmp, "%d\n", partno);
    21142115                fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    2115                 paranoid_free(tmp);
    2116                 paranoid_free(tmp1);
     2116                mr_free(tmp);
     2117                mr_free(tmp1);
    21172118                tmp1 = last_line_of_file(FDISK_LOG);
    21182119                log_msg(5, "A - last line = '%s'", tmp1);
    21192120            }
    2120             paranoid_free(tmp1);
    2121 
    2122             asprintf(&tmp, "%s\n", partcode);
     2121            mr_free(tmp1);
     2122
     2123            mr_asprintf(&tmp, "%s\n", partcode);
    21232124            fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    2124             paranoid_free(tmp);
     2125            mr_free(tmp);
    21252126            tmp1 = last_line_of_file(FDISK_LOG);
    21262127            log_msg(5, "B - last line = '%s'",tmp1);
    2127             paranoid_free(tmp1);
     2128            mr_free(tmp1);
    21282129
    21292130            fput_string_one_char_at_a_time(pout_to_fdisk, "\n");
    21302131            tmp1 = last_line_of_file(FDISK_LOG);
    21312132            log_msg(5, "C - last line = '%s'",tmp1);
    2132             paranoid_free(tmp1);
     2133            mr_free(tmp1);
    21332134
    21342135            tmp = last_line_of_file(FDISK_LOG);
     
    21382139                fput_string_one_char_at_a_time(pout_to_fdisk, "\n");
    21392140            }
    2140             paranoid_free(tmp);
     2141            mr_free(tmp);
    21412142            fput_string_one_char_at_a_time(pout_to_fdisk, "p\n");
    21422143        } else {
    2143             asprintf(&output, "t\n%d\n%s\nw\n", partno, partcode);
    2144             asprintf(&command, "parted2fdisk %s >> %s 2>> %s", drive,
     2144            mr_asprintf(&output, "t\n%d\n%s\nw\n", partno, partcode);
     2145            mr_asprintf(&command, "parted2fdisk %s >> %s 2>> %s", drive,
    21452146                    MONDO_LOGFILE, MONDO_LOGFILE);
    21462147            log_msg(5, "output = '%s'", output);
     
    21562157                paranoid_pclose(fout);
    21572158            }
    2158             paranoid_free(command);
    2159             paranoid_free(output);
     2159            mr_free(command);
     2160            mr_free(output);
    21602161        }
    21612162        /* BERLIOS: Useless as command not initialized in all cases
     
    21652166        */
    21662167    }
    2167     paranoid_free(partcode);
     2168    mr_free(partcode);
    21682169
    21692170
     
    21902191        return 1;
    21912192    }
    2192     asprintf(&program, "vinum start -f %s", raid_device);
     2193    mr_asprintf(&program, "vinum start -f %s", raid_device);
    21932194#else
    2194     asprintf(&program, "raidstart %s", raid_device);
     2195    mr_asprintf(&program, "raidstart %s", raid_device);
    21952196#endif
    21962197    log_msg(1, "program = %s", program);
     
    21992200        fprintf(g_fprep, "%s\n", program);
    22002201    }
    2201     paranoid_free(program);
     2202    mr_free(program);
    22022203
    22032204    if (res) {
     
    22342235        return 1;
    22352236    }
    2236     asprintf(&program, "vinum stop -f %s", raid_device);
     2237    mr_asprintf(&program, "vinum stop -f %s", raid_device);
    22372238#else
    22382239    // use raidstop if it exists, otherwise use mdadm
    22392240    if (run_program_and_log_output("which raidstop", FALSE)) {
    2240         asprintf(&program, "mdadm -S %s", raid_device);
     2241        mr_asprintf(&program, "mdadm -S %s", raid_device);
    22412242    } else {
    2242         asprintf(&program, "raidstop %s", raid_device);
     2243        mr_asprintf(&program, "raidstop %s", raid_device);
    22432244    }
    22442245#endif
     
    22482249        fprintf(g_fprep, "%s\n", program);
    22492250    }
    2250     paranoid_free(program);
     2251    mr_free(program);
    22512252
    22522253    if (res) {
     
    23222323            return (1);
    23232324        }
    2324         for (getline(&incoming, &n, fin); !feof(fin);
    2325              getline(&incoming, &n, fin)) {
     2325        for (mr_getline(&incoming, &n, fin); !feof(fin);
     2326             mr_getline(&incoming, &n, fin)) {
    23262327            retval += stop_raid_device(incoming);
    23272328        }
     
    23322333            return (1);
    23332334        }
    2334         for (getline(&incoming, &n, fin); !feof(fin);
    2335              getline(&incoming, &n, fin)) {
     2335        for (mr_getline(&incoming, &n, fin); !feof(fin);
     2336             mr_getline(&incoming, &n, fin)) {
    23362337            for (p = incoming;
    23372338                 *p != '\0' && (*p != 'm' || *(p + 1) != 'd'
    23382339                                || !isdigit(*(p + 2))); p++);
    23392340            if (*p != '\0') {
    2340                 asprintf(&dev, "/dev/%s", p);
     2341                mr_asprintf(&dev, "/dev/%s", p);
    23412342                /* BERLIOS : 32 Hard coded value */
    23422343                for (p = dev; *p > 32; p++);
    23432344                *p = '\0';
    23442345                res = stop_raid_device(dev);
    2345                 paranoid_free(dev);
    2346             }
    2347         }
    2348 #endif
    2349         paranoid_free(incoming);
     2346                mr_free(dev);
     2347            }
     2348        }
     2349#endif
     2350        mr_free(incoming);
    23502351    }
    23512352    paranoid_fclose(fin);
     
    23812382    if (strcmp(format, "swap") == 0) {
    23822383#ifdef __FreeBSD__
    2383         asprintf(&program, "true");
     2384        mr_asprintf(&program, "true");
    23842385#else
    2385         asprintf(&program, "mkswap");
     2386        mr_asprintf(&program, "mkswap");
    23862387#endif
    23872388    } else if (strcmp(format, "vfat") == 0) {
    2388         asprintf(&program, "format-and-kludge-vfat");
     2389        mr_asprintf(&program, "format-and-kludge-vfat");
    23892390#ifndef __FreeBSD__
    23902391    } else if (strcmp(format, "reiserfs") == 0) {
    2391         asprintf(&program, "mkreiserfs -ff");
     2392        mr_asprintf(&program, "mkreiserfs -ff");
    23922393    } else if (strcmp(format, "xfs") == 0) {
    2393         asprintf(&program, "mkfs.xfs -f -q");
     2394        mr_asprintf(&program, "mkfs.xfs -f -q");
    23942395    } else if (strcmp(format, "jfs") == 0) {
    2395         asprintf(&program, "mkfs.jfs");
     2396        mr_asprintf(&program, "mkfs.jfs");
    23962397    } else if (strcmp(format, "ext3") == 0) {
    2397         asprintf(&program, "mkfs -t ext2 -F -j -q");
     2398        mr_asprintf(&program, "mkfs -t ext2 -F -j -q");
    23982399    } else if (strcmp(format, "minix") == 0) {
    2399         asprintf(&program, "mkfs.minix");
     2400        mr_asprintf(&program, "mkfs.minix");
    24002401#endif
    24012402    } else if (strcmp(format, "ext2") == 0) {
    2402         asprintf(&program, "mke2fs -F -q");
     2403        mr_asprintf(&program, "mke2fs -F -q");
    24032404    } else {
    24042405#ifdef __FreeBSD__
    2405         asprintf(&program, "newfs_%s", format);
     2406        mr_asprintf(&program, "newfs_%s", format);
    24062407#else
    2407         asprintf(&program, "mkfs -t %s -c", format);    // -c checks for bad blocks
    2408 #endif
    2409         asprintf(&tmp, "Unknown format (%s) - assuming '%s' will do", format,
     2408        mr_asprintf(&program, "mkfs -t %s -c", format); // -c checks for bad blocks
     2409#endif
     2410        mr_asprintf(&tmp, "Unknown format (%s) - assuming '%s' will do", format,
    24102411                program);
    24112412        log_it(tmp);
    2412         paranoid_free(tmp);
     2413        mr_free(tmp);
    24132414        res = 0;
    24142415    }
     
    24482449            original_size_of_drive += mountlist->el[partno].size;
    24492450        } else {
    2450             asprintf(&tmp, "Skipping %s", mountlist->el[partno].device);
     2451            mr_asprintf(&tmp, "Skipping %s", mountlist->el[partno].device);
    24512452//                      log_to_screen(tmp);
    2452             paranoid_free(tmp);
     2453            mr_free(tmp);
    24532454        }
    24542455    }
     
    25122513        return;
    25132514    }
    2514     asprintf(&tmp, _("Expanding entries to suit drive %s (%ld MB)"),
     2515    mr_asprintf(&tmp, _("Expanding entries to suit drive %s (%ld MB)"),
    25152516            drive_name, current_size_of_drive);
    25162517    log_to_screen(tmp);
    2517     paranoid_free(tmp);
     2518    mr_free(tmp);
    25182519
    25192520    drivemntlist = malloc(sizeof(struct mountlist_reference));
     
    25322533
    25332534    if (original_size_of_drive <= 0) {
    2534         asprintf(&tmp, _("Cannot resize %s's entries. Drive not found."),
     2535        mr_asprintf(&tmp, _("Cannot resize %s's entries. Drive not found."),
    25352536                drive_name);
    25362537        log_to_screen(tmp);
    2537         paranoid_free(tmp);
     2538        mr_free(tmp);
    25382539        return;
    25392540    }
    25402541    factor =
    25412542        (float) (current_size_of_drive) / (float) (original_size_of_drive);
    2542     asprintf(&tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f",
     2543    mr_asprintf(&tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f",
    25432544            drive_name, original_size_of_drive, current_size_of_drive,
    25442545            factor);
    25452546    log_to_screen(tmp);
    2546     paranoid_free(tmp);
     2547    mr_free(tmp);
    25472548
    25482549    lastpart = drivemntlist->entries - 1;
     
    25632564            newsizL = (long) new_size;
    25642565        }
    2565         asprintf(&tmp, _("Changing %s from %lld KB to %ld KB"),
     2566        mr_asprintf(&tmp, _("Changing %s from %lld KB to %ld KB"),
    25662567                drivemntlist->el[partno]->device,
    25672568                drivemntlist->el[partno]->size, newsizL);
    25682569        log_to_screen(tmp);
    2569         paranoid_free(tmp);
     2570        mr_free(tmp);
    25702571        drivemntlist->el[partno]->size = newsizL;
    25712572    }
    25722573    final_size = get_phys_size_of_drive(drive_name);
    2573     asprintf(&tmp, _("final_size = %ld MB"), final_size);
     2574    mr_asprintf(&tmp, _("final_size = %ld MB"), final_size);
    25742575    log_to_screen(tmp);
    2575     paranoid_free(tmp);
     2576    mr_free(tmp);
    25762577}
    25772578
     
    26132614    }
    26142615    log_to_screen(_("Mountlist adjusted to suit current hard drive(s)"));
    2615     paranoid_free(drivelist);
     2616    mr_free(drivelist);
    26162617}
    26172618
     
    26372638    log_msg(1, "Creating list of partitions for drive %s", drive_name);
    26382639
    2639     asprintf(&tmp_drive_name,drive_name);
     2640    mr_asprintf(&tmp_drive_name,drive_name);
    26402641    if (!tmp_drive_name)
    26412642        fatal_error("Out of memory");
     
    26572658        }
    26582659    }
    2659     paranoid_free(tmp_drive_name);
     2660    mr_free(tmp_drive_name);
    26602661}
    26612662
Note: See TracChangeset for help on using the changeset viewer.