Ignore:
Timestamp:
Jun 3, 2009, 7:10:19 PM (15 years ago)
Author:
Bruno Cornec
Message:

r3089@localhost: bruno | 2009-05-18 06:41:05 +0200

  • move call to asprintf to call to mr_asprintf (suppress a compiler warning)
  • remove all the most obvious bad call to strcat and replace by mr_strcat as appropriate
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.9/mondo/src/mondorestore/mondorestore.c

    r2209 r2211  
    22$Id$
    33restores mondoarchive data
     4The main file for mondorestore.
    45***************************************************************************/
    5 
    6 /**
    7  * @file
    8  * The main file for mondorestore.
    9  */
    106
    117/**************************************************************************
     
    1410#include <pthread.h>
    1511#include "my-stuff.h"
     12#include "mr_mem.h"
    1613#include "../common/mondostructures.h"
    1714#include "../common/libmondo.h"
     
    364361
    365362    /* Clean up blkid cache file if they exist */
    366     asprintf(&tmp1,"%s/etc/blkid.tab",bkpinfo->restore_path);
     363    mr_asprintf(&tmp1,"%s/etc/blkid.tab",bkpinfo->restore_path);
    367364    (void)unlink(tmp1);
    368365    paranoid_free(tmp1);
    369     asprintf(&tmp1,"%s/etc/blkid.tab.old",bkpinfo->restore_path);
     366    mr_asprintf(&tmp1,"%s/etc/blkid.tab.old",bkpinfo->restore_path);
    370367    (void)unlink(tmp1);
    371368    paranoid_free(tmp1);
     
    379376
    380377    /* Clean up multiconf cache file if they exist */
    381     asprintf(&tmp1,"%s/var/lib/multipath/bindings",bkpinfo->restore_path);
     378    mr_asprintf(&tmp1,"%s/var/lib/multipath/bindings",bkpinfo->restore_path);
    382379    (void)unlink(tmp1);
    383380    paranoid_free(tmp1);
    384381
    385382    /* Edit multipath.conf if needed to adapt wwid */
    386     asprintf(&tmp1,"%s/etc/multipath.conf", MNT_RESTORING);
     383    mr_asprintf(&tmp1,"%s/etc/multipath.conf", MNT_RESTORING);
    387384    if (does_file_exist(tmp1)) {
    388385        log_msg(2, "We may need to clean /etc/multipath.conf");
     
    394391
    395392    if (bkpinfo->restore_mode != nuke) {
    396         asprintf(&editor, "%s", find_my_editor());
    397         asprintf(&tmp1,"chroot %s %s /etc/multipath.conf", MNT_RESTORING, editor);
     393        mr_asprintf(&editor, "%s", find_my_editor());
     394        mr_asprintf(&tmp1,"chroot %s %s /etc/multipath.conf", MNT_RESTORING, editor);
    398395        popup_and_OK("You will now edit multipath.conf");
    399396        if (!g_text_mode) {
     
    788785    assert(raidlist != NULL);
    789786
    790     asprintf(&tmpA, "%s", "xxxxxxxxx");
    791     asprintf(&tmpB, "%s", "xxxxxxxxx");
    792     asprintf(&tmpC, "%s", "xxxxxxxxx");
     787    mr_asprintf(&tmpA, "%s", "         ");
     788    mr_asprintf(&tmpB, "%s", "         ");
     789    mr_asprintf(&tmpC, "%s", "         ");
    793790
    794791    log_msg(2, "nuke_mode --- starting");
     
    16711668
    16721669  /** malloc **/
    1673     char *command;
     1670    char *command = NULL;
    16741671    char *tmp;
    16751672    char *filelist_name;
     
    16851682
    16861683    assert_string_is_neither_NULL_nor_zerolength(tarball_fname);
    1687     malloc_string(command);
    16881684    malloc_string(tmp);
    16891685    malloc_string(filelist_name);
     
    16981694    use_star = (strstr(tarball_fname, ".star")) ? TRUE : FALSE;
    16991695//  sprintf(files_to_restore_this_time_fname, "/tmp/ftrttf.%d.%d", (int)getpid(), (int)random());
    1700     sprintf(command, "mkdir -p %s/tmp", MNT_RESTORING);
     1696    mr_asprintf(&command, "mkdir -p %s/tmp", MNT_RESTORING);
    17011697    run_program_and_log_output(command, 9);
     1698    paranoid_free(command);
     1699
    17021700    sprintf(temp_log, "/tmp/%d.%d", (int) (random() % 32768),
    17031701            (int) (random() % 32768));
     
    17831781//      if (strstr(tarball_fname, ".star."))
    17841782        if (use_star) {
    1785             sprintf(command,
     1783            mr_asprintf(&command,
    17861784                    "star -x -force-remove -U " STAR_ACL_SZ
    17871785                    " errctl= file=%s", tarball_fname);
    17881786            if (strstr(tarball_fname, ".bz2")) {
    1789                 strcat(command, " -bz");
     1787                mr_strcat(command, " -bz");
    17901788            }
    17911789        } else {
    17921790            if (filelist_subset_fname[0] != '\0') {
    1793                 sprintf(command,
     1791                mr_asprintf(&command,
    17941792                        "afio -i -M 8m -b %ld -c %ld %s -w '%s' %s",
    17951793                        TAPE_BLOCK_SIZE,
     
    17981796                        tarball_fname);
    17991797            } else {
    1800                 sprintf(command,
     1798                mr_asprintf(&command,
    18011799                        "afio -i -b %ld -c %ld -M 8m %s %s",
    18021800                        TAPE_BLOCK_SIZE,
     
    18041802            }
    18051803        }
     1804
    18061805#undef BUFSIZE
    1807         sprintf(command + strlen(command), " 2>> %s >> %s", temp_log,
    1808                 temp_log);
     1806        mr_strcat(command, " 2>> %s >> %s", temp_log, temp_log);
    18091807        log_msg(1, "command = '%s'", command);
    18101808        unlink(temp_log);
     
    18181816            }
    18191817        }
     1818        paranoid_free(command);
     1819
    18201820        if (res && length_of_file(temp_log) < 5) {
    18211821            res = 0;
     
    18491849        }
    18501850        if (retval) {
    1851             sprintf(command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
     1851            mr_asprintf(&command, "cat %s >> %s", temp_log, MONDO_LOGFILE);
    18521852            system(command);
     1853            paranoid_free(command);
     1854
    18531855            log_msg(2, "Errors occurred while processing fileset #%d",
    18541856                    current_tarball_number);
     
    18671869
    18681870  leave_sub:
    1869     paranoid_free(command);
    18701871    paranoid_free(tmp);
    18711872    paranoid_free(filelist_name);
     
    22492250    long max_val;
    22502251  /**malloc ***/
    2251     char *tmp;
     2252    char *tmp = NULL;
     2253    char *tmp1 = NULL;
    22522254    char *tarball_fname;
    22532255    char *progress_str;
     
    22712273    read_cfg_var(g_mondo_cfg_file, "last-filelist-number", tmp);
    22722274    max_val = atol(tmp) + 1;
     2275    paranoid_free(tmp);
     2276
    22732277    sprintf(progress_str, "Restoring from %s #%d",
    22742278            media_descriptor_string(bkpinfo->backup_media_type),
     
    23342338                                              filelist);
    23352339            }
    2336             sprintf(tmp, "%s #%d, fileset #%ld - restore ",
     2340            mr_asprintf(&tmp1, "%s #%d, fileset #%ld - restore ",
    23372341                    media_descriptor_string(bkpinfo->backup_media_type),
    23382342                    g_current_media_number, current_tarball_number);
    23392343            if (res) {
    2340                 strcat(tmp, "reported errors");
     2344                mr_strcat(tmp1, "reported errors");
    23412345            } else if (attempts > 1) {
    2342                 strcat(tmp, "succeeded");
     2346                mr_strcat(tmp1, "succeeded");
    23432347            } else {
    2344                 strcat(tmp, "succeeded");
     2348                mr_strcat(tmp1, "succeeded");
    23452349            }
    23462350            if (attempts > 1) {
    2347                 sprintf(tmp + strlen(tmp), " (%d attempts) - review logs",
    2348                         attempts);
    2349             }
    2350             strcpy(comment, tmp);
     2351                mr_strcat(tmp1, " (%d attempts) - review logs", attempts);
     2352            }
     2353            strcpy(comment, tmp1);
     2354            paranoid_free(tmp1);
    23512355            if (attempts > 1) {
    23522356                log_to_screen(comment);
     
    23642368        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    23652369    }
    2366     paranoid_free(tmp);
    23672370    paranoid_free(tarball_fname);
    23682371    paranoid_free(progress_str);
Note: See TracChangeset for help on using the changeset viewer.