Changeset 1197


Ignore:
Timestamp:
Feb 22, 2007, 1:57:52 AM (13 years ago)
Author:
bruno
Message:

merge trunk memeory management for mondo-prep.c
logging in newt-specific.c reviewed once more

Location:
branches/stable/mondo/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/common/newt-specific.c

    r1196 r1197  
    973973            }
    974974            if (percentage >= 3) {
    975                 mr_asprintf(&tmp1,
    976                         "] %3d%% done; %2ld:%02ld to go", percentage,
    977                         time_remaining / 60, time_remaining % 60);
    978                 mr_strcat(taskprogress, tmp1);
    979                 mr_free(tmp1);
     975                mr_strcat(taskprogress, _("] %3d%% done; %2ld:%02ld to go"), percentage, time_remaining / 60, time_remaining % 60);
    980976                printf("---evalcall------ %s\n", taskprogress);
    981977                mr_free(taskprogress);
     
    10981094            mr_msg(2, _("percentage = %d"), percentage);
    10991095        }
    1100         mr_asprintf(&tmp,_("] %3d%c done; %2ld:%02ld to go"), percentage, '%',
    1101             time_remaining / 60, time_remaining % 60);
    1102         mr_strcat(taskprogress, tmp);
    1103         mr_free(tmp);
     1096        mr_strcat(taskprogress, ,_("] %3d%% done; %2ld:%02ld to go"), percentage, time_remaining / 60, time_remaining % 60);
    11041097        printf(_("---progress-form---4--- %s\n"), taskprogress);
    11051098        mr_free(taskprogress);
  • branches/stable/mondo/src/mondorestore/mondo-prep.c

    r1196 r1197  
    16131613
    16141614    /** buffers **********************************************************/
    1615     char *program;
    1616     char *partition_name;
    1617     char *tmp;
    1618     char *logfile;
    1619     char *output;
     1615    char *program = NULL;
     1616    char *partition_name = NULL;
     1617    char *tmp = NULL;
     1618    char *output = NULL;
    16201619
    16211620    /** pointers **********************************************************/
    1622     char *p;
    1623     char *part_table_fmt;
    1624     FILE *fout;
     1621    char *p = NULL;
     1622    char *part_table_fmt = NULL;
     1623    FILE *fout = NULL;
    16251624
    16261625    /** end ***************************************************************/
    1627 
    1628     malloc_string(program);
    1629     malloc_string(partition_name);
    1630     malloc_string(tmp);
    1631     malloc_string(logfile);
    1632     malloc_string(output);
    16331626
    16341627    assert_string_is_neither_NULL_nor_zerolength(drive);
     
    16391632
    16401633    if (!strncmp(drive, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))) {
    1641         sprintf(tmp, "Not partitioning %s - it is a virtual drive", drive);
    1642         log_it(tmp);
    1643         mr_free(program);
    1644         mr_free(partition_name);
    1645         mr_free(tmp);
    1646         mr_free(logfile);
    1647         mr_free(output);
     1634        log_it("Not partitioning %s - it is a virtual drive", drive);
    16481635        return (0);
    16491636    }
     1637
     1638    malloc_string(partition_name);
     1639
    16501640    build_partition_name(partition_name, drive, partno);
    16511641    if (partsize <= 0) {
    1652         sprintf(tmp, "Partitioning device %s (max size)", partition_name);
     1642        mr_asprintf(&tmp, "Partitioning device %s (max size)", partition_name);
    16531643    } else {
    1654         sprintf(tmp, "Partitioning device %s (%lld MB)", partition_name,
     1644        mr_asprintf(&tmp, "Partitioning device %s (%lld MB)", partition_name,
    16551645                (long long) partsize / 1024);
    16561646    }
    16571647    update_progress_form(tmp);
    16581648    log_it(tmp);
     1649    mr_free(tmp);
    16591650
    16601651    if (is_this_device_mounted(partition_name)) {
    1661         sprintf(tmp, "%s is mounted, and should not be partitioned",
     1652        log_to_screen("%s is mounted, and should not be partitioned",
    16621653                partition_name);
    1663         log_to_screen(tmp);
    1664         mr_free(program);
    16651654        mr_free(partition_name);
    1666         mr_free(tmp);
    1667         mr_free(logfile);
    1668         mr_free(output);
    16691655        return (1);
    1670 /*
    1671     } else if (does_partition_exist(drive, partno)) {
    1672         sprintf(tmp, "%s already has a partition", partition_name);
    1673         log_to_screen(tmp);
    1674         return (1);
    1675 */
    1676     }
    1677 
    1678 
    1679     /*  sprintf(tmp,"Partitioning %s  ",partition_name); */
    1680     /*  mvaddstr_and_log_it(g_currentY+1,30,tmp); */
     1656    }
     1657
    16811658    p = (char *) strrchr(partition_name, '/');
    1682     sprintf(logfile, "/tmp/fdisk.log.%s", ++p);
    1683     sprintf(program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE,
    1684             MONDO_LOGFILE);
    1685 
    1686     /* BERLIOS: shoould not be called each time */
     1659
     1660    /* BERLIOS: should not be called each time */
    16871661    part_table_fmt = which_partition_format(drive);
    1688     output[0] = '\0';
    16891662    /* make it a primary/extended/logical */
    16901663    if (partno <= 4) {
    1691         sprintf(output + strlen(output), "n\np\n%d\n", partno);
     1664        mr_asprintf(&output,"n\np\n%d\n", partno);
    16921665    } else {
    16931666        /* MBR needs an extended partition if more than 4 partitions */
     
    16961669                if (prev_partno >= 4) {
    16971670                    log_to_screen
    1698                         ("You need to leave at least one partition free, for 'extended/logical'");
    1699                     mr_free(program);
     1671                        (_
     1672                         ("You need to leave at least one partition free, for 'extended/logical'"));
    17001673                    mr_free(partition_name);
    1701                     mr_free(tmp);
    1702                     mr_free(logfile);
    1703                     mr_free(output);
    17041674                    return (1);
    17051675                } else {
    1706                     sprintf(output + strlen(output), "n\ne\n%d\n\n\n",
    1707                             prev_partno + 1);
     1676                    mr_asprintf(&output,"n\ne\n%d\n\n\n",prev_partno + 1);
    17081677                }
    17091678            }
    1710             strcat(output + strlen(output), "n\nl\n");
     1679            mr_strcat(output, "n\nl\n");
    17111680        } else {
    17121681            /* GPT allows more than 4 primary partitions */
    1713             sprintf(output + strlen(output), "n\np\n%d\n", partno);
    1714         }
    1715     }
    1716     strcat(output + strlen(output), "\n");  /*start block (ENTER for next free blk */
     1682            mr_asprintf(&output,"n\np\n%d\n",partno);
     1683        }
     1684    }
     1685    /*start block (ENTER for next free blk */
     1686    mr_strcat(output, "\n");   
    17171687    if (partsize > 0) {
    17181688        if (!strcmp(format, "7")) {
     
    17201690            partsize += 512;
    17211691        }
    1722         sprintf(output + strlen(output), "+%lldK", (long long) (partsize));
    1723     }
    1724     strcat(output + strlen(output), "\n");
     1692        mr_strcat(output, "+%lldK", (long long) (partsize));
     1693    }
     1694    mr_strcat(output, "\n");
    17251695#if 0
    17261696/*
    17271697#endif
    1728     sprintf(tmp,"PARTSIZE = +%ld",(long)partsize);
    1729     log_it(tmp);
     1698    log_it("PARTSIZE = +%ld",(long)partsize);
    17301699    log_it("---fdisk command---");
    17311700    log_it(output);
     
    17411710        fput_string_one_char_at_a_time(pout_to_fdisk, output);
    17421711        fput_string_one_char_at_a_time(pout_to_fdisk, "\n\np\n");
    1743         strcpy(tmp, last_line_of_file(FDISK_LOG));
     1712        mr_asprintf(&tmp, last_line_of_file(FDISK_LOG));
    17441713        if (strstr(tmp, " (m ")) {
    17451714            mr_msg(1, "Successfully created %s%d", drive, partno);
     
    17491718                    partno);
    17501719        }
     1720        mr_free(tmp);
     1721
    17511722        if (!retval) {
    17521723            mr_msg(1, "Trying to set %s%d's partition type now", drive,
     
    17661737        }
    17671738    } else {
    1768         strcat(output, "w\n\n");
     1739        mr_strcat(output, "w\n\n");
     1740        mr_asprintf(&program, "parted2fdisk %s >> %s 2>> %s", drive, MONDO_LOGFILE,
     1741            MONDO_LOGFILE);
     1742
    17691743        if (g_fprep) {
    17701744            fprintf(g_fprep, "echo \"%s\" | %s\n", output, program);
     
    17771751            paranoid_pclose(fout);
    17781752        }
     1753        mr_free(program);
     1754
    17791755        if (!does_partition_exist(drive, partno) && partsize > 0) {
    17801756            log_it("Vaccum-packing");
     
    17841760                                 format, -1);
    17851761            if (res) {
    1786                 sprintf(tmp, "Failed to vacuum-pack %s", partition_name);
    1787                 log_it(tmp);
     1762                log_it("Failed to vacuum-pack %s", partition_name);
    17881763                retval++;
    17891764            } else {
     
    17961771                                   partsize);
    17971772            if (retval) {
    1798                 sprintf(tmp, "Partitioned %s but failed to set its type",
     1773                log_it("Partitioned %s but failed to set its type",
    17991774                        partition_name);
    1800                 log_it(tmp);
    18011775            } else {
    18021776                if (partsize > 0) {
    1803                     sprintf(tmp, "Partition %s created+configured OK",
     1777                    log_to_screen(_("Partition %s created+configured OK"),
    18041778                            partition_name);
    1805                     log_to_screen(tmp);
    18061779                } else {
    18071780                    log_it("Returning from a successful vacuum-pack");
     
    18091782            }
    18101783        } else {
    1811             sprintf(tmp, "Failed to partition %s", partition_name);
     1784            mr_asprintf(&tmp, "Failed to partition %s", partition_name);
    18121785            if (partsize > 0) {
    18131786                log_to_screen(tmp);
     
    18151788                log_it(tmp);
    18161789            }
     1790            mr_free(tmp);
    18171791            retval++;
    18181792        }
     
    18201794    g_current_progress++;
    18211795    log_it("partition_device() --- leaving");
    1822     mr_free(program);
    18231796    mr_free(partition_name);
    1824     mr_free(tmp);
    1825     mr_free(logfile);
    18261797    mr_free(output);
    18271798    return (retval);
    18281799}
    1829 
    18301800
    18311801
     
    18401810{
    18411811    /** int ************************************************************/
    1842     int lino;
     1812    int lino = 0;
    18431813    int retval = 0;
    1844     int i;
    1845     int res;
     1814    int i = 0;
     1815    int res = 0;
    18461816
    18471817    /** buffer *********************************************************/
    1848     struct list_of_disks *drivelist;
    1849     /*  struct mountlist_itself new_mtlist, *mountlist; */
     1818    struct list_of_disks *drivelist = NULL;
    18501819
    18511820    /** end ************************************************************/
     
    18561825    log_it("partition_everything() --- starting");
    18571826    mvaddstr_and_log_it(g_currentY, 0, "Partitioning hard drives      ");
    1858     /*  mountlist=orig_mtlist; */
    18591827    if (mountlist_contains_raid_devices(mountlist)) {
    18601828        /*      mountlist=&new_mtlist; */
     
    18791847    mr_msg(0, "Done.");
    18801848
    1881 /* 
    1882     if (does_file_exist("/tmp/i-want-my-lvm"))
    1883       {
    1884         wipe_MBRs_and_reboot_if_necessary(mountlist); // i.e. if it wasn't done recently
    1885       }
    1886 */
    1887 
    1888     open_progress_form("Partitioning devices",
    1889                        "I am now going to partition all your drives.",
    1890                        "This should not take more than five minutes.", "",
    1891                        mountlist->entries);
     1849    open_progress_form(_("Partitioning devices"),
     1850                       _("I am now going to partition all your drives."),
     1851                       _("This should not take more than five minutes."),
     1852                       "", mountlist->entries);
    18921853
    18931854    make_list_of_drives_in_mountlist(mountlist, drivelist);
     
    19001861    close_progress_form();
    19011862    if (retval) {
    1902         mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1863        mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
    19031864        log_to_screen
    1904             ("Errors occurred during the partitioning of your hard drives.");
     1865            (_
     1866             ("Errors occurred during the partitioning of your hard drives."));
    19051867    } else {
    1906         mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1868        mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
    19071869        paranoid_system("rm -f /tmp/fdisk*.log 2> /dev/null");
    19081870    }
     
    19131875    return (retval);
    19141876}
    1915 
    1916 
    1917 
    1918 
    19191877
    19201878
     
    19321890{
    19331891    /** buffers *********************************************************/
    1934     char *partition;
    1935     char *command;
    1936     char *output;
    1937     char *tmp;
    1938     char *partcode;
    1939     char *logfile;
     1892    char *partition = NULL;
     1893    char *command = NULL;
     1894    char *output = NULL;
     1895    char *tmp = NULL;
     1896    char *tmp1 = NULL;
     1897    char *partcode = NULL;
    19401898
    19411899    /** pointers *********************************************************/
    1942     char *p;
    1943     FILE *fout;
     1900    char *p = NULL;
     1901    FILE *fout = NULL;
    19441902
    19451903    /** int **************************************************************/
     
    19521910
    19531911    malloc_string(partition);
    1954     malloc_string(command);
    1955     malloc_string(output);
    1956     malloc_string(tmp);
    1957     malloc_string(partcode);
    1958     malloc_string(logfile);
    19591912
    19601913    build_partition_name(partition, drive, partno);
    19611914    p = (char *) strrchr(partition, '/');
    1962     sprintf(logfile, "/tmp/fdisk-set-type.%s.log", ++p);
    19631915    if (strcmp(format, "swap") == 0) {
    1964         strcpy(partcode, "82");
     1916        mr_asprintf(&partcode, "82");
    19651917    } else if (strcmp(format, "vfat") == 0) {
    19661918        if (partsize / 1024 > 8192) {
    1967             strcpy(partcode, "c");
     1919            mr_asprintf(&partcode, "c");
    19681920        } else {
    1969             strcpy(partcode, "b");
     1921            mr_asprintf(&partcode, "b");
    19701922        }
    19711923    } else if (strcmp(format, "ext2") == 0
     
    19731925               || strcmp(format, "ext3") == 0 || strcmp(format, "xfs") == 0
    19741926               || strcmp(format, "jfs") == 0) {
    1975         strcpy(partcode, "83");
     1927        mr_asprintf(&partcode, "83");
    19761928    } else if (strcmp(format, "minix") == 0) {
    1977         strcpy(partcode, "81");
     1929        mr_asprintf(&partcode, "81");
    19781930    } else if (strcmp(format, "raid") == 0) {
    1979         strcpy(partcode, "fd");
     1931        mr_asprintf(&partcode, "fd");
    19801932    } else if ((strcmp(format, "ufs") == 0)
    19811933               || (strcmp(format, "ffs") == 0)) {   /* raid autodetect */
    1982         strcpy(partcode, "a5");
     1934        mr_asprintf(&partcode, "a5");
    19831935    } else if (strcmp(format, "lvm") == 0) {
    1984         strcpy(partcode, "8e");
     1936        mr_asprintf(&partcode, "8e");
    19851937    } else if (format[0] == '\0') { /* LVM physical partition */
    1986         partcode[0] = '\0';
     1938        mr_asprintf(&partcode, "");
    19871939    } else if (strlen(format) >= 1 && strlen(format) <= 2) {
    1988         strcpy(partcode, format);
     1940        mr_asprintf(&partcode, format);
    19891941    } else {
    19901942        /* probably an image */
    1991         sprintf(tmp,
     1943        mr_asprintf(&tmp,
    19921944                "Unknown format ('%s') - using supplied string anyway",
    19931945                format);
    19941946        mvaddstr_and_log_it(g_currentY++, 0, tmp);
     1947        mr_free(tmp);
    19951948#ifdef __FreeBSD__
    1996         strcpy(partcode, format);   // was a5
     1949        mr_asprintf(&partcode, format); // was a5
    19971950#else
    1998         strcpy(partcode, format);   // was 83
    1999 #endif
    2000     }
    2001     sprintf(tmp, "Setting %s's type to %s (%s)", partition, format,
     1951        mr_asprintf(&partcode, format); // was 83
     1952#endif
     1953    }
     1954    mr_asprintf(&tmp, "Setting %s's type to %s (%s)", partition, format,
    20021955            partcode);
    20031956    mr_msg(1, tmp);
     1957    mr_free(tmp);
     1958
    20041959    if (partcode[0] != '\0' && strcmp(partcode, "83")) {    /* no need to set type if 83: 83 is default */
    20051960
     
    20101965                || strstr(last_line_of_file(FDISK_LOG), " (1-4)")) {
    20111966                mr_msg(5, "Specifying partno (%d) - yay", partno);
    2012                 sprintf(tmp, "%d\n", partno);
     1967                mr_asprintf(&tmp, "%d\n", partno);
    20131968                fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    20141969                mr_msg(5, "A - last line = '%s'",
    20151970                        last_line_of_file(FDISK_LOG));
    2016             }
    2017 
    2018             sprintf(tmp, "%s\n", partcode);
     1971                mr_free(tmp);
     1972            }
     1973
     1974            mr_asprintf(&tmp, "%s\n", partcode);
    20191975            fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
     1976            mr_free(tmp);
     1977
    20201978            mr_msg(5, "B - last line = '%s'",
    20211979                    last_line_of_file(FDISK_LOG));
     1980
    20221981            fput_string_one_char_at_a_time(pout_to_fdisk, "\n");
    20231982            mr_msg(5, "C - last line = '%s'",
    20241983                    last_line_of_file(FDISK_LOG));
    20251984
    2026             strcpy(tmp, last_line_of_file(FDISK_LOG));
     1985            mr_asprintf(&tmp, last_line_of_file(FDISK_LOG));
    20271986            if (!strstr(tmp, " (m ")) {
    20281987                mr_msg(1, "last line = '%s'; part type set failed", tmp);
     
    20301989                fput_string_one_char_at_a_time(pout_to_fdisk, "\n");
    20311990            }
     1991            mr_free(tmp);
    20321992            fput_string_one_char_at_a_time(pout_to_fdisk, "p\n");
    20331993        } else {
    2034             sprintf(output, "t\n%d\n%s\n", partno, partcode);
    2035             strcat(output, "w\n");
    2036             sprintf(command, "parted2fdisk %s >> %s 2>> %s", drive,
     1994            mr_asprintf(&output, "t\n%d\n%s\nw\n", partno, partcode);
     1995            mr_asprintf(&command, "parted2fdisk %s >> %s 2>> %s", drive,
    20371996                    MONDO_LOGFILE, MONDO_LOGFILE);
    20381997            mr_msg(5, "output = '%s'", output);
     
    20482007                paranoid_pclose(fout);
    20492008            }
    2050         }
     2009            mr_free(command);
     2010            mr_free(output);
     2011        }
     2012        /* BERLIOS: Useless as command not initialized in all cases
    20512013        if (res) {
    20522014            log_OS_error(command);
    20532015        }
     2016        */
    20542017    }
    20552018
    20562019    mr_free(partition);
    2057     mr_free(command);
    2058     mr_free(output);
    2059     mr_free(tmp);
    20602020    mr_free(partcode);
    2061     mr_free(logfile);
    20622021
    20632022    return (res);
     
    20682027{
    20692028    /** int *************************************************************/
    2070     int res;
     2029    int res = 0;
    20712030    int retval = 0;
    20722031
    20732032    /** buffers *********************************************************/
    2074     char *program;
     2033    char *program = NULL;
    20752034
    20762035    /** end *************************************************************/
    20772036
    20782037    assert_string_is_neither_NULL_nor_zerolength(raid_device);
    2079     malloc_string(program);
    20802038
    20812039#ifdef __FreeBSD__
     
    20842042        return 1;
    20852043    }
    2086     sprintf(program, "vinum start -f %s", raid_device);
     2044    mr_asprintf(&program, "vinum start -f %s", raid_device);
    20872045#else
    2088     sprintf(program, "raidstart %s", raid_device);
     2046    // use raidstart if it exists, otherwise use mdadm
     2047    if (run_program_and_log_output("which raidstart", FALSE)) {
     2048        // BERLIOS: Not sure it's sufficient
     2049        mr_asprintf(&program, "mdadm -A %s", raid_device);
     2050    } else {
     2051        mr_asprintf(&program, "raidstart %s", raid_device);
     2052    }
    20892053#endif
    20902054    mr_msg(1, "program = %s", program);
     
    20932057        fprintf(g_fprep, "%s\n", program);
    20942058    }
     2059    mr_free(program);
     2060
    20952061    if (res) {
    20962062        mr_msg(1, "Warning - failed to start RAID device %s",
     
    21012067    return (retval);
    21022068}
    2103 
    21042069
    21052070
     
    21122077{
    21132078    /** int *************************************************************/
    2114     int res;
     2079    int res = 0;
    21152080    int retval = 0;
    21162081
    21172082    /** buffers *********************************************************/
    2118     char *program;
     2083    char *program = NULL;
    21192084
    21202085    /** end *************************************************************/
    21212086
    21222087    assert_string_is_neither_NULL_nor_zerolength(raid_device);
    2123     malloc_string(program);
    21242088
    21252089#ifdef __FreeBSD__
     
    21282092        return 1;
    21292093    }
    2130     sprintf(program, "vinum stop -f %s", raid_device);
     2094    mr_asprintf(&program, "vinum stop -f %s", raid_device);
    21312095#else
    2132     // use raidstop if it exists, otherwise use mdadm
    2133     if (run_program_and_log_output("which raidstop", FALSE)) {
    2134         sprintf(program, "mdadm -S %s", raid_device);
     2096    // use raidstop if it exists, otherwise use mdadm
     2097    if (run_program_and_log_output("which raidstop", FALSE)) {
     2098        mr_asprintf(&program, "mdadm -S %s", raid_device);
    21352099    } else {
    2136         sprintf(program, "raidstop %s", raid_device);
     2100        mr_asprintf(&program, "raidstop %s", raid_device);
    21372101    }
    21382102#endif
     
    21422106        fprintf(g_fprep, "%s\n", program);
    21432107    }
     2108    mr_free(program);
     2109
    21442110    if (res) {
    21452111        mr_msg(1, "Warning - failed to stop RAID device %s", raid_device);
     
    21522118int start_all_raid_devices(struct mountlist_itself *mountlist)
    21532119{
    2154     int i;
     2120    int i = 0;
    21552121    int retval = 0;
    2156     int res;
     2122    int res = 0;
    21572123
    21582124    for (i = 0; i < mountlist->entries; i++) {
     
    21732139}
    21742140
     2141
    21752142/**
    21762143 * Stop all software RAID devices listed in @p mountlist.
     
    21842151    int retval = 0;
    21852152#ifndef __FreeBSD__
    2186     int res;
     2153    int res = 0;
    21872154#endif
    21882155
    21892156    /** char ************************************************************/
    2190     char *incoming;
     2157    char *incoming = NULL;
    21912158#ifndef __FreeBSD__
    2192     char *dev;
     2159    char *dev = NULL;
    21932160#endif
    21942161    /** pointers ********************************************************/
    21952162#ifndef __FreeBSD__
    2196     char *p;
    2197 #endif
    2198     FILE *fin;
    2199     int i;
     2163    char *p = NULL;
     2164#endif
     2165    FILE *fin = NULL;
     2166    int i = 0;
     2167    size_t n = 0;
    22002168
    22012169    /** end ****************************************************************/
    22022170
    2203     malloc_string(dev);
    2204     malloc_string(incoming);
    22052171    assert(mountlist != NULL);
    22062172
     
    22122178             "r");
    22132179        if (!fin) {
    2214             mr_free(dev);
    2215             mr_free(incoming);
    22162180            return (1);
    22172181        }
    2218         for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    2219              fgets(incoming, MAX_STR_LEN - 1, fin)) {
     2182        for (mr_getline(&incoming, &n, fin); !feof(fin);
     2183             mr_getline(&incoming, &n, fin)) {
    22202184            retval += stop_raid_device(incoming);
    22212185        }
     
    22242188        if (!fin) {
    22252189            log_OS_error("/proc/mdstat");
    2226             mr_free(dev);
    2227             mr_free(incoming);
    22282190            return (1);
    22292191        }
    2230         for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    2231              fgets(incoming, MAX_STR_LEN - 1, fin)) {
     2192        for (mr_getline(&incoming, &n, fin); !feof(fin);
     2193             mr_getline(&incoming, &n, fin)) {
    22322194            for (p = incoming;
    22332195                 *p != '\0' && (*p != 'm' || *(p + 1) != 'd'
    22342196                                || !isdigit(*(p + 2))); p++);
    22352197            if (*p != '\0') {
    2236                 sprintf(dev, "/dev/%s", p);
     2198                mr_asprintf(&dev, "/dev/%s", p);
     2199                /* BERLIOS : 32 Hard coded value */
    22372200                for (p = dev; *p > 32; p++);
    22382201                *p = '\0';
    22392202                res = stop_raid_device(dev);
    2240             }
    2241         }
    2242 #endif
     2203                mr_free(dev);
     2204            }
     2205        }
     2206#endif
     2207        mr_free(incoming);
    22432208    }
    22442209    paranoid_fclose(fin);
     
    22462211        mr_msg(1, "Warning - unable to stop some RAID devices");
    22472212    }
    2248     mr_free(dev);
    2249     mr_free(incoming);
    2250     system("sync");
    2251     system("sync");
    2252     system("sync");
     2213    sync();
     2214    sync();
     2215    sync();
    22532216    sleep(1);
    22542217    return (retval);
    22552218}
    2256 
    22572219
    22582220
     
    22682230    int res = 0;
    22692231
    2270     /** buffers *********************************************************/
    2271     char *tmp;
    2272 
    22732232    /** end ***************************************************************/
    22742233
    2275     malloc_string(tmp);
    22762234    assert_string_is_neither_NULL_nor_zerolength(format);
    22772235    assert(program != NULL);
     
    23052263        sprintf(program, "mkfs -t %s -c", format);  // -c checks for bad blocks
    23062264#endif
    2307         sprintf(tmp, "Unknown format (%s) - assuming '%s' will do", format,
     2265        log_it("Unknown format (%s) - assuming '%s' will do", format,
    23082266                program);
    2309         log_it(tmp);
    23102267        res = 0;
    23112268    }
    2312     mr_free(tmp);
    23132269    return (res);
    23142270}
     
    23262282{
    23272283    /** long ************************************************************/
    2328     long original_size_of_drive;
     2284    long original_size_of_drive = 0L;
    23292285
    23302286    /** int *************************************************************/
    2331     int partno;
    2332 
    2333     /** buffers *********************************************************/
    2334     char *tmp;
     2287    int partno = 0;
    23352288
    23362289    /** end *************************************************************/
    23372290
    2338     malloc_string(tmp);
    23392291    assert(mountlist != NULL);
    23402292    assert_string_is_neither_NULL_nor_zerolength(drive_name);
     
    23462298             strlen(drive_name)) == 0) {
    23472299            original_size_of_drive += mountlist->el[partno].size;
    2348         } else {
    2349             sprintf(tmp, "Skipping %s", mountlist->el[partno].device);
    2350 //                      log_to_screen(tmp);
    23512300        }
    23522301    }
    23532302    original_size_of_drive = original_size_of_drive / 1024;
    2354     mr_free(tmp);
    23552303    return (original_size_of_drive);
    23562304}
     
    23722320                                                     char *drive_name)
    23732321{
    2374     /**buffers **********************************************************/
    2375     char *tmp;
    2376 
    23772322    /** int *************************************************************/
    2378     int partno, lastpart;
     2323    int partno = 0, lastpart = 0;
    23792324               /** remove driveno, noof_drives stan benoit apr 2002**/
    23802325
     
    23822327    float factor;
    23832328    float new_size;
    2384 //  float newcylinderno;
    23852329
    23862330    /** long *************************************************************/
    2387     long newsizL;
    2388     long current_size_of_drive = 0;
    2389     long original_size_of_drive = 0;
    2390     long final_size;            /* all in Megabytes */
    2391     struct mountlist_reference *drivemntlist;
     2331    long newsizL = 0L;
     2332    long current_size_of_drive = 0L;
     2333    long original_size_of_drive = 0L;
     2334    long final_size = 0L;           /* all in Megabytes */
     2335    struct mountlist_reference *drivemntlist = NULL;
    23922336
    23932337    /** structures *******************************************************/
     
    23952339    /** end **************************************************************/
    23962340
    2397     malloc_string(tmp);
    23982341    assert(mountlist != NULL);
    23992342    assert_string_is_neither_NULL_nor_zerolength(drive_name);
     
    24022345        if (strncmp(drive_name, RAID_DEVICE_STUB, strlen(RAID_DEVICE_STUB))
    24032346            == 0) {
    2404             mr_free(tmp);
    24052347            return;
    24062348        }
    24072349    }
    2408 
    2409     /*
    2410        sprintf (tmp, "cp -f %s %s.pre-resize", g_mountlist_fname, g_mountlist_fname);
    2411        run_program_and_log_output (tmp, FALSE);
    2412      */
    24132350
    24142351    current_size_of_drive = get_phys_size_of_drive(drive_name);
     
    24162353    if (current_size_of_drive <= 0) {
    24172354        log_it("Not resizing to match %s - can't find drive", drive_name);
    2418         mr_free(tmp);
    24192355        return;
    24202356    }
    2421     sprintf(tmp, "Expanding entries to suit drive %s (%ld MB)", drive_name,
     2357    log_to_screen("Expanding entries to suit drive %s (%ld MB)", drive_name,
    24222358            current_size_of_drive);
    2423     log_to_screen(tmp);
    24242359
    24252360    drivemntlist = mr_malloc(sizeof(struct mountlist_reference));
     
    24352370
    24362371    if (original_size_of_drive <= 0) {
    2437         sprintf(tmp, "Cannot resize %s's entries. Drive not found.",
     2372        log_to_screen(_("Cannot resize %s's entries. Drive not found."),
    24382373                drive_name);
    2439         log_to_screen(tmp);
    2440         mr_free(tmp);
    24412374        return;
    24422375    }
    24432376    factor =
    24442377        (float) (current_size_of_drive) / (float) (original_size_of_drive);
    2445     sprintf(tmp, "Disk %s was %ld MB; is now %ld MB; factor = %f",
     2378    log_to_screen(_("Disk %s was %ld MB; is now %ld MB; factor = %f"),
    24462379            drive_name, original_size_of_drive, current_size_of_drive,
    24472380            factor);
    2448     log_to_screen(tmp);
    24492381
    24502382    lastpart = drivemntlist->entries - 1;
     
    24652397            newsizL = (long) new_size;
    24662398        }
    2467         sprintf(tmp, "Changing %s from %lld KB to %ld KB",
     2399        log_to_screen(_("Changing %s from %lld KB to %ld KB"),
    24682400                drivemntlist->el[partno]->device,
    24692401                drivemntlist->el[partno]->size, newsizL);
    2470         log_to_screen(tmp);
    24712402        drivemntlist->el[partno]->size = newsizL;
    24722403    }
    24732404    final_size = get_phys_size_of_drive(drive_name);
    2474     sprintf(tmp, "final_size = %ld MB", final_size);
    2475     mr_free(tmp);
    2476     log_to_screen(tmp);
     2405    log_to_screen(_("final_size = %ld MB"), final_size);
    24772406}
    24782407
     
    24882417{
    24892418    /** buffers *********************************************************/
    2490     struct list_of_disks *drivelist;
     2419    struct list_of_disks *drivelist = NULL;
    24912420
    24922421    /** int *************************************************************/
    2493     int driveno;
     2422    int driveno = 0;
    24942423
    24952424    /** end *************************************************************/
     
    25012430            ("resize_mountlist_prop...() - warning - mountlist fname is blank");
    25022431        log_it("That does NOT affect the functioning of this subroutine.");
    2503         log_it("--- Hugo, 2002/11/20");
    25042432    }
    25052433    iamhere("Resizing mountlist");
     
    25122440                                                        device);
    25132441    }
    2514     log_to_screen("Mountlist adjusted to suit current hard drive(s)");
     2442    log_to_screen(_("Mountlist adjusted to suit current hard drive(s)"));
    25152443    mr_free(drivelist);
    25162444}
     
    25282456                                struct mountlist_reference *drivemntlist)
    25292457{
    2530     int partno;
    2531     char *tmp_drive_name, *c;
     2458    int partno = 0;
     2459    char *tmp_drive_name = NULL, *c = NULL;
    25322460
    25332461    assert(mountlist != NULL);
     
    25372465    mr_msg(1, "Creating list of partitions for drive %s", drive_name);
    25382466
    2539     tmp_drive_name = strdup(drive_name);
    2540     if (!tmp_drive_name)
    2541         fatal_error("Out of memory");
     2467    mr_asprintf(&tmp_drive_name, drive_name);
    25422468
    25432469    /* devfs devices? */
     
    25452471    if (c && strncmp(c, "/disc", 5) == 0) {
    25462472        /* yup its devfs, change the "disc" to "part" so the existing code works */
    2547         strcpy(c + 1, "part");
     2473        strncpy(c + 1, "part", (size_t)5);
    25482474    }
    25492475    drivemntlist->entries = 0;
     
    25572483        }
    25582484    }
    2559     if (tmp_drive_name)
    2560         mr_free(tmp_drive_name);
     2485    mr_free(tmp_drive_name);
    25612486}
    25622487
Note: See TracChangeset for help on using the changeset viewer.