Changeset 2272 in MondoRescue


Ignore:
Timestamp:
Jul 12, 2009, 2:05:33 AM (15 years ago)
Author:
Bruno Cornec
Message:

r3224@localhost: bruno | 2009-07-11 15:05:24 +0200
Replace sprintf by mr_asprintf in libmondo-files.c

File:
1 edited

Legend:

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

    r2242 r2272  
    4747    /*@ buffers ***************************************************** */
    4848    static char output[MAX_STR_LEN];
    49     char command[MAX_STR_LEN * 2];
    50     char tmp[MAX_STR_LEN];
     49    char *command = NULL;
     50    char *tmp = NULL;
    5151
    5252    /*@ pointers **************************************************** */
     
    6262    assert_string_is_neither_NULL_nor_zerolength(filename);
    6363    if (does_file_exist(filename)) {
    64         sprintf(command, "md5sum \"%s\"", filename);
     64        mr_asprintf(&command, "md5sum \"%s\"", filename);
    6565        fin = popen(command, "r");
    6666        if (fin) {
     
    6969            paranoid_pclose(fin);
    7070        }
     71        mr_free(command);
    7172    } else {
    72         sprintf(tmp, "File '%s' not found; cannot calc checksum",
     73        mr_asprintf(&tmp, "File '%s' not found; cannot calc checksum",
    7374                filename);
    7475        log_it(tmp);
     76        mr_free(tmp);
    7577    }
    7678    if (p) {
     
    126128
    127129    /*@ buffers ***************************************************** */
    128     char command[MAX_STR_LEN * 2];
     130    char *command = NULL;
    129131    char incoming[MAX_STR_LEN];
    130     char tmp[MAX_STR_LEN];
     132    char *tmp = NULL;
    131133
    132134    /*@ long ******************************************************** */
     
    141143    assert_string_is_neither_NULL_nor_zerolength(filename);
    142144    if (!does_file_exist(filename)) {
    143         sprintf(tmp,
     145        mr_asprintf(&tmp,
    144146                "%s does not exist, so I cannot found the number of lines in it",
    145147                filename);
    146148        log_it(tmp);
     149        mr_free(tmp);
    147150        return (0);
    148151    }
    149     sprintf(command, "cat %s | wc -l", filename);
     152    mr_asprintf(&command, "cat %s | wc -l", filename);
    150153    if (!does_file_exist(filename)) {
     154        mr_free(command);
    151155        return (-1);
    152156    }
    153157    fin = popen(command, "r");
     158    mr_free(command);
    154159    if (fin) {
    155160        if (feof(fin)) {
     
    207212void exclude_nonexistent_files(char *inout)
    208213{
    209     char infname[MAX_STR_LEN];
    210     char outfname[MAX_STR_LEN];
    211     char tmp[MAX_STR_LEN];
     214    char *infname = NULL;
     215    char *outfname = NULL;
     216    char *tmp  NULL;
    212217    char incoming[MAX_STR_LEN];
    213218
     
    222227
    223228    assert_string_is_neither_NULL_nor_zerolength(inout);
    224     sprintf(infname, "%s.in", inout);
    225     sprintf(outfname, "%s", inout);
    226     sprintf(tmp, "cp -f %s %s", inout, infname);
     229    mr_asprintf(&infname, "%s.in", inout);
     230    mr_asprintf(&outfname, "%s", inout);
     231    mr_asprintf(&tmp, "cp -f %s %s", inout, infname);
    227232    run_program_and_log_output(tmp, FALSE);
     233    mr_free(tmp);
     234
    228235    if (!(fin = fopen(infname, "r"))) {
    229236        log_OS_error("Unable to openin infname");
     237        mr_free(infname);
    230238        return;
    231239    }
    232240    if (!(fout = fopen(outfname, "w"))) {
    233241        log_OS_error("Unable to openout outfname");
     242        mr_free(outfname);
    234243        return;
    235244    }
     245    mr_free(outfname);
     246
    236247    for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin);
    237248         fgets(incoming, MAX_STR_LEN, fin)) {
     
    243254            fprintf(fout, "%s\n", incoming);
    244255        } else {
    245             sprintf(tmp, "Excluding '%s'-nonexistent\n", incoming);
     256            mr_asprintf(&tmp, "Excluding '%s'-nonexistent\n", incoming);
    246257            log_it(tmp);
     258            mr_free(tmp);
    247259        }
    248260    }
     
    250262    paranoid_fclose(fin);
    251263    unlink(infname);
     264    mr_free(infname);
    252265}
    253266
     
    269282int figure_out_kernel_path_interactively_if_necessary(char *kernel)
    270283{
    271     char tmp[MAX_STR_LEN];
    272     char *command;
     284    char *tmp = NULL;
     285    char *command = NULL;;
    273286
    274287    if (!kernel[0]) {
     
    279292    // If we didn't get anything back, check whether mindi raised a fatal error
    280293    if (!kernel[0]) {
    281         malloc_string(command);
    282         strcpy(command, "grep 'Fatal error' /var/log/mindi.log");
    283         strcpy(tmp, call_program_and_get_last_line_of_output(command));
     294        mr_asprintf(&command, "%s", "grep 'Fatal error' /var/log/mindi.log");
     295        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    284296        if (strlen(tmp) > 1) {
    285297            popup_and_OK(tmp);
     298            mr_free(tmp);
     299            mr_free(command);
    286300            fatal_error("Mindi gave a fatal error. Please check '/var/log/mindi.log'.");
    287301        }
    288         paranoid_free(command);
     302        mr_free(tmp);
     303        mr_free(command);
    289304    }
    290305    log_it("Calling Mindi with kernel path of '%s'", kernel);
     
    301316                ("Kernel not found. Please specify with the '-k' flag.");
    302317        }
    303         sprintf(tmp, "User says kernel is at %s", kernel);
     318        mr_asprintf(&tmp, "User says kernel is at %s", kernel);
    304319        log_it(tmp);
     320        mr_free(tmp);
    305321    }
    306322    return (0);
     
    326342    static char output[MAX_STR_LEN];
    327343    char *incoming;
    328     char *command;
     344    char *command = NULL;
    329345
    330346    malloc_string(incoming);
    331     malloc_string(command);
    332347    incoming[0] = '\0';
    333348    /*@******************************* */
    334349
    335350    assert_string_is_neither_NULL_nor_zerolength(fname);
    336     sprintf(command, "which %s 2> /dev/null", fname);
     351    mr_asprintf(&command, "which %s 2> /dev/null", fname);
    337352    strcpy(incoming, call_program_and_get_last_line_of_output(command));
     353    mr_free(command);
    338354    if (incoming[0] == '\0') {
    339355        if (system("which file > /dev/null 2> /dev/null")) {
    340356            paranoid_free(incoming);
    341             paranoid_free(command);
    342357            output[0] = '\0';
    343358            return (NULL);      // forget it :)
    344359        }
    345         sprintf(command,
     360        mr_asprintf(&command,
    346361                "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null",
    347362                incoming);
    348363        strcpy(incoming,
    349364               call_program_and_get_last_line_of_output(command));
     365        mr_free(command);
    350366    }
    351367    if (incoming[0] == '\0')    // yes, it is == '\0' twice, not once :)
    352368    {
    353         sprintf(command, "dirname %s 2> /dev/null", incoming);
     369        mr_asprintf(&command, "dirname %s 2> /dev/null", incoming);
    354370        strcpy(incoming,
    355371               call_program_and_get_last_line_of_output(command));
     372        mr_free(command);
    356373    }
    357374    strcpy(output, incoming);
     
    364381    }
    365382    paranoid_free(incoming);
    366     paranoid_free(command);
    367383    if (!output[0]) {
    368384        return (NULL);
     
    412428    for (; len > 0 && isdigit(datablock[len - 1]); len--);
    413429    trackno = atoi(datablock + len);
    414     /*
    415        sprintf(tmp,"datablock=%s; trackno=%d",datablock+len, trackno);
    416        log_it(tmp);
    417      */
    418430    return (trackno);
    419431}
     
    435447
    436448    /*@ buffers ***************************************************** */
    437     char tmp[MAX_STR_LEN];
    438449    char lastline[MAX_STR_LEN];
    439     char command[MAX_STR_LEN];
     450    char *command = NULL;
    440451    /*@ pointers **************************************************** */
    441452    char *p;
     
    448459         && !strstr(err_log_lines[i], "% done"); i--);
    449460    if (i < 0) {
    450         sprintf(command,
     461        mr_asprintf(&command,
    451462                "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'",
    452463                filename, '%');
    453464        strcpy(lastline,
    454465               call_program_and_get_last_line_of_output(command));
     466        mr_free(command);
    455467        if (!lastline[0]) {
    456468            return (0);
     
    464476        *p = '\0';
    465477    }
    466 //  log_msg(2, "lastline='%s', ", p, lastline);
    467478    if (!p) {
    468479        return (0);
     
    475486    i = atoi(p);
    476487
    477     sprintf(tmp, "'%s' --> %d", p, i);
    478 //     log_to_screen(tmp);
    479 
    480488    return (i);
    481489}
     
    495503    /*@ buffers ***************************************************** */
    496504    static char output[MAX_STR_LEN];
    497     static char command[MAX_STR_LEN * 2];
    498     static char tmp[MAX_STR_LEN];
     505    char *command = NULL
     506    char *tmp = NULL;
    499507
    500508    /*@ pointers **************************************************** */
     
    504512
    505513    if (!does_file_exist(filename)) {
    506         sprintf(tmp, "Tring to get last line of nonexistent file (%s)",
     514        mr_asprintf(&tmp, "Tring to get last line of nonexistent file (%s)",
    507515                filename);
    508516        log_it(tmp);
     517        mr_free(tmp);
    509518        output[0] = '\0';
    510519        return (output);
    511520    }
    512     sprintf(command, "tail -n1 %s", filename);
     521    mr_asprintf(&command, "tail -n1 %s", filename);
    513522    fin = popen(command, "r");
     523    mr_free(command);
     524
    514525    (void) fgets(output, MAX_STR_LEN, fin);
    515526    paranoid_pclose(fin);
     
    567578    char curr_fname[1000];
    568579    char curr_cksum[1000];
    569     char tmp[1000];
     580    char *tmp = NULL;
    570581
    571582    /*@ long [long] ************************************************* */
     
    581592    start_time = get_time();
    582593    filelist_length = length_of_file(filelist);
    583     sprintf(tmp, "filelist = %s; cksumlist = %s", filelist, cksumlist);
    584     log_it(tmp);
     594    log_it("filelist = %s; cksumlist = %s", filelist, cksumlist);
     595
    585596    fin = fopen(filelist, "r");
    586597    if (fin == NULL) {
     
    601612            stub_fname[i] = '\0';
    602613        }
    603         sprintf(tmp, "%s%s", comppath, stub_fname);
     614        mr_asprintf(&tmp, "%s%s", comppath, stub_fname);
    604615        strcpy(curr_fname, tmp + 1);
     616        mr_free(tmp);
     617
    605618        strcpy(curr_cksum, calc_file_ugly_minichecksum(curr_fname));
    606619        fprintf(fout, "%s\t%s\n", curr_fname, curr_cksum);
     
    617630                time_remaining =
    618631                    time_taken * 100 / (long) (percentage) - time_taken;
    619                 sprintf(tmp,
     632                mr_asprintf(&tmp,
    620633                        "%02d%% done   %02d:%02d taken   %02d:%02d remaining  %-37s\r",
    621634                        percentage, (int) (time_taken / 60),
     
    624637                        (int) (time_remaining % 60), curr_fname);
    625638                log_to_screen(tmp);
     639                mr_free(tmp);
    626640            }
    627641            sync();
     
    642656int make_hole_for_dir(char *outdir_fname)
    643657{
    644     char tmp[MAX_STR_LEN * 2];
     658    char *tmp = NULL;
    645659    int res = 0;
    646660
    647661    assert_string_is_neither_NULL_nor_zerolength(outdir_fname);
    648     sprintf(tmp, "mkdir -p %s", outdir_fname);
     662    mr_asprintf(&tmp, "mkdir -p %s", outdir_fname);
    649663    res = system(tmp);
     664    mr_free(tmp);
    650665    return (res);
    651666}
     
    661676{
    662677    /*@ buffer ****************************************************** */
    663     char command[MAX_STR_LEN * 2];
     678    char *command = NULL;
    664679
    665680    /*@ int  ******************************************************** */
     
    671686    assert(!strstr(outfile_fname, MNT_CDROM));
    672687    assert(!strstr(outfile_fname, "/dev/cdrom"));
    673     sprintf(command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);
     688    mr_asprintf(&command, "mkdir -p \"%s\" 2> /dev/null", outfile_fname);
    674689    res += system(command);
    675     sprintf(command, "rmdir \"%s\" 2> /dev/null", outfile_fname);
     690    mr_free(command);
     691
     692    mr_asprintf(&command, "rmdir \"%s\" 2> /dev/null", outfile_fname);
    676693    res += system(command);
    677     sprintf(command, "rm -f \"%s\" 2> /dev/null", outfile_fname);
     694    mr_free(command);
     695
     696    mr_asprintf(&command, "rm -f \"%s\" 2> /dev/null", outfile_fname);
    678697    res += system(command);
     698    mr_free(command);
     699
    679700    unlink(outfile_fname);
    680701    return (0);
     
    731752long size_of_partition_in_mountlist_K(char *tmpdir, char *dev)
    732753{
    733     char command[MAX_STR_LEN];
    734     char mountlist[MAX_STR_LEN];
     754    char *command = NULL;
     755    char *mountlist = NULL;
    735756    char sz_res[MAX_STR_LEN];
    736757    long file_len_K;
    737758
    738     sprintf(mountlist, "%s/mountlist.txt", tmpdir);
    739     sprintf(command,
     759    mr_asprintf(&mountlist, "%s/mountlist.txt", tmpdir);
     760    mr_asprintf(&command,
    740761            "grep \"%s \" %s/mountlist.txt | head -n1 | awk '{print $4}'",
    741762            dev, tmpdir);
     763    mr_free(mountlist);
     764
    742765    log_it(command);
    743766    strcpy(sz_res, call_program_and_get_last_line_of_output(command));
    744767    file_len_K = atol(sz_res);
    745768    log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K);
     769    mr_free(command);
     770
    746771    return (file_len_K);
    747772}
     
    756781    /*@ buffers ***************************************************** */
    757782    char *fname;
    758     char *biggielist;
    759     char *comment;
    760     char *tmp;
    761     char *command;
     783    char *biggielist = NULL;
     784    char *comment = NULL;
     785    char *tmp = NULL;
     786    char *command = NULL;
    762787
    763788    /*@ long ******************************************************** */
     
    765790    long file_len_K;
    766791
     792    int res = 0;
     793
    767794    /*@ pointers *************************************************** */
    768795    FILE *fin = NULL;
     
    771798
    772799    malloc_string(fname);
    773     malloc_string(biggielist);
    774     malloc_string(comment);
    775     malloc_string(tmp);
    776     malloc_string(command);
    777800    log_it("Calculating size of all biggiefiles (in total)");
    778     sprintf(biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
     801    mr_asprintf(&biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
    779802    log_it("biggielist = %s", biggielist);
    780     if (!(fin = fopen(biggielist, "r"))) {
    781         log_OS_error
    782             ("Cannot open biggielist. OK, so estimate is based on filesets only.");
     803    fin = fopen(biggielist, "r");
     804    mr_free(biggielist);
     805
     806    if (!(fin)) {
     807        log_OS_error("Cannot open biggielist. OK, so estimate is based on filesets only.");
    783808    } else {
    784809        log_msg(4, "Reading it...");
     
    793818                        fatal_error("ntfsresize not found");
    794819                    }
    795                     sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);
     820                    mr_asprintf(&command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);
    796821                    log_it("command = %s", command);
    797                     strcpy (tmp, call_program_and_get_last_line_of_output(command));
     822                    mr_asorintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     823                    mr_free(command);
     824
    798825                    log_it("res of it = %s", tmp);
    799826                    file_len_K = atoll(tmp) / 1024L;
     827                    mr_free(tmp);
    800828                } else {
    801829                    file_len_K = get_phys_size_of_drive(fname) * 1024L;
     
    809837                log_msg(4, "%s --> %ld K", fname, file_len_K);
    810838            }
    811             sprintf(comment,
     839            mr_asprintf(&comment,
    812840                    "After adding %s, scratchL+%ld now equals %ld", fname,
    813841                    file_len_K, scratchL);
    814842            log_msg(4, comment);
     843            mr_free(comment);
    815844            if (feof(fin)) {
    816845                break;
     
    822851    log_it("Finished calculating total size of all biggiefiles");
    823852    paranoid_free(fname);
    824     paranoid_free(biggielist);
    825     paranoid_free(comment);
    826     paranoid_free(tmp);
    827     paranoid_free(command);
    828853    return (scratchL);
    829854}
     
    839864    /*@ buffer ****************************************************** */
    840865    char tmp[MAX_STR_LEN];
    841     char command[MAX_STR_LEN * 2];
     866    char *command = NULL;
    842867    long long llres;
    843868    /*@ pointers **************************************************** */
     
    847872    /*@ end vars *************************************************** */
    848873
    849     sprintf(command, "du -sk %s", mountpt);
     874    mr_asprintf(&command, "du -sk %s", mountpt);
    850875    errno = 0;
    851876    fin = popen(command, "r");
     
    865890      }
    866891    }
     892    mr_free(command);
    867893
    868894    return (llres);
     
    912938{
    913939    /*@ buffers *** */
    914     char command[MAX_STR_LEN * 2];
    915     char errorstr[MAX_STR_LEN];
    916 
    917 
    918     sprintf(command, "which %s > /dev/null 2> /dev/null", fname);
    919     sprintf(errorstr,
    920             "Please install '%s'. I cannot find it on your system.",
    921             fname);
    922     if (system(command)) {
     940    char *command = NULL;
     941    char *errorstr = NULL;
     942    int res = 0;
     943
     944    mr_asprintf(&command, "which %s > /dev/null 2> /dev/null", fname);
     945    res = system(command);
     946    mr_free(command);
     947
     948    if (res) {
     949        mr_asprintf(&errorstr, "Please install '%s'. I cannot find it on your system.", fname);
    923950        log_to_screen(errorstr);
    924         log_to_screen
    925             ("There may be hyperlink at http://www.mondorescue.com which");
     951        mr_free(errorstr);
     952        log_to_screen("There may be hyperlink at http://www.mondorescue.com which");
    926953        log_to_screen("will take you to the relevant (missing) package.");
    927954        return (1);
     
    10211048{
    10221049    /*@ Char buffers ** */
    1023     char command[MAX_STR_LEN * 2];
     1050    char *command = NULL;
    10241051    char tmp[MAX_STR_LEN];
    10251052    char old_pwd[MAX_STR_LEN];
     1053    int res = 0;
    10261054
    10271055    mvaddstr_and_log_it(g_currentY, 0,
     
    10321060        find_and_store_mondoarchives_home(g_mondo_home);
    10331061    }
    1034     sprintf(command, CP_BIN " --parents -pRdf %s %s", g_mondo_home,
     1062    mr_asprintf(&command, CP_BIN " --parents -pRdf %s %s", g_mondo_home,
    10351063            bkpinfo->scratchdir);
    10361064
    10371065    log_msg(4, "command = %s", command);
    1038     if (run_program_and_log_output(command, 1)) {
     1066    res = run_program_and_log_output(command, 1);
     1067    mr_free(command);
     1068
     1069    if (res) {
    10391070        fatal_error("Failed to copy Mondo's stuff to scratchdir");
    10401071    }
     
    10461077        (void) getcwd(old_pwd, MAX_STR_LEN - 1);
    10471078        chdir(bkpinfo->scratchdir);
    1048         sprintf(command, "tar -zxvf %s", tmp);
    1049         if (run_program_and_log_output(command, FALSE)) {
     1079        mr_asprintf(&command, "tar -zxvf %s", tmp);
     1080        res = run_program_and_log_output(command, FALSE);
     1081        mr_free(command);
     1082
     1083        if (res) {
    10501084            fatal_error("Failed to untar payload");
    10511085        }
     
    10531087    }
    10541088
    1055     sprintf(command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir,
     1089    mr_asprintf(&command, "cp -f %s/LAST-FILELIST-NUMBER %s", bkpinfo->tmpdir,
    10561090            bkpinfo->scratchdir);
    1057 
    1058     if (run_program_and_log_output(command, FALSE)) {
     1091    res = run_program_and_log_output(command, FALSE);
     1092    mr_free(command);
     1093
     1094    if (res) {
    10591095        fatal_error("Failed to copy LAST-FILELIST-NUMBER to scratchdir");
    10601096    }
     
    10661102            ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?");
    10671103    }
    1068     sprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
    1069     if (run_program_and_log_output(command, FALSE)) {
     1104    mr_asprintf(&command, "cp -f %s %s", tmp, bkpinfo->tmpdir);
     1105    res = run_program_and_log_output(command, FALSE);
     1106    mr_free(command);
     1107
     1108    if (res) {
    10701109        fatal_error("Failed to copy mondorestore to tmpdir");
    10711110    }
    10721111
    1073     sprintf(command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);
     1112    mr_asprintf(&command, "hostname > %s/HOSTNAME", bkpinfo->scratchdir);
    10741113    paranoid_system(command);
     1114    mr_free(command);
    10751115
    10761116    if (bkpinfo->postnuke_tarball[0]) {
    1077         sprintf(command, "cp -f %s %s/post-nuke.tgz",
     1117        mr_asprintf(&command, "cp -f %s %s/post-nuke.tgz",
    10781118                bkpinfo->postnuke_tarball, bkpinfo->tmpdir);
    1079         if (run_program_and_log_output(command, FALSE)) {
     1119        res = run_program_and_log_output(command, FALSE);
     1120        mr_free(command);
     1121
     1122        if (res) {
    10801123            fatal_error("Unable to copy post-nuke tarball to tmpdir");
    10811124        }
    10821125    }
    1083 
    10841126
    10851127    mvaddstr_and_log_it(g_currentY++, 74, "Done.");
     
    11021144
    11031145    /*@ buffers ******** */
    1104     char nfs_dev[MAX_STR_LEN];
    1105     char mac_addr[MAX_STR_LEN];
    1106     char nfs_mount[MAX_STR_LEN];
    1107     char nfs_client_ipaddr[MAX_STR_LEN];
    1108     char nfs_client_netmask[MAX_STR_LEN];
    1109     char nfs_client_broadcast[MAX_STR_LEN];
    1110     char nfs_client_defgw[MAX_STR_LEN];
    1111     char nfs_server_ipaddr[MAX_STR_LEN];
    1112     char tmp[MAX_STR_LEN];
    1113     char command[MAX_STR_LEN * 2];
     1146    char *nfs_dev = NULL;
     1147    char *mac_addr = NULL;
     1148    char *nfs_mount = NULL;
     1149    char *nfs_client_ipaddr = NULL;
     1150    char *nfs_client_netmask = NULL;
     1151    char *nfs_client_broadcast = NULL;
     1152    char *nfs_client_defgw = NULL;
     1153    char *nfs_server_ipaddr = NULL;
     1154    char *tmp = NULL;
     1155    char *command = NULL
    11141156
    11151157    /*@ pointers ***** */
     
    11171159
    11181160    log_it("Storing NFS configuration");
    1119     strcpy(tmp, bkpinfo->nfs_mount);
     1161    mr_asprintf(&tmp, "%s", bkpinfo->nfs_mount);
    11201162    p = strchr(tmp, ':');
    11211163    if (!p) {
     
    11241166    }
    11251167    *(p++) = '\0';
    1126     strcpy(nfs_server_ipaddr, tmp);
    1127     strcpy(nfs_mount, p);
     1168    mr_asprintf(&nfs_server_ipaddr, tmp);
     1169    mr_asprintf(&nfs_mount, p);
     1170    mr_free(tmp);
    11281171
    11291172    /* BERLIOS : there is a bug #67 here as it only considers the first NIC */
    1130     sprintf(command,
     1173    mr_asprintf(&command,
    11311174            "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1");
    1132     strcpy(nfs_dev, call_program_and_get_last_line_of_output(command));
    1133     sprintf(command,
    1134             "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2");
    1135     strcpy(nfs_client_ipaddr,
    1136            call_program_and_get_last_line_of_output(command));
    1137     sprintf(command,
    1138             "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2");
    1139     strcpy(nfs_client_netmask,
    1140            call_program_and_get_last_line_of_output(command));
    1141     sprintf(command,
    1142             "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2");
    1143     strcpy(nfs_client_broadcast,
    1144            call_program_and_get_last_line_of_output(command));
    1145     sprintf(command,
    1146             "route -n | grep '^0.0.0.0' | awk '{print $2}'");
    1147     strcpy(nfs_client_defgw,
    1148            call_program_and_get_last_line_of_output(command));
    1149     sprintf(tmp,
    1150             "nfs_client_ipaddr=%s; nfs_server_ipaddr=%s; nfs_mount=%s",
    1151             nfs_client_ipaddr, nfs_server_ipaddr, nfs_mount);
     1175    mr_asprintf(&nfs_dev, "%s", call_program_and_get_last_line_of_output(command));
     1176    mr-free(command);
     1177
     1178    mr_asprintf(&command,
     1179            "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2");
     1180    mr_asprintf(&nfs_client_ipaddr, "%s", call_program_and_get_last_line_of_output(command));
     1181    mr-free(command);
     1182
     1183    mr_asprintf(&command,
     1184            "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2");
     1185    mr_asprintf(&nfs_client_netmask, "%s", call_program_and_get_last_line_of_output(command));
     1186    mr-free(command);
     1187
     1188    mr_asprintf(&command,
     1189            "%s", "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2");
     1190    mr_asprintf(&nfs_client_broadcast, "%s", call_program_and_get_last_line_of_output(command));
     1191    mr-free(command);
     1192
     1193    mr_asprintf(&command,
     1194            "%s", "route -n | grep '^0.0.0.0' | awk '{print $2}'");
     1195    mr_asprintf(&nfs_client_defgw, "%s", call_program_and_get_last_line_of_output(command));
     1196    mr-free(command);
     1197
    11521198    if (strlen(nfs_dev) < 2) {
    11531199        fatal_error
     
    11651211    if (!strncmp(nfs_dev, "bond", 4) || !strncmp(nfs_dev, "alb", 3) || !strncmp(nfs_dev, "aft", 3)) {
    11661212        log_to_screen("Found bonding device %s; looking for corresponding ethN slave device\n", nfs_dev);
    1167         sprintf(command,
    1168                 "ifconfig %s | awk '{print $5}' | head -n1", nfs_dev);
    1169         strcpy(mac_addr, call_program_and_get_last_line_of_output(command));
    1170         sprintf(command,
    1171                 "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1", mac_addr,nfs_dev);
    1172         strcpy(nfs_dev, call_program_and_get_last_line_of_output(command));
     1213        mr_asprintf(&command,
     1214                "%s", "ifconfig %s | awk '{print $5}' | head -n1", nfs_dev);
     1215        mr_asprintf(&mac_addr, "%s", call_program_and_get_last_line_of_output(command));
     1216        mr-free(command);
     1217
     1218        mr_asprintf(&command, "ifconfig | grep -E '%s' | grep -v '%s' | head -n1 | cut -d' ' -f1", mac_addr,nfs_dev);
     1219        mr_free(mac_addr);
     1220        mr_free(nfs_dev);
     1221
     1222        mr_asprintf(&nfs_dev, call_program_and_get_last_line_of_output(command));
     1223        mr-free(command);
     1224
    11731225        log_to_screen("Replacing it with %s\n", nfs_dev);
    11741226    }
    11751227
    1176     sprintf(tmp, "%s/NFS-DEV", bkpinfo->tmpdir);
     1228    mr_asprintf(tmp, "%s/NFS-DEV", bkpinfo->tmpdir);
    11771229    write_one_liner_data_file(tmp, nfs_dev);
    1178 
    1179     sprintf(tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir);
     1230    mr_free(nfs_dev);
     1231    mr_free(tmp);
     1232
     1233    mr_asprintf(tmp, "%s/NFS-CLIENT-IPADDR", bkpinfo->tmpdir);
    11801234    write_one_liner_data_file(tmp, nfs_client_ipaddr);
    1181     sprintf(tmp, "%s/NFS-CLIENT-NETMASK", bkpinfo->tmpdir);
     1235    mr_free(nfs_client_ipaddr);
     1236    mr_free(tmp);
     1237
     1238    mr_asprintf(tmp, "%s/NFS-CLIENT-NETMASK", bkpinfo->tmpdir);
    11821239    write_one_liner_data_file(tmp, nfs_client_netmask);
    1183     sprintf(tmp, "%s/NFS-CLIENT-BROADCAST", bkpinfo->tmpdir);
     1240    mr_free(nfs_client_netmask);
     1241    mr_free(tmp);
     1242
     1243    mr_asprintf(tmp, "%s/NFS-CLIENT-BROADCAST", bkpinfo->tmpdir);
    11841244    write_one_liner_data_file(tmp, nfs_client_broadcast);
    1185     sprintf(tmp, "%s/NFS-CLIENT-DEFGW", bkpinfo->tmpdir);
     1245    mr_free(nfs_client_broadcast);
     1246    mr_free(tmp);
     1247
     1248    mr_asprintf(tmp, "%s/NFS-CLIENT-DEFGW", bkpinfo->tmpdir);
    11861249    write_one_liner_data_file(tmp, nfs_client_defgw);
    1187     sprintf(tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir);
     1250    mr_free(nfs_client_defgw);
     1251    mr_free(tmp);
     1252
     1253    mr_asprintf(tmp, "%s/NFS-SERVER-IPADDR", bkpinfo->tmpdir);
    11881254    write_one_liner_data_file(tmp, nfs_server_ipaddr);
    1189     sprintf(tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir);
     1255    mr_free(tmp);
     1256    mr_free(nfs_server_ipaddr);
     1257
     1258    mr_asprintf(tmp, "%s/NFS-SERVER-MOUNT", bkpinfo->tmpdir);
    11901259    write_one_liner_data_file(tmp, bkpinfo->nfs_mount);
    1191     sprintf(tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir);
     1260    mr_free(tmp);
     1261    mr_free(nfs_mount);
     1262
     1263    mr_asprintf(tmp, "%s/NFS-SERVER-PATH", bkpinfo->tmpdir);
    11921264    write_one_liner_data_file(tmp, bkpinfo->nfs_remote_dir);
    1193     sprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
     1265    mr_free(tmp);
     1266
     1267    mr_asprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);
    11941268    write_one_liner_data_file(tmp, bkpinfo->prefix);
     1269    mr_free(tmp);
     1270
    11951271    log_it("Finished storing NFS configuration");
    11961272}
     
    12211297{
    12221298    /*@ buffers *************** */
    1223     char tmp[MAX_STR_LEN];
     1299    char *tmp = NULL;
    12241300    char *mds = NULL;
    12251301
     
    12501326    if (scratchLL <= 1) {
    12511327        mds = media_descriptor_string(bkpinfo->backup_media_type);
    1252         sprintf(tmp,
    1253                 "Your backup will probably occupy a single %s. Maybe two.", mds);
     1328        mr_asprintf(&tmp, "Your backup will probably occupy a single %s. Maybe two.", mds);
    12541329        mr_free(mds);
    12551330    } else if (scratchLL > 4) {
    1256         sprintf(tmp,
     1331        mr_asprintf(&tmp,
    12571332                "Your backup will occupy one meeeeellion media! (maybe %s)",
    12581333                number_to_text((int) (scratchLL + 1)));
    12591334    } else {
    1260         sprintf(tmp, "Your backup will occupy approximately %s media.",
     1335        mr_asprintf(&tmp, "Your backup will occupy approximately %s media.",
    12611336                number_to_text((int) (scratchLL + 1)));
    12621337    }
     
    12641339        log_to_screen(tmp);
    12651340    }
     1341    mr_free(tmp);
    12661342}
    12671343
     
    12981374{
    12991375    char do_not_compress_these[MAX_STR_LEN];
    1300     char tmp[MAX_STR_LEN];
     1376    char *tmp = NULL;
    13011377    char *p;
    13021378    char *q = NULL;
     
    13071383    }
    13081384
    1309     sprintf(tmp, "%s/do-not-compress-these", g_mondo_home);
     1385    mr_asprintf(&tmp, "%s/do-not-compress-these", g_mondo_home);
    13101386    if (!does_file_exist(tmp)) {
     1387        mr_free(tmp);
    13111388        return (FALSE);
    13121389    }
    13131390    /* BERLIOS: This is just plain WRONG !! */
    13141391    strcpy(do_not_compress_these,last_line_of_file(tmp));
     1392    mr_free(tmp);
    13151393
    13161394    for (p = do_not_compress_these; p != NULL; p++) {
    1317         strcpy(tmp, p);
     1395        mr_asprintf(&tmp, "%s", p);
    13181396        if (strchr(tmp, ' ')) {
    13191397            *(strchr(tmp, ' ')) = '\0';
    13201398        }
    13211399        if (!strcmp(q, tmp)) {
     1400            mr_free(tmp);
    13221401            return (TRUE);
    13231402        }
     
    13251404            break;
    13261405        }
     1406        mr_free(tmp);
    13271407    }
    13281408    return (FALSE);
    13291409}
    1330 
    13311410
    13321411
     
    13541433{
    13551434    FILE *fout;
    1356     char *tmp;
     1435    char *tmp = NULL;
    13571436    int retval = 0;
    13581437
    1359     malloc_string(tmp);
    13601438    if ((fout = fopen(outfile, "w"))) {
    13611439        fprintf(fout,
     
    13631441        paranoid_fclose(fout);
    13641442        log_msg(2, "Created %s", outfile);
    1365         sprintf(tmp, "chmod +x %s", outfile);
     1443        mr_asprintf(&tmp, "chmod +x %s", outfile);
    13661444        paranoid_system(tmp);
     1445        mr_free(tmp);
    13671446        retval = 0;
    13681447    } else {
    13691448        retval = 1;
    13701449    }
    1371     paranoid_free(tmp);
    13721450    return (retval);
    13731451}
Note: See TracChangeset for help on using the changeset viewer.