Ignore:
Timestamp:
Jul 17, 2006, 3:44:46 PM (13 years ago)
Author:
bcornec
Message:

Huge memory management patch.
Still not finished but a lot as been done.
What remains is around some functions returning strings, and some structure members.
(Could not finish due to laptop failure !)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/common/libmondo-archive.c

    r687 r688  
    2727#include <sys/ipc.h>
    2828#include <stdarg.h>
     29#include <unistd.h>
    2930#define DVDRWFORMAT 1
    3031
     
    230231        log_msg(5, "command='%s'", command);
    231232        res = system(command);
    232         asprintf(&tmp, "%s", last_line_of_file(MONDO_LOGFILE));
     233        tmp = last_line_of_file(MONDO_LOGFILE));
    233234        log_msg(1, "res=%d; tmp='%s'", res, tmp);
    234235        if (bkpinfo->use_star && (res == 254 || res == 65024)
     
    296297
    297298    /*@ buffers ******************************************************** */
    298     char *command;
     299    char *command = NULL;
    299300    char *zipparams = NULL;
    300     char *tmp, *tmp1;
     301    char *tmp = NULL;
     302    char *tmp1 = NULL;
    301303
    302304    assert(bkpinfo != NULL);
     
    389391
    390392    if (g_tmpfs_mountpt[0] != '\0') {
    391         i = atoi(call_program_and_get_last_line_of_output
    392                  ("df -m -P | grep dev/shm | grep -v none | tr -s ' ' '\t' | cut -f4"));
     393        tmp = call_program_and_get_last_line_of_output
     394                 ("df -m -P | grep dev/shm | grep -v none | tr -s ' ' '\t' | cut -f4");
     395        i = atoi(tmp);
     396        paranoid_free(tmp);
     397
    393398        if (i > 0) {
    394399            if (free_ramdisk_space > i) {
     
    466471    copy_mondo_and_mindi_stuff_to_scratchdir(bkpinfo);  // payload, too, if it exists
    467472#if __FreeBSD__ == 5
    468     strcpy(bkpinfo->kernel_path, "/boot/kernel/kernel");
     473    paranoid_alloc(bkpinfo->kernel_path, "/boot/kernel/kernel");
    469474#elif __FreeBSD__ == 4
    470     strcpy(bkpinfo->kernel_path, "/kernel");
     475    paranoid_alloc(bkpinfo->kernel_path, "/kernel");
    471476#elif linux
    472477    if (figure_out_kernel_path_interactively_if_necessary
     
    523528{
    524529    /*@ buffer ************************************************************ */
    525     char *tmp;
    526     char *command;
    527     char *use_lzo_sz;
    528     char *use_comp_sz;
    529     char *use_star_sz;
    530     char *bootldr_str;
    531     char *tape_device;
    532     char *last_filelist_number;
    533     char *broken_bios_sz;
    534     char *cd_recovery_sz;
    535     char *tape_size_sz;
    536     char *devs_to_exclude;
    537     char *use_lilo_sz;
    538     char *value;
    539     char *bootdev;
     530    char *tmp = NULL;
     531    char *command = NULL;
     532    char *use_lzo_sz = NULL;
     533    char *use_comp_sz = NULL;
     534    char *use_star_sz = NULL;
     535    char *bootldr_str = NULL;
     536    char *tape_device = NULL;
     537    char *last_filelist_number = NULL;
     538    char *broken_bios_sz = NULL;
     539    char *cd_recovery_sz = NULL;
     540    char *tape_size_sz = NULL;
     541    char *devs_to_exclude = NULL;
     542    char *use_lilo_sz = NULL;
     543    char *value = NULL;
     544    char *bootdev = NULL;
    540545
    541546
     
    556561             "echo '%s' | tr -s ' ' '\n' | grep -x '/dev/.*' | tr -s '\n' ' ' | awk '{print $0\"\\n\";}'",
    557562             bkpinfo->exclude_paths);
    558     asprintf(&devs_to_exclude,
    559              call_program_and_get_last_line_of_output(tmp));
     563    devs_to_exclude = call_program_and_get_last_line_of_output(tmp);
    560564    paranoid_free(tmp);
    561565    asprintf(&tmp, "devs_to_exclude = '%s'", devs_to_exclude);
     
    576580    paranoid_free(tmp);
    577581    asprintf(&tmp, "%s/LAST-FILELIST-NUMBER", bkpinfo->tmpdir);
    578     asprintf(&last_filelist_number, last_line_of_file(tmp));
     582    last_filelist_number = last_line_of_file(tmp);
    579583    paranoid_free(tmp);
    580584    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
     
    617621    if (!bkpinfo->nonbootable_backup
    618622        && (bkpinfo->boot_loader == '\0'
    619             || bkpinfo->boot_device[0] == '\0')) {
     623            || bkpinfo->boot_device == NULL)) {
    620624
    621625#ifdef __FreeBSD__
    622         asprintf(&bootdev, call_program_and_get_last_line_of_output
    623                  ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
    624         if (!bootdev[0]) {
     626        bootdev = call_program_and_get_last_line_of_output
     627                 ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'");
     628        if (!bootdev) {
     629            bootdev = call_program_and_get_last_line_of_output
     630                     ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'");
     631        }
     632#else
     633        bootdev = call_program_and_get_last_line_of_output
     634                 ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'");
     635        if (!bootdev) {
     636            bootdev = call_program_and_get_last_line_of_output
     637                     ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'");
     638        }
     639        if ((bootdev) && (strstr(bootdev, "/dev/cciss/"))) {
    625640            paranoid_free(bootdev);
    626             asprintf(&bootdev, call_program_and_get_last_line_of_output
    627                      ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
    628         }
    629 #else
    630         asprintf(&bootdev, call_program_and_get_last_line_of_output
    631                  ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
    632         if (strstr(bootdev, "/dev/cciss/")) {
    633             paranoid_free(bootdev);
    634             asprintf(&bootdev, call_program_and_get_last_line_of_output
    635                      ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
    636         }
    637         if (!bootdev[0]) {
    638             paranoid_free(bootdev);
    639             asprintf(&bootdev, call_program_and_get_last_line_of_output
    640                      ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
    641             if (strstr(bootdev, "/dev/cciss/")) {
    642                 paranoid_free(bootdev);
    643                 asprintf(&bootdev, call_program_and_get_last_line_of_output
    644                          ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | cut -dp -f1"));
    645             }
     641            bootdev = call_program_and_get_last_line_of_output
     642                     ("mount | grep ' /boot ' | head -1 | cut -d' ' -f1 | cut -dp -f1");
    646643        }
    647644#endif
    648         if (bootdev[0])
     645        if (bootdev)
    649646            ch = which_boot_loader(bootdev);
    650647        else
     
    658655            bkpinfo->boot_loader = ch;
    659656        }
    660         if (bkpinfo->boot_device[0] != '\0') {
     657        if (bkpinfo->boot_device != NULL) {
    661658            asprintf(&tmp, "User specified boot device. It is '%s'.",
    662659                     bkpinfo->boot_device);
    663660            log_msg(2, tmp);
    664661            paranoid_free(tmp);
     662            paranoid_free(bootdev);
    665663        } else {
    666             strcpy(bkpinfo->boot_device, bootdev);
    667         }
    668     }
    669     paranoid_free(bootdev);
     664            bkpinfo->boot_device = bootdev;
     665        }
     666    }
    670667
    671668    if (
     
    797794    estimated_total_noof_slices =
    798795        size_of_all_biggiefiles_K(bkpinfo) / bkpinfo->optimal_set_size + 1;
    799 /* add nfs stuff here? */
    800796    asprintf(&command, "mkdir -p %s/images", bkpinfo->scratchdir);
    801797    if (system(command)) {
     
    916912        log_to_screen("Mindi failed to create your boot+data disks.");
    917913        asprintf(&command, "grep 'Fatal error' /var/log/mindi.log");
    918         asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     914        tmp = call_program_and_get_last_line_of_output(command);
    919915        paranoid_free(command);
    920916        if (strlen(tmp) > 1) {
     
    11761172    asprintf(&data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir);
    11771173
    1178     asprintf(&g_serial_string,
    1179              call_program_and_get_last_line_of_output("dd \
     1174    g_serial_string = call_program_and_get_last_line_of_output("dd \
    11801175if=/dev/urandom bs=16 count=1 2> /dev/null | \
    11811176hexdump | tr -s ' ' '0' | head -n1"));
    1182     strip_spaces(g_serial_string);
    11831177    asprintf(&tmp, "%s...word.", g_serial_string);
    11841178    paranoid_free(g_serial_string);
     
    12711265    }
    12721266/* if not Debian then go ahead & use fdformat */
    1273     asprintf(&tempfile, "%s",
    1274              call_program_and_get_last_line_of_output
    1275              ("mktemp -q /tmp/mondo.XXXXXXXX"));
     1267    tempfile = call_program_and_get_last_line_of_output("mktemp -q /tmp/mondo.XXXXXXXX"));
    12761268    asprintf(&command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile,
    12771269             tempfile, tempfile);
     
    17291721                    ("Failed to write to disk. I shall blank it and then try again.");
    17301722                sleep(5);
    1731                 system("sync");
     1723                sync();
    17321724                pause_for_N_seconds(5, "Letting DVD drive settle");
    17331725
     
    19211913    char *tmp;
    19221914    char *command;
     1915    bool ret = TRUE;
    19231916    asprintf(&command,
    19241917             "dd if=%s bs=512 count=1 2> /dev/null | strings | head -n1",
    19251918             bigfile_fname);
    19261919    log_msg(1, "command = '%s'", command);
    1927     asprintf(&tmp, "%s",
    1928              call_program_and_get_last_line_of_output(command));
     1920    tmp = call_program_and_get_last_line_of_output(command));
    19291921    log_msg(1, "--> tmp = '%s'", tmp);
    19301922    paranoid_free(command);
    19311923    if (strstr(tmp, "NTFS")) {
    19321924        iamhere("TRUE");
    1933         paranoid_free(tmp);
    1934         return (TRUE);
    19351925    } else {
    19361926        iamhere("FALSE");
    1937         paranoid_free(tmp);
    1938         return (FALSE);
    1939     }
     1927        ret = FALSE;
     1928    }
     1929    paranoid_free(tmp);
     1930    return(ret);
    19401931}
    19411932
     
    28702861            log_to_screen("%s found in drive. It's a Mondo disk.",
    28712862                          media_descriptor_string(g_backup_media_type));
    2872             cd_number = atoi(last_line_of_file(szcdno));
     2863            tmp1 = last_line_of_file(szcdno);
     2864            cd_number = atoi(tmp1);
     2865            paranoid_free(tmp1);
    28732866            asprintf(&tmp1, "cat %s 2> /dev/null", szserfname);
    2874             asprintf(&our_serial_str, "%s",
    2875                      call_program_and_get_last_line_of_output(tmp1));
     2867            our_serial_str = call_program_and_get_last_line_of_output(tmp1);
    28762868            paranoid_free(tmp1);
    28772869            // FIXME - should be able to use last_line_of_file(), surely?
     
    29162908    }
    29172909    paranoid_free(mtpt);
    2918 
    2919 /*
    2920   if (g_current_media_number > ask_for_one_if_more_than_this)
    2921     {
    2922       ok_go_ahead_burn_it = FALSE;
    2923       log_it("paafcd: %d > %d, so I'll definitely pause.", g_current_media_number > ask_for_one_if_more_than_this);
    2924     }
    2925 */
    29262910
    29272911    if (!ok_go_ahead_burn_it) {
     
    30773061        sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", biggie_filename);
    30783062        log_it("command = %s", command);
    3079         strcpy (tmp, call_program_and_get_last_line_of_output(command));
     3063        tmp = call_program_and_get_last_line_of_output(command);
    30803064        log_it("res of it = %s", tmp);
    30813065        totallength = (off_t)atoll(tmp);
     3066        paranoid_free(tmp);
    30823067    } else {
    30833068        file_to_openin = biggie_filename;
     
    31053090    paranoid_free(checksum_line);
    31063091
    3107     asprintf(&tmp, "%s",
    3108              slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, ""));
     3092    tmp = slice_fname(biggie_file_number, 0, bkpinfo->tmpdir, "");
    31093093    fout = fopen(tmp, "w");
    31103094    paranoid_free(tmp);
     
    31243108        return (1);
    31253109    }
     3110    tmp = slice_fname(biggie_file_number, 0,bkpinfo->tmpdir, "");
    31263111    if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) {
    3127         res = move_files_to_stream(bkpinfo,
    3128                                    slice_fname(biggie_file_number, 0,
    3129                                                bkpinfo->tmpdir, ""), NULL);
     3112        res = move_files_to_stream(bkpinfo,tmp,NULL);
    31303113    } else {
    3131         res =
    3132             move_files_to_cd(bkpinfo, mrconf,
    3133                              slice_fname(biggie_file_number, 0,
    3134                                          bkpinfo->tmpdir, ""), NULL);
    3135     }
     3114        res = move_files_to_cd(bkpinfo, mrconf, tmp, NULL);
     3115    }
     3116    paranoid_free(tmp);
    31363117    i = bkpinfo->optimal_set_size / 256;
    31373118    for (slice_num = 1; !finished; slice_num++) {
    3138         asprintf(&curr_slice_fname_uncompressed, "%s",
    3139                  slice_fname(biggie_file_number, slice_num,
    3140                              bkpinfo->tmpdir, ""));
    3141         asprintf(&curr_slice_fname_compressed, "%s",
    3142                  slice_fname(biggie_file_number, slice_num,
    3143                              bkpinfo->tmpdir, suffix));
     3119        curr_slice_fname_uncompressed = slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, "");
     3120        curr_slice_fname_compressed = slice_fname(biggie_file_number, slice_num, bkpinfo->tmpdir, suffix));
    31443121
    31453122        tmp = percent_media_full_comment(bkpinfo);
     
    35733550                            "Verifying archives against live filesystem");
    35743551        if (bkpinfo->backup_media_type == cdstream) {
    3575             paranoid_alloc(bkpinfo->media_device,
    3576                             "/dev/cdrom");
     3552            paranoid_alloc(bkpinfo->media_device,"/dev/cdrom");
    35773553        }
    35783554        verify_tape_backups(bkpinfo);
     
    35883564        g_current_media_number = cdno;
    35893565        if (bkpinfo->backup_media_type != iso) {
    3590             paranoid_free(bkpinfo->media_device);
    3591             bkpinfo->media_device = find_cdrom_device(FALSE);
     3566            bkpinfo->media_device = find_cdrom_device(FALSE));
    35923567        }
    35933568        chdir("/");
     
    37173692        }
    37183693        if (((blockno + 1) % 128) == 0) {
    3719             paranoid_system("sync");    /* fflush doesn't work; dunno why */
     3694            sync(); /* fflush doesn't work; dunno why */
    37203695            update_evalcall_form(percentage);
    37213696        }
Note: See TracChangeset for help on using the changeset viewer.