Changeset 1178


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

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

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

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/common/libmondo-string-EXT.h

    r1168 r1178  
    1010                                      int lino);
    1111extern long friendly_sizestr_to_sizelong(char *incoming);
    12 extern char *leftpad_string(char *incoming, int width);
    1312extern char *marker_to_string(int marker);
    1413extern char *mountlist_entry_to_string(struct mountlist_itself *mountlist,
  • branches/stable/mondo/src/common/libmondo-string.c

    r1168 r1178  
    1 /* $Id$ */
    2 
     1/*
     2   $Id$
     3*/
    34
    45/**
     
    1415#include "libmondo-string.h"
    1516#include "libmondo-files-EXT.h"
    16 #include "libmondo-gui-EXT.h"
     17#include "newt-specific-EXT.h"
    1718#include "libmondo-tools-EXT.h"
     19#include <math.h>
    1820
    1921/*@unused@*/
     
    2224extern int g_current_media_number;
    2325extern long long g_tape_posK;
    24 
    2526
    2627/**
     
    3839char *build_partition_name(char *partition, const char *drive, int partno)
    3940{
    40     char *p, *c;
     41    char *p = NULL;
     42    char *c = NULL;
    4143
    4244    assert(partition != NULL);
     
    4951    if (c && strncmp(c, "/disc", 5) == 0) {
    5052        /* yup it's devfs, return the "part" path */
     53        /* format /dev/.../disc */
    5154        strcpy(c + 1, "part");
    5255        p = c + 5;
     
    6770
    6871
    69 
    70 
    71 
    72 
    73 
    74 
    75 
    76 
    77 
    78 
    79 
    8072/**
    8173 * Pad a string on both sides so it appears centered.
     
    8577void center_string(char *in_out, int width)
    8678{
    87     char scratch[MAX_STR_LEN];
    88     char *p;
    89     int i;                      /* purpose */
    90     int len;                    /* purpose */
    91     int mid;                    /* purpose */
    92     int x;                      /* purpose */
     79    char *scratch = NULL;
     80    char *out = NULL;
     81    char *p = NULL;
     82    int i = 0;                      /* purpose */
     83    int len = 0;                    /* purpose */
     84    int mid = 0;                    /* purpose */
     85    int x = 0;                      /* purpose */
    9386
    9487    assert(in_out != NULL);
     
    9891        return;
    9992    }
    100     for (p = in_out; *p == ' '; p++);
    101     strcpy(scratch, p);
    102     mr_strip_spaces (scratch);
     93    mr_asprintf(&scratch, in_out);
     94    mr_strip_spaces(scratch);
    10395    len = (int) strlen(scratch);
    10496    mid = width / 2;
     
    129121    *q = *p;                    // for the final '\0'
    130122}
    131 
    132 
    133 
    134 /**
    135  * Add commas every third place in @p input.
    136  * @param input The string to commarize.
    137  * @return The string with commas.
    138  * @note The returned string points to static storage that will be overwritten with each call.
    139  */
    140 char *commarize(char *input)
    141 {
    142     char pos_w_commas[MAX_STR_LEN];
    143     static char output[MAX_STR_LEN];
    144     char tmp[MAX_STR_LEN];
    145     int j;
    146 
    147     assert(input != NULL);
    148 
    149     strcpy(tmp, input);
    150     if (strlen(tmp) > 6) {
    151         strcpy(pos_w_commas, tmp);
    152         j = (int) strlen(pos_w_commas);
    153         tmp[j - 6] = ',';
    154         strcpy(tmp + j - 5, pos_w_commas + j - 6);
    155 //      tmp[j-2] = ',';
    156 //      strcpy(tmp+j-1, pos_w_commas+j-3);
    157         strcpy(pos_w_commas, tmp);
    158     }
    159     if (strlen(tmp) > 3) {
    160         j = (int) strlen(tmp);
    161         strcpy(pos_w_commas, tmp);
    162         pos_w_commas[j - 3] = ',';
    163         strcpy(pos_w_commas + j - 2, tmp + j - 3);
    164     } else {
    165         strcpy(pos_w_commas, tmp);
    166     }
    167     strcpy(output, pos_w_commas);
    168     return (output);
    169 }
    170 
    171 
    172 
    173 
    174 
    175 
    176 
    177123
    178124
     
    201147
    202148
    203 
    204 
    205 
    206149/**
    207150 * Turn a "friendly" sizestring into a number of megabytes.
     
    213156long friendly_sizestr_to_sizelong(char *incoming)
    214157{
    215     long outval;
    216     int i;
    217     char *tmp;
    218     char ch;
     158    long outval = 0L;
     159    int i = 0;
     160    char *tmp = NULL;
     161    char ch = ' ';
    219162
    220163    assert_string_is_neither_NULL_nor_zerolength(incoming);
    221164
    222     malloc_string(tmp);
    223165    if (!incoming[0]) {
    224         mr_free(tmp);
    225         return (0);
     166        return(0L);
    226167    }
    227168    if (strchr(incoming, '.')) {
    228169        fatal_error("Please use integers only. No decimal points.");
    229170    }
    230     strcpy(tmp, incoming);
     171    mr_asprintf(&tmp, "%s", incoming);
    231172    i = (int) strlen(tmp);
    232173    if (tmp[i - 1] == 'B' || tmp[i - 1] == 'b') {
     
    237178    tmp[i] = '\0';
    238179    outval = atol(tmp);
     180    mr_free(tmp);
     181
    239182    if (ch == 'g' || ch == 'G') {
    240183        outval = outval * 1024;
     
    249192            ("Oh my gosh. You actually think a YOTTABYTE will get you anywhere? What're you going to do with 1,208,925,819,614,629,174,706,176 bytes of data?!?!");
    250193        popup_and_OK
    251             ("That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)");
     194            (_("That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)"));
    252195        fatal_error("Integer overflow.");
    253196    } else if (ch != 'm' && ch != 'M') {
    254         sprintf(tmp, "Re: parameter '%s' - bad multiplier ('%c')",
    255                 incoming, ch);
     197        mr_asprintf(&tmp, "Re: parameter '%s' - bad multiplier ('%c')",
     198                 incoming, ch);
    256199        fatal_error(tmp);
    257200    }
    258     mr_free(tmp);
    259201    return (outval);
    260202}
    261 
    262 
    263 
    264 /**
    265  * Add spaces to the right of @p incoming to make it @p width characters wide.
    266  * @param incoming The string to left-pad.
    267  * @param width The width to pad it to.
    268  * @return The left-padded string.
    269  * @note The returned string points to static storage that will be overwritten with each call.
    270  * @bug Why does center_string() modify its argument but leftpad_string() returns a modified copy?
    271  */
    272 char *leftpad_string(char *incoming, int width)
    273 {
    274     /*@ buffers ***************************************************** */
    275     static char output[MAX_STR_LEN];
    276 
    277     /*@ ints ******************************************************** */
    278     int i;
    279 
    280     /*@ end vars **************************************************** */
    281     assert(incoming != NULL);
    282     assert(width > 2);
    283 
    284     strcpy(output, incoming);
    285     for (i = (int) strlen(output); i < width; i++) {
    286         output[i] = ' ';
    287     }
    288     output[i] = '\0';
    289     return (output);
    290 }
    291 
    292203
    293204
     
    374285    return (outstr);
    375286}
    376 
    377 
    378287
    379288
     
    405314
    406315
    407 
    408 
    409 
    410 
    411316/**
    412317 * Generate a friendly string containing "X blah blah disk(s)"
     
    424329
    425330    /*@ char     ******************************************************** */
    426     char p;
     331    char p = NULL;
    427332
    428333    assert(label != NULL);
     
    495400    return (output);
    496401}
    497 
    498 
    499402
    500403
     
    530433    mr_free(input);
    531434}
    532 
    533 
    534 
    535435
    536436
     
    555455    /*@ buffers **************************************************** */
    556456    static char output[MAX_STR_LEN];
    557     static char suffix[MAX_STR_LEN];
     457    char *suffix = NULL;
    558458
    559459    /*@ end vars *************************************************** */
     
    561461    assert_string_is_neither_NULL_nor_zerolength(path);
    562462    if (s[0] != '\0') {
    563         sprintf(suffix, ".%s", s);
     463        mr_asprintf(&suffix, ".%s", s);
    564464    } else {
    565         suffix[0] = '\0';
     465        mr_asprintf(&suffix, "");
    566466    }
    567467    sprintf(output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno, sliceno,
    568468            suffix);
     469    mr_free(suffix);
    569470    return (output);
    570471}
     
    597498
    598499
    599 
    600 
    601500/**
    602501 * Wrap @p flaws_str across three lines. The first two are no more than 74 characters wide.
     
    650549
    651550
    652 
    653551/**
    654552 * Compare @p stringA and @p stringB. This uses an ASCII sort for everything
     
    698596    numA = atol(stringA + start_of_numbers_in_A);
    699597    numB = atol(stringB + start_of_numbers_in_B);
    700     /*
    701        sprintf(tmp,"Comparing %s and %s --> %ld,%ld\n",stringA,stringB,numA,numB);
    702        log_to_screen(tmp);
    703      */
    704598    return ((int) (numA - numB));
    705599}
     
    773667{
    774668    int i = strlen(partition) - 1;
    775     char *c;
     669    char *c = NULL;
    776670
    777671#ifdef __FreeBSD__
     
    793687    if (c && strncmp(c, "/part", 5) == 0) {
    794688        /* yup it's devfs, return the "disc" path */
    795         strcpy(c + 1, "disc");
     689        strncpy(c + 1, "disc", (size_t)5);
    796690        return partition;
    797691    }
     
    808702    return partition;
    809703}
    810 
    811 
    812 
    813704
    814705
     
    838729
    839730
    840 
    841 
    842 
    843 
    844 
    845 
    846 
    847731/**
    848732 * Determine the severity (1-3, 1 being low) of the fact that
     
    854738int severity_of_difference(char *fn, char *out_reason)
    855739{
    856     int sev;
    857     char *reason;
    858     char *filename;
    859 
    860     malloc_string(reason);
    861     malloc_string(filename);
    862 // out_reason might be null on purpose, so don't bomb if it is :) OK?
     740    int sev = 0;
     741    char *reason = NULL;
     742    char *filename = NULL;
     743
     744    // out_reason might be null on purpose, so don't bomb if it is :) OK?
    863745    assert_string_is_neither_NULL_nor_zerolength(fn);
    864746    if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING))) {
    865         strcpy(filename, fn + strlen(MNT_RESTORING));
     747        mr_asprintf(&filename, fn + strlen(MNT_RESTORING));
    866748    } else if (fn[0] != '/') {
    867         sprintf(filename, "/%s", fn);
     749        mr_asprintf(&filename, "/%s", fn);
    868750    } else {
    869         strcpy(filename, fn);
    870     }
    871 
    872     sev = 3;
    873     sprintf(reason,
    874             "Changed since backup. Consider running a differential backup in a day or two.");
     751        mr_asprintf(&filename, fn);
     752    }
     753
    875754    if (!strncmp(filename, "/var/", 5)) {
    876755        sev = 2;
    877         sprintf(reason,
    878                 "/var's contents will change regularly, inevitably.");
     756        mr_asprintf(&reason,
     757                 _("/var's contents will change regularly, inevitably."));
    879758    }
    880759    if (!strncmp(filename, "/home", 5)) {
    881760        sev = 2;
    882         sprintf(reason,
    883                 "It's in your /home partiton. Therefore, it is important.");
     761        mr_asprintf(&reason,
     762                 _("It's in your /home partiton. Therefore, it is important."));
    884763    }
    885764    if (!strncmp(filename, "/usr/", 5)) {
    886765        sev = 3;
    887         sprintf(reason,
    888                 "You may have installed/removed software during the backup.");
     766        mr_asprintf(&reason,
     767                 _("You may have installed/removed software during the backup."));
    889768    }
    890769    if (!strncmp(filename, "/etc/", 5)) {
    891770        sev = 3;
    892         sprintf(reason,
    893                 "Do not edit config files while backing up your PC.");
     771        mr_asprintf(&reason,
     772                 _("Do not edit config files while backing up your PC."));
    894773    }
    895774    if (!strcmp(filename, "/etc/adjtime")
    896775        || !strcmp(filename, "/etc/mtab")) {
    897776        sev = 1;
    898         sprintf(reason, "This file changes all the time. It's OK.");
     777        mr_asprintf(&reason, _("This file changes all the time. It's OK."));
    899778    }
    900779    if (!strncmp(filename, "/root/", 6)) {
    901780        sev = 3;
    902         sprintf(reason, "Were you compiling/editing something in /root?");
     781        mr_asprintf(&reason,
     782                 _("Were you compiling/editing something in /root?"));
    903783    }
    904784    if (!strncmp(filename, "/root/.", 7)) {
    905785        sev = 2;
    906         sprintf(reason, "Temp or 'dot' files changed in /root.");
     786        mr_asprintf(&reason, _("Temp or 'dot' files changed in /root."));
    907787    }
    908788    if (!strncmp(filename, "/var/lib/", 9)) {
    909789        sev = 2;
    910         sprintf(reason, "Did you add/remove software during backing?");
     790        mr_asprintf(&reason, _("Did you add/remove software during backing?"));
    911791    }
    912792    if (!strncmp(filename, "/var/lib/rpm", 12)) {
    913793        sev = 3;
    914         sprintf(reason, "Did you add/remove software during backing?");
     794        mr_asprintf(&reason, _("Did you add/remove software during backing?"));
    915795    }
    916796    if (!strncmp(filename, "/var/lib/slocate", 16)) {
    917797        sev = 1;
    918         sprintf(reason,
    919                 "The 'update' daemon ran during backup. This does not affect the integrity of your backup.");
     798        mr_asprintf(&reason,
     799                 _("The 'update' daemon ran during backup. This does not affect the integrity of your backup."));
    920800    }
    921801    if (!strncmp(filename, "/var/log/", 9)
     
    923803        || !strcmp(filename + strlen(filename) - 4, ".log")) {
    924804        sev = 1;
    925         sprintf(reason,
    926                 "Log files change frequently as the computer runs. Fret not.");
     805        mr_asprintf(&reason,
     806                 _("Log files change frequently as the computer runs. Fret not."));
    927807    }
    928808    if (!strncmp(filename, "/var/spool", 10)) {
    929809        sev = 1;
    930         sprintf(reason,
    931                 "Background processes or printers were active. This does not affect the integrity of your backup.");
     810        mr_asprintf(&reason,
     811                 _("Background processes or printers were active. This does not affect the integrity of your backup."));
    932812    }
    933813    if (!strncmp(filename, "/var/spool/mail", 10)) {
    934814        sev = 2;
    935         sprintf(reason, "Mail was sent/received during backup.");
     815        mr_asprintf(&reason, _("Mail was sent/received during backup."));
    936816    }
    937817    if (filename[strlen(filename) - 1] == '~') {
    938818        sev = 1;
    939         sprintf(reason,
    940                 "Backup copy of another file which was modified recently.");
     819        mr_asprintf(&reason,
     820                 _("Backup copy of another file which was modified recently."));
    941821    }
    942822    if (strstr(filename, "cache")) {
    943823        sev = 1;
    944         sprintf(reason,
    945                 "Part of a cache of data. Caches change from time to time. Don't worry.");
     824        mr_asprintf(&reason,
     825                 _("Part of a cache of data. Caches change from time to time. Don't worry."));
    946826    }
    947827    if (!strncmp(filename, "/var/run/", 9)
     
    950830        || strstr(filename, "/.Xauthority")) {
    951831        sev = 1;
    952         sprintf(reason,
    953                 "Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence.");
     832        mr_asprintf(&reason,
     833                _("Temporary file (a lockfile, perhaps) used by software such as X or KDE to register its presence."));
     834    }
     835    mr_free(filename);
     836
     837    if (sev == 0) {
     838        sev = 3;
     839        mr_asprintf(&reason,
     840                 _("Changed since backup. Consider running a differential backup in a day or two."));
    954841    }
    955842    if (out_reason) {
    956843        strcpy(out_reason, reason);
    957844    }
    958     mr_free(filename);
     845
    959846    mr_free(reason);
    960847    return (sev);
    961848}
    962 
    963849
    964850
     
    982868    return (res);
    983869}
    984 
    985 
    986 
    987 
    988 
    989870
    990871
     
    1002883{
    1003884    /*@ int *********************************************** */
    1004     int percentage;
    1005     int j;
     885    int percentage = 0;
     886    int i = 0;
     887    int j = 0;
    1006888
    1007889    /*@ buffers ******************************************* */
    1008890    static char outstr[MAX_STR_LEN];
    1009     char *pos_w_commas, *tmp;
    1010891
    1011892    assert(bkpinfo != NULL);
    1012     malloc_string(pos_w_commas);
    1013     malloc_string(tmp);
    1014     sprintf(tmp, "%lld", g_tape_posK);
    1015     strcpy(pos_w_commas, commarize(tmp));
    1016 
    1017 
    1018 
    1019     if (bkpinfo->media_size[g_current_media_number] <= 0)
    1020 //    { fatal_error( "percentage_media_full_comment() - unknown media size"); }
    1021     {
    1022         sprintf(outstr, "Volume %d: %s kilobytes archived so far",
    1023                 g_current_media_number, pos_w_commas);
     893
     894    if (bkpinfo->media_size[g_current_media_number] <= 0) {
     895        sprintf(outstr, _("Volume %d: %'lld kilobytes archived so far"),
     896                g_current_media_number, g_tape_posK);
    1024897        return (outstr);
    1025898    }
    1026899
    1027 /* update screen */
     900    /* update screen */
    1028901    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    1029902        percentage =
     
    1033906            percentage = 100;
    1034907        }
    1035         sprintf(outstr, "Volume %d: [", g_current_media_number);
     908        sprintf(outstr, _("Volume %d: ["), g_current_media_number);
    1036909    } else {
    1037910        percentage =
     
    1039912                   bkpinfo->media_size[g_current_media_number]);
    1040913        sprintf(outstr, "%s %d: [",
    1041                 media_descriptor_string(bkpinfo->backup_media_type),
     914                bkpinfo->backup_media_string,
    1042915                g_current_media_number);
    1043916    }
     
    1050923    j = (int) strlen(outstr);
    1051924    sprintf(outstr + j, "] %d%% used", percentage);
    1052     mr_free(pos_w_commas);
    1053     mr_free(tmp);
    1054925    return (outstr);
    1055926}
     927
     928
    1056929
    1057930/**
     
    1063936char *media_descriptor_string(t_bkptype type_of_bkp)
    1064937{
    1065     static char *type_of_backup = NULL;
    1066 
    1067     if (!type_of_backup) {
    1068         malloc_string(type_of_backup);
    1069     }
    1070 
    1071     switch (type_of_bkp) {
    1072     case dvd:
    1073         strcpy(type_of_backup, "DVD");
    1074         break;
    1075     case cdr:
    1076         strcpy(type_of_backup, "CDR");
    1077         break;
    1078     case cdrw:
    1079         strcpy(type_of_backup, "CDRW");
    1080         break;
    1081     case tape:
    1082         strcpy(type_of_backup, "tape");
    1083         break;
    1084     case cdstream:
    1085         strcpy(type_of_backup, "CDR");
    1086         break;
    1087     case udev:
    1088         strcpy(type_of_backup, "udev");
    1089         break;
    1090     case iso:
    1091         strcpy(type_of_backup, "ISO");
    1092         break;
    1093     case nfs:
    1094         strcpy(type_of_backup, "nfs");
    1095         break;
    1096     case usb:
    1097         strcpy(type_of_backup, "USB");
    1098         break;
    1099     default:
    1100         strcpy(type_of_backup, "ISO");
    1101     }
    1102     return (type_of_backup);
    1103 }
     938       static char *type_of_backup = NULL;
     939
     940       if (!type_of_backup) {
     941               malloc_string(type_of_backup);
     942       }
     943
     944       switch (type_of_bkp) {
     945       case dvd:
     946               strcpy(type_of_backup, "DVD");
     947               break;
     948       case cdr:
     949               strcpy(type_of_backup, "CDR");
     950               break;
     951       case cdrw:
     952               strcpy(type_of_backup, "CDRW");
     953               break;
     954       case tape:
     955               strcpy(type_of_backup, "tape");
     956               break;
     957       case cdstream:
     958               strcpy(type_of_backup, "CDR");
     959               break;
     960       case udev:
     961               strcpy(type_of_backup, "udev");
     962               break;
     963       case iso:
     964               strcpy(type_of_backup, "ISO");
     965               break;
     966       case nfs:
     967               strcpy(type_of_backup, "nfs");
     968               break;
     969       case usb:
     970               strcpy(type_of_backup, "USB");
     971               break;
     972       default:
     973               strcpy(type_of_backup, "ISO");
     974       }
     975       return (type_of_backup);
     976}
     977
  • 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
  • branches/stable/mondo/src/include/mr_mem.h

    r1162 r1178  
    2323#define mr_malloc(x) mr_malloc_int((size_t)x,__LINE__,__FILE__)
    2424#define mr_setenv(x,y) mr_setenv_int(x,y,__LINE__,__FILE__)
     25#define mr_strcat(x,y) mr_strcat_int((char **)&x,y, __LINE__,__FILE__);
    2526
    2627/* Internal function bringing debuging info
     
    3233extern inline void *mr_malloc_int(size_t size, int line, char *file);
    3334extern inline void mr_setenv_int(const char *name, const char *value, int line, char *file);
     35extern void mr_strcat_int(char **in, const char *add, int line, char *file);
    3436
    3537#endif                          /* MR_MEM_H */
  • branches/stable/mondo/src/include/mr_str.h

    r1168 r1178  
    1111/* functions (public methods) */
    1212
    13 extern inline char *mr_strtok(char *instr, const char *delims, int *lastpos);
    14 extern inline char *mr_stresc(char *instr, char *toesc, const char escchr);
     13extern char *mr_strtok(char *instr, const char *delims, int *lastpos);
     14extern char *mr_stresc(char *instr, char *toesc, const char escchr);
    1515extern inline char *mr_date(void);
    16 extern inline void mr_strip_spaces(char *in_out);
    1716
    1817#endif                          /* MR_STR_H */
  • branches/stable/mondo/src/lib/mr_mem.c

    r1174 r1178  
    110110    }
    111111}
     112
     113/*
     114 * Equivalent function of strcat but safe
     115 * from memory allocation point of view
     116 */
     117void mr_strcat_int(char **in, const char *add, int line, char *file) {
     118    char *p =NULL;
     119   
     120    if (add == NULL) {
     121        return;
     122    }
     123    if (in == NULL) {
     124        mr_msg_int(1,line,file,"Unable to add %s to NULL pointer\nExiting...", add);
     125        mr_exit(-1, "Unable to add to a NULL pointer");
     126    }
     127    if (*in == NULL) {
     128        mr_asprintf_int(&p,line,file,add);
     129    } else {
     130        mr_asprintf_int(&p,line,file,"%s%s",*in,add);
     131        mr_free_int((void **)in,line,file);
     132    }
     133    *in = p;
     134}
  • branches/stable/mondo/src/lib/mr_str.c

    r1168 r1178  
    122122 * @param in_out The string to strip spaces/control characters from (modified).
    123123 */
    124 void mr_strip_spaces(char *in_out)
    125 {
    126     /*@ int ******************************************************** */
     124void mr_strip_spaces(char *in_out) {
    127125    int i;
    128126    int j;
    129127    size_t length;
    130 
    131     /*@ end vars *************************************************** */
    132128
    133129    if (in_out == NULL) {
  • branches/stable/mondo/src/test/test-mem.c

    r1140 r1178  
    11#include <stdio.h>
    22#include <stdlib.h>
     3#include <string.h>
    34#include <assert.h>
    45
     
    3132    mr_free(str);
    3233
     34    printf("*** Test with mr_strcat\n");
     35    mr_asprintf(&str,"Another Chain");
     36    mr_strcat(str," of trust");
     37    printf("Result: %s\n",str);
     38    mr_free(str);
     39
    3340    printf("*** Test with mr_getline/mr_free\n");
    3441    fd = mr_fopen("/etc/passwd","r");
  • branches/stable/mondo/src/test/test-mem.res

    r1134 r1178  
    1 *** Test with mr_free
     1*** Test with mr_malloc/mr_free
    22pointer is NOT null
    33pointer is null
     4*** Test with mr_asprintf/mr_free
     5Result: Chain of trust
     6*** Test with mr_strcat
     7Result: Another Chain of trust
     8*** Test with mr_getline/mr_free
     91st Result: root:x:0:0:root:/root:/bin/bash
     102nd Result: bin:x:1:1:bin:/bin:/bin/sh
     113rd Result: another line
    412*** Test with NULL
    513pointer is null
Note: See TracChangeset for help on using the changeset viewer.