Ignore:
Timestamp:
Jul 17, 2006, 3:44:46 PM (13 years ago)
Author:
bcornec
Message:

Huge memory management patch.
Still not finished but a lot as been done.
What remains is around some functions returning strings, and some structure members.
(Could not finish due to laptop failure !)

File:
1 edited

Legend:

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

    r687 r688  
    1 /* $Id$
     1/*
     2 * $Id$
    23 * Subroutines for handling devices
    34 */
     
    1920#include <sys/ioctl.h>
    2021#include <sys/types.h>
     22#include <unistd.h>
    2123#ifdef __FreeBSD__
    2224#define DKTYPENAMES
     
    6062{
    6163    if (bkpinfo->media_device != NULL) {
    62         paranoid_free(g_cdrom_drive_is_here);
    63         asprintf(&g_cdrom_drive_is_here, bkpinfo->media_device);    // just in case
     64        paranoid_alloc(g_cdrom_drive_is_here, bkpinfo->media_device);   // just in case
    6465    }
    6566    if (bkpinfo->media_device != NULL) {
    66         paranoid_free(g_dvd_drive_is_here);
    67         asprintf(&g_dvd_drive_is_here, bkpinfo->media_device);  // just in case
     67        paranoid_alloc(g_dvd_drive_is_here, bkpinfo->media_device); // just in case
    6868    }
    6969}
     
    320320    char *incoming = NULL;
    321321    char *searchstr;
     322    char *tmp;
    322323
    323324    /*@ ints ******************************************************* */
     
    332333    assert_string_is_neither_NULL_nor_zerolength(drive);
    333334    assert(partno >= 0 && partno < 999);
    334 
    335     malloc_string(searchstr);
    336335
    337336#ifdef __FreeBSD__
     
    353352    paranoid_free(program);
    354353
    355     (void) build_partition_name(searchstr, drive, partno);
    356     strcat(searchstr, " ");
     354    searchstr = build_partition_name(drive, partno);
     355    asprintf(&tmp, "%s ", searchstr);
     356    paranoid_free(searchstr);
     357
    357358    for (res = 0; !res && getline(&incoming, &n, fin);) {
    358         if (strstr(incoming, searchstr)) {
     359        if (strstr(incoming, tmp)) {
    359360            res = 1;
    360361        }
     
    365366        log_OS_error("Cannot pclose fin");
    366367    }
    367     paranoid_free(searchstr);
     368    paranoid_free(tmp);
    368369    return (res);
    369370}
     
    459460            asprintf(&dev, g_cdrom_drive_is_here);
    460461        } else {
     462            // find_cdrom_device allocates the string
    461463            dev = find_cdrom_device(FALSE);
    462464        }
     
    468470
    469471    if ((dev == NULL) || (! mount_CDROM_here(dev, mountpoint))) {
     472        paranoid_free(dev);
    470473        if (!popup_and_get_string
    471             (_("CD-ROM device"), _("Please enter your CD-ROM's /dev device"),
    472              dev, MAX_STR_LEN / 4)) {
     474            (_("CD-ROM device"), _("Please enter your CD-ROM's /dev device"), dev)) {
    473475            res = FALSE;
    474476        } else {
     
    556558{
    557559    /*@ pointers **************************************************** */
    558     FILE *fin;
    559     char *p;
    560     char *q;
    561     char *r;
     560    FILE *fin = NULL;
     561    char *p = NULL;
     562    char *q = NULL;
     563    char *r = NULL;
    562564    char *output = NULL;
    563565    size_t n = 0;
     
    568570    /*@ buffers ***************************************************** */
    569571    char *tmp = NULL;
    570     char *cdr_exe;
     572    char *cdr_exe = NULL;
    571573#ifndef __FreeBSD__
    572574    char *phrase_two = NULL;
    573575    char *dvd_last_resort = NULL;
    574576#endif
    575     char *command;
    576     char *mountpoint;
    577     static char the_last_place_i_found_it[MAX_STR_LEN] = "";
     577    char *command = NULL;
     578    char *mountpoint = NULL;
     579    static char *the_last_place_i_found_it = NULL;
    578580
    579581    /*@ end vars **************************************************** */
     
    584586        return(output);
    585587    }
    586     if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) {
     588    if ((the_last_place_i_found_it != NULL) && !try_to_mount) {
    587589        asprintf(&output, the_last_place_i_found_it);
    588590        log_msg(3,
     
    834836        }
    835837        log_msg(3, "(find_cdrom_device) --> '%s'", output);
    836         strcpy(the_last_place_i_found_it, output);
     838        asprintf(&the_last_place_i_found_it, output);
    837839        paranoid_free(g_cdrom_drive_is_here);
    838840        asprintf(&g_cdrom_drive_is_here, output);
     
    863865char *find_dvd_device()
    864866{
    865     char *tmp;
     867    char *tmp = NULL;
    866868    int retval = 0, devno = -1;
    867869    char *output = NULL;
     
    10081010bool is_this_a_valid_disk_format(char *format)
    10091011{
    1010     char *good_formats;
    1011     char *command;
    1012     char *format_sz;
    1013 
    1014     FILE *pin;
     1012    char *good_formats = NULL;
     1013    char *command = NULL;
     1014    char *tmp = NULL;
     1015    char *format_sz = NULL;
     1016
     1017    FILE *pin = NULL;
    10151018    bool retval;
    1016     malloc_string(good_formats);
     1019    size_t n = 0;
    10171020    assert_string_is_neither_NULL_nor_zerolength(format);
    10181021
     
    10341037        retval = FALSE;
    10351038    } else {
    1036         strcpy(good_formats, " ");
    1037         (void) fgets(good_formats + 1, MAX_STR_LEN, pin);
     1039        getline(&good_formats, &n , pin);
    10381040        if (pclose(pin)) {
    10391041            log_OS_error("Cannot pclose good formats");
    10401042        }
    10411043        strip_spaces(good_formats);
    1042         strcat(good_formats, " swap lvm raid ntfs 7 "); // " ntfs 7 " -- um, cheating much? :)
     1044        // " ntfs 7 " -- um, cheating much? :)
     1045        asprintf(&tmp, " %s swap lvm raid ntfs 7 ",good_formats);
     1046        paranoid_free(good_formats);
     1047        good_formats = tmp;
     1048
    10431049        if (strstr(good_formats, format_sz)) {
    10441050            retval = TRUE;
     
    10461052            retval = FALSE;
    10471053        }
    1048     }
    1049     paranoid_free(good_formats);
     1054        paranoid_free(good_formats);
     1055    }
    10501056    paranoid_free(format_sz);
    10511057    return (retval);
     
    11411147char *make_vn(char *fname)
    11421148{
    1143     char *device;
     1149    char *device = NULL;
    11441150    char *mddevice = NULL;
    11451151    char *command = NULL;
     
    12241230{
    12251231    /*@ buffer ****************************************************** */
    1226     char *command;
    1227     int retval;
     1232    char *command = NULL;
     1233    int retval = 0;
    12281234
    12291235    assert_string_is_neither_NULL_nor_zerolength(device);
     
    12381244
    12391245#ifdef __FreeBSD__
    1240         char *dev;
     1246        char *dev = NULL;
    12411247
    12421248        dev = make_vn(device));
     
    13611367
    13621368        while (what_number_cd_is_this(bkpinfo) != cd_number_i_want) {
    1363             paranoid_system("sync");
     1369            sync();
    13641370            if (is_this_device_mounted(MNT_CDROM)) {
    13651371                res =
     
    13831389                inject_device(bkpinfo->media_device);
    13841390            }
    1385             paranoid_system("sync");
     1391            sync();
    13861392        }
    13871393        paranoid_free(request);
     
    14101416// archiving_to_media is FALSE if I'm being called by mondorestore
    14111417{
    1412     char *tmp;
     1418    char *tmp = NULL;
     1419    char *tmp1 = NULL;
     1420    char *tmp2 = NULL;
    14131421    char *sz_size = NULL;
    1414     char *command;
    1415     char *comment;
     1422    char *command = NULL;
     1423    char *comment = NULL;
    14161424    char *prompt = NULL;
    1417     int i;
    1418     FILE *fin;
     1425    int i = 0;
     1426    FILE *fin = NULL;
    14191427
    14201428    assert(bkpinfo != NULL);
     
    14801488                    media_descriptor_string(bkpinfo->backup_media_type));
    14811489            if (bkpinfo->backup_media_type == dvd) {
    1482                 paranoid_free(bkpinfo->media_device);
    14831490                bkpinfo->media_device = find_dvd_device();
    14841491                asprintf(&tmp, "1");
     
    14921499            }
    14931500            if (bkpinfo->backup_media_type != dvd) {
    1494                 if (!popup_and_get_string(_("Speed"), comment, tmp, 4)) {
     1501                if (!popup_and_get_string(_("Speed"), comment, tmp)) {
    14951502                    log_to_screen(_("User has chosen not to backup the PC"));
    14961503                    finish(1);
     
    15061513                    media_descriptor_string(bkpinfo->backup_media_type));
    15071514
    1508             if (!popup_and_get_string("Size", comment, sz_size, 5)) {
     1515            if (!popup_and_get_string("Size", comment, sz_size)) {
    15091516                log_to_screen(_("User has chosen not to backup the PC"));
    15101517                finish(1);
     
    15151522                bkpinfo->media_size[i] = atoi(sz_size);
    15161523            }
     1524            paranoid_free(sz_size);
     1525
    15171526            if (bkpinfo->media_size[0] <= 0) {
    15181527                log_to_screen(_("User has chosen not to backup the PC"));
    15191528                finish(1);
    15201529            }
    1521             paranoid_free(sz_size);
    15221530        }
    15231531    case cdstream:
     
    15291537                   || bkpinfo->backup_media_type == dvd) {
    15301538            if (bkpinfo->media_device == NULL) {
    1531                 paranoid_alloc(bkpinfo->media_device, "/dev/cdrom");
     1539                asprintf(&bkpinfo->media_device, "/dev/cdrom");
    15321540            }                   // just for the heck of it :)
    15331541            log_msg(1, "bkpinfo->media_device = %s",
     
    15441552                                                backup_media_type));
    15451553                if (!popup_and_get_string
    1546                     (_("Device?"), comment, bkpinfo->media_device,
    1547                      MAX_STR_LEN / 4)) {
     1554                    (_("Device?"), comment, bkpinfo->media_device)) {
    15481555                    log_to_screen(_("User has chosen not to backup the PC"));
    15491556                    finish(1);
     
    15551562                    bkpinfo->media_device);
    15561563        } else {
    1557             paranoid_free(bkpinfo->media_device);
    15581564            bkpinfo->media_device = find_cdrw_device();
    15591565            if (bkpinfo->media_device != NULL) {
     
    15711577                    i = popup_and_get_string(_("Device node?"),
    15721578                                             _("What is the SCSI node of your CD (re)writer, please?"),
    1573                                              bkpinfo->media_device,
    1574                                              MAX_STR_LEN / 4);
     1579                                             bkpinfo->media_device);
    15751580                } else {
    15761581                    i = popup_and_get_string(_("/dev entry?"),
    15771582                                             _("What is the /dev entry of your CD (re)writer, please?"),
    1578                                              bkpinfo->media_device,
    1579                                              MAX_STR_LEN / 4);
     1583                                             bkpinfo->media_device);
    15801584                }
    15811585                if (!i) {
     
    16021606        if (find_tape_device_and_size(bkpinfo->media_device, sz_size)) {
    16031607            log_msg(3, _("Ok, using vanilla scsi tape."));
    1604             paranoid_alloc(bkpinfo->media_device,VANILLA_SCSI_TAPE );
     1608            paranoid_alloc(bkpinfo->media_device,VANILLA_SCSI_TAPE"0" );
    16051609            if ((fin = fopen(bkpinfo->media_device, "r"))) {
    16061610                paranoid_fclose(fin);
     
    16301634                (_("Device name?"),
    16311635                 _("What is the /dev entry of your tape streamer?"),
    1632                  bkpinfo->media_device, MAX_STR_LEN / 4)) {
     1636                 bkpinfo->media_device)) {
    16331637                log_to_screen(_("User has chosen not to backup the PC"));
    16341638                finish(1);
     
    16421646        paranoid_free(tmp);
    16431647        log_msg(4, "sz_size = %s", sz_size);
    1644         sz_size[0] = '\0';
     1648        paranoid_free(sz_size);
    16451649        bkpinfo->media_size[0] = 0;
    16461650        log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]);
     
    16771681                (_("NFS dir."),
    16781682                 _("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.)"),
    1679                  bkpinfo->nfs_mount, MAX_STR_LEN / 4)) {
     1683                 bkpinfo->nfs_mount)) {
    16801684                log_to_screen(_("User has chosen not to backup the PC"));
    16811685                finish(1);
     
    17011705            asprintf(&comment,
    17021706                    _("How much data (in Megabytes) will each media store?"));
    1703             if (!popup_and_get_string(_("Size"), comment, sz_size, 5)) {
     1707            if (!popup_and_get_string(_("Size"), comment, sz_size)) {
    17041708                log_to_screen(_("User has chosen not to backup the PC"));
    17051709                finish(1);
     
    17181722            if (!popup_and_get_string
    17191723                (_("NFS share"), _("Which remote NFS share should I mount?"),
    1720                  bkpinfo->nfs_mount, MAX_STR_LEN)) {
     1724                 bkpinfo->nfs_mount)) {
    17211725                log_to_screen(_("User has chosen not to backup the PC"));
    17221726                finish(1);
     
    17421746            finish(1);
    17431747        }
    1744         asprintf(&tmp, bkpinfo->nfs_remote_dir);
    17451748        if (!popup_and_get_string
    1746             (_("Directory"), _("Which directory within that mountpoint?"), tmp,
    1747              MAX_STR_LEN)) {
     1749            (_("Directory"), _("Which directory within that mountpoint?"),bkpinfo->nfs_remote_dir)) {
    17481750            log_to_screen(_("User has chosen not to backup the PC"));
    17491751            finish(1);
    17501752        }
    1751         strcpy(bkpinfo->nfs_remote_dir, tmp);
    1752         paranoid_free(tmp);
    1753 
    1754         // check whether writable - we better remove surrounding spaces for this
    1755         strip_spaces(bkpinfo->nfs_remote_dir);
    1756         asprintf(&command, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir,
     1753
     1754        asprintf(&command, "echo hi > '%s/%s/.dummy.txt'", bkpinfo->isodir,
    17571755                bkpinfo->nfs_remote_dir);
    17581756        while (run_program_and_log_output(command, FALSE)) {
    1759             paranoid_free(tmp);
    1760             paranoid_free(prompt);
    1761             asprintf(&tmp, bkpinfo->nfs_remote_dir);
    17621757            asprintf(&prompt,
    17631758                     _("Directory '%s' under mountpoint '%s' does not exist or is not writable. You can fix this or change the directory and retry or cancel the backup."),
    17641759                     bkpinfo->nfs_remote_dir, bkpinfo->isodir);
    17651760            if (!popup_and_get_string
    1766                 (_("Directory"), prompt, tmp, MAX_STR_LEN)) {
     1761                (_("Directory"), prompt, bkpinfo->nfs_remote_dir)) {
    17671762                log_to_screen(_("User has chosen not to backup the PC"));
    17681763                finish(1);
    17691764            }
    1770             strcpy(bkpinfo->nfs_remote_dir, tmp);
    1771             // check whether writable - we better remove surrounding spaces for this */
    1772             strip_spaces(bkpinfo->nfs_remote_dir);
     1765            paranoid_free(prompt);
     1766
     1767            paranoid_free(command);
    17731768            asprintf(&command, "echo hi > %s/%s/.dummy.txt",
    17741769                     bkpinfo->isodir, bkpinfo->nfs_remote_dir);
    17751770        }
    17761771        paranoid_free(command);
    1777         paranoid_free(tmp);
    1778         paranoid_free(prompt);
    17791772
    17801773        if (!popup_and_get_string
    17811774            (_("Prefix."),
    17821775             _("Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files"),
    1783             bkpinfo->prefix, MAX_STR_LEN / 4)) {
     1776            bkpinfo->prefix)) {
    17841777            log_to_screen(_("User has chosen not to backup the PC"));
    17851778            finish(1);
     
    18001793                (_("Storage dir."),
    18011794                 _("Please enter the full path that contains your ISO images.  Example: /mnt/raid0_0"),
    1802                  bkpinfo->isodir, MAX_STR_LEN / 4)) {
     1795                 bkpinfo->isodir)) {
    18031796                log_to_screen(_("User has chosen not to backup the PC"));
    18041797                finish(1);
     
    18121805                if (!popup_and_get_string
    18131806                    (_("ISO size."),
    1814                      _("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 or DVD's you plan to backup to."),
    1815                      sz_size, 16)) {
     1807                     _("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 or DVD's you plan to backup to."), sz_size)) {
    18161808                    log_to_screen(_("User has chosen not to backup the PC"));
    18171809                    finish(1);
     
    18251817                    (_("Prefix."),
    18261818                     _("Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files"),
    1827                      bkpinfo->prefix, MAX_STR_LEN / 4)) {
     1819                     bkpinfo->prefix)) {
    18281820                    log_to_screen("User has chosen not to backup the PC");
    18291821                    finish(1);
     
    18441836
    18451837#ifdef __FreeBSD__
    1846         strcpy(bkpinfo->boot_device,
    1847                call_program_and_get_last_line_of_output
     1838        bkpinfo->boot_device = call_program_and_get_last_line_of_output
    18481839               ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
    18491840#else
    1850         strcpy(bkpinfo->boot_device,
    1851                call_program_and_get_last_line_of_output
     1841        bkpinfo->boot_device = call_program_and_get_last_line_of_output
    18521842               ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
    18531843#endif
     
    18601850                (_("Boot device"),
    18611851                 _("What is your boot device? (e.g. /dev/ad0)"),
    1862                  bkpinfo->boot_device, MAX_STR_LEN / 4)) {
     1852                 bkpinfo->boot_device)) {
    18631853                log_to_screen(_("User has chosen not to backup the PC"));
    18641854                finish(1);
     
    18691859                (_("Boot device"),
    18701860                 _("What is your boot device? (e.g. /dev/hda)"),
    1871                  bkpinfo->boot_device, MAX_STR_LEN / 4)) {
     1861                 bkpinfo->boot_device)) {
    18721862                log_to_screen(_("User has chosen not to backup the PC"));
    18731863                finish(1);
     
    19011891        }
    19021892        bkpinfo->boot_loader = i;
    1903         strcpy(bkpinfo->include_paths, "/");
     1893        asprintf(&bkpinfo->include_paths, "/");
    19041894        if (!popup_and_get_string
    19051895            (_("Backup paths"),
    19061896             _("Please enter paths which you want me to backup. The default is '/' (i.e. everything)."),
    1907              bkpinfo->include_paths, MAX_STR_LEN)) {
     1897             bkpinfo->include_paths)) {
    19081898            log_to_screen(_("User has chosen not to backup the PC"));
    19091899            finish(1);
    19101900        }
     1901
    19111902        tmp = list_of_NFS_mounts_only();
    19121903        if (strlen(tmp) > 2) {
    1913             if (bkpinfo->exclude_paths[0]) {
    1914                 strcat(bkpinfo->exclude_paths, " ");
    1915             }
    1916             strncpy(bkpinfo->exclude_paths, tmp, MAX_STR_LEN);
     1904            if (bkpinfo->exclude_paths != NULL) {
     1905                tmp1 = bkpinfo->exclude_paths;
     1906                asprintf(&bkpinfo->exclude_paths, "%s %s", tmp1, tmp);
     1907                paranoid_free(tmp1);
     1908            } else {
     1909                bkpinfo->exclude_paths = tmp;
     1910            }
    19171911        }
    19181912        paranoid_free(tmp);
    19191913// NTFS
    1920         asprintf(&tmp,
    1921                call_program_and_get_last_line_of_output
    1922                ("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'"));
     1914        tmp = call_program_and_get_last_line_of_output
     1915               ("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'");
    19231916        if (strlen(tmp) > 2) {
    19241917            if (!popup_and_get_string
    19251918                (_("NTFS partitions"),
    19261919                 _("Please enter/confirm the NTFS partitions you wish to backup as well."),
    1927                  tmp, MAX_STR_LEN / 4)) {
     1920                 tmp1)) {
    19281921                log_to_screen(_("User has chosen not to backup the PC"));
    19291922                finish(1);
    19301923            }
    1931             strncpy(bkpinfo->image_devs, tmp, MAX_STR_LEN / 4);
     1924            if (bkpinfo->image_devs != NULL) {
     1925                tmp2 = bkpinfo->image_devs;
     1926                asprintf(&bkpinfo->image_devs, "%s %s", tmp2, tmp1);
     1927                paranoid_free(tmp2);
     1928            } else {
     1929                bkpinfo->image_devs = tmp1;
     1930            }
     1931            paranoid_free(tmp1);
    19321932        }
    19331933        paranoid_free(tmp);
     
    19361936            (_("Exclude paths"),
    19371937             _("Please enter paths which you do NOT want to backup. Separate them with spaces. NB: /tmp and /proc are always excluded. :-) Just hit 'Enter' if you want to do a full system backup."),
    1938              bkpinfo->exclude_paths, MAX_STR_LEN)) {
     1938             bkpinfo->exclude_paths)) {
    19391939            log_to_screen(_("User has chosen not to backup the PC"));
    19401940            finish(1);
     
    20052005 * Get a space-separated list of NFS mounts.
    20062006 * @return The list created.
    2007  * @note The return value points to static data that will be overwritten with each call.
     2007 * @note The return value should be freed by caller
    20082008 * @bug Even though we only want the mounts, the devices are still checked.
    20092009 */
    20102010char *list_of_NFS_mounts_only(void)
    20112011{
    2012     char *exclude_these_devices;
    2013     char *exclude_these_directories;
    2014     char *result_sz;
    2015 
    2016     asprintf(&exclude_these_directories,
    2017            call_program_and_get_last_line_of_output
     2012    return(call_program_and_get_last_line_of_output
    20182013           ("mount -t coda,ncpfs,nfs,smbfs,cifs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
     2014    /* BERLIOS : Useless
    20192015    asprintf(&exclude_these_devices,
    20202016           call_program_and_get_last_line_of_output
    20212017           ("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|nfs|smbfs|cifs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
    2022     asprintf(&result_sz, "%s", exclude_these_directories);
    2023     paranoid_free(exclude_these_devices);
    2024     paranoid_free(exclude_these_directories);
    2025     return (result_sz);
     2018           */
    20262019}
    20272020
     
    20602053void sensibly_set_tmpdir_and_scratchdir(struct s_bkpinfo *bkpinfo)
    20612054{
    2062     char *tmp, *command, *sz;
     2055    char *tmp = NULL;
     2056    char *command = NULL;
     2057    char *sz = NULL;
     2058    int i = 0;
    20632059
    20642060    assert(bkpinfo != NULL);
    20652061
    20662062#ifdef __FreeBSD__
    2067     asprintf(&tmp,
    2068            call_program_and_get_last_line_of_output
    2069            ("df -m -P -t nonfs,msdosfs,ntfs,smbfs,smb,cifs | tr -s '\t' ' ' | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
     2063    tmp = call_program_and_get_last_line_of_output
     2064           ("df -m -P -t nonfs,msdosfs,ntfs,smbfs,smb,cifs | tr -s '\t' ' ' | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'");
    20702065#else
    2071     asprintf(&tmp,
    2072            call_program_and_get_last_line_of_output
    2073            ("df -m -P -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs | sed 's/                  /devdev/' | tr -s '\t' ' ' | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
     2066    tmp = call_program_and_get_last_line_of_output
     2067           ("df -m -P -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs | sed 's/                  /devdev/' | tr -s '\t' ' ' | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'");
    20742068#endif
    20752069
     
    20822076        fatal_error("I couldn't figure out the tempdir!");
    20832077    }
    2084     sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%d", tmp,
    2085             (int) (random() % 32768));
     2078    i = (int) (random() % 32768);
     2079    asprintf(&bkpinfo->tmpdir, "%s/mondo.tmp.%d", tmp, i);
    20862080    log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir);
    20872081
    2088     sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp,
    2089             (int) (random() % 32768));
     2082    asprintf(&bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, i);
    20902083    log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);
    20912084
    2092     sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
     2085    asprintf(&g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
    20932086            bkpinfo->scratchdir);
    20942087
    2095     asprintf(&command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp);
     2088    asprintf(&command, "rm -Rf %s/mondo.tmp.* %s/mondo.scratch.*", tmp, tmp);
    20962089    paranoid_free(tmp);
    20972090
     
    21522145{
    21532146    int cd_number = -1;
    2154     char *mountdev;
    2155     char *tmp;
     2147    char *mountdev = NULL;
     2148    char *tmp = NULL;
     2149    char *tmp1 = NULL;
    21562150
    21572151    assert(bkpinfo != NULL);
     
    21592153        asprintf(&tmp, "mount | grep iso9660 | awk '{print $3;}'");
    21602154
    2161         asprintf(&mountdev, "%s/archives/THIS-CD-NUMBER", call_program_and_get_last_line_of_output(tmp));
     2155        tmp1 = call_program_and_get_last_line_of_output(tmp);
    21622156        paranoid_free(tmp);
    21632157
    2164         cd_number = atoi(last_line_of_file(mountdev));
     2158        asprintf(&mountdev, "%s/archives/THIS-CD-NUMBER", tmp1);
     2159        paranoid_free(tmp1);
     2160
     2161        tmp = last_line_of_file(mountdev);
     2162        cd_number = atoi(tmp);
    21652163        paranoid_free(mountdev);
     2164        paranoid_free(tmp);
    21662165
    21672166        return (cd_number);
     
    21762175        (void)mount_CDROM_here(bkpinfo->media_device, MNT_CDROM);
    21772176    }
    2178     cd_number =
    2179         atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"));
     2177    tmp = last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER");
     2178    cd_number = atoi(tmp);
     2179    paranoid_free(tmp);
    21802180    return (cd_number);
    21812181}
     
    21912191char *where_is_root_mounted()
    21922192{
    2193     /*@ buffers **************** */
    21942193    char *tmp;
    21952194
    2196 
    21972195#ifdef __FreeBSD__
    2198     asprintf(&tmp, call_program_and_get_last_line_of_output
    2199            ("mount | grep \" on / \" | cut -d' ' -f1"));
     2196    tmp = call_program_and_get_last_line_of_output
     2197           ("mount | grep \" on / \" | cut -d' ' -f1");
    22002198#else
    2201     asprintf(&tmp, call_program_and_get_last_line_of_output
    2202            ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//"));
     2199    tmp = call_program_and_get_last_line_of_output
     2200           ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//");
    22032201    if (strstr(tmp, "/dev/cciss/")) {
    22042202        paranoid_free(tmp);
    2205         asprintf(&tmp, call_program_and_get_last_line_of_output
    2206                ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1"));
     2203        tmp = call_program_and_get_last_line_of_output
     2204               ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1");
    22072205    }
    22082206    if (strstr(tmp, "/dev/md")) {
    22092207        paranoid_free(tmp);
    2210         asprintf(&tmp,
    2211                call_program_and_get_last_line_of_output
    2212                ("mount | grep \" on / \" | cut -d' ' -f1"));
     2208        tmp = call_program_and_get_last_line_of_output
     2209               ("mount | grep \" on / \" | cut -d' ' -f1");
    22132210    }
    22142211#endif
     
    23732370char *resolve_softlinks_to_get_to_actual_device_file(char *incoming)
    23742371{
    2375     char *output;
    2376     char *command;
    2377     char *curr_fname;
    2378     char *scratch;
    2379     char *tmp;
    2380     char *p;
     2372    char *output = NULL;
     2373    char *command = NULL;
     2374    char *curr_fname = NULL;
     2375    char *scratch = NULL;
     2376    char *tmp = NULL;
     2377    char *p = NULL;
    23812378
    23822379    struct stat statbuf;
     
    23912388            log_msg(1, "curr_fname = %s", curr_fname);
    23922389            asprintf(&command, "file %s", curr_fname);
    2393             asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     2390            tmp = call_program_and_get_last_line_of_output(command);
    23942391            paranoid_free(command);
    23952392
     
    24002397            for (p = scratch; *p != '\0' && *p != '\''; p++);
    24012398            *p = '\0';
    2402             log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp,
    2403                     scratch);
     2399            log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, scratch);
    24042400            paranoid_free(tmp);
    24052401
     
    24392435char *which_partition_format(const char *drive)
    24402436{
    2441     char *output;
    2442     char *tmp;
    2443     char *command;
    2444     char *fdisk;
     2437    char *output = NULL;
     2438    char *tmp = NULL;
     2439    char *command = NULL;
     2440    char *fdisk = NULL;
    24452441
    24462442    log_msg(0, "Looking for partition table format type");
     
    24502446    paranoid_free(fdisk);
    24512447
    2452     asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     2448    tmp = call_program_and_get_last_line_of_output(command);
    24532449    paranoid_free(command);
    24542450
Note: See TracChangeset for help on using the changeset viewer.