Ignore:
Timestamp:
Aug 18, 2009, 5:28:18 PM (15 years ago)
Author:
Bruno Cornec
Message:

r3369@localhost: bruno | 2009-08-18 16:57:27 +0200

  • Transform bout 100 strcpy in dyn. allocation. Quality is improving
  • function figure_out_kernel_path_interactively_if_necessary now return a dynamically allocated string
  • mondoarchive checked with valgrind in text an newt modes
File:
1 edited

Legend:

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

    r2331 r2334  
    443443    char *p = NULL;
    444444    char *tmp1 = NULL;
    445     char *fstab_fname;
     445    char *fstab_fname = NULL;
    446446    char *old_restpath = NULL;
    447447
     
    453453
    454454    malloc_string(tmp);
    455     malloc_string(fstab_fname);
    456455    assert(bkpinfo != NULL);
    457456    assert(mountlist != NULL);
     
    640639                            "Using tune2fs to identify your ext2,3,4 partitions");
    641640        if (does_file_exist("/tmp/fstab.new")) {
    642             strcpy(fstab_fname, "/tmp/fstab.new");
     641            mr_asprintf(fstab_fname, "/tmp/fstab.new");
    643642        } else {
    644             strcpy(fstab_fname, "/tmp/fstab");
     643            mr_asprintf(fstab_fname, "/tmp/fstab");
    645644        }
    646645        mr_asprintf(tmp1, "label-partitions-as-necessary %s < %s >> %s 2>> %s", g_mountlist_fname, fstab_fname, MONDO_LOGFILE, MONDO_LOGFILE);
     646        mr_free(fstab_fname);
     647
    647648        res = system(tmp1);
    648649        mr_free(tmp1);
     
    665666  end_of_func:
    666667    paranoid_free(tmp);
    667     paranoid_free(fstab_fname);
    668668    log_it("Leaving interactive_mode()");
    669669    return (retval);
     
    10181018
    10191019  /** malloc ***/
    1020     char *checksum;
     1020    char *checksum = NULL;
    10211021    char *outfile_fname = NULL;
    10221022    char *tmp = NULL;
    10231023    char *bzip2_command = NULL;
    1024     char *ntfsprog_command, *suffix;
     1024    char *ntfsprog_command;
     1025    char *suffix = NULL;
    10251026    char *sz_devfile = NULL;
    10261027    char *bigblk;
    1027     char *p;
    10281028    char *mds = NULL;
    10291029    int retval = 0;
     
    10311031    long sliceno;
    10321032    long siz;
    1033     char ntfsprog_fifo[MAX_STR_LEN];
     1033    char *ntfsprog_fifo = NULL;
    10341034    char *file_to_openout = NULL;
    10351035    struct s_filename_and_lstat_info biggiestruct;
     
    10451045    assert(bkpinfo != NULL);
    10461046
    1047     malloc_string(checksum);
    10481047    malloc_string(ntfsprog_command);
    1049     malloc_string(suffix);
    10501048
    10511049    pathname_of_last_file_restored[0] = '\0';
     
    10671065    paranoid_fclose(fin);
    10681066
    1069     strcpy(checksum, biggiestruct.checksum);
    1070 
     1067    mr_asprintf(checksum, "%s", biggiestruct.checksum);
    10711068    if (!checksum[0]) {
    10721069        log_msg(3, "Warning - bigfile %ld does not have a checksum", bigfileno + 1);
    1073         p = checksum;
    1074     }
     1070    }
     1071    mr_free(checksum);
    10751072
    10761073    if (!strncmp(biggiestruct.filename, "/dev/", 5))    // Whether NTFS or not :)
     
    10851082        node = find_string_at_node(filelist, biggiestruct.filename);
    10861083        if (!node) {
    1087             log_msg(0, "Skipping %s (name isn't in filelist)",
    1088                     biggiestruct.filename);
     1084            log_msg(0, "Skipping %s (name isn't in filelist)", biggiestruct.filename);
    10891085            pathname_of_last_file_restored[0] = '\0';
    10901086            return (0);
    10911087        } else if (!(node->selected)) {
    1092             log_msg(1, "Skipping %s (name isn't in biggielist subset)",
    1093                     biggiestruct.filename);
     1088            log_msg(1, "Skipping %s (name isn't in biggielist subset)", biggiestruct.filename);
    10941089            pathname_of_last_file_restored[0] = '\0';
    10951090            return (0);
    10961091        }
    10971092    }
     1093
    10981094    /* otherwise, continue */
    1099 
    11001095    log_msg(1, "DEFINITELY restoring %s", biggiestruct.filename);
    11011096    if (biggiestruct.use_ntfsprog) {
    11021097        if (strncmp(biggiestruct.filename, "/dev/", 5)) {
    1103             log_msg(1,
    1104                     "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
     1098            log_msg(1, "I was in error when I set biggiestruct.use_ntfsprog to TRUE.");
    11051099            log_msg(1, "%s isn't even in /dev", biggiestruct.filename);
    11061100            biggiestruct.use_ntfsprog = FALSE;
     
    11091103
    11101104    if (biggiestruct.use_ntfsprog)  // if it's an NTFS device
    1111 //  if (!strncmp ( biggiestruct.filename, "/dev/", 5))
    11121105    {
    11131106        g_loglevel = 4;
     
    11161109        mr_asprintf(sz_devfile, "/tmp/%d.%d.000", (int) (random() % 32768), (int) (random() % 32768));
    11171110        mkfifo(sz_devfile, 0x770);
    1118         strcpy(ntfsprog_fifo, sz_devfile);
     1111        mr_asprintf(ntfsprog_fifo, "%s", sz_devfile);
    11191112        mr_free(sz_devfile);
    11201113        file_to_openout = ntfsprog_fifo;
     
    11231116            fatal_error("Fork failure");
    11241117        case 0:
    1125             log_msg(3,
    1126                     "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)",
    1127                     biggiestruct.filename, ntfsprog_fifo);
    1128             res =
    1129                 feed_outfrom_ntfsprog(biggiestruct.filename,
    1130                                        ntfsprog_fifo);
    1131 //          log_msg(3, "CHILD - fip - exiting");
     1118            log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", biggiestruct.filename, ntfsprog_fifo);
     1119            res = feed_outfrom_ntfsprog(biggiestruct.filename, ntfsprog_fifo);
     1120            mr_free(ntfsprog_fifo);
    11321121            exit(res);
    11331122            break;
    11341123        default:
    1135             log_msg(3,
    1136                     "feed_into_ntfsprog() called in background --- pid=%ld",
    1137                     (long int) (pid));
    1138         }
     1124            log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
     1125        }
     1126        mr_free(ntfsprog_fifo);
    11391127    } else {
    11401128        use_ntfsprog_hack = FALSE;
    1141         ntfsprog_fifo[0] = '\0';
    11421129        file_to_openout = outfile_fname;
    11431130        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
     
    11551142     */
    11561143
    1157     strncpy(pathname_of_last_file_restored, biggiestruct.filename,
    1158             MAX_STR_LEN - 1);
     1144    strncpy(pathname_of_last_file_restored, biggiestruct.filename, MAX_STR_LEN - 1);
    11591145    pathname_of_last_file_restored[MAX_STR_LEN - 1] = '\0';
    11601146
     
    11671153
    11681154    for (sliceno = 1, finished = FALSE; !finished;) {
    1169         if (!does_file_exist
    1170             (slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))
    1171             &&
    1172             !does_file_exist(slice_fname
    1173                              (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))
    1174             &&
    1175             !does_file_exist(slice_fname
    1176                              (bigfileno, sliceno, ARCHIVES_PATH, "gz"))
    1177             &&
    1178             !does_file_exist(slice_fname
    1179                              (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
    1180             log_msg(3,
    1181                     "Cannot find a data slice or terminator slice on CD %d",
    1182                     g_current_media_number);
     1155        if (!does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "")) &&
     1156            !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo")) &&
     1157            !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "gz")) &&
     1158            !does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
     1159            log_msg(3, "Cannot find a data slice or terminator slice on CD %d", g_current_media_number);
    11831160            g_current_media_number++;
    11841161            mds = media_descriptor_string(bkpinfo->backup_media_type);
     
    11931170            mr_asprintf(tmp, "%s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""));
    11941171            if (does_file_exist(tmp) && length_of_file(tmp) == 0) {
    1195                 log_msg(2,
    1196                         "End of bigfile # %ld (slice %ld is the terminator)",
    1197                         bigfileno + 1, sliceno);
     1172                log_msg(2, "End of bigfile # %ld (slice %ld is the terminator)", bigfileno + 1, sliceno);
    11981173                finished = TRUE;
    11991174                mr_free(tmp);
    12001175                continue;
    12011176            } else {
    1202                 if (does_file_exist
    1203                     (slice_fname
    1204                      (bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
     1177                if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "lzo"))) {
    12051178                    mr_asprintf(bzip2_command, "lzop");
    1206                     strcpy(suffix, "lzo");
     1179                    mr_asprintf(suffix, "lzo");
    12071180                } else
    1208                     if (does_file_exist
    1209                         (slice_fname
    1210                          (bigfileno, sliceno, ARCHIVES_PATH, "gz"))) {
     1181                    if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "gz"))) {
    12111182                    mr_asprintf(bzip2_command, "gzip");
    1212                     strcpy(suffix, "gz");
     1183                    mr_asprintf(suffix, "gz");
    12131184                } else
    1214                     if (does_file_exist
    1215                         (slice_fname
    1216                          (bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
     1185                    if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, "bz2"))) {
    12171186                    mr_asprintf(bzip2_command, "bzip2");
    1218                     strcpy(suffix, "bz2");
     1187                    mr_asprintf(suffix, "bz2");
    12191188                } else
    1220                     if (does_file_exist
    1221                         (slice_fname
    1222                          (bigfileno, sliceno, ARCHIVES_PATH, ""))) {
     1189                    if (does_file_exist(slice_fname(bigfileno, sliceno, ARCHIVES_PATH, ""))) {
    12231190                    mr_asprintf(bzip2_command, "");
    1224                     strcpy(suffix, "");
     1191                    mr_asprintf(suffix, "");
    12251192                } else {
    12261193                    log_to_screen("OK, that's pretty fsck0red...");
     
    12351202                mr_asprintf(bzip2_command, "cat %s 2>> %s", slice_fname(bigfileno, sliceno, ARCHIVES_PATH, suffix), MONDO_LOGFILE);
    12361203            }
     1204            mr_free(suffix);
     1205
    12371206            mds = media_descriptor_string(bkpinfo->backup_media_type);
    12381207            mr_asprintf(tmp, "Working on %s #%d, file #%ld, slice #%ld    ", mds, g_current_media_number, bigfileno + 1, sliceno);
     
    12881257    mr_free(outfile_fname);
    12891258    paranoid_free(bigblk);
    1290     paranoid_free(checksum);
    12911259    paranoid_free(ntfsprog_command);
    1292     paranoid_free(suffix);
    12931260
    12941261    return (retval);
     
    13311298    char *ntfsprog_command;
    13321299    char *sz_devfile = NULL;
    1333     char *ntfsprog_fifo;
     1300    char *ntfsprog_fifo = NULL;
    13341301    char *file_to_openout = NULL;
    13351302
     
    13501317
    13511318    malloc_string(tmp);
    1352     malloc_string(ntfsprog_fifo);
    13531319    malloc_string(ntfsprog_command);
    13541320    old_loglevel = g_loglevel;
     
    14071373        mr_asprintf(sz_devfile, "%s/%d.%d.000", bkpinfo->tmpdir, (int) (random() % 32768), (int) (random() % 32768));
    14081374        mkfifo(sz_devfile, 0x770);
    1409         strcpy(ntfsprog_fifo, sz_devfile);
     1375        mr_asprintf(ntfsprog_fifo, "%s", sz_devfile);
    14101376        mr_free(sz_devfile);
    14111377
     
    14171383            log_msg(3, "CHILD - fip - calling feed_outfrom_ntfsprog(%s, %s)", outfile_fname, ntfsprog_fifo);
    14181384            res = feed_outfrom_ntfsprog(outfile_fname, ntfsprog_fifo);
     1385            mr_free(ntfsprog_fifo);
    14191386            exit(res);
    14201387            break;
     
    14221389            log_msg(3, "feed_into_ntfsprog() called in background --- pid=%ld", (long int) (pid));
    14231390        }
     1391        mr_free(ntfsprog_fifo);
    14241392    } else {
    14251393        if (!strncmp(orig_bf_fname, "/dev/", 5))    {
     
    14311399        }
    14321400        use_ntfsprog_hack = FALSE;
    1433         ntfsprog_fifo[0] = '\0';
    14341401        file_to_openout = outfile_fname;
    14351402        if (!does_file_exist(outfile_fname))    // yes, it looks weird with the '!' but it's correct that way
     
    15391506    paranoid_free(tmp);
    15401507    paranoid_free(ntfsprog_command);
    1541     paranoid_free(ntfsprog_fifo);
    15421508    g_loglevel = old_loglevel;
    15431509    return (retval);
     
    20992065    char *tarball_fname = NULL;
    21002066    char *progress_str = NULL;
    2101     char *comment;
    2102 
    2103     malloc_string(comment);
    21042067
    21052068    assert(bkpinfo != NULL);
     
    21822145                mr_strcat(tmp1, " (%d attempts) - review logs", attempts);
    21832146            }
    2184             strcpy(comment, tmp1);
     2147            if (attempts > 1) {
     2148                log_to_screen(tmp1);
     2149            }
    21852150            mr_free(tmp1);
    2186             if (attempts > 1) {
    2187                 log_to_screen(comment);
    2188             }
    21892151
    21902152            retval += res;
     
    22032165        mvaddstr_and_log_it(g_currentY++, 74, "Done.");
    22042166    }
    2205     paranoid_free(comment);
    22062167
    22072168    return (retval);
     
    26332594    struct raidlist_itself *raidlist;
    26342595    struct s_node *filelist;
    2635     char *a, *b;
     2596    char *tmp1 = NULL;
     2597    char *tmp2 = NULL;
    26362598    bool run_postnuke = FALSE;
    26372599
     
    26632625    run_program_and_log_output("mkdir -p " MNT_CDROM, FALSE);
    26642626
    2665     malloc_string(a);
    2666     malloc_string(b);
    26672627    setup_MR_global_filenames();    // malloc() and set globals, using bkpinfo->tmpdir etc.
    26682628    bkpinfo->backup_media_type = none;  // in case boot disk was made for one backup type but user wants to restore from another backup type
     
    27532713        toggle_path_selection(filelist, "/usr/share", TRUE);
    27542714        save_filelist(filelist, "/tmp/out.txt");
    2755         strcpy(a, argv[3]);
    2756         strcpy(b, argv[4]);
    2757 
    2758         res = save_filelist_entries_in_common(a, filelist, b, FALSE);
     2715        mr_asprintf(tmp1, "%s", argv[3]);
     2716        mr_asprintf(tmp2, "%s", argv[4]);
     2717
     2718        res = save_filelist_entries_in_common(tmp1, filelist, tmp2, FALSE);
     2719        mr_free(tmp1);
     2720        mr_free(tmp2);
     2721
    27592722        free_filelist(filelist);
    27602723        printf("res = %d", res);
     
    30292992    paranoid_MR_finish(retval); // frees global stuff plus bkpinfo
    30302993    free_libmondo_global_strings(); // it's fine to have this here :) really :)
    3031     paranoid_free(a);
    3032     paranoid_free(b);
    30332994
    30342995    unlink("/tmp/filelist.full");
Note: See TracChangeset for help on using the changeset viewer.