Ignore:
Timestamp:
Sep 25, 2013, 8:55:45 AM (11 years ago)
Author:
Bruno Cornec
Message:
  • Lots of memory management backports from 3.1 to 3.2 - still not finished, nor working ATM. the common subdir was done during travel, so this is essentially a backup !
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mondo/src/common/libmondo-devices.c

    r3185 r3191  
    2121#include "libmondo-stream-EXT.h"
    2222
     23extern void mr_strip_spaces(char *);
     24
    2325#include <sys/types.h>
    2426#ifdef __FreeBSD__
     
    127129{
    128130    char *tmp = NULL;
    129     char *comment;
    130131    bool is_this_a_ramdisk = FALSE;
    131132
    132     malloc_string(comment);
    133133    mr_asprintf(tmp, "%s", where_is_root_mounted());
    134     sprintf(comment, "root is mounted at %s\n", tmp);
    135     log_msg(0, comment);
    136     log_msg(0,
    137             "No, Schlomo, that doesn't mean %s is the root partition. It's just a debugging message. Relax. It's part of am_I_in_disaster_recovery_mode().",
    138             tmp);
     134    log_msg(0, "root is mounted at %s\n", tmp);
     135    log_msg(0, "That doesn't mean %s is the root partition. It's just a debugging message. Relax. It's part of am_I_in_disaster_recovery_mode().", tmp);
    139136
    140137#ifdef __FreeBSD__
     
    156153    if (is_this_a_ramdisk) {
    157154        if (!does_file_exist("/THIS-IS-A-RAMDISK")) {
    158             log_to_screen
    159                 ("Using /dev/root is stupid of you but I'll forgive you.");
     155            log_to_screen("Using /dev/root is stupid of you but I'll forgive you.");
    160156            is_this_a_ramdisk = FALSE;
    161157        }
     
    164160        is_this_a_ramdisk = TRUE;
    165161    }
    166     paranoid_free(comment);
    167     log_msg(1, "Is this a ramdisk? result = %d", is_this_a_ramdisk);
     162
     163    log_msg(1, "Is this a ramdisk? result = %s", (is_this_a_ramdisk) ? "TRUE" : "FALSE");
    168164    return (is_this_a_ramdisk);
    169165}
     
    229225int eject_device(char *dev)
    230226{
    231     char *command;
     227    char *command = NULL;
    232228    int res1 = 0, res2 = 0;
    233229
    234     malloc_string(command);
     230    if (dev == NULL) {
     231        return (1);
     232    }
    235233
    236234    if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type)
    237235        && g_backup_media_type != udev) {
    238         sprintf(command, "mt -f %s offline", dev);
     236        mr_asprintf(command, "mt -f %s offline", dev);
    239237        res1 = run_program_and_log_output(command, 1);
     238        mr_free(command);
    240239    } else {
    241240        res1 = 0;
     
    244243#ifdef __FreeBSD__
    245244    if (strstr(dev, "acd")) {
    246         sprintf(command, "cdcontrol -f %s eject", dev);
     245        mr_asprintf(command, "cdcontrol -f %s eject", dev);
    247246    } else {
    248         sprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`",
    249                 dev);
     247        mr_asprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`", dev);
    250248    }
    251249#else
    252     sprintf(command, "eject %s", dev);
     250    mr_asprintf(command, "eject %s", dev);
    253251#endif
    254252
    255253    log_msg(3, "Ejecting %s", dev);
    256254    res2 = run_program_and_log_output(command, 1);
    257     paranoid_free(command);
     255    mr_free(command);
    258256    if (res1 && res2) {
    259257        return (1);
     
    270268int inject_device(char *dev)
    271269{
    272     char *command;
     270    char *command = NULL;
    273271    int i;
    274272
    275     malloc_string(command);
    276 
     273    if (dev == NULL) {
     274        return (1);
     275    }
    277276
    278277#ifdef __FreeBSD__
    279278    if (strstr(dev, "acd")) {
    280         sprintf(command, "cdcontrol -f %s close", dev);
     279        mr_asprintf(command, "cdcontrol -f %s close", dev);
    281280    } else {
    282         sprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`",
    283                 dev);
     281        mr_asprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`", dev);
    284282    }
    285283#else
    286     sprintf(command, "eject -t %s", dev);
     284    mr_asprintf(command, "eject -t %s", dev);
    287285#endif
    288286    i = run_program_and_log_output(command, FALSE);
    289     paranoid_free(command);
     287    mr_free(command);
    290288    return (i);
    291289}
     
    301299
    302300    /*@ buffers *********************************************************** */
    303     char *tmp;
     301    char *tmp = NULL;
    304302    bool ret;
    305303
    306     malloc_string(tmp);
    307304    assert_string_is_neither_NULL_nor_zerolength(device);
    308305
    309     sprintf(tmp, "ls %s > /dev/null 2> /dev/null", device);
     306    mr_asprintf(tmp, "ls %s > /dev/null 2> /dev/null", device);
    310307
    311308    if (system(tmp)) {
     
    314311        ret = TRUE;
    315312    }
    316     paranoid_free(tmp);
     313    mr_free(tmp);
    317314    return (ret);
    318315}
     
    345342{
    346343    /*@ buffers **************************************************** */
    347     char *program;
    348     char *incoming;
     344    char *program = NULL;
     345    char *incoming = NULL;
    349346    char *searchstr = NULL;
    350     char *tmp;
    351     char *p;
    352347
    353348    /*@ ints ******************************************************* */
     
    356351    /*@ pointers *************************************************** */
    357352    FILE *fin;
    358 
    359353
    360354    /*@ end vars *************************************************** */
     
    362356    assert(partno >= 0 && partno < 999);
    363357
    364     malloc_string(program);
    365     malloc_string(incoming);
    366358    malloc_string(searchstr);
    367     malloc_string(tmp);
    368359
    369360#ifdef __FreeBSD__
    370361    // We assume here that this is running from mondorestore. (It is.)
    371     sprintf(program, "ls %s %s >/dev/null 2>&1", drive,
    372             build_partition_name(tmp, drive, partno));
    373     return system(program);
    374 #else
    375     tmp[0] = '\0';
    376 #endif
    377 
    378     sprintf(program, "parted2fdisk -l %s 2> /dev/null", drive);
     362    mr_asprintf(program, "ls %s %s >/dev/null 2>&1", drive, build_partition_name(tmp, drive, partno));
     363    res = system(program);
     364    mr_free(program);
     365    return(res);
     366#endif
     367
     368    mr_asprintf(program, "parted2fdisk -l %s 2> /dev/null", drive);
    379369    fin = popen(program, "r");
    380370    if (!fin) {
    381371        log_it("program=%s", program);
    382372        log_OS_error("Cannot popen-in program");
     373        mr_free(program);
    383374        return (0);
    384375    }
     376    mr_free(program);
     377
    385378    (void) build_partition_name(searchstr, drive, partno);
    386379    strcat(searchstr, " ");
    387     for (res = 0; !res && (p = fgets(incoming, MAX_STR_LEN - 1, fin));) {
     380    for (res = 0, mr_getline(incoming, fin); !res && !feof(fin) ; mr_getline(incoming, fin)) {
    388381        if (strstr(incoming, searchstr)) {
    389382            res = 1;
    390383        }
    391     }
     384        mr_free(incoming);
     385    }
     386    mr_free(incoming);
     387
    392388    if (pclose(fin)) {
    393389        log_OS_error("Cannot pclose fin");
    394390    }
    395     paranoid_free(program);
    396     paranoid_free(incoming);
    397391    paranoid_free(searchstr);
    398     paranoid_free(tmp);
    399392    return (res);
    400393}
     
    413406{
    414407    /*@ buffers **************************************************** */
    415     char *command;
     408    char *command = NULL;
    416409
    417410    /*@ end vars *************************************************** */
     
    421414    assert_string_is_neither_NULL_nor_zerolength(str);
    422415
    423     malloc_string(command);
    424     sprintf(command,
    425             "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null",
    426             dev, str);
     416    /* For UEFI detection, this should be extended to count=2 */
     417    mr_asprintf(command, "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", dev, str);
    427418    i = system(command);
    428     paranoid_free(command);
     419    mr_free(command);
    429420    if (i) {
    430421        return (FALSE);
     
    444435{
    445436    /*@ buffers **************************************************** */
    446     char *command;
     437    char *command = NULL;
    447438    /*@ end vars *************************************************** */
    448439    int i;
    449440
    450     malloc_string(command);
    451     sprintf(command,
    452             "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null",
    453             dev, n, str);
     441    mr_asprintf(command, "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", dev, n, str);
    454442    i = system(command);
    455     paranoid_free(command);
     443    mr_free(command);
    456444    if (i) {
    457445        return (FALSE);
     
    466454 * Try to mount CD-ROM at @p mountpoint. If the CD-ROM is not found or has
    467455 * not been specified, call find_cdrom_device() to find it.
    468  * @param bkpinfo The backup information structure. The only field used is @c bkpinfo->media_device.
    469456 * @param mountpoint Where to mount the CD-ROM.
    470457 * @return 0 for success, nonzero for failure.
    471458 * @see mount_CDROM_here
    472459 */
    473 int find_and_mount_actual_cd(char *mountpoint)
    474 {
     460int find_and_mount_actual_cd(char *mountpoint) {
     461
    475462    /*@ buffers ***************************************************** */
    476463
    477464    /*@ int's  ****************************************************** */
    478465    int res;
    479     char *dev;
     466    char *dev = NULL;
    480467
    481468    /*@ end vars **************************************************** */
     
    532519{
    533520    /*@ buffers ************************ */
    534     char *comment;
    535521    char *tmp = NULL;
    536522    char *cdr_exe = NULL;
    537     char *command;
    538 
    539     malloc_string(comment);
    540     malloc_string(command);
     523    char *command = NULL;
     524
    541525    if (g_cdrw_drive_is_here[0]) {
    542526        strcpy(cdrw_device, g_cdrw_drive_is_here);
    543527        log_msg(3, "Been there, done that. Returning %s", cdrw_device);
    544         paranoid_free(comment);
    545         paranoid_free(command);
    546528        return (0);
    547529    }
    548530    if (g_backup_media_type == dvd) {
    549         log_msg(1,
    550                 "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?");
    551         paranoid_free(comment);
    552         paranoid_free(command);
     531        log_msg(1, "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?");
    553532        return (1);
    554533    }
     
    560539    }
    561540    if (find_home_of_exe(cdr_exe)) {
    562         sprintf(command,
    563                 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -E '[D|C][V|D]' | cut -d' ' -f2 | head -n1",
    564                 cdr_exe);
     541        mr_asprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -E '[D|C][V|D]' | cut -d' ' -f2 | head -n1", cdr_exe);
    565542        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     543        mr_free(command);
    566544    }
    567545    if ((tmp == NULL) || (strlen(tmp) < 2)) {
    568         paranoid_free(comment);
    569546        mr_free(tmp);
    570547        mr_free(cdr_exe);
    571         paranoid_free(command);
    572548        return 1;
    573549    } else {
    574550        strcpy(cdrw_device, tmp);
    575         sprintf(comment, "Found CDRW device - %s", cdrw_device);
    576         log_it(comment);
     551        log_it("Found CDRW device - %s", cdrw_device);
    577552        strcpy(g_cdrw_drive_is_here, cdrw_device);
    578         paranoid_free(comment);
    579553        mr_free(tmp);
    580554        mr_free(cdr_exe);
    581         paranoid_free(command);
    582555        return (0);
    583556    }
    584557}
    585 
    586 
    587558
    588559
     
    609580
    610581    /*@ buffers ***************************************************** */
    611     char *tmp;
     582    char *tmp = NULL;
    612583    char *tmp1 = NULL;
    613584    char *cdr_exe = NULL;
    614585    char *phrase_one;
    615     char *phrase_two;
    616     char *command;
    617     char *dvd_last_resort;
    618     char *mountpoint;
     586    char *phrase_two = NULL;
     587    char *command = NULL;
     588#ifndef __FreeBSD__
     589    char *dvd_last_resort = NULL;
     590#endif
     591    char *mountpoint = NULL;
    619592    static char the_last_place_i_found_it[MAX_STR_LEN] = "";
    620593
     
    622595    malloc_string(tmp);
    623596    malloc_string(phrase_one);
    624     malloc_string(phrase_two);
    625     malloc_string(command);
    626     malloc_string(dvd_last_resort);
    627597    malloc_string(mountpoint);
    628598
    629599    output[0] = '\0';
    630600    phrase_one[0] = '\0';
    631     phrase_two[0] = '\0';
    632     dvd_last_resort[0] = '\0';
    633601
    634602    /*@ end vars **************************************************** */
     
    642610    if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) {
    643611        strcpy(output, the_last_place_i_found_it);
    644         log_msg(3,
    645                 "find_cdrom_device() --- returning last found location - '%s'",
    646                 output);
     612        log_msg(3, "find_cdrom_device() --- returning last found location - '%s'", output);
    647613        retval = 0;
    648614        goto end_of_find_cdrom_device;
     
    671637    }
    672638
    673     sprintf(command, "%s -scanbus 2> /dev/null", cdr_exe);
     639    mr_asprintf(command, "%s -scanbus 2> /dev/null", cdr_exe);
    674640    fin = popen(command, "r");
    675641    if (!fin) {
     
    677643        log_OS_error("Cannot popen command");
    678644        mr_free(cdr_exe);
     645        mr_free(command);
    679646        return (1);
    680647    }
     648    mr_free(command);
     649
    681650    for (tmp1 = fgets(tmp, MAX_STR_LEN, fin); !feof(fin) && (tmp1 != NULL);
    682651         tmp1 = fgets(tmp, MAX_STR_LEN, fin)) {
     
    696665                        }
    697666                        *q = '\0';
    698                         strcpy(phrase_two, p);
     667                        mr_asprintf(phrase_two, "%s", p);
    699668                    }
    700669                }
     
    705674
    706675#ifndef __FreeBSD__
    707     if (strlen(phrase_two) == 0) {
     676    if (!phrase_two || strlen(phrase_two) == 0) {
    708677        log_msg(4, "Not running phase two. String is empty.");
    709678    } else {
    710         sprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two);
     679        mr_asprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two);
    711680        fin = popen(command, "r");
     681        mr_free(command);
     682
    712683        if (!fin) {
    713684            log_msg(4, "Cannot run 2nd command - non-fatal, fortunately");
     
    721692                        *p = '\0';
    722693                        if (strstr(tmp, "DVD")) {
    723                             sprintf(dvd_last_resort, "/dev/%s", tmp);
    724                             log_msg(4,
    725                                     "Ignoring '%s' because it's a DVD drive",
    726                                     tmp);
     694                            mr_free(dvd_last_resort);
     695                            mr_asprintf(dvd_last_resort, "/dev/%s", tmp);
     696                            log_msg(4, "Ignoring '%s' because it's a DVD drive", tmp);
    727697                        } else {
    728698                            sprintf(output, "/dev/%s", tmp);
     
    775745#else
    776746    if (!found_it && strlen(dvd_last_resort) > 0) {
    777         log_msg(4, "Well, I'll use the DVD - %s - as a last resort",
    778                 dvd_last_resort);
     747        log_msg(4, "Well, I'll use the DVD - %s - as a last resort", dvd_last_resort);
    779748        strcpy(output, dvd_last_resort);
    780749        found_it = TRUE;
    781750    }
    782751    if (found_it) {
    783         sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null",
    784                 strrchr(output, '/') + 1);
     752        sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", strrchr(output, '/') + 1);
    785753        if (system(tmp) == 0) {
    786             log_msg(4,
    787                     "%s is not right. It's being SCSI-emulated. Continuing.",
    788                     output);
     754            log_msg(4, "%s is not right. It's being SCSI-emulated. Continuing.", output);
    789755            found_it = FALSE;
    790756            output[0] = '\0';
     
    852818                found_it = FALSE;
    853819            } else {
    854                 sprintf(command, "umount %s", output);
     820                mr_asprintf(command, "umount %s", output);
    855821                paranoid_system(command);
     822                mr_free(command);
     823
    856824                log_msg(4, "I'm confident the Mondo CD is in %s", output);
    857825            }
     
    872840    }
    873841
    874     sprintf(command,
    875             "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep -E \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2",
    876             cdr_exe, g_cdrw_drive_is_here);
     842    mr_asprintf(command, "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep -E \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2", cdr_exe, g_cdrw_drive_is_here);
     843
    877844    log_msg(1, "command=%s", command);
    878845    mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output(command));
     846    mr_free(command);
     847
    879848    if (strlen(tmp1) > 0) {
    880849        strcpy(output, tmp1);
     
    888857
    889858  end_of_find_cdrom_device:
     859    mr_free(cdr_exe);
     860    mr_free(phrase_two);
     861    mr_free(dvd_last_resort);
     862
    890863    paranoid_free(tmp);
    891     mr_free(cdr_exe);
    892864    paranoid_free(phrase_one);
    893     paranoid_free(phrase_two);
    894     paranoid_free(command);
    895     paranoid_free(dvd_last_resort);
    896865    paranoid_free(mountpoint);
    897866    return (retval);
     
    899868
    900869
    901 
    902 
    903 
    904870int find_dvd_device(char *output, bool try_to_mount)
    905871{
    906     char *command;
    907872    char *tmp;
    908873    int retval = 0, devno = -1;
    909 
    910     malloc_string(command);
    911     malloc_string(tmp);
    912874
    913875    if (g_dvd_drive_is_here[0]) {
     
    917879    }
    918880
    919     sprintf(tmp, "%s", call_program_and_get_last_line_of_output("dvdrecord -scanbus 2> /dev/null | grep -E '\)\ \'' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1"));
     881    malloc_string(tmp);
     882    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("dvdrecord -scanbus 2> /dev/null | grep -E '\)\ \'' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1"));
    920883    log_msg(5, "tmp = '%s'", tmp);
    921     if (!tmp[0])
    922         sprintf(tmp, "%s", call_program_and_get_last_line_of_output
    923                 ("cdrecord -scanbus 2> /dev/null | grep \)\ \' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1")
    924             );
     884    if (!tmp[0]) {
     885        mr_free(tmp);
     886        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("cdrecord -scanbus 2> /dev/null | grep \)\ \' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1"));
     887    }
    925888    if (tmp[0]) {
    926889        devno = atoi(tmp) - 1;
    927890    }
     891    mr_free(tmp);
     892
    928893    if (devno >= 0) {
    929894        retval = 0;
     
    936901    }
    937902
    938     if (try_to_mount) {
    939         log_msg(1, "Ignoring the fact that try_to_mount==TRUE");
    940     }
    941903    return (retval);
    942904}
     
    10531015{
    10541016    char *good_formats = NULL;
    1055     char *command;
    1056     char *format_sz;
     1017    char *command = NULL;
     1018    char *format_sz = NULL;
    10571019    char *p;
    10581020
     
    10601022    int retval;
    10611023    malloc_string(good_formats);
    1062     malloc_string(command);
    1063     malloc_string(format_sz);
    10641024
    10651025    assert_string_is_neither_NULL_nor_zerolength(format);
    10661026
    1067     sprintf(format_sz, "%s ", format);
     1027    mr_asprintf(format_sz, "%s ", format);
    10681028
    10691029#ifdef __FreeBSD__
    1070     sprintf(command,
    1071             "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '");
     1030    mr_asprintf(command, "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '");
    10721031#else
    1073     sprintf(command,
    1074             "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '");
     1032    mr_asprintf(command, "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '");
    10751033#endif
    10761034
    10771035    pin = popen(command, "r");
     1036    mr_free(command);
     1037
    10781038    if (!pin) {
    10791039        log_OS_error("Unable to read good formats");
     
    10941054    }
    10951055    paranoid_free(good_formats);
    1096     paranoid_free(command);
    1097     paranoid_free(format_sz);
     1056    mr_free(format_sz);
     1057
    10981058    return (retval);
    10991059}
     
    11141074
    11151075    /*@ buffers ***************************************************** */
    1116     char *incoming;
     1076    char *incoming = NULL;
    11171077    char *device_with_tab = NULL;
    11181078    char *device_with_space = NULL;
     
    11281088    /*@ end vars **************************************************** */
    11291089
    1130     malloc_string(incoming);
    1131     assert(device_raw != NULL);
    1132 //  assert_string_is_neither_NULL_nor_zerolength(device_raw);
     1090    if (device_raw == NULL) {
     1091        return(FALSE);
     1092    }
     1093
    11331094    if (device_raw[0] != '/' && !strstr(device_raw, ":/")) {
    11341095        log_msg(1, "%s needs to have a '/' prefixed - I'll do it",
     
    11531114        return(FALSE);
    11541115    }
    1155     for (tmp = fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) && (tmp != NULL);
    1156          tmp = fgets(incoming, MAX_STR_LEN - 1, fin)) {
    1157         if (strstr(incoming, device_with_space) //> incoming
    1158             || strstr(incoming, device_with_tab))   // > incoming)
    1159         {
     1116
     1117    for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
     1118        if (strstr(incoming, device_with_space) || strstr(incoming, device_with_tab)) {
    11601119            paranoid_pclose(fin);
    1161             paranoid_free(incoming);
     1120            mr_free(incoming);
    11621121            return(TRUE);
    11631122        }
    1164     }
     1123        mr_free(incoming);
     1124    }
     1125    mr_free(incoming);
    11651126    mr_free(device_with_tab);
    11661127    paranoid_pclose(fin);
     
    11721133    }
    11731134    mr_free(tmp);
    1174     paranoid_free(incoming);
    11751135    return(retval);
    11761136}
     
    11891149    char command[MAX_STR_LEN];
    11901150    int vndev = 2;
    1191     if (atoi
    1192         (call_program_and_get_last_line_of_output
    1193          ("/sbin/sysctl -n kern.osreldate")) < 500000) {
     1151    if (atoi(call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate")) < 500000) {
    11941152        do {
    11951153            sprintf(mddevice, "vn%ic", vndev++);
     
    12231181int kick_vn(char *dname)
    12241182{
    1225     char command[MAX_STR_LEN];
     1183    char *command = NULL;
     1184    int res = 0;
    12261185
    12271186    if (strncmp(dname, "/dev/", 5) == 0) {
     
    12291188    }
    12301189
    1231     if (atoi
    1232         (call_program_and_get_last_line_of_output
    1233          ("/sbin/sysctl -n kern.osreldate")) < 500000) {
    1234         sprintf(command, "vnconfig -d %s", dname);
    1235         return system(command);
     1190    if (atoi(call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate")) < 500000) {
     1191        mr_asprintf(command, "vnconfig -d %s", dname);
    12361192    } else {
    1237         sprintf(command, "mdconfig -d -u %s", dname);
    1238         return system(command);
    1239     }
    1240      /*NOTREACHED*/ return 255;
     1193        mr_asprintf(command, "mdconfig -d -u %s", dname);
     1194    }
     1195    res = system(command);
     1196    mr_free(command);
     1197    return(res);
    12411198}
    12421199#endif
     
    12521209{
    12531210    /*@ buffer ****************************************************** */
    1254     char *command;
     1211    char *command = NULL;
    12551212    int retval;
    12561213
    1257     malloc_string(command);
    12581214    assert_string_is_neither_NULL_nor_zerolength(device);
    12591215    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
     
    12631219        return(1);
    12641220    }
    1265     log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device,
    1266             mountpoint);
     1221    log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device, mountpoint);
    12671222
    12681223#ifdef __FreeBSD__
    1269     sprintf(command, "mount_vfat %s %s 2>> %s",
    1270             device, mountpoint, MONDO_LOGFILE);
     1224    mr_asprintf(command, "mount_vfat %s %s 2>> %s", device, mountpoint, MONDO_LOGFILE);
    12711225
    12721226#else
    1273     sprintf(command, "mount %s -t vfat %s 2>> %s",
    1274             device, mountpoint, MONDO_LOGFILE);
     1227    mr_asprintf(command, "mount %s -t vfat %s 2>> %s", device, mountpoint, MONDO_LOGFILE);
    12751228#endif
    12761229
     
    12781231    retval = system(command);
    12791232    log_msg(1, "system(%s) returned %d", command, retval);
    1280 
    1281     paranoid_free(command);
     1233    mr_free(command);
     1234
    12821235    return (retval);
    12831236}
     
    12891242 * @return 0 for success, nonzero for failure.
    12901243 */
    1291 int mount_CDROM_here(char *device, char *mountpoint)
     1244int mount_CDROM_here(char *device, const char *mountpoint)
    12921245{
    12931246    /*@ buffer ****************************************************** */
     
    13271280
    13281281    }
    1329     log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device,
    1330             mountpoint);
     1282    log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, mountpoint);
    13311283    /*@ end vars *************************************************** */
    13321284
     
    13451297    retval = system(command);
    13461298    log_msg(1, "system(%s) returned %d", command, retval);
    1347     paranoid_free(command);
     1299    mr_free(command);
    13481300
    13491301    return (retval);
     
    13621314int mount_media()
    13631315{
    1364 char *mount_cmd;
     1316char *mount_cmd = NULL;
    13651317char *mountdir = NULL;
    13661318int i, res;
    13671319#ifdef __FreeBSD__
    1368 char mdd[32];
    1369 char *mddev = mdd;
    1370 #endif
    1371 
    1372 malloc_string(mount_cmd);
    1373 assert(bkpinfo != NULL);
    1374 
    1375     if (bkpinfo->backup_media_type == tape
    1376         || bkpinfo->backup_media_type == udev) {
     1320    char mdd[32];
     1321    char *mddev = mdd;
     1322#endif
     1323
     1324    if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) {
    13771325        log_msg(8, "Tape/udev. Therefore, no need to mount a media.");
    1378         paranoid_free(mount_cmd);
    13791326        return 0;
    13801327    }
     
    13821329    if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) {
    13831330        log_msg(2, "mount_media() - media already mounted. Fair enough.");
    1384         paranoid_free(mount_cmd);
    13851331        return (0);
    13861332    }
     
    13891335        log_msg(2, "Mounting for Network thingy");
    13901336        log_msg(2, "isodir = %s", bkpinfo->isodir);
    1391         if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/"))
    1392             && am_I_in_disaster_recovery_mode()) {
     1337        if ((!bkpinfo->isodir[0] || !strcmp(bkpinfo->isodir, "/")) && am_I_in_disaster_recovery_mode()) {
    13931338            strcpy(bkpinfo->isodir, "/tmp/isodir");
    13941339            log_msg(1, "isodir is being set to %s", bkpinfo->isodir);
    13951340        }
    13961341#ifdef __FreeBSD__
    1397         sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir,
     1342        mr_asprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir,
    13981343            bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number);
    13991344        mddev = make_vn(mount_cmd);
    1400         sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
     1345        mr_free(mount_cmd);
     1346
     1347        mr_asprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev);
    14011348#else
    1402         sprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s",
    1403             bkpinfo->isodir, bkpinfo->netfs_remote_dir,
    1404             bkpinfo->prefix, g_current_media_number, MNT_CDROM);
     1349        mr_asprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s", bkpinfo->isodir, bkpinfo->netfs_remote_dir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);
    14051350#endif
    14061351
     
    14121357        }
    14131358#ifdef __FreeBSD__
    1414         sprintf(mount_cmd, "%s/%s-%d.iso", mountdir,
    1415             bkpinfo->prefix, g_current_media_number);
     1359        mr_asprintf(mount_cmd, "%s/%s-%d.iso", mountdir, bkpinfo->prefix, g_current_media_number);
    14161360        mddev = make_vn(mount_cmd);
    1417         sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
     1361        mr_free(mount_cmd);
     1362
     1363        mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM);
    14181364#else
    1419         sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s",
    1420             mountdir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);
     1365        mr_asprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", mountdir, bkpinfo->prefix, g_current_media_number, MNT_CDROM);
    14211366#endif
    14221367        mr_free(mountdir);
    14231368    } else if (bkpinfo->backup_media_type == usb) {
    1424         sprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM);
     1369        mr_asprintf(mount_cmd, "mount -t vfat %s %s", bkpinfo->media_device, MNT_CDROM);
    14251370    } else if (strstr(bkpinfo->media_device, "/dev/")) {
    14261371#ifdef __FreeBSD__
    1427         sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
    1428         MNT_CDROM);
     1372        mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM);
    14291373#else
    1430         sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
    1431         bkpinfo->media_device, MNT_CDROM);
     1374        mr_asprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM);
    14321375#endif
    14331376    } else {
     
    14411384
    14421385#ifdef __FreeBSD__
    1443     sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,
    1444         MNT_CDROM);
     1386        mr_asprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, MNT_CDROM);
    14451387#else
    1446     sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",
    1447         bkpinfo->media_device, MNT_CDROM);
     1388        mr_asprintf(mount_cmd, "mount %s -t iso9660 -o ro %s", bkpinfo->media_device, MNT_CDROM);
    14481389#endif
    14491390    }
     
    14571398            log_msg(2, "Failed to mount device.");
    14581399            sleep(5);
    1459             run_program_and_log_output("sync", FALSE);
    1460         }
    1461     }
     1400            sync();
     1401        }
     1402    }
     1403    mr_free(mount_cmd);
    14621404
    14631405    if (res) {
     
    14661408        log_msg(2, "Mounted media drive OK");
    14671409    }
    1468     paranoid_free(mount_cmd);
    14691410    return (res);
    14701411}
     
    14961437
    14971438    /*@ buffers ********************************************************* */
    1498     char *tmp;
     1439    char *tmp = NULL;
    14991440    char *mds = NULL;
    1500     char *request;
     1441    char *request = NULL;
    15011442
    15021443    assert(bkpinfo != NULL);
     
    15101451        return;
    15111452    }
    1512     if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso
    1513         || bkpinfo->backup_media_type == netfs) {
     1453    mr_asprintf(tmp, "mkdir -p " MNT_CDROM);
     1454    run_program_and_log_output(tmp, 5);
     1455    mr_free(tmp);
     1456
     1457    if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso || bkpinfo->backup_media_type == netfs) {
    15141458        g_ISO_restore_mode = TRUE;
    15151459    }
    1516     malloc_string(tmp);
    1517     malloc_string(request);
    1518     sprintf(tmp, "mkdir -p " MNT_CDROM);
    1519     run_program_and_log_output(tmp, 5);
    15201460    if ((res = what_number_cd_is_this()) != cd_number_i_want) {
    1521         log_msg(3, "Currently, we hold %d but we want %d", res,
    1522                 cd_number_i_want);
     1461        log_msg(3, "Currently, we hold %d but we want %d", res, cd_number_i_want);
    15231462
    15241463        /* Now we need to umount the current media to have the next mounted after */
     
    15291468
    15301469        mds = media_descriptor_string(bkpinfo->backup_media_type);
    1531         sprintf(tmp, "Insisting on %s #%d", mds, cd_number_i_want);
    1532         sprintf(request, "Please insert %s #%d and press Enter.", mds, cd_number_i_want);
     1470        log_msg(3, "Insisting on %s #%d", mds, cd_number_i_want);
     1471        mr_asprintf(request, "Please insert %s #%d and press Enter.", mds, cd_number_i_want);
    15331472        mr_free(mds);
    1534         log_msg(3, tmp);
     1473
    15351474        while (what_number_cd_is_this() != cd_number_i_want) {
    1536             paranoid_system("sync");
     1475            sync();
    15371476            if (is_this_device_mounted(MNT_CDROM)) {
    15381477                res =
     
    15561495                inject_device(bkpinfo->media_device);
    15571496            }
    1558             paranoid_system("sync");
    1559         }
     1497            sync();
     1498        }
     1499        mr_free(request);
     1500
    15601501        log_msg(1, "Thankyou. Proceeding...");
    15611502        g_current_media_number = cd_number_i_want;
    15621503    }
    1563     paranoid_free(tmp);
    1564     paranoid_free(request);
    15651504}
    15661505
     
    16761615    log_msg(5, "Running: %s", command);
    16771616    mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
    1678     paranoid_free(command);
     1617    mr_free(command);
    16791618
    16801619    mount_cnt = atoi(mounted_file_system);
    16811620    log_msg (5, "mount_cnt: %d", mount_cnt);
    1682     paranoid_free(mounted_file_system);
     1621    mr_free(mounted_file_system);
    16831622
    16841623    for (i=mount_cnt; i > 0; i--) {
     
    16861625        log_msg(5, "Running: %s", command);
    16871626        mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
    1688         paranoid_free(command);
     1627        mr_free(command);
    16891628
    16901629        log_msg (5, "mounted_file_system: %s", mounted_file_system);
    16911630        if ((token = mr_strtok(mounted_file_system, token_chars, &lastpos)) == NULL) {
    16921631            log_msg (4, "Could not get the list of mounted file systems");
    1693             paranoid_free(mounted_file_system);
     1632            mr_free(mounted_file_system);
    16941633            mr_free(token);
    16951634            return (1);
     
    17191658        mr_free(mounted_file_system);
    17201659    }
    1721     /********
    1722     * DSFptr = DSF_Head;
    1723     * while (DSFptr != NULL) {
    1724     * printf ("Dev: %s  MP: %s  Check: %d\n", DSFptr->device, DSFptr->mount_point, DSFptr->check);
    1725     * DSFptr = DSFptr->next;
    1726     * }
    1727     ********/
    17281660    return (0);
    17291661}
     
    17731705    log_msg(5, "  Executing: %s", command);
    17741706    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    1775     paranoid_free(command);
     1707    mr_free(command);
    17761708
    17771709    log_msg(5, "  Return value: %s", tmp);
    17781710    c = atoi(tmp);
    1779     paranoid_free(tmp);
     1711    mr_free(tmp);
    17801712
    17811713    if (!c) {
     
    17991731    log_msg(5, "Executing: %s", command);
    18001732    mr_asprintf(partition_list, "%s", call_program_and_get_last_line_of_output(command));
    1801     paranoid_free(command);
     1733    mr_free(command);
    18021734    log_msg(4, "Partition list for %s: %s", dsf, partition_list);
    18031735    if (!strlen(partition_list)) {
     
    18621794        log_msg(4, "Processing partition: %s", partitions[i]);
    18631795        /* See if it's swap. If it is, ignore it. */
    1864         mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'",
    1865           ndsf, partitions[i]);
     1796        mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", ndsf, partitions[i]);
    18661797        log_msg(5, "  Running: %s", command);
    18671798        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    1868         paranoid_free(command);
     1799        mr_free(command);
     1800
    18691801        log_msg(5, "  Return value: %s", tmp);
    18701802        c = strlen(tmp);
    1871         paranoid_free(tmp);
     1803        mr_free(tmp);
     1804
    18721805        if (c) {
    18731806            log_msg(4, "It's swap. Ignoring partition %s", partitions[i]);
    18741807            continue;
    18751808        }
     1809
    18761810        /* It's not swap. See if we can find the mount point from the mount command. */
    18771811        mr_asprintf(command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
    18781812        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    1879         paranoid_free(command);
     1813        mr_free(command);
     1814
    18801815        if (strlen(tmp)) {
    18811816            log_msg(4, "  %s is mounted: %s", partitions[i], tmp);
    18821817            if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) {
    18831818                log_msg (4, "Can't find mount point %s in mounted file systems list", tmp);
    1884                 paranoid_free(tmp);
     1819                mr_free(tmp);
    18851820                return (1);
    18861821            }
    18871822            DSFptr->check = 1;
    1888             paranoid_free(tmp);
     1823            mr_free(tmp);
    18891824            continue;
    18901825        }
    1891         paranoid_free(tmp);
     1826        mr_free(tmp);
     1827
    18921828        /* It's not swap and it's not mounted. See if it's LVM */
    18931829        log_msg(4, "  It's not mounted. Checking to see if it's LVM...");
     1830
    18941831        /* Check for LVM */
    18951832        mr_asprintf(command, "pvdisplay -c %s 2> /dev/null", partitions[i]);
    18961833        log_msg(5, "  Running: %s", command);
    18971834        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    1898         paranoid_free(command);
     1835        mr_free(command);
     1836
    18991837        if (strlen(tmp)) {
    19001838            log_msg(4, "Found an LVM partition at %s. Find the VG it's in...", partitions[i]);
     
    19031841            log_msg(5, "  Running: %s", command);
    19041842            strcpy(VG, call_program_and_get_last_line_of_output(command));
    1905             paranoid_free(command);
     1843            mr_free(command);
     1844
    19061845            log_msg(4, "  Volume Group: %s", VG);
    19071846            if (strlen(VG)) {
     
    19111850                log_msg(5, "  Running: %s", command);
    19121851                mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
    1913                 paranoid_free(command);
     1852                mr_free(command);
     1853
    19141854                log_msg(4, "  VG %s mount_list: %s", VG, mount_list);
    19151855                lastpos = 0;
     
    19181858                    if ((DSFptr = find_mount_point_in_list(token)) == NULL) {
    19191859                        log_msg (4, "Can't find mount point %s in mounted file systems list", token);
    1920                         paranoid_free(tmp);
     1860                        mr_free(tmp);
    19211861                        mr_free(token);
    19221862                        return (1);
     
    19291869                 * any of the Logical Volumes on the Volume Group.
    19301870                 *******/
    1931                 paranoid_free(mount_list);
     1871                mr_free(mount_list);
    19321872
    19331873                mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    19341874                log_msg (5, "Running: %s", command);
    19351875                mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
    1936                 paranoid_free(command);
     1876                mr_free(command);
    19371877                log_msg(4, "  Software raid device list: %s", mount_list);
    19381878                lastpos = 0;
     
    19401880                    mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
    19411881                    log_msg (5, "Running: %s", command);
    1942                     paranoid_free(tmp);
     1882                    mr_free(tmp);
    19431883                    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    1944                     paranoid_free(command);
     1884                    mr_free(command);
    19451885                    log_msg(4, "Number of Software raid device: %s", tmp);
    19461886                    if (atoi(tmp)) {
     
    19481888                        if ((DSFptr = find_device_in_list(token)) == NULL) {
    19491889                            log_msg (4, "Can't find device %s in mounted file systems list", token);
    1950                             paranoid_free(tmp);
     1890                            mr_free(tmp);
    19511891                            mr_free(token);
    19521892                            return (1);
     
    19591899            } else {
    19601900                log_msg (4, "Error finding Volume Group for partition %s", partitions[i]);
    1961                 paranoid_free(tmp);
     1901                mr_free(tmp);
    19621902                return (1);
    19631903            }
    1964             paranoid_free(tmp);
     1904            mr_free(tmp);
    19651905            continue;
    19661906        } else {
    19671907            log_msg (4, "Error finding partition type for the partition %s", partitions[i]);
    19681908        }
    1969         paranoid_free(tmp);
     1909        mr_free(tmp);
     1910
    19701911        /********
    19711912         * It's not swap, mounted, or LVM. See if it's used in a software raid device.
     
    19751916        log_msg(4, "  Running: %s", command);
    19761917        mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    1977         paranoid_free(command);
     1918        mr_free(command);
     1919
    19781920        if (!strlen(tmp)) {
    19791921            log_msg(4, "  Partition %s is not used in a non-LVM software raid device", partitions[i]);
    1980             paranoid_free(tmp);
     1922            mr_free(tmp);
    19811923            continue;
    19821924        }
    19831925        log_msg (5, "  UUID: %s", tmp);
     1926
    19841927        /* Get the Software raid device list */
    19851928        mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    19861929        log_msg (5, "  Running: %s", command);
    19871930        mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
    1988         paranoid_free(command);
     1931        mr_free(command);
     1932
    19891933        log_msg(4, "  Software raid device list: %s", mount_list);
    19901934        /* Loop through the software raid device list to see if we can find the partition */
     
    19931937            mr_asprintf(command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);
    19941938            log_msg(4, "  Running: %s", command);
    1995             paranoid_free(tmp);
     1939            mr_free(tmp);
    19961940            mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
    1997             paranoid_free(command);
     1941            mr_free(command);
     1942
    19981943            if (!atoi(tmp)) {
    19991944                log_msg (4,"  Didn't find partition %s in software raid device %s", partitions[i], token);
     
    20011946                if ((DSFptr = find_device_in_list(token)) == NULL) {
    20021947                    log_msg (4, "Can't find device %s in mounted file systems list", token);
    2003                     paranoid_free(tmp);
     1948                    mr_free(tmp);
    20041949                    mr_free(token);
    20051950                    return (1);
     
    20101955            mr_free(token);
    20111956        }
    2012         paranoid_free(tmp);
    2013         paranoid_free(mount_list);
     1957        mr_free(tmp);
     1958        mr_free(mount_list);
    20141959    }
    20151960
     
    20471992    return (0);
    20481993}
    2049 
    2050 
    2051 
    20521994
    20531995
     
    20992041            log_to_screen("Archiving only the following file systems on %s:", token);
    21002042            log_to_screen("==> %s", mounted_on_dsf);
    2101             strcpy(bkpinfo->include_paths, "/");
     2043            mr_free(bkpinfo->include_paths);
     2044            mr_asprintf(bkpinfo->include_paths, "%s", "/");
    21022045            if (strlen(not_mounted_on_dsf)) {
    21032046                log_msg (5, "Adding to bkpinfo->exclude_paths due to -I option: %s", not_mounted_on_dsf);
     
    21362079            mr_asprintf(tmp,"|%s|",bkpinfo->include_paths);
    21372080            if (strstr(tmp,tmp2) == NULL) {
    2138                 strcat(bkpinfo->include_paths,tmp1);
     2081                mr_strcat(bkpinfo->include_paths, "%s", tmp1);
    21392082            }
    21402083            mr_free(tmp1);
     
    21812124    char *q = NULL;
    21822125    char p[16*MAX_STR_LEN];
    2183     char *sz_size;
    2184     char *command;
     2126    char *sz_size = NULL;
     2127    char *command = NULL;
    21852128    char *compression_type = NULL;
    2186     char *comment;
    2187     char *prompt;
     2129    char *comment = NULL;
    21882130    int i;
    21892131    FILE *fin;
    21902132
    2191     malloc_string(sz_size);
    2192     malloc_string(command);
    2193     malloc_string(comment);
    2194     malloc_string(prompt);
    21952133    malloc_string(tmp1);
    21962134    assert(bkpinfo != NULL);
    2197     sz_size[0] = '\0';
    21982135    bkpinfo->nonbootable_backup = FALSE;
    21992136
     
    22322169        setup_scratchdir(tmp);
    22332170    }
    2234     log_msg(3, "media type = %s",
    2235             bkptype_to_string(bkpinfo->backup_media_type));
     2171    log_msg(3, "media type = %s", bkptype_to_string(bkpinfo->backup_media_type));
    22362172    bkpinfo->cdrw_speed = (bkpinfo->backup_media_type == cdstream) ? 2 : 4;
    2237     bkpinfo->compression_level =
    2238         (bkpinfo->backup_media_type == cdstream) ? 1 : 5;
    2239     bkpinfo->use_lzo =
    2240         (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE;
     2173    bkpinfo->compression_level = (bkpinfo->backup_media_type == cdstream) ? 1 : 5;
     2174    bkpinfo->use_lzo = (bkpinfo->backup_media_type == cdstream) ? TRUE : FALSE;
    22412175    mvaddstr_and_log_it(2, 0, " ");
    22422176
     
    22532187        if (archiving_to_media) {
    22542188            if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) {
    2255                 if (ask_me_yes_or_no
    2256                     ("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?"))
    2257                 {
     2189                if (ask_me_yes_or_no("Is your computer a laptop, or does the CD writer incorporate BurnProof technology?")) {
    22582190                    bkpinfo->manual_cd_tray = TRUE;
    22592191                }
     
    22632195                finish(1);
    22642196            }
    2265             if ((bkpinfo->compression_level =
    2266                 which_compression_level()) == -1) {
     2197
     2198            if ((bkpinfo->compression_level = which_compression_level()) == -1) {
    22672199                log_to_screen("User has chosen not to backup the PC");
    22682200                finish(1);
    22692201            }
    22702202            mds = media_descriptor_string(bkpinfo->backup_media_type);
    2271             sprintf(comment, "What speed is your %s (re)writer?", mds);
     2203            mr_asprintf(comment, "What speed is your %s (re)writer?", mds);
    22722204            if (bkpinfo->backup_media_type == dvd) {
    22732205                find_dvd_device(bkpinfo->media_device, FALSE);
    22742206                strcpy(tmp1, "1");
    2275                 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE);  // 4.7 salesman's GB = 4.482 real GB = 4482 MB
     2207                mr_asprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE);  // 4.7 salesman's GB = 4.482 real GB = 4482 MB
    22762208                log_msg(1, "Setting to DVD defaults");
    22772209            } else {
    22782210                strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM);
    22792211                strcpy(tmp1, "4");
    2280                 strcpy(sz_size, "650");
     2212                mr_asprintf(sz_size, "%d", 650);
    22812213                log_msg(1, "Setting to CD defaults");
    22822214            }
     
    22842216                if (!popup_and_get_string("Speed", comment, tmp1, 4)) {
    22852217                    log_to_screen("User has chosen not to backup the PC");
     2218                    mr_free(comment);
    22862219                    finish(1);
    22872220                }
    22882221            }
     2222            mr_free(comment);
    22892223            bkpinfo->cdrw_speed = atoi(tmp1);   // if DVD then this shouldn't ever be used anyway :)
    22902224
    2291             sprintf(comment,
    2292                     "How much data (in Megabytes) will each %s store?", mds);
     2225            strcpy(tmp1, sz_size);
     2226            mr_asprintf(comment, "How much data (in Megabytes) will each %s store?", mds);
    22932227            mr_free(mds);
    2294             if (!popup_and_get_string("Size", comment, sz_size, 5)) {
     2228            if (!popup_and_get_string("Size", comment, tmp1, 5)) {
    22952229                log_to_screen("User has chosen not to backup the PC");
    22962230                finish(1);
    22972231            }
     2232            mr_asprintf(sz_size, "%s", tmp1);
    22982233            bkpinfo->media_size = atoi(sz_size);
     2234
    22992235            if (bkpinfo->media_size <= 0) {
    23002236                log_to_screen("User has chosen not to backup the PC");
     
    23082244        if ((bkpinfo->disaster_recovery) && (bkpinfo->backup_media_type != usb)) {
    23092245            strcpy(bkpinfo->media_device, "/dev/cdrom");
    2310             log_msg(2, "CD-ROM device assumed to be at %s",
    2311                     bkpinfo->media_device);
    2312         } else if ((bkpinfo->restore_data && (bkpinfo->backup_media_type != usb))
    2313                    || bkpinfo->backup_media_type == dvd) {
     2246            log_msg(2, "CD-ROM device assumed to be at %s", bkpinfo->media_device);
     2247        } else if ((bkpinfo->restore_data && (bkpinfo->backup_media_type != usb))  || bkpinfo->backup_media_type == dvd) {
    23142248            if (!bkpinfo->media_device[0]) {
    23152249                strcpy(bkpinfo->media_device, "/dev/cdrom");
    23162250            }                   // just for the heck of it :)
    2317             log_msg(1, "bkpinfo->media_device = %s",
    2318                     bkpinfo->media_device);
    2319             if (bkpinfo->backup_media_type == dvd
    2320                 || find_cdrom_device(bkpinfo->media_device, FALSE)) {
    2321                 log_msg(1, "bkpinfo->media_device = %s",
    2322                         bkpinfo->media_device);
    2323                 sprintf(comment,
    2324                         "Please specify your %s drive's /dev entry", mds);
    2325                 if (!popup_and_get_string
    2326                     ("Device?", comment, bkpinfo->media_device,
    2327                      MAX_STR_LEN / 4)) {
     2251            log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device);
     2252            if (bkpinfo->backup_media_type == dvd || find_cdrom_device(bkpinfo->media_device, FALSE)) {
     2253                log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device);
     2254                mr_asprintf(comment, "Please specify your %s drive's /dev entry", mds);
     2255                if (!popup_and_get_string("Device?", comment, bkpinfo->media_device, MAX_STR_LEN / 4)) {
    23282256                    log_to_screen("User has chosen not to backup the PC");
    23292257                    finish(1);
     
    23992327            } else {
    24002328                if (does_file_exist("/tmp/mondo-restore.cfg")) {
    2401                     read_cfg_var("/tmp/mondo-restore.cfg", "media-dev",
    2402                                  bkpinfo->media_device);
     2329                    read_cfg_var("/tmp/mondo-restore.cfg", "media-dev", bkpinfo->media_device);
    24032330                }
    24042331            }
     
    24552382                finish(1);
    24562383            }
    2457             if ((bkpinfo->compression_level =
    2458                  which_compression_level()) == -1) {
     2384            if ((bkpinfo->compression_level = which_compression_level()) == -1) {
    24592385                log_to_screen("User has chosen not to backup the PC");
    24602386                finish(1);
     
    24682394        /* Never try to eject a NETFS device */
    24692395        bkpinfo->please_dont_eject = TRUE;
     2396        /*  Force NFS to be the protocol by default */
     2397        if (bkpinfo->netfs_proto == NULL) {
     2398            mr_asprintf(bkpinfo->netfs_proto, "nfs");
     2399        }
    24702400
    24712401        /* Initiate bkpinfo netfs_mount path from running environment if not already done */
    2472         if (!bkpinfo->netfs_mount[0]) {
    2473             strcpy(bkpinfo->netfs_mount,
    2474                    call_program_and_get_last_line_of_output
    2475                    ("mount | grep \":\" | cut -d' ' -f1 | head -n1"));
     2402        if (!bkpinfo->netfs_mount == NULL) {
     2403            mr_asprintf(bkpinfo->netfs_mount, call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1"));
    24762404        }
    24772405#ifdef __FreeBSD__
     
    24842412                ("Network shared dir.",
    24852413                 "Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)",
    2486                  bkpinfo->netfs_mount, MAX_STR_LEN / 4)) {
     2414                 p, MAX_STR_LEN / 4)) {
    24872415                log_to_screen("User has chosen not to backup the PC");
    24882416                finish(1);
    24892417            }
     2418            mr_free(bkpinfo->netfs_mount);
     2419            mr_asprintf(bkpinfo->netfs_mount, "%s", p;
    24902420            if (!bkpinfo->restore_data) {
    24912421                if ((compression_type = which_compression_type()) == NULL) {
     
    24932423                    finish(1);
    24942424                }
    2495                 if ((bkpinfo->compression_level =
    2496                     which_compression_level()) == -1) {
     2425
     2426                if ((bkpinfo->compression_level = which_compression_level()) == -1) {
    24972427                    log_to_screen("User has chosen not to backup the PC");
    24982428                    finish(1);
     
    25012431            // check whether already mounted - we better remove
    25022432            // surrounding spaces and trailing '/' for this
    2503             strip_spaces(bkpinfo->netfs_mount);
     2433            mr_strip_spaces(bkpinfo->netfs_mount);
    25042434            if (bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] == '/')
    25052435                bkpinfo->netfs_mount[strlen(bkpinfo->netfs_mount) - 1] = '\0';
     
    25132443                strcpy(tmp1,bkpinfo->netfs_mount);
    25142444            }
    2515             sprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", tmp1);
     2445            mr_asprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", tmp1);
    25162446            strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(command));
     2447            mr_free(command);
    25172448
    25182449            if (!bkpinfo->restore_data) {
    2519                 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE);  // 4.7 salesman's GB = 4.482 real GB = 4482 MB
    2520                 sprintf(comment,
    2521                     "How much data (in Megabytes) will each media store?");
    2522                 if (!popup_and_get_string("Size", comment, sz_size, 5)) {
     2450                mr_sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE);   // 4.7 salesman's GB = 4.482 real GB = 4482 MB
     2451                mr_asprintf(comment, "How much data (in Megabytes) will each media store?");
     2452                strcpy(tmp1, sz_size);
     2453                mr_free(sz_size);
     2454                if (!popup_and_get_string("Size", comment, tmp1, 5)) {
    25232455                    log_to_screen("User has chosen not to backup the PC");
    25242456                    finish(1);
    25252457                }
     2458                mr_free(comment);
     2459                mr_asprintf(sz_size, "%s", tmp1);
    25262460            } else {
    2527                 strcpy(sz_size, "0");
     2461                mr_asprintf(sz_size, "0");
    25282462            }
    25292463            bkpinfo->media_size = atoi(sz_size);
     2464            mr_free(sz_size);
     2465
    25302466            if (bkpinfo->media_size < 0) {
    25312467                log_to_screen("User has chosen not to backup the PC");
     
    25332469            }
    25342470        }
    2535         /*  Force NFS to be the protocol by default */
    2536         if (bkpinfo->netfs_proto == NULL) {
    2537             mr_asprintf(bkpinfo->netfs_proto, "nfs");
    2538         }
    25392471        if (bkpinfo->disaster_recovery) {
    2540             sprintf(command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir);
     2472            mr_asprintf(command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir);
    25412473            paranoid_system(command);
     2474            mr_free(command);
     2475
    25422476        }
    25432477        strcpy(tmp1, bkpinfo->netfs_proto);
    2544         if (!popup_and_get_string
    2545             ("Network protocol", "Which protocol should I use (nfs/sshfs/smbfs) ?",
    2546              tmp1, MAX_STR_LEN)) {
     2478        if (!popup_and_get_string("Network protocol", "Which protocol should I use (nfs/sshfs/smbfs) ?",tmp1, MAX_STR_LEN)) {
    25472479            log_to_screen("User has chosen not to backup the PC");
    25482480            finish(1);
     
    25502482        mr_free(bkpinfo->netfs_proto);
    25512483        mr_asprintf(bkpinfo->netfs_proto, "%s", tmp1);
    2552         if (!popup_and_get_string
    2553             ("Network share", "Which remote share should I mount?",
    2554              bkpinfo->netfs_mount, MAX_STR_LEN)) {
     2484
     2485        strcpy(tmp1, bkpinfo->netfs_mount);
     2486        if (!popup_and_get_string("Network share", "Which remote share should I mount?", tmp1, MAX_STR_LEN)) {
    25552487            log_to_screen("User has chosen not to backup the PC");
    25562488            finish(1);
    25572489        }
     2490        mr_free(bkpinfo->netfs_mount);
     2491        mr_asprintf(bkpinfo->netfs_mount, "%s", tmp1);
    25582492
    25592493        if (bkpinfo->netfs_user) {
     
    25622496            strcpy(tmp1, "");
    25632497        }
    2564         if (!popup_and_get_string
    2565             ("Network user", "Which user should I use if any ?",
    2566              tmp1, MAX_STR_LEN)) {
     2498        if (!popup_and_get_string("Network user", "Which user should I use if any ?",tmp1)) {
    25672499            log_to_screen("User has chosen not to backup the PC");
    25682500            finish(1);
     
    25752507        /* Initiate bkpinfo isodir path from running environment if mount already done */
    25762508        if (is_this_device_mounted(bkpinfo->netfs_mount)) {
    2577             strcpy(bkpinfo->isodir,
    2578                    call_program_and_get_last_line_of_output
    2579                    ("mount | grep \":\" | cut -d' ' -f3 | head -n1"));
     2509            strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f3 | head -n1"));
    25802510        } else {
    25812511            sprintf(bkpinfo->isodir, "%s/netfsdir", bkpinfo->tmpdir);
    2582             sprintf(command, "mkdir -p %s", bkpinfo->isodir);
     2512            mr_asprintf(command, "mkdir -p %s", bkpinfo->isodir);
    25832513            run_program_and_log_output(command, 5);
     2514            mr_free(command);
    25842515
    25852516            if (bkpinfo->restore_data) {
     
    26152546        }
    26162547        if (!is_this_device_mounted(bkpinfo->netfs_mount)) {
    2617             popup_and_OK
    2618                 ("Please mount that partition before you try to backup to or restore from it.");
     2548            popup_and_OK("Please mount that partition before you try to backup to or restore from it.");
    26192549            finish(1);
    26202550        }
     
    26402570        log_msg(3, "prefix set to %s", bkpinfo->prefix);
    26412571
    2642         log_msg(3, "Just set netfs_remote_dir to %s",
    2643                 bkpinfo->netfs_remote_dir);
     2572        log_msg(3, "Just set netfs_remote_dir to %s", bkpinfo->netfs_remote_dir);
    26442573        log_msg(3, "isodir is still %s", bkpinfo->isodir);
    26452574        break;
     
    26592588                    finish(1);
    26602589                }
    2661                 if ((bkpinfo->compression_level =
    2662                      which_compression_level()) == -1) {
     2590                if ((bkpinfo->compression_level = which_compression_level()) == -1) {
    26632591                    log_to_screen("User has chosen not to backup the PC");
    26642592                    finish(1);
    26652593                }
    2666                 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE);  // 4.7 salesman's GB = 4.482 real GB = 4482 MB
     2594                sprintf(tmp1, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB
    26672595                if (!popup_and_get_string
    26682596                    ("ISO size.",
    26692597                     "Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s (700) or DVD's (4480) you plan to backup to.",
    2670                      sz_size, 16)) {
     2598                     tmp1, 16)) {
    26712599                    log_to_screen("User has chosen not to backup the PC");
    26722600                    finish(1);
    26732601                }
    2674                 bkpinfo->media_size = atoi(sz_size);
     2602                bkpinfo->media_size = atoi(tmp1);
    26752603            } else {
    26762604                bkpinfo->media_size = 650;
     
    27232651                finish(1);
    27242652            }
    2725             if (does_string_exist_in_boot_block
    2726                 (bkpinfo->boot_device, "LILO")) {
     2653            if (does_string_exist_in_boot_block(bkpinfo->boot_device, "LILO")) {
    27272654                i = 'L';
    27282655            } else
    2729                 if (does_string_exist_in_boot_block
    2730                     (bkpinfo->boot_device, "ELILO")) {
     2656                if (does_string_exist_in_boot_block(bkpinfo->boot_device, "ELILO")) {
    27312657                i = 'E';
    27322658            } else
    2733                 if (does_string_exist_in_boot_block
    2734                     (bkpinfo->boot_device, "GRUB")) {
     2659                if (does_string_exist_in_boot_block(bkpinfo->boot_device, "GRUB")) {
    27352660                i = 'G';
    27362661            } else {
     
    27392664#endif
    27402665            if (i == 'U') {
    2741                 if (ask_me_yes_or_no
    2742                     ("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?"))
    2743                 {
     2666                if (ask_me_yes_or_no("Unidentified boot loader. Shall I restore it byte-for-byte at restore time and hope for the best?")) {
    27442667                    i = 'R';    // raw
    27452668                } else {
    2746                     log_to_screen
    2747                         ("I cannot find your boot loader. Please run mondoarchive with parameters.");
     2669                    log_to_screen("I cannot find your boot loader. Please run mondoarchive with parameters.");
    27482670                    finish(1);
    27492671                }
     
    27512673        }
    27522674        bkpinfo->boot_loader = i;
    2753         strcpy(bkpinfo->include_paths, "/");
     2675
     2676        mr_free(bkpinfo->include_paths);
     2677        strcpy(tmp1, "/");
    27542678        if (!popup_and_get_string
    27552679            ("Backup paths",
    27562680             "Please enter paths (separated by '|') which you want me to backup. The default is '/' (i.e. everything).",
    2757              bkpinfo->include_paths, MAX_STR_LEN)) {
     2681             tmp1, MAX_STR_LEN)) {
    27582682            log_to_screen("User has chosen not to backup the PC");
    27592683            finish(1);
    27602684        }
     2685        mr_asprintf(bkpinfo->include_paths, "%s", tmp1);
     2686
    27612687        tmp = list_of_NETFS_mounts_only();
    27622688        if (strlen(tmp) > 2) {
     
    28152741        if (ask_me_yes_or_no("Do you want to backup extended attributes?")) {
    28162742            if (find_home_of_exe("getfattr")) {
     2743                mr_free(g_getfattr);
    28172744                mr_asprintf(g_getfattr,"getfattr");
    28182745            }
    28192746            if (find_home_of_exe("getfacl")) {
     2747                mr_free(g_getfacl);
    28202748                mr_asprintf(g_getfacl,"getfacl");
    28212749            }
     
    28352763            strcpy(bkpinfo->zip_exe, "gzip");
    28362764            strcpy(bkpinfo->zip_suffix, "gz");
    2837         //} else if (strcmp(compression_type,"lzma") == 0) {
     2765        } else if (strcmp(compression_type,"lzma") == 0) {
    28382766            //strcpy(bkpinfo->zip_exe, "xy");
    28392767            //strcpy(bkpinfo->zip_suffix, "xy");
     
    28492777            ("Will you want to verify your backups after Mondo has created them?");
    28502778
    2851 #ifndef __FreeBSD__
    2852         if (!ask_me_yes_or_no
    2853             ("Are you confident that your kernel is a sane, sensible, standard Linux kernel? Say 'no' if you are using a Gentoo <1.4 or Debian <3.0, please."))
    2854 #endif
    2855         {
    2856             strcpy(bkpinfo->kernel_path, "FAILSAFE");
    2857         }
    2858 
    28592779        if (!ask_me_yes_or_no
    28602780            ("Are you sure you want to proceed? Hit 'no' to abort.")) {
     
    28752795#else
    28762796    if (bkpinfo->backup_media_type == netfs) {
    2877         log_msg(3, "I think the Remote mount is mounted at %s",
    2878                 bkpinfo->isodir);
     2797        log_msg(3, "I think the Remote mount is mounted at %s", bkpinfo->isodir);
    28792798    }
    28802799    log_it("isodir = %s", bkpinfo->isodir);
    2881     log_it("netfs_mount = '%s'", bkpinfo->netfs_mount);
     2800    if (bkpinfo->netfs_mount) {
     2801        log_it("netfs_mount = '%s'", bkpinfo->netfs_mount);
     2802    }
     2803    if (bkpinfo->netfs_user) {
     2804        log_it("netfs_user = '%s'", bkpinfo->netfs_user);
     2805    }
    28822806    if (bkpinfo->netfs_proto) {
    28832807        log_it("netfs_proto = '%s'", bkpinfo->netfs_proto);
    2884     }
    2885     if (bkpinfo->netfs_user) {
    2886         log_it("netfs_user = '%s'", bkpinfo->netfs_user);
    28872808    }
    28882809#endif
     
    28912812    log_it("media size = %ld", bkpinfo->media_size);
    28922813    log_it("media type = %s", bkptype_to_string(bkpinfo->backup_media_type));
    2893     log_it("prefix = %s", bkpinfo->prefix);
     2814    if (bkpinfo->prefix) {
     2815        log_it("prefix = %s", bkpinfo->prefix);
     2816    }
    28942817    log_it("compression = %ld", bkpinfo->compression_level);
    28952818    log_it("exclude_path = %s", bkpinfo->exclude_paths);
     
    28972820
    28982821    /* Handle devices passed in bkpinfo and print result */
    2899     /*  the mr_make_devlist_from_pathlist function appends 
    2900      *  to the *_paths variables so copy before */
     2822    /*  the mr_make_devlist_from_pathlist function appends
     2823    /*  to the *_paths variables so copy before */
    29012824    mr_make_devlist_from_pathlist(bkpinfo->exclude_paths, 'E');
    29022825    mr_make_devlist_from_pathlist(bkpinfo->include_paths, 'I');
     
    29042827    log_it("scratchdir = '%s'", bkpinfo->scratchdir);
    29052828    log_it("tmpdir = '%s'", bkpinfo->tmpdir);
    2906     log_it("image_devs = '%s'", bkpinfo->image_devs);
    2907     log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device,
    2908            bkpinfo->boot_loader);
     2829    if (bkpinfo->image_devs) {
     2830        log_it("image_devs = '%s'", bkpinfo->image_devs);
     2831    }
     2832    log_it("boot_device = '%s' (loader=%c)", bkpinfo->boot_device, bkpinfo->boot_loader);
    29092833    if (bkpinfo->media_size < 0) {
    29102834        if (archiving_to_media) {
     
    29172841    paranoid_free(sz_size);
    29182842    paranoid_free(tmp1);
    2919     paranoid_free(command);
    2920     paranoid_free(comment);
    2921     paranoid_free(prompt);
    29222843    return (0);
    29232844}
     
    31703091
    31713092    malloc_string(current_drive);
     3093
     3094    /* UEFI is not supported here - but should be managed as a BIOS/UEFI option not a Boot Loader one per se */
    31723095
    31733096#ifdef __IA64__
Note: See TracChangeset for help on using the changeset viewer.