Changeset 688 in MondoRescue for trunk/mondo/mondo/common/libmondo-tools.c


Ignore:
Timestamp:
Jul 17, 2006, 3:44:46 PM (18 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-tools.c

    r687 r688  
    218218    d = 5.2;                    // :-)
    219219#else
    220     asprintf(&tmp, call_program_and_get_last_line_of_output("uname -r"));
     220    tmp = call_program_and_get_last_line_of_output("uname -r");
    221221    p = strchr(tmp, '.');
    222222    if (p) {
     
    390390    rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB;
    391391#ifdef __FreeBSD__
    392     asprintf(&tmp,
    393              call_program_and_get_last_line_of_output
    394              ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6"));
     392    tmp = call_program_and_get_last_line_of_output
     393             ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6");
    395394    avm += atol(tmp);
    396395    paranoid_free(tmp);
    397     asprintf(&tmp,
    398              call_program_and_get_last_line_of_output
    399              ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc"));
     396    tmp = call_program_and_get_last_line_of_output
     397             ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc");
    400398    avm += atol(tmp);
    401399    paranoid_free(tmp);
     
    403401             g_tmpfs_mountpt);
    404402#else
    405     asprintf(&tmp,
    406              call_program_and_get_last_line_of_output
    407              ("free | grep \":\" | tr -s ' ' '\t' | cut -f2 | head -n1"));
     403    tmp = call_program_and_get_last_line_of_output
     404             ("free | grep \":\" | tr -s ' ' '\t' | cut -f2 | head -n1");
    408405    avm += atol(tmp);
    409406    paranoid_free(tmp);
     
    478475        if (getenv ("SUDO_COMMAND")) {
    479476            asprintf(&command, "strings `which growisofs` | grep -c SUDO_COMMAND");
    480             if (!strcmp(call_program_and_get_last_line_of_output(command), "1")) {
     477            tmp = call_program_and_get_last_line_of_output(command);
     478            if (!strcmp(tmp, "1")) {
    481479                popup_and_OK("Fatal Error: Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details.");
    482480                fatal_error("Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details.");
    483481            }       
     482            paranoid_free(tmp);
    484483            paranoid_free(command);
    485484        }
     
    574573                 bkpinfo->isodir);
    575574        log_it("command = %s", command);
    576         asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     575        tmp = call_program_and_get_last_line_of_output(command);
    577576        paranoid_free(command);
    578577        log_it("res of it = %s", tmp);
     
    585584        paranoid_free(tmp);
    586585        log_it("command = %s", command);
    587         asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     586        tmp = call_program_and_get_last_line_of_output(command);
    588587        paranoid_free(command);
    589588        log_it("res of it = %s", tmp);
     
    704703    }
    705704    g_current_media_number = 1;
    706     bkpinfo->postnuke_tarball[0] = bkpinfo->nfs_mount[0] = '\0';
     705    bkpinfo->postnuke_tarball = NULL;
     706    bkpinfo->nfs_mount = NULL;
    707707    return (res);
    708708}
     
    717717void reset_bkpinfo(struct s_bkpinfo *bkpinfo)
    718718{
    719     int i;
     719    int i = 0;
    720720
    721721    log_msg(1, "Hi");
     722
    722723    assert(bkpinfo != NULL);
     724    /* BERLIOS : Useless
    723725    memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo));
     726    */
     727
    724728    bkpinfo->manual_cd_tray = FALSE;
    725729    bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
    726     paranoid_free(bkpinfo->media_device);
     730    bkpinfo->boot_loader = '\0';
     731
    727732    for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
    728733        bkpinfo->media_size[i] = -1;
    729734    }
    730     bkpinfo->boot_loader = '\0';
    731     bkpinfo->boot_device[0] = '\0';
    732     bkpinfo->zip_exe[0] = '\0';
    733     bkpinfo->zip_suffix[0] = '\0';
    734     bkpinfo->restore_path[0] = '\0';
     735
     736    paranoid_free(bkpinfo->media_device);
     737    paranoid_free(bkpinfo->boot_device);
     738    paranoid_free(bkpinfo->zip_exe);
     739    paranoid_free(bkpinfo->zip_suffix);
     740    paranoid_free(bkpinfo->restore_path);
    735741    bkpinfo->use_lzo = FALSE;
    736     bkpinfo->do_not_compress_these[0] = '\0';
     742    paranoid_free(bkpinfo->do_not_compress_these);
    737743    bkpinfo->verify_data = FALSE;
    738744    bkpinfo->backup_data = FALSE;
     
    741747        (am_I_in_disaster_recovery_mode()? TRUE : FALSE);
    742748    if (bkpinfo->disaster_recovery) {
    743         strcpy(bkpinfo->isodir, "/");
     749        paranoid_alloc(bkpinfo->isodir, "/");
    744750    } else {
    745         strcpy(bkpinfo->isodir, "/var/cache/mondo/iso");
    746     }
    747     strcpy(bkpinfo->prefix, STD_PREFIX);
    748 
    749     bkpinfo->scratchdir[0] = '\0';
     751        paranoid_alloc(bkpinfo->isodir, "/var/cache/mondo/iso");
     752    }
     753    paranoid_alloc(bkpinfo->prefix, STD_PREFIX);
     754
     755    paranoid_free(bkpinfo->scratchdir);
    750756    bkpinfo->make_filelist = TRUE;  // unless -J supplied to mondoarchive
    751     sprintf(bkpinfo->tmpdir, "/tmp/tmpfs/mondo.tmp.%d", (int) (random() % 32768));  // for mondorestore
     757    paranoid_free(bkpinfo->tmpdir);
     758    asprintf(&bkpinfo->tmpdir, "/tmp/tmpfs/mondo.tmp.%d", (int) (random() % 32768));    // for mondorestore
    752759    bkpinfo->optimal_set_size = 0;
    753760    bkpinfo->backup_media_type = none;
    754     strcpy(bkpinfo->include_paths, "/");
    755     bkpinfo->exclude_paths[0] = '\0';
    756     bkpinfo->call_before_iso[0] = '\0';
    757     bkpinfo->call_make_iso[0] = '\0';
    758     bkpinfo->call_burn_iso[0] = '\0';
    759     bkpinfo->call_after_iso[0] = '\0';
    760     bkpinfo->image_devs[0] = '\0';
    761     bkpinfo->postnuke_tarball[0] = '\0';
    762     bkpinfo->kernel_path[0] = '\0';
    763     bkpinfo->nfs_mount[0] = '\0';
    764     bkpinfo->nfs_remote_dir[0] = '\0';
     761    paranoid_alloc(bkpinfo->include_paths, "/");
     762    paranoid_free(bkpinfo->exclude_paths);
     763    paranoid_free(bkpinfo->call_before_iso);
     764    paranoid_free(bkpinfo->call_make_iso);
     765    paranoid_free(bkpinfo->call_burn_iso);
     766    paranoid_free(bkpinfo->call_after_iso);
     767    paranoid_free(bkpinfo->image_devs);
     768    paranoid_free(bkpinfo->postnuke_tarball);
     769    paranoid_free(bkpinfo->kernel_path);
     770    paranoid_free(bkpinfo->nfs_mount);
     771    paranoid_free(bkpinfo->nfs_remote_dir);
    765772    bkpinfo->wipe_media_first = FALSE;
    766773    bkpinfo->differential = FALSE;
     
    773780
    774781
    775 
    776 
    777782/**
    778783 * Get the remaining free space (in MB) on @p partition.
     
    782787long free_space_on_given_partition(char *partition)
    783788{
    784     char *command, *out_sz;
     789    char *command = NULL;
     790    char *out_sz = NULL;
    785791    long res;
    786792
     
    795801    asprintf(&command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4",
    796802             partition);
    797     asprintf(&out_sz, call_program_and_get_last_line_of_output(command));
     803    out_sz = call_program_and_get_last_line_of_output(command);
    798804    paranoid_free(command);
    799805    if (strlen(out_sz) == 0) {
     
    840846            ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE);
    841847    }
    842     asprintf(&tmp,
    843              call_program_and_get_last_line_of_output
    844              ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));
     848    tmp = call_program_and_get_last_line_of_output
     849             ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2");
    845850    if (atol(tmp) < 35000) {
    846851        retval++;
     
    928933    run_program_and_log_output
    929934        ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5);
    930     asprintf(&tmp,
    931              call_program_and_get_last_line_of_output
    932              ("mount | grep -E \"cdr(om|w)\""));
     935    tmp = call_program_and_get_last_line_of_output("mount | grep -E \"cdr(om|w)\"");
    933936    if (strcmp("", tmp)) {
    934937        if (strstr(tmp, "autofs")) {
     
    10211024{
    10221025    /*@ buffer ****************************************************** */
    1023     char *command;
    1024     char *tmp;
     1026    char *command = NULL;
     1027    char *tmp = NULL;
    10251028
    10261029    /*@ end vars *************************************************** */
     
    10281031    assert_string_is_neither_NULL_nor_zerolength(config_file);
    10291032    assert_string_is_neither_NULL_nor_zerolength(label);
     1033
    10301034    if (!does_file_exist(config_file)) {
    10311035        asprintf(&tmp, "(read_cfg_var) Cannot find %s config file",
     
    10331037        log_to_screen(tmp);
    10341038        paranoid_free(tmp);
    1035         value[0] = '\0';
     1039        value = NULL;
    10361040        return (1);
    10371041    } else if (strstr(value, "/dev/") && strstr(value, "t0")
     
    10431047        asprintf(&command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5",
    10441048                label, config_file);
    1045         strcpy(value, call_program_and_get_last_line_of_output(command));
     1049        value = call_program_and_get_last_line_of_output(command);
    10461050        paranoid_free(command);
    10471051        if (strlen(value) == 0) {
     
    10521056    }
    10531057}
    1054 
    10551058
    10561059
     
    11011104             "grep -v \":\" /etc/fstab | grep -vx \"#.*\" | grep -w \"/boot\" | tr -s ' ' '\t' | cut -f1 | head -n1");
    11021105    log_msg(4, "Cool. Command = '%s'", command);
    1103     asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     1106    tmp = call_program_and_get_last_line_of_output(command);
    11041107    paranoid_free(command);
    11051108
    11061109    log_msg(4, "tmp = '%s'", tmp);
    1107     if (tmp[0]) {
     1110    if (tmp) {
    11081111        log_it("/boot is at %s according to /etc/fstab", tmp);
    11091112        if (strstr(tmp, "LABEL=")) {
     
    11991202        return (1);
    12001203    }
    1201     asprintf(&tempfile,
    1202              call_program_and_get_last_line_of_output
    1203              ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX"));
     1204    tempfile = call_program_and_get_last_line_of_output
     1205             ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX");
    12041206    if (does_file_exist(config_file)) {
    12051207        asprintf(&command, "grep -vx '%s .*' %s > %s",
     
    12281230    if (mal) {
    12291231        iamhere("Malloc'ing globals");
    1230         malloc_string(g_erase_tmpdir_and_scratchdir);
     1232        g_erase_tmpdir_and_scratchdir = NULL;
    12311233        malloc_string(g_serial_string);
    1232         malloc_string(g_magicdev_command);
    12331234    } else {
    12341235        iamhere("Freeing globals");
     
    12681269void stop_magicdev_if_necessary()
    12691270{
    1270     strcpy(g_magicdev_command,
    1271            call_program_and_get_last_line_of_output
    1272            ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"));
    1273     if (g_magicdev_command[0]) {
     1271    g_magicdev_command = call_program_and_get_last_line_of_output
     1272           ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99");
     1273    if (g_magicdev_command) {
    12741274        log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
    12751275        paranoid_system("killall magicdev");
     
    12831283void restart_magicdev_if_necessary()
    12841284{
    1285     char *tmp;
    1286 
    1287     if (g_magicdev_command && g_magicdev_command[0]) {
     1285    char *tmp = NULL;
     1286
     1287    if (!g_magicdev_command) {
    12881288        asprintf(&tmp, "%s &", g_magicdev_command);
    12891289        paranoid_system(tmp);
Note: See TracChangeset for help on using the changeset viewer.