Ignore:
Timestamp:
Feb 17, 2007, 2:27:26 AM (17 years ago)
Author:
Bruno Cornec
Message:

Continue to merge trunk memory management enhancements for libmondo-tools.c & libmondo-string.c
Introduction + test of a new function mr_strcat

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/common/libmondo-tools.c

    r1165 r1178  
    1 /* libmondo-tools.c                                  misc tools
    2    $Id$
     1/* $Id$
     2misc tools
    33*/
    4 
    54
    65/**
     
    1615#include "mondostructures.h"
    1716#include "libmondo-tools.h"
    18 #include "libmondo-gui-EXT.h"
     17#include "newt-specific-EXT.h"
    1918#include "libmondo-files-EXT.h"
    2019#include "libmondo-fork-EXT.h"
     
    4544
    4645/**
    47  * The place where /boot is mounted.
    48  */
    49 char *g_boot_mountpt = NULL;
     46 * The place where /boot is mounted. - Used locally only
     47 */
     48static char *g_boot_mountpt = NULL;
    5049
    5150/**
     
    7776
    7877extern t_bkptype g_backup_media_type;
     78extern char *g_backup_media_string;
    7979
    8080extern bool am_I_in_disaster_recovery_mode(void);
     
    111111        newtSuspend();
    112112#endif
    113     printf("ASSERTION FAILED: `%s'\n", exp);
    114     printf("\tat %s:%d in %s\n\n", file, line, function);
    115     printf("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ");
     113    printf(_("ASSERTION FAILED: `%s'\n"), exp);
     114    printf(_("\tat %s:%d in %s\n\n"), file, line, function);
     115    printf(_("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? "));
    116116    do {
    117117        is_valid = TRUE;
     
    140140        case '\n':
    141141            printf
    142                 ("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? ");
     142                (_("(I)gnore, ignore (A)ll, (D)ebug, a(B)ort, or (E)xit? "));
    143143            break;
    144144        default:
    145145            is_valid = FALSE;
    146             printf("Invalid choice.\n");
     146            printf(_("Invalid choice.\n"));
    147147            break;
    148148        }
     
    171171    char *tmp;
    172172
    173     malloc_string(tmp);
    174     strcpy(tmp,
    175            "for i in `find /root /home -type d -name Desktop -maxdepth 2`; do \
     173    mr_asprintf(&tmp,
     174             "for i in `find /root /home -type d -name Desktop -maxdepth 2`; do \
    176175file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \
    177176awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } \
     
    202201    return ("i386");
    203202#endif
     203#ifdef __X86_64__
     204    return ("x86_64");
     205#endif
    204206#ifdef __IA64__
    205207    return ("ia64");
     
    209211
    210212
    211 
     213/* BERLIOS: Use uname instead */
    212214double get_kernel_version(void)
    213215{
     
    237239
    238240
    239 
    240 
    241 
    242241/**
    243242 * Get the current time.
     
    248247    return (long) time((void *) 0);
    249248}
    250 
    251 
    252 
    253 
    254 
    255249
    256250
     
    295289
    296290
    297 
    298 
    299291/**
    300292 * Insert modules that Mondo requires.
     
    308300    system("kldstat | grep ext2fs  || kldload ext2fs 2> /dev/null");
    309301#else
    310     system("modprobe dos &> /dev/null");
    311     system("modprobe fat &> /dev/null");
    312     system("modprobe vfat &> /dev/null");
    313     //  system("modprobe osst &> /dev/null");
     302    system("modprobe -a dos fat vfat loop &> /dev/null");
    314303#endif
    315304}
     
    349338int post_param_configuration(struct s_bkpinfo *bkpinfo)
    350339{
    351     char *extra_cdrom_params;
    352     char *mondo_mkisofs_sz;
    353     char *command;
    354     char *mtpt;
    355     char *hostname, *ip_address;
     340    char *extra_cdrom_params = NULL;
     341    char *mondo_mkisofs_sz = NULL;
     342    char *command = NULL;
     343    char *hostname = NULL;
     344    char *ip_address = NULL;
    356345    int retval = 0;
    357346    long avm = 0;
    358     char *colon;
    359     char *cdr_exe;
    360     char *tmp;
    361     char call_before_iso_user[MAX_STR_LEN] = "\0";
     347    char *colon = NULL;
     348    char *cdr_exe = NULL;
     349    char *tmp = NULL;
     350    char *tmp1 = NULL;
     351    char *call_before_iso_user = NULL;
    362352    int rdsiz_MB;
    363     char *iso_dev;
    364     char *iso_mnt;
    365     char *iso_tmp;
    366     char *iso_path;
     353    char *iso_dev = NULL;
     354    char *iso_mnt = NULL;
     355    char *iso_tmp = NULL;
     356    char *iso_path = NULL;
    367357    FILE *fd1 = NULL;
    368358
    369359    assert(bkpinfo != NULL);
    370     malloc_string(extra_cdrom_params);
    371     malloc_string(mondo_mkisofs_sz);
    372     malloc_string(command);
    373     malloc_string(mtpt);
    374     malloc_string(hostname);
    375     malloc_string(ip_address);
    376     malloc_string(cdr_exe);
    377     malloc_string(tmp);
    378     malloc_string(iso_dev);
    379     malloc_string(iso_mnt);
    380     malloc_string(iso_tmp);
    381     malloc_string(iso_path);
    382360    bkpinfo->optimal_set_size =
    383361        (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) *
     
    387365    if (bkpinfo->backup_media_type == tape) {
    388366        mr_msg(1, "Bar");
    389         sprintf(tmp, "mt -f %s status", bkpinfo->media_device);
     367        mr_asprintf(&tmp, "mt -f %s status", bkpinfo->media_device);
    390368        mr_msg(1, "tmp = '%s'", tmp);
    391369        if (run_program_and_log_output(tmp, 3)) {
     
    393371                ("Unable to open tape device. If you haven't specified it with -d, do so. If you already have, check your parameter. I think it's wrong.");
    394372        }
     373        mr_free(tmp);
    395374    }
    396375    make_hole_for_dir(bkpinfo->scratchdir);
     
    403382    run_program_and_log_output("cat /etc/*issue*", 5);
    404383    sprintf(g_tmpfs_mountpt, "%s/tmpfs", bkpinfo->tmpdir);
    405     sprintf(command, "mkdir -p %s", g_tmpfs_mountpt);
     384    mr_asprintf(&command, "mkdir -p %s", g_tmpfs_mountpt);
    406385    paranoid_system(command);
     386    mr_free(command);
    407387    rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB;
    408388#ifdef __FreeBSD__
    409     strcpy(tmp,
     389    mr_asprintf(&tmp,
    410390           call_program_and_get_last_line_of_output
    411391           ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6"));
    412392    avm += atol(tmp);
    413     strcpy(tmp,
     393    mr_free(tmp);
     394    mr_asprintf(&tmp,
    414395           call_program_and_get_last_line_of_output
    415396           ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc"));
    416397    avm += atol(tmp);
    417     sprintf(command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm',
    418             g_tmpfs_mountpt);
     398    mr_free(tmp);
     399    mr_asprintf(&command, "mdmfs -s %d%c md9 %s", rdsiz_MB, 'm',
     400             g_tmpfs_mountpt);
    419401#else
    420     strcpy(tmp,
     402    mr_asprintf(&tmp,
    421403           call_program_and_get_last_line_of_output
    422404           ("free | grep ':' | tr -s ' ' '\t' | cut -f2 | head -n1"));
    423405    avm += atol(tmp);
    424     sprintf(command, "mount /dev/shm -t tmpfs %s -o size=%d%c",
     406    mr_free(tmp);
     407    mr_asprintf(&command, "mount /dev/shm -t tmpfs %s -o size=%d%c",
    425408            g_tmpfs_mountpt, rdsiz_MB, 'm');
    426409    run_program_and_log_output("cat /proc/cpuinfo", 5);
     410    /* BERLIOS: rpm is not necessarily there ! */
    427411    run_program_and_log_output
    428412        ("rpm -q newt newt-devel slang slang-devel ncurses ncurses-devel gcc",
     
    440424        log_it("It doesn't seem you have enough swap to use tmpfs. Fine.");
    441425    }
     426    mr_free(command);
    442427
    443428    if (bkpinfo->use_lzo) {
     
    457442
    458443    if (bkpinfo->backup_media_type == dvd) {
    459         extra_cdrom_params[0] = '\0';
    460         mondo_mkisofs_sz[0] = '\0';
    461444        if (find_home_of_exe("growisofs")) {
    462             strcpy(cdr_exe, "growisofs");
    463         }                       // unlikely to be used
    464         else {
     445            mr_asprintf(&cdr_exe, "growisofs");
     446        } else {
    465447            fatal_error("Please install growisofs.");
    466448        }
    467449        if (bkpinfo->nonbootable_backup) {
    468             strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);
     450            mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);
    469451        } else if
    470452#ifdef __FreeBSD__
     
    475457#ifdef __IA64__
    476458    {
    477         strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);
     459        mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);
    478460    }
    479461#else
    480462    {
    481         strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);
     463        mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);
    482464    }
    483465#endif
    484466        else
    485467        {
    486             strcat(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
     468            mr_asprintf(&mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);
    487469        }
    488470        if (bkpinfo->manual_cd_tray) {
     
    492474            sprintf(bkpinfo->call_make_iso,
    493475                    "%s %s -Z %s . 2>> _ERR_",
    494                     mondo_mkisofs_sz,
    495                     extra_cdrom_params, bkpinfo->media_device);
    496         }
     476                    mondo_mkisofs_sz, "", bkpinfo->media_device);
     477        }
     478        mr_free(mondo_mkisofs_sz);
     479
    497480        if (getenv ("SUDO_COMMAND")) {
    498             sprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND");
     481            mr_asprintf(&command, "strings `which growisofs` | grep -c SUDO_COMMAND");
    499482            if (!strcmp(call_program_and_get_last_line_of_output(command), "1")) {
    500483                popup_and_OK("Fatal Error: Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details.");
    501484                fatal_error("Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details.");
    502             }       
     485            }
     486            mr_free(command);
    503487        }
    504488        mr_msg(2, "call_make_iso (DVD res) is ... %s",
     
    509493    if (bkpinfo->backup_media_type == cdrw
    510494        || bkpinfo->backup_media_type == cdr) {
    511         extra_cdrom_params[0] = '\0';
    512495        if (!bkpinfo->manual_cd_tray) {
    513             strcat(extra_cdrom_params, "-waiti ");
     496            mr_strcat(extra_cdrom_params, "-waiti ");
    514497        }
    515498        if (bkpinfo->backup_media_type == cdrw) {
    516             strcat(extra_cdrom_params, "blank=fast ");
     499            mr_strcat(extra_cdrom_params, "blank=fast ");
    517500        }
    518501        if (find_home_of_exe("cdrecord")) {
    519             strcpy(cdr_exe, "cdrecord");
     502            mr_asprintf(&cdr_exe, "cdrecord");
    520503        } else if (find_home_of_exe("dvdrecord")) {
    521             strcpy(cdr_exe, "dvdrecord");
     504            mr_asprintf(&cdr_exe, "dvdrecord");
    522505        } else {
    523506            fatal_error("Please install either cdrecord or dvdrecord.");
    524507        }
    525508        if (bkpinfo->nonbootable_backup) {
    526             strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT);
     509            mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT);
    527510        } else if
    528511#ifdef __FreeBSD__
     
    533516#ifdef __IA64__
    534517    {
    535         strcat(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);
     518        mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);
    536519    }
    537520#else
    538521    {
    539         strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);
     522        mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);
    540523    }
    541524#endif
    542525        else
    543526        {
    544             strcpy(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);
     527            mr_asprintf(&mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);
    545528        }
    546529        if (bkpinfo->manual_cd_tray) {
     
    549532                        "%s -o %s/temporary.iso . 2>> _ERR_",
    550533                        mondo_mkisofs_sz, bkpinfo->tmpdir);
    551                 } else {
    552                 strncpy(call_before_iso_user, bkpinfo->call_before_iso, MAX_STR_LEN);
     534            } else {
     535                mr_asprintf(&call_before_iso_user, bkpinfo->call_before_iso);
    553536                sprintf (bkpinfo->call_before_iso,
    554537                                    "( %s -o %s/temporary.iso . 2>> _ERR_ ; %s )",
    555538                        mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user);
     539                mr_free(call_before_iso_user);
    556540            }
    557541            log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso);
     
    569553                    bkpinfo->cdrw_speed);
    570554        }
     555        mr_free(mondo_mkisofs_sz);
     556        mr_free(cdr_exe);
     557        mr_free(extra_cdrom_params);
    571558    }                           // end of CD code
    572 
    573     /*
    574        if (bkpinfo->backup_data && bkpinfo->backup_media_type == tape)
    575        {
    576        sprintf (tmp,
    577        "dd if=/dev/zero of=%s bs=%ld count=32 2> /dev/null",
    578        bkpinfo->media_device, bkpinfo->internal_tape_block_size);
    579        if (system(tmp))
    580        {
    581        retval++;
    582        fprintf (stderr,
    583        "Cannot write to tape device. Is the tape set read-only?\n");
    584        }
    585        } // end of tape code
    586      */
    587 
    588559
    589560    if (bkpinfo->backup_media_type == iso) {
     
    597568
    598569        log_it("isodir = %s", bkpinfo->isodir);
    599         sprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1",
    600                 bkpinfo->isodir);
     570        mr_asprintf(&command, "df -P %s | tail -n1 | cut -d' ' -f1",
     571                 bkpinfo->isodir);
    601572        log_it("command = %s", command);
    602         sprintf(iso_dev, "%s",
    603                 call_program_and_get_last_line_of_output(command));
     573        mr_asprintf(&iso_dev, call_program_and_get_last_line_of_output(command));
     574        mr_free(command);
    604575        log_it("res of it = %s", iso_dev);
    605576
     
    607578        mr_fprintf(fd1, "iso-dev=%s\n", iso_dev);
    608579
    609         sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
    610                 iso_dev);
     580        mr_asprintf(&command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3",
     581                 iso_dev);
     582        mr_free(iso_dev);
     583
    611584        log_it("command = %s", command);
    612         sprintf(iso_mnt, "%s",
    613                 call_program_and_get_last_line_of_output(command));
     585        mr_asprintf(&iso_mnt,call_program_and_get_last_line_of_output(command));
     586        mr_free(command);
    614587
    615588        log_it("res of it = %s", iso_mnt);
     
    617590        log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt));
    618591
    619         sprintf(iso_tmp, "%s", bkpinfo->isodir);
    620         if (strlen(iso_tmp) < strlen(iso_mnt)) {
    621             iso_path[0] = '\0';
     592        mr_asprintf(&iso_tmp, "%s", bkpinfo->isodir);
     593        if (strlen(iso_tmp) >= strlen(iso_mnt)) {
     594            mr_asprintf(&iso_path, "%s", iso_tmp + strlen(iso_mnt));
    622595        } else {
    623             sprintf(iso_path, "%s", iso_tmp + strlen(iso_mnt));
    624         }
     596            mr_asprintf(&iso_path, "");
     597        }
     598        mr_free(iso_tmp);
     599        mr_free(iso_mnt);
     600
    625601        log_it("isodir: %s", iso_path);
    626602        mr_fprintf(fd1, "isodir=%s\n", iso_path);
     603        mr_free(iso_path);
    627604
    628605        log_it("iso-prefix: %s",  bkpinfo->prefix);
     
    633610
    634611    if (bkpinfo->backup_media_type == nfs) {
    635         strcpy(hostname, bkpinfo->nfs_mount);
     612        mr_asprintf(&hostname, bkpinfo->nfs_mount);
    636613        colon = strchr(hostname, ':');
    637614        if (!colon) {
     
    648625                retval++;
    649626            } else {
    650                 strcpy(ip_address, inet_ntoa
    651                        ((struct in_addr)
    652                         *((struct in_addr *) hent->h_addr)));
    653                 strcat(ip_address, strchr(bkpinfo->nfs_mount, ':'));
     627                mr_asprintf(&ip_address, "%s%s", inet_ntoa((struct in_addr)
     628                                                *((struct in_addr *) hent->h_addr)),
     629                                                strchr(bkpinfo->nfs_mount, ':'));
    654630                strcpy(bkpinfo->nfs_mount, ip_address);
     631                mr_free(ip_address);
    655632            }
    656633        }
    657634        store_nfs_config(bkpinfo);
     635        mr_free(hostname);
    658636    }
    659637
     
    662640        fprintf(stderr, "Type 'man mondoarchive' for help.\n");
    663641    }
    664     sprintf(tmp, "%s", MONDO_TMPISOS);  /* added #define 22 apr 2002 */
     642    mr_asprintf(&tmp, "%s", MONDO_TMPISOS);
    665643    if (does_file_exist(tmp)) {
    666644        unlink(tmp);
    667645    }
     646    mr_free(tmp);
     647
    668648    if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) {
    669649        log_it("tmpdir or scratchdir are blank/missing");
     
    677657    chmod(bkpinfo->tmpdir, 0700);
    678658    g_backup_media_type = bkpinfo->backup_media_type;
    679     mr_free(mtpt);
    680     mr_free(extra_cdrom_params);
    681     mr_free(mondo_mkisofs_sz);
    682     mr_free(command);
    683     mr_free(hostname);
    684     mr_free(ip_address);
    685     mr_free(cdr_exe);
    686     mr_free(tmp);
    687     mr_free(iso_dev);
    688     mr_free(iso_mnt);
    689     mr_free(iso_tmp);
    690     mr_free(iso_path);
     659    g_backup_media_string = bkpinfo->backup_media_string;
    691660    return (retval);
    692661}
    693 
    694662
    695663
     
    745713
    746714    mr_msg(1, "Hi");
     715
    747716    assert(bkpinfo != NULL);
     717    /* BERLIOS : Useless ?? */
    748718    memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo));
     719
    749720    bkpinfo->manual_cd_tray = FALSE;
    750721    bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
     
    769740        strcpy(bkpinfo->isodir, "/");
    770741    } else {
    771         strcpy(bkpinfo->isodir, "/root/images/mondo");
     742        strcpy(bkpinfo->isodir, "/var/cache/mondo/iso");
    772743    }
    773744    strcpy(bkpinfo->prefix, STD_PREFIX);
     
    778749    bkpinfo->optimal_set_size = 0;
    779750    bkpinfo->backup_media_type = none;
     751    bkpinfo->backup_media_string[0] = '\0';
    780752    strcpy(bkpinfo->include_paths, "/");
    781753    bkpinfo->exclude_paths[0] = '\0';
     
    799771
    800772
    801 
    802 
    803773/**
    804774 * Get the remaining free space (in MB) on @p partition.
     
    808778long free_space_on_given_partition(char *partition)
    809779{
    810     char command[MAX_STR_LEN], out_sz[MAX_STR_LEN];
    811     long res;
     780    char *command = NULL;
     781    char *out_sz = NULL;
     782    long res = 0L;
    812783
    813784    assert_string_is_neither_NULL_nor_zerolength(partition);
    814785
    815     sprintf(command, "df -m -P %s &> /dev/null", partition);
     786    mr_asprintf(&command, "df -m -P %s &> /dev/null", partition);
    816787    if (system(command)) {
    817788        return (-1);
    818789    }                           // partition does not exist
    819     sprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
     790    mr_free(command);
     791
     792    mr_asprintf(&command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
    820793            partition);
    821     strcpy(out_sz, call_program_and_get_last_line_of_output(command));
     794    mr_asprintf(&out_sz, call_program_and_get_last_line_of_output(command));
     795    mr_free(command);
     796
    822797    if (strlen(out_sz) == 0) {
    823798        return (-1);
    824799    }                           // error within df, probably
    825800    res = atol(out_sz);
     801    mr_free(out_sz);
    826802    return (res);
    827803}
    828 
    829804
    830805
     
    845820
    846821    /*@ buffers ************ */
    847     char tmp[MAX_STR_LEN];
     822    char *tmp = NULL;
    848823
    849824    /*@ int's *************** */
     
    852827
    853828
    854     mvaddstr_and_log_it(g_currentY, 0, "Checking sanity of your Linux distribution");
     829    mvaddstr_and_log_it(g_currentY, 0,
     830                        "Checking sanity of your Linux distribution");
    855831#ifndef __FreeBSD__
    856832    if (system("which mkfs.vfat &> /dev/null")
     
    861837            ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
    862838    }
    863     strcpy(tmp,
     839    mr_asprintf(&tmp,
    864840           call_program_and_get_last_line_of_output
    865841           ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
    866842    if (atol(tmp) < 35000) {
    867843        retval++;
    868         log_to_screen("You must have at least 32MB of RAM to use Mondo.");
     844        log_to_screen(_("You must have at least 32MB of RAM to use Mondo."));
    869845    }
    870846    if (atol(tmp) < 66000) {
    871847        log_to_screen
    872             ("WARNING! You have very little RAM. Please upgrade to 64MB or more.");
    873     }
     848            (_("WARNING! You have very little RAM. Please upgrade to 64MB or more."));
     849    }
     850    mr_free(tmp);
    874851#endif
    875852
     
    878855
    879856    if (Lres < 50) {
    880               fatal_error("Your /var/cache partition has <50MB free. Please adjust your partition table to something saner.");
     857        fatal_error("Your /var/cache partition has <50MB free. Please adjust your partition table to something saner.");
    881858    }
    882859
     
    892869        ("grep ramdisk /proc/devices", FALSE)) {
    893870        if (!ask_me_yes_or_no
    894             ("Your kernel has no ramdisk support. That's mind-numbingly stupid but I'll allow it if you're planning to use a failsafe kernel. Are you?"))
     871            (_("Your kernel has no ramdisk support. That's mind-numbingly stupid but I'll allow it if you're planning to use a failsafe kernel. Are you?")))
    895872        {
    896873            //          retval++;
    897874            log_to_screen
    898                 ("It looks as if your kernel lacks ramdisk and initrd support.");
     875                (_("It looks as if your kernel lacks ramdisk and initrd support."));
    899876            log_to_screen
    900                 ("I'll allow you to proceed but FYI, if I'm right, your kernel is broken.");
     877                (_("I'll allow you to proceed but FYI, if I'm right, your kernel is broken."));
    901878        }
    902879    }
     
    921898        !run_program_and_log_output
    922899        ("mount | grep -w dos | grep -vE \"/dev/fd|nexdisk\"", 0)) {
    923         log_to_screen("I think you have a Windows 9x partition.");
     900        log_to_screen(_("I think you have a Windows 9x partition."));
    924901        retval += whine_if_not_found("parted");
    925902#ifndef __IA64__
     
    946923    run_program_and_log_output
    947924        ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
    948     strcpy(tmp,
     925    mr_asprintf(&tmp,
    949926           call_program_and_get_last_line_of_output
    950927           ("mount | grep -E \"cdr(om|w)\""));
     
    952929        if (strstr(tmp, "autofs")) {
    953930            log_to_screen
    954                 ("Your CD-ROM is mounted via autofs. I therefore cannot tell");
     931                (_("Your CD-ROM is mounted via autofs. I therefore cannot tell"));
    955932            log_to_screen
    956                 ("if a CD actually is inserted. If a CD is inserted, please");
    957             log_to_screen("eject it. Thank you.");
     933                (_("if a CD actually is inserted. If a CD is inserted, please"));
     934            log_to_screen(_("eject it. Thank you."));
    958935            log_it
    959936                ("Ignoring autofs CD-ROM 'mount' since we hope nothing's in it.");
     
    965942        }
    966943    }
     944    mr_free(tmp);
    967945#ifndef __FreeBSD__
    968946    if (!does_file_exist("/etc/modules.conf")) {
     
    981959            retval++;
    982960            log_to_screen
    983                 ("Please find out what happened to /etc/modules.conf");
     961                (_("Please find out what happened to /etc/modules.conf"));
    984962        }
    985963    }
     
    994972
    995973    if (run_program_and_log_output("mindi -V", 1)) {
    996         log_to_screen("Could not ascertain mindi's version number.");
     974        log_to_screen(_("Could not ascertain mindi's version number."));
    997975        log_to_screen
    998             ("You have not installed Mondo and/or Mindi properly.");
    999         log_to_screen("Please uninstall and reinstall them both.");
     976            (_("You have not installed Mondo and/or Mindi properly."));
     977        log_to_screen(_("Please uninstall and reinstall them both."));
    1000978        fatal_error("Please reinstall Mondo and Mindi.");
    1001979    }
     
    1003981        ("mindi --makemountlist /tmp/mountlist.txt.test", 5)) {
    1004982        log_to_screen
    1005             ("Mindi --makemountlist /tmp/mountlist.txt.test failed for some reason.");
     983            (_("Mindi --makemountlist /tmp/mountlist.txt.test failed for some reason."));
    1006984        log_to_screen
    1007             ("Please run that command by hand and examine /var/log/mindi.log");
     985            (_("Please run that command by hand and examine /var/log/mindi.log"));
    1008986        log_to_screen
    1009             ("for more information. Perhaps your /etc/fstab file is insane.");
     987            (_("for more information. Perhaps your /etc/fstab file is insane."));
    1010988        log_to_screen
    1011             ("Perhaps Mindi's MakeMountlist() subroutine has a bug. We'll see.");
     989            (_("Perhaps Mindi's MakeMountlist() subroutine has a bug. We'll see."));
    1012990        retval++;
    1013991    }
     
    1016994        && !does_file_exist("/etc/raidtab")) {
    1017995        log_to_screen
    1018             ("You have RAID partitions but no /etc/raidtab - creating one from /proc/mdstat");
     996            (_("You have RAID partitions but no /etc/raidtab - creating one from /proc/mdstat"));
    1019997        create_raidtab_from_mdstat("/etc/raidtab");
    1020998    }
    1021999
    10221000    if (retval) {
    1023         mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     1001        mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
    10241002    } else {
    1025         mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     1003        mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
    10261004    }
    10271005    return (retval);
     
    10381016{
    10391017    /*@ buffer ****************************************************** */
    1040     char command[MAX_STR_LEN * 2];
    1041     char tmp[MAX_STR_LEN];
     1018    char *command = NULL;
     1019    char *tmp = NULL;
    10421020
    10431021    /*@ end vars *************************************************** */
     
    10451023    assert_string_is_neither_NULL_nor_zerolength(config_file);
    10461024    assert_string_is_neither_NULL_nor_zerolength(label);
     1025
    10471026    if (!does_file_exist(config_file)) {
    1048         sprintf(tmp, "(read_cfg_var) Cannot find %s config file",
    1049                 config_file);
     1027        mr_asprintf(&tmp, "(read_cfg_var) Cannot find %s config file",
     1028                 config_file);
    10501029        log_to_screen(tmp);
     1030        mr_free(tmp);
    10511031        value[0] = '\0';
    10521032        return (1);
    1053     } else if (strstr(value, "/dev/") && strstr(value, "t0")
     1033    /* } BERLIOS: Useless:
     1034         else if (strstr(value, "/dev/") && strstr(value, "t0")
    10541035               && !strcmp(label, "media-dev")) {
    10551036        mr_msg(2, "FYI, I shan't read new value for %s - already got %s",
    10561037                label, value);
    10571038        return (0);
    1058     } else {
    1059         sprintf(command, "grep '%s .*' %s| cut -d'=' -f2,3,4,5",
     1039    */ } else {
     1040        mr_asprintf(&command, "grep '%s .*' %s| cut -d'=' -f2,3,4,5",
    10601041                label, config_file);
    10611042        strcpy(value, call_program_and_get_last_line_of_output(command));
     1043        mr_free(command);
    10621044        if (strlen(value) == 0) {
    10631045            return (1);
     
    10691051
    10701052
    1071 
    10721053/**
    10731054 * Remount @c supermount if it was unmounted earlier.
     
    11011082
    11021083/**
    1103  * Whether we had to stop autofs (if so, restart it at end).
    1104  */
    1105 bool g_autofs_stopped = FALSE;
    1106 
    1107 /**
    1108  * Path to the autofs initscript ("" if none exists).
    1109  */
    1110 char g_autofs_exe[MAX_STR_LEN];
    1111 
    1112 /**
    1113  * Autofs initscript in Xandros Linux distribution.
    1114  */
    1115 #define XANDROS_AUTOFS_FNAME "/etc/init.d/xandros-autofs"
    1116 
    1117 /**
    1118  * Autofs initscript in most Linux distributions.
    1119  */
    1120 #define STOCK_AUTOFS_FNAME "/etc/rc.d/init.d/autofs"
    1121 
    1122 /**
    1123  * If autofs is mounted, stop it (restart at end).
    1124  */
    1125 void stop_autofs_if_necessary()
    1126 {
    1127     char tmp[MAX_STR_LEN];
    1128 
    1129     g_autofs_exe[0] = '\0';
    1130     if (does_file_exist(XANDROS_AUTOFS_FNAME)) {
    1131         strcpy(g_autofs_exe, XANDROS_AUTOFS_FNAME);
    1132     } else if (does_file_exist(STOCK_AUTOFS_FNAME)) {
    1133         strcpy(g_autofs_exe, STOCK_AUTOFS_FNAME);
    1134     }
    1135 
    1136     if (!g_autofs_exe[0]) {
    1137         mr_msg(3, "No autofs detected.");
    1138     } else {
    1139         mr_msg(3, "%s --- autofs detected", g_autofs_exe);
    1140 // FIXME -- only disable it if it's running ---  sprintf(tmp, "%s status", autofs_exe);
    1141         sprintf(tmp, "%s stop", g_autofs_exe);
    1142         if (run_program_and_log_output(tmp, 2)) {
    1143             log_it("Failed to stop autofs - I assume it wasn't running");
    1144         } else {
    1145             g_autofs_stopped = TRUE;
    1146             log_it("Stopped autofs OK");
    1147         }
    1148     }
    1149 }
    1150 
    1151 /**
    1152  * If autofs was stopped earlier, restart it.
    1153  */
    1154 void restart_autofs_if_necessary()
    1155 {
    1156     char tmp[MAX_STR_LEN];
    1157 
    1158     if (!g_autofs_stopped || !g_autofs_exe[0]) {
    1159         mr_msg(3, "No autofs detected.");
    1160         return;
    1161     }
    1162     sprintf(tmp, "%s start", g_autofs_exe);
    1163     if (run_program_and_log_output(tmp, 2)) {
    1164         log_it("Failed to start autofs");
    1165     } else {
    1166         g_autofs_stopped = FALSE;
    1167         log_it("Started autofs OK");
    1168     }
    1169 }
    1170 
    1171 
    1172 /**
    11731084 * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it.
    11741085 */
    11751086void mount_boot_if_necessary()
    11761087{
    1177     char tmp[MAX_STR_LEN];
    1178     char command[MAX_STR_LEN];
     1088    char *tmp = NULL;
     1089    char *tmp1 = NULL;
     1090    char *command = NULL;
    11791091
    11801092    mr_msg(1, "Started sub");
    11811093    mr_msg(4, "About to set g_boot_mountpt[0] to '\\0'");
    11821094    g_boot_mountpt[0] = '\0';
    1183     mr_msg(4, "Done. Great. Seeting command to something");
    1184     strcpy(command,
    1185            "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[   ]/boot[     ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
     1095    mr_msg(4, "Done. Great. Setting command to something");
     1096    mr_asprintf(&command,
     1097             "grep -v ':' /etc/fstab | grep -vE '^#.*$' | grep -E \"[   ]/boot[     ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");
    11861098    mr_msg(4, "Cool. Command = '%s'", command);
    1187     strcpy(tmp, call_program_and_get_last_line_of_output(command));
     1099    mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     1100    mr_free(command);
     1101
    11881102    mr_msg(4, "tmp = '%s'", tmp);
    11891103    if (tmp[0]) {
     
    11971111            }
    11981112        } else {
    1199             sprintf(command, "mount | grep -E '^%s'", tmp);
     1113            mr_asprintf(&command, "mount | grep -E '^%s'", tmp);
    12001114            mr_msg(3, "command = %s", command);
    12011115            if (run_program_and_log_output(command, 5)) {
    12021116                strcpy(g_boot_mountpt, tmp);
    1203                 sprintf(tmp,
     1117                mr_asprintf(&tmp1,
    12041118                        "%s (your /boot partition) is not mounted. I'll mount it before backing up",
    12051119                        g_boot_mountpt);
    1206                 log_it(tmp);
    1207                 sprintf(tmp, "mount %s", g_boot_mountpt);
    1208                 if (run_program_and_log_output(tmp, 5)) {
     1120                log_it(tmp1);
     1121                mr_free(tmp1);
     1122
     1123                mr_asprintf(&tmp1, "mount %s", g_boot_mountpt);
     1124                if (run_program_and_log_output(tmp1, 5)) {
    12091125                    g_boot_mountpt[0] = '\0';
    12101126                    mr_msg(1, "Plan B");
     
    12171133                    }
    12181134                }
     1135                mr_free(tmp1);
    12191136            }
    1220         }
    1221     }
     1137            mr_free(command);
     1138        }
     1139    }
     1140    mr_free(tmp);
    12221141    mr_msg(1, "Ended sub");
    12231142}
     
    12291148void unmount_boot_if_necessary()
    12301149{
    1231     char tmp[MAX_STR_LEN];
     1150    char *tmp;
    12321151
    12331152    mr_msg(3, "starting");
    12341153    if (g_boot_mountpt[0]) {
    1235         sprintf(tmp, "umount %s", g_boot_mountpt);
     1154        mr_asprintf(&tmp, "umount %s", g_boot_mountpt);
    12361155        if (run_program_and_log_output(tmp, 5)) {
    12371156            log_it("WARNING - unable to unmount /boot");
    12381157        }
     1158        mr_free(tmp);
    12391159    }
    12401160    mr_msg(3, "leaving");
    12411161}
    1242 
    12431162
    12441163
     
    12541173{
    12551174    /*@ buffers ***************************************************** */
    1256     char command[MAX_STR_LEN * 2];
    1257     char tempfile[MAX_STR_LEN];
    1258     char tmp[MAX_STR_LEN];
     1175    char *command = NULL;
     1176    char *tempfile = NULL;
     1177    char *tmp = NULL;
    12591178
    12601179
     
    12631182    assert_string_is_neither_NULL_nor_zerolength(label);
    12641183    assert(value != NULL);
     1184
    12651185    if (!does_file_exist(config_file)) {
    1266         sprintf(tmp, "(write_cfg_file) Cannot find %s config file",
    1267                 config_file);
     1186        mr_asprintf(&tmp, "(write_cfg_file) Cannot find %s config file",
     1187                 config_file);
    12681188        log_to_screen(tmp);
     1189        mr_free(tmp);
    12691190        return (1);
    12701191    }
    1271     strcpy(tempfile,
     1192    mr_asprintf(&tempfile,
    12721193           call_program_and_get_last_line_of_output
    12731194           ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX"));
    12741195    if (does_file_exist(config_file)) {
    1275         sprintf(command, "grep -vE '^%s .*$' %s > %s",
     1196        mr_asprintf(&command, "grep -vE '^%s .*$' %s > %s",
    12761197                label, config_file, tempfile);
    12771198        paranoid_system(command);
    1278     }
    1279     sprintf(command, "echo \"%s %s\" >> %s", label, value, tempfile);
     1199        mr_free(command);
     1200    }
     1201    mr_asprintf(&command, "echo \"%s %s\" >> %s", label, value, tempfile);
    12801202    paranoid_system(command);
    1281     sprintf(command, "mv -f %s %s", tempfile, config_file);
     1203    mr_free(command);
     1204
     1205    mr_asprintf(&command, "mv -f %s %s", tempfile, config_file);
    12821206    paranoid_system(command);
     1207    mr_free(command);
    12831208    unlink(tempfile);
     1209    mr_free(tempfile);
    12841210    return (0);
    12851211}
    12861212
    1287 
    1288 /**
    1289  * If @p y, malloc @p x, else free @p x.
    1290  * @bug This function seems orphaned. Please remove.
    1291  */
    1292 #define do_alloc_or_free_depending(x,y) { if(y) {x=mr_malloc(MAX_STR_LEN);} else {mr_free(x);} }
    12931213
    12941214/**
     
    13581278void restart_magicdev_if_necessary()
    13591279{
    1360     char *tmp;
    1361 
    1362     malloc_string(tmp);
     1280    char *tmp = NULL;
     1281
    13631282    if (g_magicdev_command && g_magicdev_command[0]) {
    1364         sprintf(tmp, "%s &", g_magicdev_command);
     1283        mr_asprintf(&tmp, "%s &", g_magicdev_command);
    13651284        paranoid_system(tmp);
    1366     }
    1367     mr_free(tmp);
     1285        mr_free(tmp);
     1286    }
    13681287}
    13691288
Note: See TracChangeset for help on using the changeset viewer.