Ignore:
Timestamp:
Aug 18, 2009, 2:34:29 PM (15 years ago)
Author:
Bruno Cornec
Message:

r3327@localhost: bruno | 2009-08-04 00:17:46 +0200
popup_and_get_string and build_partition_name now return an allocated string

File:
1 edited

Legend:

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

    r2306 r2316  
    323323    char *incoming;
    324324    char *searchstr = NULL;
    325     char *tmp;
     325    char *tmp = NULL;
    326326
    327327    /*@ ints ******************************************************* */
     
    337337
    338338    malloc_string(incoming);
    339     malloc_string(searchstr);
    340     malloc_string(tmp);
    341339
    342340#ifdef __FreeBSD__
    343341    // We assume here that this is running from mondorestore. (It is.)
    344     mr_asprintf(&program, "ls %s %s >/dev/null 2>&1", drive, build_partition_name(tmp, drive, partno));
     342    tmp = build_partition_name(drive, partno);
     343    mr_asprintf(&program, "ls %s %s >/dev/null 2>&1", drive, tmp);
     344    mr_free(tmp);
     345
    345346    res = system(program);
    346347    mr_free(program);
    347348    return (res);
    348349#else
    349     tmp[0] = '\0';
     350    /* To avoid compiler warnings */
     351    tmp = NULL;
    350352#endif
    351353
     
    360362    mr_free(program);
    361363
    362     (void) build_partition_name(searchstr, drive, partno);
    363     strcat(searchstr, " ");
     364    searchstr = build_partition_name(drive, partno);
     365    mr_strcat(searchstr, " ");
    364366    for (res = 0; !res && fgets(incoming, MAX_STR_LEN - 1, fin);) {
    365367        if (strstr(incoming, searchstr)) {
     
    367369        }
    368370    }
     371    mr_free(searchstr);
     372
    369373    if (pclose(fin)) {
    370374        log_OS_error("Cannot pclose fin");
    371375    }
    372376    paranoid_free(incoming);
    373     paranoid_free(searchstr);
    374     paranoid_free(tmp);
    375377    return (res);
    376378}
     
    448450    int res;
    449451    char *dev;
     452    char *p = NULL;
    450453
    451454    /*@ end vars **************************************************** */
     
    472475
    473476    if (!dev[0] || (res = mount_CDROM_here(dev, mountpoint))) {
    474         if (!popup_and_get_string
    475             ("CD-ROM device", "Please enter your CD-ROM's /dev device",
    476              dev, MAX_STR_LEN / 4)) {
     477        p = popup_and_get_string ("CD-ROM device", "Please enter your CD-ROM's /dev device",dev);
     478        if (p == NULL) {
    477479            res = 1;
    478480        } else {
    479             res = mount_CDROM_here(dev, mountpoint);
    480         }
     481            res = mount_CDROM_here(p, mountpoint);
     482        }
     483        mr_free(p);
    481484    }
    482485    if (res) {
     
    10251028    FILE *pin;
    10261029    int retval;
    1027     malloc_string(good_formats);
    10281030
    10291031    assert_string_is_neither_NULL_nor_zerolength(format);
     
    10441046        retval = 0;
    10451047    } else {
    1046         strcpy(good_formats, " ");
    1047         (void) fgets(good_formats + 1, MAX_STR_LEN - 1, pin);
     1048        mr_getline(&good_formats, pin);
    10481049        if (pclose(pin)) {
    10491050            log_OS_error("Cannot pclose good formats");
    10501051        }
    1051         strip_spaces(good_formats);
    1052         strcat(good_formats, " swap lvm raid ntfs-3g ntfs 7 "); // " ntfs 7 " -- um, cheating much? :)
     1052        mr_strip_spaces(good_formats);
     1053        mr_strcat(good_formats, " swap lvm raid ntfs-3g ntfs 7 ");  // " ntfs 7 " -- um, cheating much? :)
    10531054        if (strstr(good_formats, format_sz)) {
    10541055            retval = 1;
     
    10561057            retval = 0;
    10571058        }
     1059        mr_free(good_formats);
    10581060    }
    10591061    mr_free(format_sz);
    10601062
    1061     paranoid_free(good_formats);
    10621063    return (retval);
    10631064}
     
    14451446{
    14461447    char *tmp = NULL;
    1447     char *tmp1 = NULL;
     1448    char *p = NULL;
    14481449    char *mds = NULL;
    14491450    char *sz_size = NULL;
     
    14551456
    14561457    malloc_string(prompt);
    1457     malloc_string(sz_size);
    14581458    malloc_string(tmp1);
    14591459    assert(bkpinfo != NULL);
     
    15141514                find_dvd_device(bkpinfo->media_device, FALSE);
    15151515                strcpy(tmp1, "1");
    1516                 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE);  // 4.7 salesman's GB = 4.482 real GB = 4482 MB
     1516                mr_asprintf(&sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB
    15171517                log_msg(1, "Setting to DVD defaults");
    15181518            } else {
    15191519                strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM);
    15201520                strcpy(tmp1, "4");
    1521                 sprintf(sz_size, "%d", 650);
     1521                mr_asprintf(&sz_size, "%d", 650);
    15221522                log_msg(1, "Setting to CD defaults");
    15231523            }
    15241524            if ((bkpinfo->backup_media_type != dvd) && (bkpinfo->backup_media_type != usb)) {
    1525                 if (!popup_and_get_string("Speed", comment, tmp1, 4)) {
     1525                p = popup_and_get_string("Speed", comment, tmp);
     1526                mr_free(tmp);
     1527
     1528                if (p == NULL) {
    15261529                    log_to_screen("User has chosen not to backup the PC");
    15271530                    mr_free(comment);
    15281531                    finish(1);
    15291532                }
     1533                /* tmp now has the new value given by the user */
     1534                tmp = p;
    15301535            }
    15311536            mr_free(comment);
     
    15351540            mr_asprintf(&comment, "How much data (in Megabytes) will each %s store?", mds);
    15361541            mr_free(mds);
    1537             if (!popup_and_get_string("Size", comment, sz_size, 5)) {
    1538                 mr_free(comment);
     1542            p = popup_and_get_string("Size", comment, sz_size);
     1543            mr_free(sz_size);
     1544            mr_free(comment);
     1545
     1546            if (p == NULL) {
    15391547                log_to_screen("User has chosen not to backup the PC");
    15401548                finish(1);
    15411549            }
    1542             mr_free(comment);
     1550            sz_size = p;
    15431551
    15441552            for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
     
    15711579                        bkpinfo->media_device);
    15721580                mr_asprintf(&comment, "Please specify your %s drive's /dev entry", mds);
    1573                 if (!popup_and_get_string
    1574                     ("Device?", comment, bkpinfo->media_device,
    1575                      MAX_STR_LEN / 4)) {
    1576                     mr_free(comment);
     1581                p = popup_and_get_string("Device?", comment, bkpinfo->media_device);
     1582                mr_free(comment);
     1583
     1584                if (p == NULL) {
    15771585                    log_to_screen("User has chosen not to backup the PC");
    15781586                    finish(1);
    15791587                }
    1580                 mr_free(comment);
     1588                strcpy(bkpinfo->media_device, p);
     1589                mr_free(p);
    15811590            }
    15821591            log_msg(2, "%s device found at %s", mds, bkpinfo->media_device);
     
    15981607            if (!bkpinfo->media_device[0]) {
    15991608                if (bkpinfo->backup_media_type == usb) {
    1600                     i = popup_and_get_string("/dev entry?",
    1601                                          "What is the /dev entry of your USB Disk/Key, please?",
    1602                                          bkpinfo->media_device,
    1603                                          MAX_STR_LEN / 4);
     1609                    p = popup_and_get_string("/dev entry?", "What is the /dev entry of your USB Disk/Key, please?", bkpinfo->media_device);
    16041610                } else {
    16051611                    if (g_kernel_version < 2.6) {
    1606                         i = popup_and_get_string("Device node?",
    1607                                              "What is the SCSI node of your CD (re)writer, please?",
    1608                                              bkpinfo->media_device,
    1609                                              MAX_STR_LEN / 4);
     1612                        p = popup_and_get_string("Device node?", "What is the SCSI node of your CD (re)writer, please?", bkpinfo->media_device);
    16101613                    } else {
    1611                         i = popup_and_get_string("/dev entry?",
    1612                                              "What is the /dev entry of your CD (re)writer, please?",
    1613                                              bkpinfo->media_device,
    1614                                              MAX_STR_LEN / 4);
     1614                        p = popup_and_get_string("/dev entry?", "What is the /dev entry of your CD (re)writer, please?", bkpinfo->media_device);
    16151615                    }
    16161616                }
    1617                 if (!i) {
     1617                if (p == NULL) {
    16181618                    log_to_screen("User has chosen not to backup the PC");
    16191619                    finish(1);
    16201620                }
     1621                strcpy(bkpinfo->media_device, p);
     1622                mr_free(p);
    16211623            }
    16221624        }
     
    16641666        }
    16651667        if (!bkpinfo->media_device[0]) {
    1666             if (!popup_and_get_string
    1667                 ("Device name?",
    1668                  "What is the /dev entry of your tape streamer?",
    1669                  bkpinfo->media_device, MAX_STR_LEN / 4)) {
     1668            p = popup_and_get_string("Device name?", "What is the /dev entry of your tape streamer?", bkpinfo->media_device);
     1669            if (p == NULL) {
    16701670                log_to_screen("User has chosen not to backup the PC");
    16711671                finish(1);
    16721672            }
     1673            strcpy(bkpinfo->media_device, p);
     1674            mr_free(p);
    16731675        }
    16741676        mr_asprintf(&tmp, "ls -l %s", bkpinfo->media_device);
     
    17161718#endif
    17171719        {
    1718             if (!popup_and_get_string
    1719                 ("NFS dir.",
    1720                  "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.)",
    1721                  bkpinfo->nfs_mount, MAX_STR_LEN / 4)) {
     1720            p = popup_and_get_string("NFS dir.", "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.)", bkpinfo->nfs_mount);
     1721            if (p == NULL) {
    17221722                log_to_screen("User has chosen not to backup the PC");
    17231723                finish(1);
    17241724            }
     1725            strcpy(bkpinfo->nfs_mount, p);
     1726            mr_free(p);
    17251727            if (!bkpinfo->restore_data) {
    17261728                if ((bkpinfo->compression_level =
     
    17431745            if (!bkpinfo->restore_data) {
    17441746                mr_asprintf(&comment, "How much data (in Megabytes) will each media store?");
    1745                 if (!popup_and_get_string("Size", comment, sz_size, 5)) {
    1746                     mr_free(comment);
     1747                // BERLIOS: 4480 shouldn't be hardcoded here
     1748                sz_size = popup_and_get_string("Size", comment, "4480");
     1749                mr_free(comment);
     1750                if (sz_size == NULL) {
    17471751                    log_to_screen("User has chosen not to backup the PC");
    17481752                    finish(1);
    17491753                }
    1750                 mr_free(comment);
    17511754            } else {
    1752                 strcpy(sz_size, "0");
     1755                mr_asprintf(&sz_size, "0");
    17531756            }
    17541757            for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
    17551758                bkpinfo->media_size[i] = atoi(sz_size);
    17561759            }
     1760            mr_free(sz_size);
    17571761            if (bkpinfo->media_size[0] < 0) {
    17581762                log_to_screen("User has chosen not to backup the PC");
     
    17651769            mr_free(command);
    17661770
    1767             if (!popup_and_get_string
    1768                 ("NFS share", "Which remote NFS share should I mount?",
    1769                  bkpinfo->nfs_mount, MAX_STR_LEN)) {
     1771            p = popup_and_get_string("NFS share", "Which remote NFS share should I mount?", bkpinfo->nfs_mount);
     1772            if (p == NULL) {
    17701773                log_to_screen("User has chosen not to backup the PC");
    17711774                finish(1);
    17721775            }
     1776            strcpy(bkpinfo->nfs_mount, p);
     1777            mr_free(p);
    17731778        }
    17741779        /* Initiate bkpinfo isodir path from running environment if mount already done */
     
    17951800            finish(1);
    17961801        }
    1797         strcpy(tmp1, bkpinfo->nfs_remote_dir);
    1798         if (!popup_and_get_string
    1799             ("Directory", "Which directory within that mountpoint?", tmp1,
    1800              MAX_STR_LEN)) {
     1802        p = popup_and_get_string("Directory", "Which directory within that mountpoint?", bkpinfo->nfs_remote_dir);
     1803        if (p == NULL) {
    18011804            log_to_screen("User has chosen not to backup the PC");
    18021805            finish(1);
    18031806        }
    1804         strcpy(bkpinfo->nfs_remote_dir, tmp1);
     1807        strcpy(bkpinfo->nfs_remote_dir, p);
     1808        mr_free(p);
    18051809
    18061810        // check whether writable - we better remove surrounding spaces for this
    18071811        strip_spaces(bkpinfo->nfs_remote_dir);
    18081812
    1809         if (!popup_and_get_string
    1810             ("Prefix.",
    1811              "Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files",
    1812             bkpinfo->prefix, MAX_STR_LEN / 4)) {
     1813        p = popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix);
     1814        if (p == NULL) {
    18131815            log_to_screen("User has chosen not to backup the PC");
    18141816            finish(1);
    18151817        }
    18161818        log_msg(3, "prefix set to %s", bkpinfo->prefix);
    1817 
    1818         for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
    1819             bkpinfo->media_size[i] = 650;
    1820         }
    1821         log_msg(3, "Just set nfs_remote_dir to %s",
    1822                 bkpinfo->nfs_remote_dir);
     1819        strcpy(bkpinfo->prefix, p);
     1820        mr_free(p);
     1821
     1822        log_msg(3, "Just set nfs_remote_dir to %s", bkpinfo->nfs_remote_dir);
    18231823        log_msg(3, "isodir is still %s", bkpinfo->isodir);
    18241824        break;
     
    18261826    case iso:
    18271827        if (!bkpinfo->disaster_recovery) {
    1828             if (!popup_and_get_string
    1829                 ("Storage dir.",
    1830                  "Please enter the full path name to the directory for your ISO images.  Example: /mnt/raid0_0",
    1831                  bkpinfo->isodir, MAX_STR_LEN / 4)) {
     1828            p = popup_and_get_string("Storage dir.", "Please enter the full path name to the directory for your ISO images.  Example: /mnt/raid0_0", bkpinfo->isodir);
     1829            if (p == NULL) {
    18321830                log_to_screen("User has chosen not to backup the PC");
    18331831                finish(1);
    18341832            }
     1833            strcpy(bkpinfo->isodir,p);
     1834            mr_free(p);
     1835
    18351836            if (archiving_to_media) {
    18361837                if ((bkpinfo->compression_level =
     
    18391840                    finish(1);
    18401841                }
    1841                 if (!popup_and_get_string
    1842                     ("ISO size.",
    1843                      "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.",
    1844                      sz_size, 16)) {
     1842                p = popup_and_get_string("ISO size.", "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);
     1843                if (p == NULL) {
    18451844                    log_to_screen("User has chosen not to backup the PC");
    18461845                    finish(1);
    18471846                }
    18481847                for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
    1849                     bkpinfo->media_size[i] = atoi(sz_size);
     1848                    bkpinfo->media_size[i] = atoi(p);
    18501849                }
     1850                mr_free(p);
    18511851            } else {
    18521852                for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
     
    18551855            }
    18561856        }
    1857         if (!popup_and_get_string
    1858             ("Prefix.",
    1859              "Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files",
    1860              bkpinfo->prefix, MAX_STR_LEN / 4)) {
     1857        p = popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix);
     1858        if (p == NULL) {
    18611859            log_to_screen("User has chosen not to backup the PC");
    18621860            finish(1);
    18631861        }
     1862        strcpy(bkpinfo->prefix, p);
     1863        mr_free(p);
    18641864        log_msg(3, "prefix set to %s", bkpinfo->prefix);
    18651865        break;
     
    18851885
    18861886#ifdef __FreeBSD__
    1887             if (!popup_and_get_string
    1888                 ("Boot device",
    1889                  "What is your boot device? (e.g. /dev/ad0)",
    1890                  bkpinfo->boot_device, MAX_STR_LEN / 4)) {
     1887            p = popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/ad0)", bkpinfo->boot_device);
     1888            if (!p == NULL) {
    18911889                log_to_screen("User has chosen not to backup the PC");
    18921890                finish(1);
    18931891            }
     1892            strcpy(bkpinfo->boot_device, p);
     1893            mr_free(p);
    18941894            i = which_boot_loader(bkpinfo->boot_device);
    18951895#else
    1896             if (!popup_and_get_string
    1897                 ("Boot device",
    1898                  "What is your boot device? (e.g. /dev/hda)",
    1899                  bkpinfo->boot_device, MAX_STR_LEN / 4)) {
     1896            p = popup_and_get_string("Boot device", "What is your boot device? (e.g. /dev/hda)", bkpinfo->boot_device);
     1897            if (p == NULL) {
    19001898                log_to_screen("User has chosen not to backup the PC");
    19011899                finish(1);
    19021900            }
    1903             if (does_string_exist_in_boot_block
    1904                 (bkpinfo->boot_device, "LILO")) {
     1901            strcpy(bkpinfo->boot_device, p);
     1902            mr_free(p);
     1903
     1904            if (does_string_exist_in_boot_block(bkpinfo->boot_device, "LILO")) {
    19051905                i = 'L';
    19061906            } else
    1907                 if (does_string_exist_in_boot_block
    1908                     (bkpinfo->boot_device, "ELILO")) {
     1907                if (does_string_exist_in_boot_block(bkpinfo->boot_device, "ELILO")) {
    19091908                i = 'E';
    19101909            } else
    1911                 if (does_string_exist_in_boot_block
    1912                     (bkpinfo->boot_device, "GRUB")) {
     1910                if (does_string_exist_in_boot_block(bkpinfo->boot_device, "GRUB")) {
    19131911                i = 'G';
    19141912            } else {
     
    19301928        bkpinfo->boot_loader = i;
    19311929        strcpy(bkpinfo->include_paths, "/");
    1932         if (!popup_and_get_string
    1933             ("Backup paths",
    1934              "Please enter paths which you want me to backup. The default is '/' (i.e. everything).",
    1935              bkpinfo->include_paths, MAX_STR_LEN)) {
     1930        p = popup_and_get_string("Backup paths", "Please enter paths which you want me to backup. The default is '/' (i.e. everything).", bkpinfo->include_paths);
     1931        if (p == NULL) {
    19361932            log_to_screen("User has chosen not to backup the PC");
    19371933            finish(1);
    19381934        }
     1935        strcpy(bkpinfo->include_paths, p);
     1936        mr_free(p);
     1937
    19391938        mr_asprintf(&tmp, "%s", list_of_NFS_mounts_only());
    19401939        if (strlen(tmp) > 2) {
     
    19481947        strcpy(tmp1, call_program_and_get_last_line_of_output("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'"));
    19491948        if (strlen(tmp1) > 2) {
    1950             if (!popup_and_get_string
    1951                 ("NTFS partitions",
    1952                  "Please enter/confirm the NTFS partitions you wish to backup as well.",
    1953                  tmp1, MAX_STR_LEN / 4)) {
     1949            p = popup_and_get_string("NTFS partitions", "Please enter/confirm the NTFS partitions you wish to backup as well.", tmp);
     1950
     1951            if (p == NULL) {
    19541952                log_to_screen("User has chosen not to backup the PC");
    19551953                finish(1);
    19561954            }
    1957             strncpy(bkpinfo->image_devs, tmp1, MAX_STR_LEN / 4);
    1958         }
    1959 
    1960 
    1961         if (!popup_and_get_string
    1962             ("Exclude paths",
    1963              "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.",
    1964              bkpinfo->exclude_paths, (4*MAX_STR_LEN)-1)) {
     1955            strncpy(bkpinfo->image_devs, p, MAX_STR_LEN / 4);
     1956            mr_free(p);
     1957        }
     1958
     1959
     1960        p = popup_and_get_string("Exclude paths", "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.", bkpinfo->exclude_paths);
     1961        if (p == NULL) {
    19651962            log_to_screen("User has chosen not to backup the PC");
    19661963            finish(1);
    19671964        }
    1968         if (!popup_and_get_string
    1969             ("Temporary directory",
    1970              "Please enter your temporary directory.",
    1971              bkpinfo->tmpdir, (4*MAX_STR_LEN)-1)) {
     1965        strcpy(bkpinfo->exclude_paths, p);
     1966        mr_free(p);
     1967
     1968        p = popup_and_get_string("Temporary directory", "Please enter your temporary directory.", bkpinfo->tmpdir);
     1969        if (p == NULL) {
    19721970            log_to_screen("User has chosen not to backup the PC");
    19731971            finish(1);
    19741972        }
    1975         if (!popup_and_get_string
    1976             ("Scratch directory",
    1977              "Please enter your scratch directory.",
    1978              bkpinfo->scratchdir, (4*MAX_STR_LEN)-1)) {
     1973        strcpy(bkpinfo->tmpdir, p);
     1974        mr_free(p);
     1975
     1976        p = popup_and_get_string("Scratch directory", "Please enter your scratch directory.", bkpinfo->scratchdir);
     1977        if (p == NULL) {
    19791978            log_to_screen("User has chosen not to backup the PC");
    19801979            finish(1);
    19811980        }
     1981        strcpy(bkpinfo->scratchdir, p);
     1982        mr_free(p);
     1983
    19821984// Interactive mode:
    19831985#ifdef __IA64__
Note: See TracChangeset for help on using the changeset viewer.