Changeset 1196 in MondoRescue


Ignore:
Timestamp:
Feb 21, 2007, 2:40:49 AM (17 years ago)
Author:
Bruno Cornec
Message:

ChangeLog for mindi UTF-8
mr_strcat much more powerful as taking a vararg (+ tests).
improved text output to log file for mondo
merge from trunk memory management for mondorestore (begining)

Location:
branches/stable
Files:
8 edited

Legend:

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

    r1193 r1196  
    10811081
    10821082    if (g_text_mode) {
     1083        /* Not very useful
    10831084        printf(_("---progress-form---1--- %s\n"), blurb1);
     1085        */
    10841086        printf(_("---progress-form---2--- %s\n"), blurb2);
     1087        /* Not very useful
    10851088        printf(_("---progress-form---3--- %s\n"), blurb3);
    1086         printf(_("---progress-form---E---\n"));
     1089        */
    10871090        mr_asprintf(&taskprogress, "TASK:  [");
    10881091        for (i = 0; i < percentage; i += 5) {
  • branches/stable/mondo/src/include/mr_mem.h

    r1178 r1196  
    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__);
     25#define mr_strcat(x,y,args...) mr_strcat_int((char **)&x, __LINE__,__FILE__, y,## args);
    2626
    2727/* Internal function bringing debuging info
     
    3333extern inline void *mr_malloc_int(size_t size, int line, char *file);
    3434extern inline void mr_setenv_int(const char *name, const char *value, int line, char *file);
    35 extern void mr_strcat_int(char **in, const char *add, int line, char *file);
     35extern void mr_strcat_int(char **in, int line, char *file, const char *fmt, ...);
    3636
    3737#endif                          /* MR_MEM_H */
  • branches/stable/mondo/src/lib/mr_mem.c

    r1178 r1196  
    114114 * Equivalent function of strcat but safe
    115115 * from memory allocation point of view
     116 * and richer from an interface point of view
    116117 */
    117 void mr_strcat_int(char **in, const char *add, int line, char *file) {
    118     char *p =NULL;
     118void mr_strcat_int(char **in, int line, const char *file, const char *fmt, ...) {
     119    char *p = NULL;
     120    char *fmt2 = NULL;
     121    va_list args;
     122    int res = 0;
    119123   
    120     if (add == NULL) {
     124    if (fmt == NULL) {
    121125        return;
    122126    }
    123127    if (in == NULL) {
    124         mr_msg_int(1,line,file,"Unable to add %s to NULL pointer\nExiting...", add);
     128        mr_msg_int(1,line,file,"Unable to add to NULL pointer\nExiting...");
    125129        mr_exit(-1, "Unable to add to a NULL pointer");
    126130    }
     131    va_start(args,fmt);
    127132    if (*in == NULL) {
    128         mr_asprintf_int(&p,line,file,add);
     133        res = vasprintf(in, fmt, args);
     134        if (res == -1) {
     135            mr_msg_int(1,line,file,"Unable to alloc memory in mr_strcat\nExiting...");
     136            mr_exit(-1,"Unable to alloc memory in mr_strcat");
     137        }
    129138    } else {
    130         mr_asprintf_int(&p,line,file,"%s%s",*in,add);
     139        mr_asprintf_int(&fmt2, line, file, "%s%s", *in, fmt);
     140        res = vasprintf(&p, fmt2, args);
     141        mr_free_int((void **)&fmt2,line,file);
    131142        mr_free_int((void **)in,line,file);
     143        *in = p;
    132144    }
    133     *in = p;
     145    va_end(args);
    134146}
     147
     148
  • branches/stable/mondo/src/mondorestore/mondo-prep.c

    r1170 r1196  
    1010
    1111#include "my-stuff.h"
    12 #include "../common/mondostructures.h"
     12#include "mondostructures.h"
    1313#include "mondoprep.h"
    14 #include "../common/libmondo.h"
     14#include "libmondo.h"
    1515#include "mondo-rstr-tools-EXT.h"
     16
    1617#include <sys/ioctl.h>
    1718#include <linux/hdreg.h>
    1819#include <math.h>
     20#include <unistd.h>
    1921#include "mr_mem.h"
    2022#include "mr_msg.h"
     
    4244extern char *g_mountlist_fname;
    4345extern long g_current_progress, g_maximum_progress;
    44 
    4546extern bool g_text_mode;
    46 
    4747extern void pause_for_N_seconds(int, char *);
    4848
    49 
    5049FILE *g_fprep = NULL;
    51 
    52 
    53 
    5450int g_partition_table_locked_up = 0;
    55 
    56 
    57 
    58 
    59 
    60 
    61 
    62 
    6351
    6452
    6553void wipe_MBRs_and_reboot_if_necessary(struct mountlist_itself *mountlist)
    6654{
    67     char *command;
    68     char *tmp;
    69     int lino;
    70     int i;
    71     FILE *fout;
    72     char *buf;
    73     const int blocksize = 512;
     55    char *command = NULL;
     56    int lino = 0;
     57    int res = 0;
     58    FILE *fout = NULL;
     59    char *buf = NULL;
    7460    struct list_of_disks *drivelist = NULL;
    75 // If LVMs are present and a zero-and-reboot wasn't recently undertaken
    76 // then zero & insist on reboot.
    77     malloc_string(command);
    78     malloc_string(tmp);
    79     buf = mr_malloc(blocksize);
     61
     62    // If LVMs are present and a zero-and-reboot wasn't recently undertaken
     63    // then zero & insist on reboot.
    8064    if (does_file_exist("/tmp/i-want-my-lvm"))  // FIXME - cheating :)
    8165    {
     
    8367        make_list_of_drives_in_mountlist(mountlist, drivelist);
    8468        for (lino = 0; lino < drivelist->entries; lino++) {
    85             sprintf(command,
    86                     "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"",
    87                     drivelist->el[lino].device, MONDO_WAS_HERE);
    88             if (!run_program_and_log_output(command, 1)) {
     69            mr_asprintf(&command,
     70                     "dd if=%s bs=512 count=1 2> /dev/null | grep \"%s\"",
     71                     drivelist->el[lino].device, MONDO_WAS_HERE);
     72            res = run_program_and_log_output(command, 1);
     73            mr_free(command);
     74            if (!res) {
    8975                mr_msg(1, "Found MONDO_WAS_HERE marker on drive#%d (%s)",
    9076                        lino, drivelist->el[lino].device);
     
    9480
    9581        if (lino == drivelist->entries) {
    96 // zero & reboot
     82            // zero & reboot
    9783            log_to_screen
    98                 ("I am sorry for the inconvenience but I must ask you to reboot.");
    99             log_to_screen
    100                 ("I need to reset the Master Boot Record; in order to be");
    101             log_to_screen
    102                 ("sure the kernel notices, I must reboot after doing it.");
     84                (_
     85                 ("I am sorry for the inconvenience but I must ask you to reboot."));
     86            log_to_screen(_
     87                          ("I need to reset the Master Boot Record; in order to be"));
     88            log_to_screen(_
     89                          ("sure the kernel notices, I must reboot after doing it."));
    10390            log_to_screen("Please hit 'Enter' to reboot.");
    10491            for (lino = 0; lino < drivelist->entries; lino++) {
    105                 for (i = 0; i < blocksize; i++) {
    106                     buf[i] = 0;
    107                 }
    108                 sprintf(buf, "%s\n", MONDO_WAS_HERE);
     92                mr_asprintf(&buf, "%s\n", MONDO_WAS_HERE);
    10993                fout = fopen(drivelist->el[lino].device, "w+");
    11094                if (!fout) {
     
    11296                            drivelist->el[lino].device);
    11397                } else {
    114                     if (1 != fwrite(buf, blocksize, 1, fout)) {
     98                    if (1 != fwrite(buf, strlen(buf)+1, 1, fout)) {
    11599                        mr_msg(1, "Failed to wipe %s",
    116100                                drivelist->el[lino].device);
     
    121105                    fclose(fout);
    122106                }
    123             }
    124             system("sync");
    125             system("sync");
    126             system("sync");
     107                mr_free(buf);
     108            }
     109            sync();
     110            sync();
     111            sync();
    127112            popup_and_OK
    128                 ("I must now reboot. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine.");
     113                (_
     114                 ("I must reboot now. Please leave the boot media in the drive and repeat your actions - e.g. type 'nuke' - and it should work fine."));
    129115            system("reboot");
    130116        }
    131117    }
    132118// Still here? Cool!
    133     mr_free(command);
    134     mr_free(tmp);
    135119    mr_msg(1, "Cool. I didn't have to wipe anything.");
    136120}
    137121
    138122
    139 
    140 
    141 
    142 
    143123int fput_string_one_char_at_a_time(FILE * fout, char *str)
    144124{
    145     int i, j;
    146     FILE *fq;
     125    int i = 0, j = 0;
     126    FILE *fq = NULL;
    147127
    148128    if (ferror(fout)) {
     
    168148    return (i);
    169149}
    170 
    171 
    172 
    173 
    174 
    175 
    176 
    177 
    178150
    179151
     
    187159 * @return The number of errors encountered (0 for success).
    188160 */
    189 
    190 
    191161int do_my_funky_lvm_stuff(bool just_erase_existing_volumes,
    192162                          bool vacuum_pack)
    193163{
    194     /**  buffers **********************************************/
    195     char *tmp;
    196     char *incoming;
    197     char *command;
    198     char *lvscan_sz;
    199     char *lvremove_sz;
    200     char *pvscan_sz;
    201     char *vgscan_sz;
    202     char *vgcreate_sz;
    203     char *vgchange_sz;
    204     char *vgremove_sz;
    205 //  char *do_this_last;
    206 
    207     /** char **************************************************/
    208     char *p;
    209     char *q;
     164    char *tmp = NULL;
     165    char *tmp1 = NULL;
     166    char *incoming = NULL;
     167    char *command = NULL;
     168    char *lvscan_sz = NULL;
     169    char *lvremove_sz = NULL;
     170    char *pvscan_sz = NULL;
     171    char *vgscan_sz = NULL;
     172    char *vgchange_sz = NULL;
     173    char *vgremove_sz = NULL;
     174    char *p = NULL;
     175    char *q = NULL;
    210176
    211177    /** int ***************************************************/
    212178    int retval = 0;
    213179    int res = 0;
    214     int i;
     180    int i = 0;
    215181    int lvmversion = 1;
    216     long extents;
     182    long extents = 0L;
    217183    fpos_t orig_pos;
     184    size_t n = 0;
     185    size_t n1 = 0;
    218186
    219187    /** pointers **********************************************/
    220     FILE *fin;
     188    FILE *fin = NULL;
    221189
    222190    /** end *****************************************************/
     
    231199    }
    232200
    233     malloc_string(tmp);
    234     malloc_string(incoming);
    235     malloc_string(lvscan_sz);
    236     malloc_string(lvremove_sz);
    237     malloc_string(vgscan_sz);
    238     malloc_string(pvscan_sz);
    239     malloc_string(vgcreate_sz);
    240     malloc_string(vgchange_sz);
    241     malloc_string(vgremove_sz);
    242 //  malloc_string(do_this_last); // postpone lvcreate call if necessary
    243     command = mr_malloc(512);
    244 
    245 //  do_this_last[0] = '\0';
    246201    iamhere("STARTING");
    247202    mr_msg(1, "OK, opened i-want-my-lvm. Shutting down LVM volumes...");
    248203    if (find_home_of_exe("lvm"))    // found it :) cool
    249204    {
    250         strcpy(lvscan_sz, "lvm lvscan");
    251         strcpy(lvremove_sz, "lvm lvremove");
    252         strcpy(vgscan_sz, "lvm vgscan");
    253         strcpy(pvscan_sz, "lvm pvscan");
    254         strcpy(vgcreate_sz, "lvm vgcreate");
    255         strcpy(vgchange_sz, "lvm vgchange");
    256         strcpy(vgremove_sz, "lvm vgremove");
     205        mr_asprintf(&lvscan_sz, "lvm lvscan");
     206        mr_asprintf(&lvremove_sz, "lvm lvremove");
     207        mr_asprintf(&vgscan_sz, "lvm vgscan");
     208        mr_asprintf(&pvscan_sz, "lvm pvscan");
     209        mr_asprintf(&vgchange_sz, "lvm vgchange");
     210        mr_asprintf(&vgremove_sz, "lvm vgremove");
    257211    } else {
    258         strcpy(lvscan_sz, "lvscan");
    259         strcpy(lvremove_sz, "lvremove");
    260         strcpy(vgscan_sz, "vgscan");
    261         strcpy(pvscan_sz, "pvscan");
    262         strcpy(vgcreate_sz, "vgcreate");
    263         strcpy(vgchange_sz, "vgchange");
    264         strcpy(vgremove_sz, "vgremove");
    265     }
    266     sprintf(command,
     212        mr_asprintf(&lvscan_sz, "lvscan");
     213        mr_asprintf(&lvremove_sz, "lvremove");
     214        mr_asprintf(&vgscan_sz, "vgscan");
     215        mr_asprintf(&pvscan_sz, "pvscan");
     216        mr_asprintf(&vgchange_sz, "vgchange");
     217        mr_asprintf(&vgremove_sz, "vgremove");
     218    }
     219    mr_asprintf(&command,
    267220            "for i in `%s | cut -d\"'\" -f2 | sort -r` ; do echo \"Shutting down lv $i\" >> "
    268221            MONDO_LOGFILE "; %s -f $i; done", lvscan_sz, lvremove_sz);
     222    mr_free(lvscan_sz);
     223    mr_free(lvremove_sz);
     224
    269225    run_program_and_log_output(command, 5);
     226    mr_free(command);
     227
    270228    sleep(1);
    271     sprintf(command,
     229    mr_asprintf(&command,
    272230            "for i in `%s | grep -i lvm | cut -d'\"' -f2` ; do %s -a n $i ; %s $i; echo \"Shutting down vg $i\" >> "
    273231            MONDO_LOGFILE "; done", vgscan_sz, vgchange_sz, vgremove_sz);
     232    mr_free(vgchange_sz);
     233    mr_free(vgremove_sz);
     234
    274235    run_program_and_log_output(command, 5);
     236    mr_free(command);
     237
    275238    if (just_erase_existing_volumes) {
    276239        paranoid_fclose(fin);
    277240        mr_msg(1, "Closed i-want-my-lvm. Finished erasing LVMs.");
    278         retval = 0;
    279         goto end_of_i_want_my_lvm;
     241        sync();
     242        sync();
     243        sync();
     244        sleep(1);
     245        iamhere("ENDING");
     246        mr_msg(1, "Not many errors. Returning 0.");
     247        return (0);
    280248    }
    281249
    282250    mr_msg(1, "OK, rewound i-want-my-lvm. Doing funky stuff...");
    283251    rewind(fin);
    284     for (fgets(incoming, 512, fin); !feof(fin); fgets(incoming, 512, fin)) {
     252    for (mr_getline(&incoming, &n1, fin); !feof(fin); mr_getline(&incoming, &n1, fin)) {
    285253        fgetpos(fin, &orig_pos);
     254        /* we want to execute lines begining with a # */
    286255        if (incoming[0] != '#') {
    287256            continue;
    288257        }
    289         if (res && strstr(command, "create") && vacuum_pack) {
    290             sleep(2);
    291             system("sync");
    292             system("sync");
    293             system("sync");
    294         }
    295258        if ((p = strstr(incoming, "vgcreate"))) {
    296 // include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm)
    297             for (fgets(tmp, 512, fin); !feof(fin); fgets(tmp, 512, fin)) {
     259            // include next line(s) if they end in /dev (cos we've got a broken i-want-my-lvm)
     260            for (mr_getline(&tmp, &n, fin); !feof(fin); mr_getline(&tmp, &n, fin)) {
    298261                if (tmp[0] == '#') {
    299262                    fsetpos(fin, &orig_pos);
     
    301264                } else {
    302265                    fgetpos(fin, &orig_pos);
    303                     strcat(incoming, tmp);
     266                    mr_strcat(incoming, tmp);
    304267                }
    305268            }
     269            mr_free(tmp);
     270
    306271            for (q = incoming; *q != '\0'; q++) {
    307272                if (*q < 32) {
     
    309274                }
    310275            }
    311             strcpy(tmp, p + strlen("vgcreate") + 1);
    312             for (q = tmp; *q > 32; q++);
     276            mr_asprintf(&tmp1, p + strlen("vgcreate") + 1);
     277            for (q = tmp1; *q > 32; q++);
    313278            *q = '\0';
    314             mr_msg(1, "Deleting old entries at /dev/%s", tmp);
    315 //             sprintf(command, "%s -f %s", vgremove_sz, tmp);
    316 //             run_program_and_log_output(command, 1);
    317             sprintf(command, "rm -Rf /dev/%s", tmp);
     279            mr_msg(1, "Deleting old entries at /dev/%s", tmp1);
     280            mr_asprintf(&command, "rm -Rf /dev/%s", tmp1);
     281            mr_free(tmp1);
     282
    318283            run_program_and_log_output(command, 1);
     284            mr_free(command);
     285
    319286            run_program_and_log_output(vgscan_sz, 1);
    320287            run_program_and_log_output(pvscan_sz, 1);
     
    324291        }
    325292        for (p = incoming + 1; *p == ' '; p++);
    326         strcpy(command, p);
     293        mr_asprintf(&command,p);
    327294        for (p = command; *p != '\0'; p++);
    328         for (; *(p - 1) < 32; p--);
     295        for (; (*(p - 1) < 32) && (p > command) ; p--);
    329296        *p = '\0';
     297
     298        /* BERLIOS: we should rather define LVMv1 or v2 and use it */
    330299        res = run_program_and_log_output(command, 5);
    331300        if (res > 0 && (p = strstr(command, "lvm "))) {
     
    341310            if (strstr(command, "lvm lvcreate"))
    342311                lvmversion = 2;
    343             log_it("%s... so I'll get creative.", tmp);
    344312            if (lvmversion == 2) {
    345                 strcpy(tmp, call_program_and_get_last_line_of_output
    346                        ("tail -n5 /var/log/mondo-archive.log | grep Insufficient | tail -n1"));
     313                mr_asprintf(&tmp, call_program_and_get_last_line_of_output
     314                       ("tail -n5 " MONDO_LOGFILE " | grep Insufficient | tail -n1"));
    347315            } else {
    348                 strcpy(tmp, call_program_and_get_last_line_of_output
    349                        ("tail -n5 /var/log/mondo-archive.log | grep lvcreate | tail -n1"));
     316                mr_asprintf(&tmp, call_program_and_get_last_line_of_output
     317                       ("tail -n5 " MONDO_LOGFILE " | grep lvcreate | tail -n1"));
    350318            }
    351319            for (p = tmp; *p != '\0' && !isdigit(*p); p++);
    352320            extents = atol(p);
    353321            mr_msg(5, "p='%s' --> extents=%ld", p, extents);
     322            mr_free(tmp);
     323
    354324            p = strstr(command, "-L");
    355325            if (!p) {
     
    363333                        *q = ' ';
    364334                    }
     335                    /* BERLIOS: Dangerous: no size control !! */
    365336                    sprintf(p, "%ld", extents);
    366337                    i = strlen(p);
     
    373344                        *(q - 1) = ' ';
    374345                    }
     346                    /* BERLIOS: Dangerous: no size control !! */
    375347                    sprintf(p, "%ld%c", extents, 'm');
    376348                    i = strlen(p);
     
    387359                mr_msg(0, "%s --> %d", command, res);
    388360                if (!res) {
    389                     mr_msg(5, "YAY! This time, it succeeded.");
     361                    mr_msg(5, "Yep! This time, it succeeded.");
    390362                }
    391363            }
     
    399371            retval++;
    400372        }
    401         sprintf(tmp, "echo \"%s\" >> /tmp/out.sh", command);
     373        mr_asprintf(&tmp, "echo \"%s\" >> /tmp/out.sh", command);
    402374        system(tmp);
     375        mr_free(tmp);
    403376        sleep(1);
    404377    }
    405378    paranoid_fclose(fin);
    406     mr_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff.");
    407   end_of_i_want_my_lvm:
    408     mr_free(tmp);
    409     mr_free(incoming);
    410     mr_free(command);
    411     mr_free(lvscan_sz);
    412     mr_free(lvremove_sz);
    413379    mr_free(vgscan_sz);
    414380    mr_free(pvscan_sz);
    415     mr_free(vgcreate_sz);
    416     mr_free(vgchange_sz);
    417     mr_free(vgremove_sz);
    418 //  mr_free(do_this_last);
    419     system("sync");
    420     system("sync");
    421     system("sync");
     381    mr_free(command);
     382    mr_free(incoming);
     383
     384    mr_msg(1, "Closed i-want-my-lvm. Finished doing funky stuff.");
     385    sync();
     386    sync();
     387    sync();
    422388    sleep(1);
    423389    iamhere("ENDING");
     
    445411                                                     *old_mountlist)
    446412{
    447     /** pointers *********************************************************/
    448     FILE *fin;
    449 
    450     /** int **************************************************************/
    451     int lino;
    452     int j;
    453 
    454     /** buffers **********************************************************/
    455     char *incoming;
    456     char *tmp;
    457 
    458     /** pointers *********************************************************/
    459     char *p;
     413    FILE *fin = NULL;
     414    int lino = 0;
     415    int j = 0;
     416    char *incoming = NULL;
     417    char *p = NULL;
     418    size_t n = 0;
    460419
    461420    /** init *************************************************************/
     
    464423    /** end **************************************************************/
    465424
    466     malloc_string(incoming);
    467     malloc_string(tmp);
    468425    assert(new_mountlist != NULL);
    469426    assert(old_mountlist != NULL);
     
    471428#ifdef __FreeBSD__
    472429    log_to_screen
    473         ("I don't know how to extrapolate the mountlist on FreeBSD. Sorry.");
     430        (_
     431         ("I don't know how to extrapolate the mountlist on FreeBSD. Sorry."));
    474432    return (1);
    475433#endif
     
    480438            if (!does_file_exist("/etc/raidtab")) {
    481439                log_to_screen
    482                     ("Cannot find /etc/raidtab - cannot extrapolate the fdisk entries");
     440                    (_
     441                     ("Cannot find /etc/raidtab - cannot extrapolate the fdisk entries"));
    483442                finish(1);
    484443            }
     
    487446                finish(1);
    488447            }
    489             for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin)
     448            for (mr_getline(&incoming, &n, fin); !feof(fin)
    490449                 && !strstr(incoming, old_mountlist->el[lino].device);
    491                  fgets(incoming, MAX_STR_LEN - 1, fin));
     450                 mr_getline(&incoming, &n, fin));
    492451            if (!feof(fin)) {
    493                 sprintf(tmp, "Investigating %s",
     452                log_it("Investigating %s",
    494453                        old_mountlist->el[lino].device);
    495                 log_it(tmp);
    496                 for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin)
     454                for (mr_getline(&incoming, &n, fin); !feof(fin)
    497455                     && !strstr(incoming, "raiddev");
    498                      fgets(incoming, MAX_STR_LEN - 1, fin)) {
     456                     mr_getline(&incoming, &n, fin)) {
    499457                    if (strstr(incoming, OSSWAP("device", "drive"))
    500458                        && !strchr(incoming, '#')) {
    501459                        for (p = incoming + strlen(incoming);
    502                              *(p - 1) <= 32; p--);
     460                             (*(p - 1) <= 32) && (p >= incoming) ; p--);
    503461                        *p = '\0';
    504                         for (p--; p > incoming && *(p - 1) > 32; p--);
    505                         sprintf(tmp, "Extrapolating %s", p);
    506                         log_it(tmp);
     462                        for (p--; (p >= incoming) && (*(p - 1) > 32); p--);
     463                        log_it("Extrapolating %s", p);
    507464                        for (j = 0;
    508465                             j < new_mountlist->entries
     
    522479                            new_mountlist->entries++;
    523480                        } else {
    524                             sprintf(tmp,
    525                                     "Not adding %s to mountlist: it's already there",
    526                                     p);
    527                             log_it(tmp);
     481                            log_it("Not adding %s to mountlist: it's already there", p);
    528482                        }
    529483                    }
    530484                }
    531485            }
     486            mr_free(incoming);
     487
    532488            paranoid_fclose(fin);
    533489        } else {
     
    543499        }
    544500    }
    545     mr_free(incoming);
    546     mr_free(tmp);
    547 
    548501    return (0);
    549502}
     
    561514{
    562515  /** int **************************************************************/
    563   int i  = 0;
    564   int j  = 0;
    565   int res = 0;
    566  
     516    int i = 0;
     517    int j = 0;
     518    int res = 0;
     519
    567520  /** buffers ***********************************************************/
    568521  char *devices = NULL;
     
    590543  mr_asprintf(&devices, raidlist->el[i].data_disks.el[0].device);
    591544  for (j = 1; j < raidlist->el[i].data_disks.entries; j++) {
    592     mr_asprintf(&strtmp, "%s", devices);
    593     mr_free(devices);
    594     mr_asprintf(&devices, "%s %s", strtmp,
    595          raidlist->el[i].data_disks.el[j].device);
    596     mr_free(strtmp);
     545    mr_strcat(devices, " %s", raidlist->el[i].data_disks.el[j].device);
    597546  }
    598547  for (j = 0; j < raidlist->el[i].spare_disks.entries; j++) {
    599     mr_asprintf(&strtmp, "%s", devices);
    600     mr_free(devices);
    601     mr_asprintf(&devices, "%s %s", strtmp,
    602          raidlist->el[i].spare_disks.el[j].device);
    603     mr_free(strtmp);
     548    mr_strcat(devices, " %s", raidlist->el[i].spare_disks.el[j].device);
    604549  }
    605550  // translate RAID level
     
    620565       raidlist->el[i].raid_device, level,
    621566       raidlist->el[i].data_disks.entries);
     567  mr_free(level);
    622568  if (raidlist->el[i].parity != -1) {
    623     mr_asprintf(&strtmp, "%s", program);
    624     mr_free(program);
    625569    switch(raidlist->el[i].parity) {
    626570    case 0:
    627       mr_asprintf(&program, "%s --parity=%s", strtmp, "la");
     571      mr_strcat(program, " --parity=%s", "la");
    628572      break;
    629573    case 1:
    630       mr_asprintf(&program, "%s --parity=%s", strtmp, "ra");
     574      mr_strcat(program, " --parity=%s", "ra");
    631575      break;
    632576    case 2:
    633       mr_asprintf(&program, "%s --parity=%s", strtmp, "ls");
     577      mr_strcat(program, " --parity=%s", "ls");
    634578      break;
    635579    case 3:
    636       mr_asprintf(&program, "%s --parity=%s", strtmp, "rs");
     580      mr_strcat(program, " --parity=%s", "rs");
    637581      break;
    638582    default:
     
    640584      break;
    641585    }
    642     mr_free(strtmp);
    643586  }
    644587  if (raidlist->el[i].chunk_size != -1) {
    645     mr_asprintf(&strtmp, "%s", program);
    646     mr_free(program);
    647     mr_asprintf(&program, "%s --chunk=%d", strtmp, raidlist->el[i].chunk_size);
    648     mr_free(strtmp);
     588        mr_strcat(program, " --chunk=%d", raidlist->el[i].chunk_size);
    649589  }
    650590  if (raidlist->el[i].spare_disks.entries > 0) {
    651     mr_asprintf(&strtmp, "%s", program);
    652     mr_free(program);
    653     mr_asprintf(&program, "%s --spare-devices=%d", strtmp,
    654          raidlist->el[i].spare_disks.entries);
    655     mr_free(strtmp);
     591        mr_strcat(program, " --spare-devices=%d", raidlist->el[i].spare_disks.entries);
    656592  }
    657   mr_asprintf(&strtmp, "%s", program);
    658   mr_free(program);
    659   mr_asprintf(&program, "%s %s", strtmp, devices);
    660   mr_free(strtmp);
     593    mr_strcat(program, " %s", devices);
    661594  res = run_program_and_log_output(program, 1);
    662595  // free memory
    663596  mr_free(devices);
    664   mr_free(level);
    665597  mr_free(program);
    666598  // return to calling instance
    667   return res;
     599  return(res);
    668600}
    669601
     
    682614{
    683615    /** int **************************************************************/
    684     int res;
     616    int res = 0;
    685617    int retval = 0;
    686618#ifdef __FreeBSD__
     
    689621
    690622    /** buffers ***********************************************************/
    691     char *program;
    692     char *tmp;
     623    char *program = NULL;
     624    char *program2 = NULL;
     625    char *tmp = NULL;
     626    char *tmp1 = NULL;
     627#ifdef __FreeBSD__
     628    char *line = NULL;
     629    char *status = NULL;
     630    FILE *pin = NULL;
     631    FILE *fin = NULL;
     632    size_t n = 0;
     633    size_t n1 = 0;
     634#endif
    693635
    694636    /** end ****************************************************************/
    695637
    696     malloc_string(program);
    697     malloc_string(tmp);
    698638    assert_string_is_neither_NULL_nor_zerolength(device);
    699639    assert(format != NULL);
    700640
    701641    if (strstr(format, "raid")) {   // do not form RAID disks; do it to /dev/md* instead
    702         sprintf(tmp, "Not formatting %s (it is a RAID disk)", device);
    703         log_it(tmp);
    704         mr_free(program);
    705         mr_free(tmp);
     642        log_it("Not formatting %s (it is a RAID disk)", device);
    706643        return (0);
    707644    }
     
    709646    if (strcmp(format, "swap") == 0) {
    710647        log_it("Not formatting %s - it's swap", device);
    711         mr_free(program);
    712         mr_free(tmp);
    713648        return (0);
    714649    }
    715650#endif
    716651    if (strlen(format) <= 2) {
    717         sprintf(tmp,
     652        mr_asprintf(&tmp,
    718653                "%s has a really small format type ('%s') - this is probably a hexadecimal string, which would suggest the partition is an image --- I shouldn't format it",
    719654                device, format);
    720         log_it(tmp);
    721         mr_free(program);
    722         mr_free(tmp);
    723655        return (0);
    724656    }
    725657    if (is_this_device_mounted(device)) {
    726         sprintf(tmp, "%s is mounted - cannot format it       ", device);
    727         log_to_screen(tmp);
    728         mr_free(program);
    729         mr_free(tmp);
     658        log_to_screen(_("%s is mounted - cannot format it       "), device);
    730659        return (1);
    731660    }
     
    736665            if (!does_file_exist("/tmp/raidconf.txt")) {
    737666                log_to_screen
    738                     ("/tmp/raidconf.txt does not exist. I therefore cannot start Vinum.");
     667                    (_
     668                     ("/tmp/raidconf.txt does not exist. I therefore cannot start Vinum."));
    739669            } else {
    740670                int res;
     
    744674                if (res) {
    745675                    log_to_screen
    746                         ("`vinum create /tmp/raidconf.txt' returned errors. Please fix them and re-run mondorestore.");
     676                        (_
     677                         ("`vinum create /tmp/raidconf.txt' returned errors. Please fix them and re-run mondorestore."));
    747678                    finish(1);
    748679                }
     
    752683
    753684        if (vinum_started_yet) {
    754             FILE *fin;
    755             char line[MAX_STR_LEN];
    756             sprintf(tmp,
    757                     "Initializing Vinum device %s (this may take a *long* time)",
     685            log_to_screen(_("Initializing Vinum device %s (this may take a *long* time)"),
    758686                    device);
    759             log_to_screen(tmp);
     687
    760688            /* format raid partition */
    761             //      sprintf (program, "mkraid --really-force %s", device); --- disabled -- BB, 02/12/2003
    762             sprintf(program,
     689            mr_asprintf(&program,
    763690                    "for plex in `vinum lv -r %s | grep '^P' | tr '\t' ' ' | tr -s ' ' | cut -d' ' -f2`; do echo $plex; done > /tmp/plexes",
    764691                    basename(device));
    765692            system(program);
     693
    766694            if (g_fprep) {
    767695                fprintf(g_fprep, "%s\n", program);
    768696            }
     697            mr_free(program);
     698
    769699            fin = fopen("/tmp/plexes", "r");
    770             while (fgets(line, MAX_STR_LEN - 1, fin)) {
     700            while (mr_getline(&line, &n, fin)) {
    771701                if (strchr(line, '\n'))
    772702                    *(strchr(line, '\n')) = '\0';   // get rid of the \n on the end
    773703
    774                 sprintf(tmp, "Initializing plex: %s", line);
     704                mr_asprintf(&tmp, "Initializing plex: %s", line);
    775705                open_evalcall_form(tmp);
    776                 sprintf(tmp, "vinum init %s", line);
     706                mr_free(tmp);
     707
     708                mr_asprintf(&tmp, "vinum init %s", line);
    777709                system(tmp);
     710                mr_free(tmp);
     711
    778712                while (1) {
    779                     sprintf(tmp,
     713                    mr_asprintf(&tmp,
    780714                            "vinum lp -r %s | grep '^S' | head -1 | tr -s ' ' | cut -d: -f2 | cut -f1 | sed 's/^ //' | sed 's/I //' | sed 's/%%//'",
    781715                            line);
    782                     FILE *pin = popen(tmp, "r");
    783                     char status[MAX_STR_LEN / 4];
    784                     fgets(status, MAX_STR_LEN / 4 - 1, pin);
     716                    pin = popen(tmp, "r");
     717                    mr_free(tmp);
     718
     719                    mr_getline(&status, &n1, pin);
    785720                    pclose(pin);
    786721
     
    790725                    update_evalcall_form(atoi(status));
    791726                    usleep(250000);
     727                    mr_free(status);
    792728                }
    793729                close_evalcall_form();
    794730            }
     731            mr_free(line);
     732
    795733            fclose(fin);
    796734            unlink("/tmp/plexes");
     
    798736        }
    799737#else
    800         sprintf(tmp, "Initializing RAID device %s", device);
    801         log_to_screen(tmp);
    802 
    803 // Shouldn't be necessary.
    804         log_to_screen("Stopping %s", device);
     738        log_to_screen(_("Initializing RAID device %s"), device);
     739
     740        // Shouldn't be necessary.
     741        log_to_screen(_("Stopping %s"), device);
    805742        stop_raid_device(device);
    806         system("sync");
     743        sync();
    807744        sleep(1);
    808         if (g_fprep) {
    809             fprintf(g_fprep, "%s\n", program);
    810         }
    811745
    812746        mr_msg(1, "Making %s", device);
     
    816750            mr_msg(1, "Creating RAID device %s via mdadm returned %d", device, res);
    817751        } else {
    818             sprintf(program, "mkraid --really-force %s", device);
     752            mr_asprintf(&program, "mkraid --really-force %s", device);
    819753            res = run_program_and_log_output(program, 1);
    820754            mr_msg(1, "%s returned %d", program, res);
    821             system("sync");
     755            sync();
    822756            sleep(3);
    823757            start_raid_device(device);
     
    825759                fprintf(g_fprep, "%s\n", program);
    826760            }
    827         }
    828         system("sync");
     761            mr_free(program);
     762        }
     763        sync();
    829764        sleep(2);
    830 //      log_to_screen("Starting %s", device);
    831 //      sprintf(program, "raidstart %s", device);
    832 //      res = run_program_and_log_output(program, 1);
    833 //      mr_msg(1, "%s returned %d", program, res);
    834 //      system("sync"); sleep(1);
    835 #endif
    836         system("sync");
     765#endif
     766        sync();
    837767        sleep(1);
    838768        newtResume();
    839769    }
    840 //#ifndef __FreeBSD__
    841 //#endif
    842770
    843771    if (!strcmp(format, "lvm")) {
    844772        mr_msg(1, "Don't format %s - it's part of an lvm volume", device);
    845         mr_free(program);
    846         mr_free(tmp);
    847773        return (0);
    848774    }
    849     res = which_format_command_do_i_need(format, program);
    850     sprintf(tmp, "%s %s", program, device);
    851     if (strstr(program, "kludge")) {
    852         strcat(tmp, " /");
    853     }
    854     sprintf(program, "sh -c 'echo -en \"y\\ny\\ny\\n\" | %s'", tmp);
    855     sprintf(tmp, "Formatting %s as %s", device, format);
     775    malloc_string(program2);
     776    res = which_format_command_do_i_need(format, program2);
     777    mr_asprintf(&tmp, "%s %s", program2, device);
     778    if (strstr(program2, "kludge")) {
     779        mr_strcat(tmp, " /");
     780    }
     781    mr_free(program2);
     782
     783    mr_asprintf(&program, "sh -c 'echo -en \"y\\ny\\ny\\n\" | %s'", tmp);
     784    mr_free(tmp);
     785
     786    mr_asprintf(&tmp, _("Formatting %s as %s"), device, format);
    856787    update_progress_form(tmp);
     788
    857789    res = run_program_and_log_output(program, FALSE);
    858790    if (res && strstr(program, "kludge")) {
    859         sprintf(tmp, "Kludge failed; using regular mkfs.%s to format %s",
    860                 format, device);
     791        mr_free(tmp);
     792        mr_asprintf(&tmp, _("Kludge failed; using regular mkfs.%s to format %s"), format, device);
     793        mr_free(program);
    861794#ifdef __FreeBSD__
    862         sprintf(program, "newfs_msdos -F 32 %s", device);
     795        mr_asprintf(&program, "newfs_msdos -F 32 %s", device);
    863796#else
    864797#ifdef __IA64__
    865798        /* For EFI partitions take fat16
    866799         * as we want to make small ones */
    867         sprintf(program, "mkfs -t %s -F 16 %s", format, device);
     800        mr_asprintf(&program, "mkfs -t %s -F 16 %s", format, device);
    868801#else
    869         sprintf(program, "mkfs -t %s -F 32 %s", format, device);
     802        mr_asprintf(&program, "mkfs -t %s -F 32 %s", format, device);
    870803#endif
    871804#endif
     
    875808        }
    876809    }
     810    mr_free(program);
     811
    877812    retval += res;
    878813    if (retval) {
    879         strcat(tmp, "...failed");
     814        mr_strcat(tmp, _("...failed"));
    880815    } else {
    881         strcat(tmp, "...OK");
    882     }
    883 
     816        mr_strcat(tmp, _("...OK"));
     817    }
    884818    log_to_screen(tmp);
    885     mr_free(program);
    886819    mr_free(tmp);
    887     system("sync");
     820
     821    sync();
    888822    sleep(1);
    889823    return (retval);
    890824}
    891 
    892 
    893 
    894825
    895826
     
    900831 * @return The number of errors encountered (0 for success).
    901832 */
    902 int format_everything(struct mountlist_itself *mountlist, bool interactively,
    903                           struct raidlist_itself *raidlist)
     833int format_everything(struct mountlist_itself *mountlist,
     834                      bool interactively, struct raidlist_itself *raidlist)
    904835{
    905836    /** int **************************************************************/
    906837    int retval = 0;
    907     int lino;
    908     int res;
    909 //  int i;
    910 //  struct list_of_disks *drivelist;
     838    int lino = 0;
     839    int res = 0;
    911840
    912841    /** long *************************************************************/
    913     long progress_step;
     842    long progress_step = 0L;
    914843
    915844    /** bools ************************************************************/
    916     bool do_it;
     845    bool do_it = FALSE;
    917846
    918847    /** buffers **********************************************************/
    919     char *tmp;
     848    char *tmp = NULL;
    920849
    921850    /** pointers *********************************************************/
    922     struct mountlist_line *me;  // mountlist entry
     851    struct mountlist_line *me = NULL;   // mountlist entry
    923852    /** end **************************************************************/
    924853
    925854    assert(mountlist != NULL);
    926     malloc_string(tmp);
    927     sprintf(tmp, "format_everything (mountlist, interactively = %s",
     855    log_it("format_everything (mountlist, interactively = %s",
    928856            (interactively) ? "true" : "false");
    929     log_it(tmp);
    930     mvaddstr_and_log_it(g_currentY, 0, "Formatting partitions     ");
    931     open_progress_form("Formatting partitions",
    932                        "I am now formatting your hard disk partitions.",
    933                        "This may take up to five minutes.", "",
     857    mvaddstr_and_log_it(g_currentY, 0, _("Formatting partitions     "));
     858    open_progress_form(_("Formatting partitions"),
     859                       _("I am now formatting your hard disk partitions."),
     860                       _("This may take up to five minutes."), "",
    934861                       mountlist->entries + 1);
    935862
     
    937864        (mountlist->entries >
    938865         0) ? g_maximum_progress / mountlist->entries : 1;
    939 // start soft-raids now (because LVM might depend on them)
    940 // ...and for simplicity's sake, let's format them at the same time :)
     866    // start soft-raids now (because LVM might depend on them)
     867    // ...and for simplicity's sake, let's format them at the same time :)
    941868    mr_msg(1, "Stopping all RAID devices");
    942869    stop_all_raid_devices(mountlist);
    943     system("sync");
    944     system("sync");
    945     system("sync");
     870    sync();
     871    sync();
     872    sync();
    946873    sleep(2);
    947874    mr_msg(1, "Prepare soft-RAIDs");    // prep and format too
     
    952879            if (interactively) {
    953880                // ask user if we should format the current device
    954                 sprintf(tmp, "Shall I format %s (%s) ?", me->device,
     881                mr_asprintf(&tmp, "Shall I format %s (%s) ?", me->device,
    955882                        me->mountpoint);
    956883                do_it = ask_me_yes_or_no(tmp);
     884                mr_free(tmp);
    957885            } else {
    958886                do_it = TRUE;
     
    965893        }
    966894    }
    967     system("sync");
    968     system("sync");
    969     system("sync");
     895    sync();
     896    sync();
     897    sync();
    970898    sleep(2);
    971 // This last step is probably necessary
    972 //  log_to_screen("Re-starting software RAIDs...");
    973 //  start_all_raid_devices(mountlist);
    974 //  system("sync"); system("sync"); system("sync");
    975 //  sleep(5);
    976 // do LVMs now
     899    // This last step is probably necessary
     900    //  log_to_screen("Re-starting software RAIDs...");
     901    //  start_all_raid_devices(mountlist);
     902    //  system("sync"); system("sync"); system("sync");
     903    //  sleep(5);
     904    // do LVMs now
    977905    mr_msg(1, "Creating LVMs");
    978906    if (does_file_exist("/tmp/i-want-my-lvm")) {
    979907        wait_until_software_raids_are_prepped("/proc/mdstat", 100);
    980         log_to_screen("Configuring LVM");
     908        log_to_screen(_("Configuring LVM"));
    981909        if (!g_text_mode) {
    982910            newtSuspend();
    983911        }
    984 /*
    985         for(i=0; i<3; i++)
    986           {
    987             res = do_my_funky_lvm_stuff(FALSE, FALSE);
    988             if (!res) { break; }
    989             sleep(3);
    990             res = do_my_funky_lvm_stuff(TRUE, FALSE);
    991             sleep(3);
    992           }
    993         if (res) {
    994             mr_msg(1, "Vacuum-packing...");
    995 */
    996912        res = do_my_funky_lvm_stuff(FALSE, TRUE);
    997 /*
    998         }
    999 */
    1000913        if (!g_text_mode) {
    1001914            newtResume();
     
    1006919            log_to_screen("Failed to initialize LVM");
    1007920        }
    1008         // retval += res;
    1009921        if (res) {
    1010922            retval++;
     
    1012924        sleep(3);
    1013925    }
    1014 // do regulars at last
     926    // do regulars at last
    1015927    sleep(2);                   // woo!
    1016928    mr_msg(1, "Formatting regulars");
     
    1018930        me = &mountlist->el[lino];  // the current mountlist entry
    1019931        if (!strcmp(me->mountpoint, "image")) {
    1020             sprintf(tmp, "Not formatting %s - it's an image", me->device);
    1021             log_it(tmp);
     932            log_it("Not formatting %s - it's an image", me->device);
    1022933        } else if (!strcmp(me->format, "raid")) {
    1023             sprintf(tmp, "Not formatting %s - it's a raid-let",
    1024                     me->device);
    1025             log_it(tmp);
     934            log_it("Not formatting %s - it's a raid-let", me->device);
    1026935            continue;
    1027936        } else if (!strcmp(me->format, "lvm")) {
    1028             sprintf(tmp, "Not formatting %s - it's an LVM", me->device);
    1029             log_it(tmp);
     937            log_it("Not formatting %s - it's an LVM", me->device);
    1030938            continue;
    1031939        } else if (!strncmp(me->device, "/dev/md", 7)) {
    1032             sprintf(tmp, "Already formatted %s - it's a soft-RAID dev",
    1033                     me->device);
    1034             log_it(tmp);
     940            log_it("Already formatted %s - it's a soft-RAID dev", me->device);
    1035941            continue;
    1036942        } else if (!does_file_exist(me->device)
    1037943                   && strncmp(me->device, "/dev/hd", 7)
    1038944                   && strncmp(me->device, "/dev/sd", 7)) {
    1039             sprintf(tmp,
    1040                     "Not formatting %s yet - doesn't exist - probably an LVM",
    1041                     me->device);
    1042             log_it(tmp);
     945            log_it("Not formatting %s yet - doesn't exist - probably an LVM", me->device);
    1043946            continue;
    1044947        } else {
    1045948            if (interactively) {
    1046949                // ask user if we should format the current device
    1047                 sprintf(tmp, "Shall I format %s (%s) ?", me->device,
     950                mr_asprintf(&tmp, "Shall I format %s (%s) ?", me->device,
    1048951                        me->mountpoint);
    1049952                do_it = ask_me_yes_or_no(tmp);
     953                mr_free(tmp);
    1050954            } else {
    1051955                do_it = TRUE;
     
    1069973
    1070974    if (retval) {
    1071         mvaddstr_and_log_it(g_currentY++, 74, "Failed.");
     975        mvaddstr_and_log_it(g_currentY++, 74, _("Failed."));
    1072976        log_to_screen
    1073             ("Errors occurred during the formatting of your hard drives.");
     977            (_
     978             ("Errors occurred during the formatting of your hard drives."));
    1074979    } else {
    1075         mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    1076     }
    1077 
    1078     sprintf(tmp, "format_everything () - %s",
     980        mvaddstr_and_log_it(g_currentY++, 74, _("Done."));
     981    }
     982
     983    log_it("format_everything () - %s",
    1079984            (retval) ? "failed!" : "finished successfully");
    1080     log_it(tmp);
    1081985
    1082986    if (g_partition_table_locked_up > 0) {
     
    1084988//123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789
    1085989            log_to_screen
    1086                 ("Partition table locked up %d times. At least one 'mkfs' (format) command",
     990                (_
     991                 ("Partition table locked up %d times. At least one 'mkfs' (format) command"),
    1087992                 g_partition_table_locked_up);
    1088             log_to_screen
    1089                 ("failed. I think these two events are related. Sometimes, fdisk's ioctl() call");
    1090             log_to_screen
    1091                 ("to refresh its copy of the partition table causes the kernel to lock the ");
    1092             log_to_screen
    1093                 ("partition table. I believe this has just happened.");
     993            log_to_screen(_
     994                          ("failed. I think these two events are related. Sometimes, fdisk's ioctl() call"));
     995            log_to_screen(_
     996                          ("to refresh its copy of the partition table causes the kernel to lock the "));
     997            log_to_screen(_
     998                          ("partition table. I believe this has just happened."));
    1094999            if (ask_me_yes_or_no
    1095                 ("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue."))
     1000                (_
     1001                 ("Please choose 'yes' to reboot and try again; or 'no' to ignore this warning and continue.")))
    10961002            {
    1097                 system("sync");
    1098                 system("sync");
    1099                 system("sync");
     1003                sync();
     1004                sync();
     1005                sync();
    11001006                system("reboot");
    11011007            }
    11021008        } else {
    11031009            log_to_screen
    1104                 ("Partition table locked up %d time%c. However, disk formatting succeeded.",
     1010                (_
     1011                 ("Partition table locked up %d time%c. However, disk formatting succeeded."),
    11051012                 g_partition_table_locked_up,
    11061013                 (g_partition_table_locked_up == 1) ? '.' : 's');
     
    11101017    system("clear");
    11111018    newtResume();
    1112     mr_free(tmp);
    11131019    return (retval);
    11141020}
     
    11271033{
    11281034    /** int **************************************************************/
    1129     int current_devno;
    1130     int previous_devno;
     1035    int current_devno = 0;
     1036    int previous_devno = 0;
    11311037    int retval = 0;
    1132     int res;
    1133 
    1134     /** buffers **********************************************************/
    1135     char *tmp;
     1038    int res = 0;
    11361039
    11371040    /** end **************************************************************/
    11381041
    1139     malloc_string(tmp);
    11401042    assert_string_is_neither_NULL_nor_zerolength(drivename);
    11411043
    11421044    if (devno_we_must_allow_for >= 5) {
    1143         sprintf(tmp, "Making dummy primary %s%d", drivename, 1);
    1144         log_it(tmp);
     1045        log_it("Making dummy primary %s%d", drivename, 1);
    11451046        g_maximum_progress++;
    11461047        res =
     
    11551056    }
    11561057    for (; current_devno < devno_we_must_allow_for; current_devno++) {
    1157         sprintf(tmp, "Creating dummy partition %s%d", drivename,
    1158                 current_devno);
    1159         log_it(tmp);
     1058        log_it("Creating dummy partition %s%d", drivename, current_devno);
    11601059        g_maximum_progress++;
    11611060        res =
     
    11651064        previous_devno = current_devno;
    11661065    }
    1167     mr_free(tmp);
    11681066    return (previous_devno);
    11691067}
     
    11961094    }
    11971095}
     1096
    11981097
    11991098/* The following 2 functions are stolen from /usr/src/sbin/disklabel/disklabel.c */
     
    12971196{
    12981197    static struct disklabel loclab;
    1299     struct partition *dp;
    1300     char lnamebuf[BBSIZE];
     1198    struct partition *dp = NULL;
     1199    char *lnamebuf = NULL;
    13011200    int f;
    13021201    u_int secsize, u;
    13031202    off_t mediasize;
    13041203
    1305     (void) snprintf(lnamebuf, BBSIZE, "%s", dkname);
     1204    mr_asprintf(&lnamebuf, "%s", dkname);
    13061205    if ((f = open(lnamebuf, O_RDONLY)) == -1) {
    13071206        warn("cannot open %s", lnamebuf);
     1207        mr_free(lnamebuf);
    13081208        return (NULL);
    13091209    }
     1210    mr_free(lnamebuf);
    13101211
    13111212    /* New world order */
     
    13781279                         char *drivename, struct disklabel *ret)
    13791280{
    1380     char subdev_str[MAX_STR_LEN];
    1381     char command[MAX_STR_LEN];
    1382     struct disklabel *lp;
     1281    char *subdev_str = NULL;
     1282    char *command = NULL;
     1283    struct disklabel *lp = NULL;
    13831284    int i, lo = 0;
    13841285    int retval = 0;
    1385     char c;
    1386     FILE *ftmp;
     1286    char c = ' ';
     1287    FILE *ftmp = NULL;
    13871288
    13881289    lp = get_virgin_disklabel(drivename);
    13891290    for (c = 'a'; c <= 'z'; ++c) {
    13901291        int idx;
    1391         sprintf(subdev_str, "%s%c", drivename, c);
     1292        mr_asprintf(&subdev_str, "%s%c", drivename, c);
    13921293        if ((idx = find_device_in_mountlist(mountlist, subdev_str)) < 0) {
    13931294            lp->d_partitions[c - 'a'].p_size = 0;
     
    14141315                lp->d_partitions[c - 'a'].p_fstype = FS_OTHER;
    14151316        }
     1317        mr_free(subdev_str);
    14161318    }
    14171319
     
    14441346    display_disklabel(ftmp, lp);
    14451347    fclose(ftmp);
    1446     sprintf(command, "disklabel -wr %s auto", canonical_name(drivename));
     1348    mr_asprintf(&command, "disklabel -wr %s auto", canonical_name(drivename));
    14471349    retval += run_program_and_log_output(command, TRUE);
    1448     sprintf(command, "disklabel -R %s /tmp/disklabel",
     1350    mr_free(command);
     1351
     1352    mr_asprintf(&command, "disklabel -R %s /tmp/disklabel",
    14491353            canonical_name(drivename));
    14501354    retval += run_program_and_log_output(command, TRUE);
     1355    mr_free(command);
    14511356    if (ret)
    14521357        *ret = *lp;
     
    14651370{
    14661371    /** int *************************************************************/
    1467     int current_devno;
     1372    int current_devno = 0;
    14681373    int previous_devno = 0;
    1469     int lino;
     1374    int lino = 0;
    14701375    int retval = 0;
    1471     int i;
     1376    int i = 0;
    14721377    FILE *pout_to_fdisk = NULL;
    14731378
    14741379#ifdef __FreeBSD__
    14751380    bool fbsd_part = FALSE;
    1476     char subdev_str[MAX_STR_LEN];
     1381    char *subdev_str = NULL;
    14771382#endif
    14781383
     
    14811386
    14821387    /** buffers *********************************************************/
    1483     char *device_str;
    1484     char *format;
    1485     char *tmp;
     1388    char *device_str = NULL;
     1389    char *format = NULL;
     1390    char *tmp = NULL;
     1391    char *tmp1 = NULL;
    14861392
    14871393    /** end *************************************************************/
     
    14901396    assert_string_is_neither_NULL_nor_zerolength(drivename);
    14911397
    1492     malloc_string(device_str);
    1493     malloc_string(format);
    1494     malloc_string(tmp);
    1495 
    1496     sprintf(tmp, "Partitioning drive %s", drivename);
    1497     log_it(tmp);
     1398    log_it("Partitioning drive %s", drivename);
    14981399
    14991400#if __FreeBSD__
     
    15021403#else
    15031404    make_hole_for_file(FDISK_LOG);
    1504     sprintf(tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG, FDISK_LOG);
     1405    mr_asprintf(&tmp, "parted2fdisk %s >> %s 2>> %s", drivename, FDISK_LOG,
     1406            FDISK_LOG);
    15051407    pout_to_fdisk = popen(tmp, "w");
     1408    mr_free(tmp);
     1409
    15061410    if (!pout_to_fdisk) {
    1507         log_to_screen("Cannot call parted2fdisk to configure %s", drivename);
    1508         mr_free(device_str);
    1509         mr_free(format);
    1510         mr_free(tmp);
     1411        log_to_screen(_("Cannot call parted2fdisk to configure %s"),
     1412                      drivename);
    15111413        return (1);
    15121414    }
    15131415#endif
     1416
     1417    malloc_string(device_str);
     1418
    15141419    for (current_devno = 1; current_devno < 99; current_devno++) {
    15151420        build_partition_name(device_str, drivename, current_devno);
     
    15221427            // then see if the user has picked 'dangerously-dedicated' mode.
    15231428            // If so, then we just call label_drive_or_slice() and return.
    1524             char c;
     1429            char c = ' ';
     1430            char *command = NULL;
     1431
    15251432            if (current_devno == 1) {
    15261433                // try DangerouslyDedicated mode
    15271434                for (c = 'a'; c <= 'z'; c++) {
    1528                     sprintf(subdev_str, "%s%c", drivename, c);
    1529                     if (find_device_in_mountlist(mountlist, subdev_str) >
    1530                         0) {
     1435                    mr_asprintf(&subdev_str, "%s%c", drivename, c);
     1436                    if (find_device_in_mountlist(mountlist, subdev_str) > 0) {
    15311437                        fbsd_part = TRUE;
    15321438                    }
     1439                    mr_free(subdev_str);
    15331440                }
    15341441                if (fbsd_part) {
     
    15361443                                                 drivename,
    15371444                                                 0);
    1538                     char command[MAX_STR_LEN];
    1539                     sprintf(command, "disklabel -B %s",
     1445                    mr_asprintf(&command, "disklabel -B %s",
    15401446                            basename(drivename));
    15411447                    if (system(command)) {
    15421448                        log_to_screen
    1543                             ("Warning! Unable to make the drive bootable.");
     1449                            (_
     1450                             ("Warning! Unable to make the drive bootable."));
    15441451                    }
     1452                    mr_free(command);
    15451453                    mr_free(device_str);
    1546                     mr_free(format);
    1547                     mr_free(tmp);
    15481454                    return r;
    15491455                }
    15501456            }
    15511457            for (c = 'a'; c <= 'z'; c++) {
    1552                 sprintf(subdev_str, "%s%c", device_str, c);
     1458                mr_asprintf(&subdev_str, "%s%c", device_str, c);
    15531459                if (find_device_in_mountlist(mountlist, subdev_str) > 0) {
    15541460                    fbsd_part = TRUE;
    15551461                }
     1462                mr_free(subdev_str);
    15561463            }
    15571464            // Now we check the subpartitions of the current partition.
     
    15591466                int i, line;
    15601467
    1561                 strcpy(format, "ufs");
     1468                mr_asprintf(&format, "ufs");
    15621469                partsize = 0;
    15631470                for (i = 'a'; i < 'z'; ++i) {
    1564                     sprintf(subdev_str, "%s%c", device_str, i);
     1471                    mr_asprintf(&subdev_str, "%s%c", device_str, i);
    15651472                    line = find_device_in_mountlist(mountlist, subdev_str);
     1473                    mr_free(subdev_str);
     1474
    15661475                    if (line > 0) {
    15671476                        // We found one! Add its size to the total size.
     
    15861495#if __FreeBSD__
    15871496            // FreeBSD doesn't let you write to blk devices in <512byte chunks.
    1588 //          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
    1589 //          if (run_program_and_log_output(tmp, TRUE)) {
    15901497            file = open(drivename, O_WRONLY);
    15911498            if (!file) {
    1592                 sprintf(tmp,
    1593                         "Warning - unable to open %s for wiping it's partition table",
    1594                         drivename);
    1595                 log_to_screen(tmp);
     1499                log_to_screen(_("Warning - unable to open %s for wiping it's partition table"), drivename);
    15961500            }
    15971501
    15981502            for (i = 0; i < 512; i++) {
    15991503                if (!write(file, "\0", 1)) {
    1600                     sprintf(tmp, "Warning - unable to write to %s",
    1601                             drivename);
    1602                     log_to_screen(tmp);
     1504                    log_to_screen(_("Warning - unable to write to %s"), drivename);
    16031505                }
    16041506            }
    1605             system("sync");
     1507            sync();
    16061508#else
    16071509            iamhere("New, kernel-friendly partition remover");
     
    16101512                fflush(pout_to_fdisk);
    16111513            }
    1612 //          sprintf(tmp, "dd if=/dev/zero of=%s count=1 bs=512", drivename);
    1613 //          run_program_and_log_output(tmp, 1);
    16141514#endif
    16151515            if (current_devno > 1) {
     
    16221522        if (!fbsd_part) {
    16231523#endif
    1624 
    1625             strcpy(format, mountlist->el[lino].format);
     1524            mr_free(format);
     1525            mr_asprintf(&format, mountlist->el[lino].format);
    16261526            partsize = mountlist->el[lino].size;
    16271527
     
    16331533        if (current_devno == 5 && previous_devno == 4) {
    16341534            log_to_screen
    1635                 ("You must leave at least one partition spare as the Extended partition.");
     1535                (_
     1536                 ("You must leave at least one partition spare as the Extended partition."));
    16361537            mr_free(device_str);
    16371538            mr_free(format);
    1638             mr_free(tmp);
    16391539            return (1);
    16401540        }
     
    16471547#ifdef __FreeBSD__
    16481548        if ((current_devno <= 4) && fbsd_part) {
    1649             sprintf(tmp, "disklabel -B %s", basename(device_str));
     1549            mr_asprintf(&tmp, "disklabel -B %s", basename(device_str));
    16501550            retval += label_drive_or_slice(mountlist, device_str, 0);
    16511551            if (system(tmp)) {
    16521552                log_to_screen
    1653                     ("Warning! Unable to make the slice bootable.");
    1654             }
     1553                    (_("Warning! Unable to make the slice bootable."));
     1554            }
     1555            mr_free(tmp);
    16551556        }
    16561557#endif
     
    16581559        previous_devno = current_devno;
    16591560    }
     1561    mr_free(device_str);
     1562    mr_free(format);
    16601563
    16611564    if (pout_to_fdisk) {
    1662 // mark relevant partition as bootable
    1663         sprintf(tmp, "a\n%s\n",
     1565        // mark relevant partition as bootable
     1566        mr_asprintf(&tmp, "a\n%s\n",
    16641567                call_program_and_get_last_line_of_output
    16651568                ("make-me-bootable /tmp/mountlist.txt dummy"));
    16661569        fput_string_one_char_at_a_time(pout_to_fdisk, tmp);
    1667 // close fdisk
     1570        mr_free(tmp);
     1571
     1572        // close fdisk
    16681573        fput_string_one_char_at_a_time(pout_to_fdisk, "w\n");
    1669         system("sync");
     1574        sync();
    16701575        paranoid_pclose(pout_to_fdisk);
    16711576        mr_msg(0,
    16721577                "------------------- fdisk.log looks like this ------------------");
    1673         sprintf(tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE);
     1578        mr_asprintf(&tmp, "cat %s >> %s", FDISK_LOG, MONDO_LOGFILE);
    16741579        system(tmp);
     1580        mr_free(tmp);
     1581
    16751582        mr_msg(0,
    16761583                "------------------- end of fdisk.log... word! ------------------");
    1677         sprintf(tmp, "tail -n6 %s | grep -F \"16: \"", FDISK_LOG);
     1584        mr_asprintf(&tmp, "tail -n6 %s | grep -F \"16: \"", FDISK_LOG);
    16781585        if (!run_program_and_log_output(tmp, 5)) {
    16791586            g_partition_table_locked_up++;
    16801587            log_to_screen
    1681                 ("A flaw in the Linux kernel has locked the partition table.");
    1682         }
    1683     }
    1684     mr_free(device_str);
    1685     mr_free(format);
    1686     mr_free(tmp);
     1588                (_
     1589                 ("A flaw in the Linux kernel has locked the partition table."));
     1590        }
     1591        mr_free(tmp);
     1592    }
    16871593    return (retval);
    16881594}
     1595
    16891596
    16901597/**
  • branches/stable/mondo/src/mondorestore/mondo-rstr-tools.c

    r1168 r1196  
    24272427                sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/");
    24282428                run_program_and_log_output(command, 1);
    2429 /*        sprintf(command, "grep \" lvm \" %s", g_mountlist_fname);
    2430           if (!run_program_and_log_output(command, 5) && !does_file_exist("/tmp/i-want-my-lvm"))
    2431             {
    2432           mr_msg(1, "Warning. You want LVM but I don't have i-want-my-lvm. FIXME.");
    2433         }
    2434               else if (run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm"))
    2435                 {
    2436           mr_msg(1, "Warning. You don't want LVM but i-want-my-lvm exists. I'll delete it. Cool.");
    2437               do_my_funky_lvm_stuff(TRUE, FALSE); // ...after I stop any LVMs :)
    2438           stop_raid_device("/dev/md0");
    2439           stop_raid_device("/dev/md1");
    2440           stop_raid_device("/dev/md2");
    2441           unlink("/tmp/i-want-my-lvm");
    2442         }
    2443           else if (!run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm"))
    2444             {
    2445           mr_msg(1, "You had better pray that i-want-my-lvm patches your mountlist. FIXME.");
    2446         }
    2447 */
    24482429            }
    24492430        }
  • branches/stable/mondo/src/test/test-mem.c

    r1178 r1196  
    3838    mr_free(str);
    3939
     40    printf("*** Test2 with mr_strcat\n");
     41    mr_asprintf(&str,"Another Chain");
     42    mr_strcat(str," %s", "of distrust");
     43    printf("Result: %s\n",str);
     44    mr_free(str);
     45
    4046    printf("*** Test with mr_getline/mr_free\n");
    4147    fd = mr_fopen("/etc/passwd","r");
  • branches/stable/mondo/src/test/test-mem.res

    r1178 r1196  
    66*** Test with mr_strcat
    77Result: Another Chain of trust
     8*** Test2 with mr_strcat
     9Result: Another Chain of distrust
    810*** Test with mr_getline/mr_free
    9111st Result: root:x:0:0:root:/root:/bin/bash
  • branches/stable/tools/quality

    r1129 r1196  
    2828
    2929# How many sprintf/strcat/strcpy vs asprintf are they
    30 for s in asprintf mr_asprintf sprintf strcat strcpy strncpy fgets malloc mr_malloc malloc_string getline mr_getline MAX_STR_LEN getcwd goto free mr_free paranoid_free; do
     30for s in asprintf mr_asprintf sprintf strcat strcpy strncpy malloc mr_malloc malloc_string fgets getline mr_getline MAX_STR_LEN getcwd goto free mr_free paranoid_free system paranoid_system mr_system; do
    3131    echo "monodrescue $s usage : "
    3232    tot=0
Note: See TracChangeset for help on using the changeset viewer.