Changeset 688 in MondoRescue for trunk/mondo/mondo/common


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 !)

Location:
trunk/mondo/mondo/common
Files:
19 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        }
  • trunk/mondo/mondo/common/libmondo-devices.c

    r687 r688  
    1 /* $Id$
     1/*
     2 * $Id$
    23 * Subroutines for handling devices
    34 */
     
    1920#include <sys/ioctl.h>
    2021#include <sys/types.h>
     22#include <unistd.h>
    2123#ifdef __FreeBSD__
    2224#define DKTYPENAMES
     
    6062{
    6163    if (bkpinfo->media_device != NULL) {
    62         paranoid_free(g_cdrom_drive_is_here);
    63         asprintf(&g_cdrom_drive_is_here, bkpinfo->media_device);    // just in case
     64        paranoid_alloc(g_cdrom_drive_is_here, bkpinfo->media_device);   // just in case
    6465    }
    6566    if (bkpinfo->media_device != NULL) {
    66         paranoid_free(g_dvd_drive_is_here);
    67         asprintf(&g_dvd_drive_is_here, bkpinfo->media_device);  // just in case
     67        paranoid_alloc(g_dvd_drive_is_here, bkpinfo->media_device); // just in case
    6868    }
    6969}
     
    320320    char *incoming = NULL;
    321321    char *searchstr;
     322    char *tmp;
    322323
    323324    /*@ ints ******************************************************* */
     
    332333    assert_string_is_neither_NULL_nor_zerolength(drive);
    333334    assert(partno >= 0 && partno < 999);
    334 
    335     malloc_string(searchstr);
    336335
    337336#ifdef __FreeBSD__
     
    353352    paranoid_free(program);
    354353
    355     (void) build_partition_name(searchstr, drive, partno);
    356     strcat(searchstr, " ");
     354    searchstr = build_partition_name(drive, partno);
     355    asprintf(&tmp, "%s ", searchstr);
     356    paranoid_free(searchstr);
     357
    357358    for (res = 0; !res && getline(&incoming, &n, fin);) {
    358         if (strstr(incoming, searchstr)) {
     359        if (strstr(incoming, tmp)) {
    359360            res = 1;
    360361        }
     
    365366        log_OS_error("Cannot pclose fin");
    366367    }
    367     paranoid_free(searchstr);
     368    paranoid_free(tmp);
    368369    return (res);
    369370}
     
    459460            asprintf(&dev, g_cdrom_drive_is_here);
    460461        } else {
     462            // find_cdrom_device allocates the string
    461463            dev = find_cdrom_device(FALSE);
    462464        }
     
    468470
    469471    if ((dev == NULL) || (! mount_CDROM_here(dev, mountpoint))) {
     472        paranoid_free(dev);
    470473        if (!popup_and_get_string
    471             (_("CD-ROM device"), _("Please enter your CD-ROM's /dev device"),
    472              dev, MAX_STR_LEN / 4)) {
     474            (_("CD-ROM device"), _("Please enter your CD-ROM's /dev device"), dev)) {
    473475            res = FALSE;
    474476        } else {
     
    556558{
    557559    /*@ pointers **************************************************** */
    558     FILE *fin;
    559     char *p;
    560     char *q;
    561     char *r;
     560    FILE *fin = NULL;
     561    char *p = NULL;
     562    char *q = NULL;
     563    char *r = NULL;
    562564    char *output = NULL;
    563565    size_t n = 0;
     
    568570    /*@ buffers ***************************************************** */
    569571    char *tmp = NULL;
    570     char *cdr_exe;
     572    char *cdr_exe = NULL;
    571573#ifndef __FreeBSD__
    572574    char *phrase_two = NULL;
    573575    char *dvd_last_resort = NULL;
    574576#endif
    575     char *command;
    576     char *mountpoint;
    577     static char the_last_place_i_found_it[MAX_STR_LEN] = "";
     577    char *command = NULL;
     578    char *mountpoint = NULL;
     579    static char *the_last_place_i_found_it = NULL;
    578580
    579581    /*@ end vars **************************************************** */
     
    584586        return(output);
    585587    }
    586     if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) {
     588    if ((the_last_place_i_found_it != NULL) && !try_to_mount) {
    587589        asprintf(&output, the_last_place_i_found_it);
    588590        log_msg(3,
     
    834836        }
    835837        log_msg(3, "(find_cdrom_device) --> '%s'", output);
    836         strcpy(the_last_place_i_found_it, output);
     838        asprintf(&the_last_place_i_found_it, output);
    837839        paranoid_free(g_cdrom_drive_is_here);
    838840        asprintf(&g_cdrom_drive_is_here, output);
     
    863865char *find_dvd_device()
    864866{
    865     char *tmp;
     867    char *tmp = NULL;
    866868    int retval = 0, devno = -1;
    867869    char *output = NULL;
     
    10081010bool is_this_a_valid_disk_format(char *format)
    10091011{
    1010     char *good_formats;
    1011     char *command;
    1012     char *format_sz;
    1013 
    1014     FILE *pin;
     1012    char *good_formats = NULL;
     1013    char *command = NULL;
     1014    char *tmp = NULL;
     1015    char *format_sz = NULL;
     1016
     1017    FILE *pin = NULL;
    10151018    bool retval;
    1016     malloc_string(good_formats);
     1019    size_t n = 0;
    10171020    assert_string_is_neither_NULL_nor_zerolength(format);
    10181021
     
    10341037        retval = FALSE;
    10351038    } else {
    1036         strcpy(good_formats, " ");
    1037         (void) fgets(good_formats + 1, MAX_STR_LEN, pin);
     1039        getline(&good_formats, &n , pin);
    10381040        if (pclose(pin)) {
    10391041            log_OS_error("Cannot pclose good formats");
    10401042        }
    10411043        strip_spaces(good_formats);
    1042         strcat(good_formats, " swap lvm raid ntfs 7 "); // " ntfs 7 " -- um, cheating much? :)
     1044        // " ntfs 7 " -- um, cheating much? :)
     1045        asprintf(&tmp, " %s swap lvm raid ntfs 7 ",good_formats);
     1046        paranoid_free(good_formats);
     1047        good_formats = tmp;
     1048
    10431049        if (strstr(good_formats, format_sz)) {
    10441050            retval = TRUE;
     
    10461052            retval = FALSE;
    10471053        }
    1048     }
    1049     paranoid_free(good_formats);
     1054        paranoid_free(good_formats);
     1055    }
    10501056    paranoid_free(format_sz);
    10511057    return (retval);
     
    11411147char *make_vn(char *fname)
    11421148{
    1143     char *device;
     1149    char *device = NULL;
    11441150    char *mddevice = NULL;
    11451151    char *command = NULL;
     
    12241230{
    12251231    /*@ buffer ****************************************************** */
    1226     char *command;
    1227     int retval;
     1232    char *command = NULL;
     1233    int retval = 0;
    12281234
    12291235    assert_string_is_neither_NULL_nor_zerolength(device);
     
    12381244
    12391245#ifdef __FreeBSD__
    1240         char *dev;
     1246        char *dev = NULL;
    12411247
    12421248        dev = make_vn(device));
     
    13611367
    13621368        while (what_number_cd_is_this(bkpinfo) != cd_number_i_want) {
    1363             paranoid_system("sync");
     1369            sync();
    13641370            if (is_this_device_mounted(MNT_CDROM)) {
    13651371                res =
     
    13831389                inject_device(bkpinfo->media_device);
    13841390            }
    1385             paranoid_system("sync");
     1391            sync();
    13861392        }
    13871393        paranoid_free(request);
     
    14101416// archiving_to_media is FALSE if I'm being called by mondorestore
    14111417{
    1412     char *tmp;
     1418    char *tmp = NULL;
     1419    char *tmp1 = NULL;
     1420    char *tmp2 = NULL;
    14131421    char *sz_size = NULL;
    1414     char *command;
    1415     char *comment;
     1422    char *command = NULL;
     1423    char *comment = NULL;
    14161424    char *prompt = NULL;
    1417     int i;
    1418     FILE *fin;
     1425    int i = 0;
     1426    FILE *fin = NULL;
    14191427
    14201428    assert(bkpinfo != NULL);
     
    14801488                    media_descriptor_string(bkpinfo->backup_media_type));
    14811489            if (bkpinfo->backup_media_type == dvd) {
    1482                 paranoid_free(bkpinfo->media_device);
    14831490                bkpinfo->media_device = find_dvd_device();
    14841491                asprintf(&tmp, "1");
     
    14921499            }
    14931500            if (bkpinfo->backup_media_type != dvd) {
    1494                 if (!popup_and_get_string(_("Speed"), comment, tmp, 4)) {
     1501                if (!popup_and_get_string(_("Speed"), comment, tmp)) {
    14951502                    log_to_screen(_("User has chosen not to backup the PC"));
    14961503                    finish(1);
     
    15061513                    media_descriptor_string(bkpinfo->backup_media_type));
    15071514
    1508             if (!popup_and_get_string("Size", comment, sz_size, 5)) {
     1515            if (!popup_and_get_string("Size", comment, sz_size)) {
    15091516                log_to_screen(_("User has chosen not to backup the PC"));
    15101517                finish(1);
     
    15151522                bkpinfo->media_size[i] = atoi(sz_size);
    15161523            }
     1524            paranoid_free(sz_size);
     1525
    15171526            if (bkpinfo->media_size[0] <= 0) {
    15181527                log_to_screen(_("User has chosen not to backup the PC"));
    15191528                finish(1);
    15201529            }
    1521             paranoid_free(sz_size);
    15221530        }
    15231531    case cdstream:
     
    15291537                   || bkpinfo->backup_media_type == dvd) {
    15301538            if (bkpinfo->media_device == NULL) {
    1531                 paranoid_alloc(bkpinfo->media_device, "/dev/cdrom");
     1539                asprintf(&bkpinfo->media_device, "/dev/cdrom");
    15321540            }                   // just for the heck of it :)
    15331541            log_msg(1, "bkpinfo->media_device = %s",
     
    15441552                                                backup_media_type));
    15451553                if (!popup_and_get_string
    1546                     (_("Device?"), comment, bkpinfo->media_device,
    1547                      MAX_STR_LEN / 4)) {
     1554                    (_("Device?"), comment, bkpinfo->media_device)) {
    15481555                    log_to_screen(_("User has chosen not to backup the PC"));
    15491556                    finish(1);
     
    15551562                    bkpinfo->media_device);
    15561563        } else {
    1557             paranoid_free(bkpinfo->media_device);
    15581564            bkpinfo->media_device = find_cdrw_device();
    15591565            if (bkpinfo->media_device != NULL) {
     
    15711577                    i = popup_and_get_string(_("Device node?"),
    15721578                                             _("What is the SCSI node of your CD (re)writer, please?"),
    1573                                              bkpinfo->media_device,
    1574                                              MAX_STR_LEN / 4);
     1579                                             bkpinfo->media_device);
    15751580                } else {
    15761581                    i = popup_and_get_string(_("/dev entry?"),
    15771582                                             _("What is the /dev entry of your CD (re)writer, please?"),
    1578                                              bkpinfo->media_device,
    1579                                              MAX_STR_LEN / 4);
     1583                                             bkpinfo->media_device);
    15801584                }
    15811585                if (!i) {
     
    16021606        if (find_tape_device_and_size(bkpinfo->media_device, sz_size)) {
    16031607            log_msg(3, _("Ok, using vanilla scsi tape."));
    1604             paranoid_alloc(bkpinfo->media_device,VANILLA_SCSI_TAPE );
     1608            paranoid_alloc(bkpinfo->media_device,VANILLA_SCSI_TAPE"0" );
    16051609            if ((fin = fopen(bkpinfo->media_device, "r"))) {
    16061610                paranoid_fclose(fin);
     
    16301634                (_("Device name?"),
    16311635                 _("What is the /dev entry of your tape streamer?"),
    1632                  bkpinfo->media_device, MAX_STR_LEN / 4)) {
     1636                 bkpinfo->media_device)) {
    16331637                log_to_screen(_("User has chosen not to backup the PC"));
    16341638                finish(1);
     
    16421646        paranoid_free(tmp);
    16431647        log_msg(4, "sz_size = %s", sz_size);
    1644         sz_size[0] = '\0';
     1648        paranoid_free(sz_size);
    16451649        bkpinfo->media_size[0] = 0;
    16461650        log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]);
     
    16771681                (_("NFS dir."),
    16781682                 _("Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)"),
    1679                  bkpinfo->nfs_mount, MAX_STR_LEN / 4)) {
     1683                 bkpinfo->nfs_mount)) {
    16801684                log_to_screen(_("User has chosen not to backup the PC"));
    16811685                finish(1);
     
    17011705            asprintf(&comment,
    17021706                    _("How much data (in Megabytes) will each media store?"));
    1703             if (!popup_and_get_string(_("Size"), comment, sz_size, 5)) {
     1707            if (!popup_and_get_string(_("Size"), comment, sz_size)) {
    17041708                log_to_screen(_("User has chosen not to backup the PC"));
    17051709                finish(1);
     
    17181722            if (!popup_and_get_string
    17191723                (_("NFS share"), _("Which remote NFS share should I mount?"),
    1720                  bkpinfo->nfs_mount, MAX_STR_LEN)) {
     1724                 bkpinfo->nfs_mount)) {
    17211725                log_to_screen(_("User has chosen not to backup the PC"));
    17221726                finish(1);
     
    17421746            finish(1);
    17431747        }
    1744         asprintf(&tmp, bkpinfo->nfs_remote_dir);
    17451748        if (!popup_and_get_string
    1746             (_("Directory"), _("Which directory within that mountpoint?"), tmp,
    1747              MAX_STR_LEN)) {
     1749            (_("Directory"), _("Which directory within that mountpoint?"),bkpinfo->nfs_remote_dir)) {
    17481750            log_to_screen(_("User has chosen not to backup the PC"));
    17491751            finish(1);
    17501752        }
    1751         strcpy(bkpinfo->nfs_remote_dir, tmp);
    1752         paranoid_free(tmp);
    1753 
    1754         // check whether writable - we better remove surrounding spaces for this
    1755         strip_spaces(bkpinfo->nfs_remote_dir);
    1756         asprintf(&command, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir,
     1753
     1754        asprintf(&command, "echo hi > '%s/%s/.dummy.txt'", bkpinfo->isodir,
    17571755                bkpinfo->nfs_remote_dir);
    17581756        while (run_program_and_log_output(command, FALSE)) {
    1759             paranoid_free(tmp);
    1760             paranoid_free(prompt);
    1761             asprintf(&tmp, bkpinfo->nfs_remote_dir);
    17621757            asprintf(&prompt,
    17631758                     _("Directory '%s' under mountpoint '%s' does not exist or is not writable. You can fix this or change the directory and retry or cancel the backup."),
    17641759                     bkpinfo->nfs_remote_dir, bkpinfo->isodir);
    17651760            if (!popup_and_get_string
    1766                 (_("Directory"), prompt, tmp, MAX_STR_LEN)) {
     1761                (_("Directory"), prompt, bkpinfo->nfs_remote_dir)) {
    17671762                log_to_screen(_("User has chosen not to backup the PC"));
    17681763                finish(1);
    17691764            }
    1770             strcpy(bkpinfo->nfs_remote_dir, tmp);
    1771             // check whether writable - we better remove surrounding spaces for this */
    1772             strip_spaces(bkpinfo->nfs_remote_dir);
     1765            paranoid_free(prompt);
     1766
     1767            paranoid_free(command);
    17731768            asprintf(&command, "echo hi > %s/%s/.dummy.txt",
    17741769                     bkpinfo->isodir, bkpinfo->nfs_remote_dir);
    17751770        }
    17761771        paranoid_free(command);
    1777         paranoid_free(tmp);
    1778         paranoid_free(prompt);
    17791772
    17801773        if (!popup_and_get_string
    17811774            (_("Prefix."),
    17821775             _("Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files"),
    1783             bkpinfo->prefix, MAX_STR_LEN / 4)) {
     1776            bkpinfo->prefix)) {
    17841777            log_to_screen(_("User has chosen not to backup the PC"));
    17851778            finish(1);
     
    18001793                (_("Storage dir."),
    18011794                 _("Please enter the full path that contains your ISO images.  Example: /mnt/raid0_0"),
    1802                  bkpinfo->isodir, MAX_STR_LEN / 4)) {
     1795                 bkpinfo->isodir)) {
    18031796                log_to_screen(_("User has chosen not to backup the PC"));
    18041797                finish(1);
     
    18121805                if (!popup_and_get_string
    18131806                    (_("ISO size."),
    1814                      _("Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s or DVD's you plan to backup to."),
    1815                      sz_size, 16)) {
     1807                     _("Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s or DVD's you plan to backup to."), sz_size)) {
    18161808                    log_to_screen(_("User has chosen not to backup the PC"));
    18171809                    finish(1);
     
    18251817                    (_("Prefix."),
    18261818                     _("Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files"),
    1827                      bkpinfo->prefix, MAX_STR_LEN / 4)) {
     1819                     bkpinfo->prefix)) {
    18281820                    log_to_screen("User has chosen not to backup the PC");
    18291821                    finish(1);
     
    18441836
    18451837#ifdef __FreeBSD__
    1846         strcpy(bkpinfo->boot_device,
    1847                call_program_and_get_last_line_of_output
     1838        bkpinfo->boot_device = call_program_and_get_last_line_of_output
    18481839               ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
    18491840#else
    1850         strcpy(bkpinfo->boot_device,
    1851                call_program_and_get_last_line_of_output
     1841        bkpinfo->boot_device = call_program_and_get_last_line_of_output
    18521842               ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
    18531843#endif
     
    18601850                (_("Boot device"),
    18611851                 _("What is your boot device? (e.g. /dev/ad0)"),
    1862                  bkpinfo->boot_device, MAX_STR_LEN / 4)) {
     1852                 bkpinfo->boot_device)) {
    18631853                log_to_screen(_("User has chosen not to backup the PC"));
    18641854                finish(1);
     
    18691859                (_("Boot device"),
    18701860                 _("What is your boot device? (e.g. /dev/hda)"),
    1871                  bkpinfo->boot_device, MAX_STR_LEN / 4)) {
     1861                 bkpinfo->boot_device)) {
    18721862                log_to_screen(_("User has chosen not to backup the PC"));
    18731863                finish(1);
     
    19011891        }
    19021892        bkpinfo->boot_loader = i;
    1903         strcpy(bkpinfo->include_paths, "/");
     1893        asprintf(&bkpinfo->include_paths, "/");
    19041894        if (!popup_and_get_string
    19051895            (_("Backup paths"),
    19061896             _("Please enter paths which you want me to backup. The default is '/' (i.e. everything)."),
    1907              bkpinfo->include_paths, MAX_STR_LEN)) {
     1897             bkpinfo->include_paths)) {
    19081898            log_to_screen(_("User has chosen not to backup the PC"));
    19091899            finish(1);
    19101900        }
     1901
    19111902        tmp = list_of_NFS_mounts_only();
    19121903        if (strlen(tmp) > 2) {
    1913             if (bkpinfo->exclude_paths[0]) {
    1914                 strcat(bkpinfo->exclude_paths, " ");
    1915             }
    1916             strncpy(bkpinfo->exclude_paths, tmp, MAX_STR_LEN);
     1904            if (bkpinfo->exclude_paths != NULL) {
     1905                tmp1 = bkpinfo->exclude_paths;
     1906                asprintf(&bkpinfo->exclude_paths, "%s %s", tmp1, tmp);
     1907                paranoid_free(tmp1);
     1908            } else {
     1909                bkpinfo->exclude_paths = tmp;
     1910            }
    19171911        }
    19181912        paranoid_free(tmp);
    19191913// NTFS
    1920         asprintf(&tmp,
    1921                call_program_and_get_last_line_of_output
    1922                ("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'"));
     1914        tmp = call_program_and_get_last_line_of_output
     1915               ("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'");
    19231916        if (strlen(tmp) > 2) {
    19241917            if (!popup_and_get_string
    19251918                (_("NTFS partitions"),
    19261919                 _("Please enter/confirm the NTFS partitions you wish to backup as well."),
    1927                  tmp, MAX_STR_LEN / 4)) {
     1920                 tmp1)) {
    19281921                log_to_screen(_("User has chosen not to backup the PC"));
    19291922                finish(1);
    19301923            }
    1931             strncpy(bkpinfo->image_devs, tmp, MAX_STR_LEN / 4);
     1924            if (bkpinfo->image_devs != NULL) {
     1925                tmp2 = bkpinfo->image_devs;
     1926                asprintf(&bkpinfo->image_devs, "%s %s", tmp2, tmp1);
     1927                paranoid_free(tmp2);
     1928            } else {
     1929                bkpinfo->image_devs = tmp1;
     1930            }
     1931            paranoid_free(tmp1);
    19321932        }
    19331933        paranoid_free(tmp);
     
    19361936            (_("Exclude paths"),
    19371937             _("Please enter paths which you do NOT want to backup. Separate them with spaces. NB: /tmp and /proc are always excluded. :-) Just hit 'Enter' if you want to do a full system backup."),
    1938              bkpinfo->exclude_paths, MAX_STR_LEN)) {
     1938             bkpinfo->exclude_paths)) {
    19391939            log_to_screen(_("User has chosen not to backup the PC"));
    19401940            finish(1);
     
    20052005 * Get a space-separated list of NFS mounts.
    20062006 * @return The list created.
    2007  * @note The return value points to static data that will be overwritten with each call.
     2007 * @note The return value should be freed by caller
    20082008 * @bug Even though we only want the mounts, the devices are still checked.
    20092009 */
    20102010char *list_of_NFS_mounts_only(void)
    20112011{
    2012     char *exclude_these_devices;
    2013     char *exclude_these_directories;
    2014     char *result_sz;
    2015 
    2016     asprintf(&exclude_these_directories,
    2017            call_program_and_get_last_line_of_output
     2012    return(call_program_and_get_last_line_of_output
    20182013           ("mount -t coda,ncpfs,nfs,smbfs,cifs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
     2014    /* BERLIOS : Useless
    20192015    asprintf(&exclude_these_devices,
    20202016           call_program_and_get_last_line_of_output
    20212017           ("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|nfs|smbfs|cifs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
    2022     asprintf(&result_sz, "%s", exclude_these_directories);
    2023     paranoid_free(exclude_these_devices);
    2024     paranoid_free(exclude_these_directories);
    2025     return (result_sz);
     2018           */
    20262019}
    20272020
     
    20602053void sensibly_set_tmpdir_and_scratchdir(struct s_bkpinfo *bkpinfo)
    20612054{
    2062     char *tmp, *command, *sz;
     2055    char *tmp = NULL;
     2056    char *command = NULL;
     2057    char *sz = NULL;
     2058    int i = 0;
    20632059
    20642060    assert(bkpinfo != NULL);
    20652061
    20662062#ifdef __FreeBSD__
    2067     asprintf(&tmp,
    2068            call_program_and_get_last_line_of_output
    2069            ("df -m -P -t nonfs,msdosfs,ntfs,smbfs,smb,cifs | tr -s '\t' ' ' | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
     2063    tmp = call_program_and_get_last_line_of_output
     2064           ("df -m -P -t nonfs,msdosfs,ntfs,smbfs,smb,cifs | tr -s '\t' ' ' | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'");
    20702065#else
    2071     asprintf(&tmp,
    2072            call_program_and_get_last_line_of_output
    2073            ("df -m -P -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs | sed 's/                  /devdev/' | tr -s '\t' ' ' | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
     2066    tmp = call_program_and_get_last_line_of_output
     2067           ("df -m -P -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs | sed 's/                  /devdev/' | tr -s '\t' ' ' | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'");
    20742068#endif
    20752069
     
    20822076        fatal_error("I couldn't figure out the tempdir!");
    20832077    }
    2084     sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%d", tmp,
    2085             (int) (random() % 32768));
     2078    i = (int) (random() % 32768);
     2079    asprintf(&bkpinfo->tmpdir, "%s/mondo.tmp.%d", tmp, i);
    20862080    log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir);
    20872081
    2088     sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp,
    2089             (int) (random() % 32768));
     2082    asprintf(&bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, i);
    20902083    log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);
    20912084
    2092     sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
     2085    asprintf(&g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
    20932086            bkpinfo->scratchdir);
    20942087
    2095     asprintf(&command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp);
     2088    asprintf(&command, "rm -Rf %s/mondo.tmp.* %s/mondo.scratch.*", tmp, tmp);
    20962089    paranoid_free(tmp);
    20972090
     
    21522145{
    21532146    int cd_number = -1;
    2154     char *mountdev;
    2155     char *tmp;
     2147    char *mountdev = NULL;
     2148    char *tmp = NULL;
     2149    char *tmp1 = NULL;
    21562150
    21572151    assert(bkpinfo != NULL);
     
    21592153        asprintf(&tmp, "mount | grep iso9660 | awk '{print $3;}'");
    21602154
    2161         asprintf(&mountdev, "%s/archives/THIS-CD-NUMBER", call_program_and_get_last_line_of_output(tmp));
     2155        tmp1 = call_program_and_get_last_line_of_output(tmp);
    21622156        paranoid_free(tmp);
    21632157
    2164         cd_number = atoi(last_line_of_file(mountdev));
     2158        asprintf(&mountdev, "%s/archives/THIS-CD-NUMBER", tmp1);
     2159        paranoid_free(tmp1);
     2160
     2161        tmp = last_line_of_file(mountdev);
     2162        cd_number = atoi(tmp);
    21652163        paranoid_free(mountdev);
     2164        paranoid_free(tmp);
    21662165
    21672166        return (cd_number);
     
    21762175        (void)mount_CDROM_here(bkpinfo->media_device, MNT_CDROM);
    21772176    }
    2178     cd_number =
    2179         atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"));
     2177    tmp = last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER");
     2178    cd_number = atoi(tmp);
     2179    paranoid_free(tmp);
    21802180    return (cd_number);
    21812181}
     
    21912191char *where_is_root_mounted()
    21922192{
    2193     /*@ buffers **************** */
    21942193    char *tmp;
    21952194
    2196 
    21972195#ifdef __FreeBSD__
    2198     asprintf(&tmp, call_program_and_get_last_line_of_output
    2199            ("mount | grep \" on / \" | cut -d' ' -f1"));
     2196    tmp = call_program_and_get_last_line_of_output
     2197           ("mount | grep \" on / \" | cut -d' ' -f1");
    22002198#else
    2201     asprintf(&tmp, call_program_and_get_last_line_of_output
    2202            ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//"));
     2199    tmp = call_program_and_get_last_line_of_output
     2200           ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//");
    22032201    if (strstr(tmp, "/dev/cciss/")) {
    22042202        paranoid_free(tmp);
    2205         asprintf(&tmp, call_program_and_get_last_line_of_output
    2206                ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1"));
     2203        tmp = call_program_and_get_last_line_of_output
     2204               ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1");
    22072205    }
    22082206    if (strstr(tmp, "/dev/md")) {
    22092207        paranoid_free(tmp);
    2210         asprintf(&tmp,
    2211                call_program_and_get_last_line_of_output
    2212                ("mount | grep \" on / \" | cut -d' ' -f1"));
     2208        tmp = call_program_and_get_last_line_of_output
     2209               ("mount | grep \" on / \" | cut -d' ' -f1");
    22132210    }
    22142211#endif
     
    23732370char *resolve_softlinks_to_get_to_actual_device_file(char *incoming)
    23742371{
    2375     char *output;
    2376     char *command;
    2377     char *curr_fname;
    2378     char *scratch;
    2379     char *tmp;
    2380     char *p;
     2372    char *output = NULL;
     2373    char *command = NULL;
     2374    char *curr_fname = NULL;
     2375    char *scratch = NULL;
     2376    char *tmp = NULL;
     2377    char *p = NULL;
    23812378
    23822379    struct stat statbuf;
     
    23912388            log_msg(1, "curr_fname = %s", curr_fname);
    23922389            asprintf(&command, "file %s", curr_fname);
    2393             asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     2390            tmp = call_program_and_get_last_line_of_output(command);
    23942391            paranoid_free(command);
    23952392
     
    24002397            for (p = scratch; *p != '\0' && *p != '\''; p++);
    24012398            *p = '\0';
    2402             log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp,
    2403                     scratch);
     2399            log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, scratch);
    24042400            paranoid_free(tmp);
    24052401
     
    24392435char *which_partition_format(const char *drive)
    24402436{
    2441     char *output;
    2442     char *tmp;
    2443     char *command;
    2444     char *fdisk;
     2437    char *output = NULL;
     2438    char *tmp = NULL;
     2439    char *command = NULL;
     2440    char *fdisk = NULL;
    24452441
    24462442    log_msg(0, "Looking for partition table format type");
     
    24502446    paranoid_free(fdisk);
    24512447
    2452     asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     2448    tmp = call_program_and_get_last_line_of_output(command);
    24532449    paranoid_free(command);
    24542450
  • trunk/mondo/mondo/common/libmondo-fifo.c

    r687 r688  
    1313#endif
    1414#include <fcntl.h>
    15 #include <stdio.h>
    1615
    1716#include <errno.h>
     
    8584    wise_upper_limit = (am_I_in_disaster_recovery_mode()? 8 : 32);
    8685    wise_lower_limit = 1;       // wise_upper_limit/2 + 1;
    87     paranoid_system("sync");
     86    sync();
    8887    for (bufsize = wise_upper_limit, res = -1;
    8988         res != 0 && bufsize >= wise_lower_limit; bufsize--) {
     
    9695    if (!res) {
    9796        bufsize++;
    98         asprintf(&tmp, _("Negotiated max buffer of %d MB ", bufsize));
     97        asprintf(&tmp, _("Negotiated max buffer of %d MB "), bufsize);
    9998        log_to_screen(tmp);
    10099        paranoid_free(tmp);
     
    160159    char *command;
    161160
    162     paranoid_system("sync");
     161    sync();
    163162    asprintf(&command,
    164163            "ps wwax | grep -F \"%s\" | grep -Fv grep | awk '{print $1;}' | grep -v PID | tr -s '\n' ' ' | awk '{ print $1; }'",
     
    167166    log_msg(2, "kill_buffer() --- command = %s", command);
    168167
    169     asprintf(&tmp, "%s",
    170              call_program_and_get_last_line_of_output(command));
     168    tmp = call_program_and_get_last_line_of_output(command);
    171169    paranoid_free(command);
    172170
     
    177175        run_program_and_log_output(command, TRUE);
    178176    }
     177    paranoid_free(tmp);
    179178    paranoid_free(command);
    180     paranoid_free(tmp);
    181179}
    182180
  • trunk/mondo/mondo/common/libmondo-filelist.c

    r687 r688  
    847847{
    848848
    849     /*@ structures ************************************************* */
    850     struct s_node *filelist;
    851 
    852     /*@ pointers *************************************************** */
    853     FILE *pin;
    854 
    855     /*@ buffers **************************************************** */
    856     char *command_to_open_fname;
     849    struct s_node *filelist = NULL;
     850    FILE *pin = NULL;
     851    char *command_to_open_fname = NULL;
    857852    char *fname = NULL;
    858     char *tmp;
    859     int pos_in_fname;
     853    char *tmp = NULL;
     854    char *tmp1 = NULL;
     855    int pos_in_fname = 0;
    860856    size_t n = 0;
    861     /*@ int ******************************************************** */
    862     int percentage;
    863 
    864     /*@ long ******************************************************* */
    865     long lines_in_filelist;
    866     long lino = 0;
    867     /*@ end vars *************************************************** */
     857    int percentage = 0;
     858
     859    long lines_in_filelist = 0L;
     860    long lino = 0L;
    868861
    869862    assert_string_is_neither_NULL_nor_zerolength(filelist_fname);
     
    876869    asprintf(&tmp, "zcat %s | wc -l", filelist_fname);
    877870    log_msg(6, "tmp = %s", tmp);
    878     lines_in_filelist =
    879         atol(call_program_and_get_last_line_of_output(tmp));
     871    tmp1 = call_program_and_get_last_line_of_output(tmp);
    880872    paranoid_free(tmp);
     873
     874    lines_in_filelist = atol(tmp1);
     875    paranoid_free(tmp1);
    881876
    882877    if (lines_in_filelist < 3) {
     
    13221317                      char *skeleton_filelist)
    13231318{
    1324     DIR *dip;
    1325     struct dirent *dit;
     1319    DIR *dip = NULL;
     1320    struct dirent *dit = NULL;
    13261321    struct stat statbuf;
    1327     char *new;
    1328     char *tmp;
     1322    char *new = NULL;
     1323    char *tmp = NULL;
     1324    char *tmp1 = NULL;
    13291325    static int percentage = 0;
    1330     char *skip_these;
    1331     char *new_with_spaces;
    1332     static char *name_of_evalcall_form;
    1333     int i;
     1326    char *skip_these = NULL;
     1327    char *new_with_spaces = NULL;
     1328    static char *name_of_evalcall_form = NULL;
     1329    int i = 0;
    13341330    static int depth = 0;
    1335     char *p;
     1331    char *p = NULL;
    13361332    static int counter = 0;
    13371333    static int uberctr = 0;
    1338     static char *find_skeleton_marker;
     1334    static char *find_skeleton_marker = NULL;
    13391335    static long skeleton_lino = 0;
    13401336    static time_t last_time = 0;
     
    13651361
    13661362        asprintf(&tmp, "wc -l %s | awk '{print $1;}'", skeleton_filelist);
    1367         g_skeleton_entries =
    1368             1 + atol(call_program_and_get_last_line_of_output(tmp));
     1363        tmp1 = call_program_and_get_last_line_of_output(tmp);
    13691364        paranoid_free(tmp);
     1365
     1366        g_skeleton_entries = 1 + atol(tmp1);
     1367        paranoid_free(tmp1);
    13701368
    13711369        asprintf(&name_of_evalcall_form, "Making catalog of %s", dir);
     
    15341532{
    15351533    char sz_datefile_wildcard[] = "/var/cache/mondo/difflevel.%d";
    1536     char *p, *q;
     1534    char *p = NULL;
     1535    char *q = NULL;
     1536    char *tmp = NULL;
     1537    char *tmp1 = NULL;
     1538    char *tmp2 = NULL;
    15371539    char *sz_datefile;
    1538     char *sz_filelist, *exclude_paths;
    1539     int i;
    1540     FILE *fout;
    1541     char *command;
     1540    char *sz_filelist = NULL;
     1541    char *exclude_paths = NULL;
     1542    int i = 0;
     1543    FILE *fout = NULL;
     1544    char *command = NULL;
    15421545    time_t time_of_last_full_backup = 0;
    15431546    struct stat statbuf;
    1544     char *skeleton_filelist;
     1547    char *skeleton_filelist = NULL;
     1548
    15451549    // The pathname to the skeleton filelist, used to give better progress reporting for mondo_makefilelist().
    1546 
    15471550    asprintf(&sz_datefile, sz_datefile_wildcard, 0);
    15481551    if (!include_paths && !userdef_filelist) {
     
    15731576        }
    15741577        make_hole_for_file(sz_datefile);
    1575         write_one_liner_data_file(sz_datefile,
    1576                                   call_program_and_get_last_line_of_output
    1577                                   ("date +%s"));
     1578        tmp = call_program_and_get_last_line_of_output("date +%s");
     1579        write_one_liner_data_file(sz_datefile, tmp);
     1580        paranoid_free(tmp);
    15781581    } else if (lstat(sz_datefile, &statbuf)) {
    15791582        log_msg(2,
     
    16001603        log_msg(2, "include_paths = '%s'", include_paths);
    16011604        log_msg(1, "Calculating filelist");
     1605        tmp = call_program_and_get_last_line_of_output("locate /win386.swp 2> /dev/null");
     1606        tmp1 = call_program_and_get_last_line_of_output("locate /hiberfil.sys 2> /dev/null");
     1607        tmp2 = call_program_and_get_last_line_of_output("locate /pagefile.sys 2> /dev/null");
    16021608        asprintf(&exclude_paths, " %s %s %s %s %s %s . .. \
    16031609" MNT_CDROM " " MNT_FLOPPY " /media/cdrom /media/cdrecorder \
    1604 /proc /sys /tmp /var/cache/mondo /var/cache/mindi", excp, call_program_and_get_last_line_of_output("locate /win386.swp 2> /dev/null"), call_program_and_get_last_line_of_output("locate /hiberfil.sys 2> /dev/null"), call_program_and_get_last_line_of_output("locate /pagefile.sys 2> /dev/null"), (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir);
     1610/proc /sys /tmp /var/cache/mondo /var/cache/mindi", excp, tmp, tmp1, tmp2, (tmpdir[0] == '/' && tmpdir[1] == '/') ? (tmpdir + 1) : tmpdir, (scratchdir[0] == '/' && scratchdir[1] == '/') ? (scratchdir + 1) : scratchdir);
     1611        paranoid_free(tmp);
     1612        paranoid_free(tmp1);
     1613        paranoid_free(tmp2);
    16051614
    16061615        log_msg(2, "Excluding paths = '%s'", exclude_paths);
  • trunk/mondo/mondo/common/libmondo-files.c

    r687 r688  
    2222//static char cvsid[] = "$Id$";
    2323
    24 extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN];
     24extern char **err_log_lines;
    2525
    2626extern int g_currentY;
     
    270270int figure_out_kernel_path_interactively_if_necessary(char *kernel)
    271271{
    272     char *tmp;
    273     char *command;
    274 
    275     if (!kernel[0]) {
    276         strcpy(kernel,
    277                call_program_and_get_last_line_of_output
     272    char *tmp = NULL;
     273    char *command = NULL;
     274
     275    if (kernel == NULL) {
     276        kernel = call_program_and_get_last_line_of_output
    278277               ("mindi --findkernel 2> /dev/null"));
    279278    }
    280279    // If we didn't get anything back, check whether mindi raised a fatal error
    281     if (!kernel[0]) {
     280    if (kernel == NULL) {
    282281        asprintf(&command, "grep 'Fatal error' /var/log/mindi.log");
    283         asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     282        tmp = call_program_and_get_last_line_of_output(command);
    284283        if (strlen(tmp) > 1) {
    285284            popup_and_OK(tmp);
     
    289288        paranoid_free(tmp);
    290289    }
    291     log_it("Calling Mindi with kernel path of '%s'", kernel);
    292     while (!kernel[0]) {
     290
     291    if (kernel != NULL) {
     292        log_it("Calling Mindi with kernel path of '%s'", kernel);
     293    } else {
     294        log_it("Calling Mindi without kernel, so asking one");
     295    }
     296
     297    while (kernel == NULL) {
    293298        if (!ask_me_yes_or_no
    294299            (_("Kernel not found or invalid. Choose another?"))) {
     
    298303            (_("Kernel path"),
    299304             _("What is the full path and filename of your kernel, please?"),
    300              kernel, MAX_STR_LEN / 4)) {
     305             kernel)) {
    301306            fatal_error
    302307                ("Kernel not found. Please specify with the '-k' flag.");
    303308        }
    304         asprintf(&tmp, "User says kernel is at %s", kernel);
    305         log_it(tmp);
    306         paranoid_free(tmp);
     309        log_it("User says kernel is at %s", kernel);
    307310    }
    308311    return (0);
     
    322325{
    323326    /*@ buffers ********************* */
    324     static char output[MAX_STR_LEN];
    325     char *incoming;
    326     char *command;
     327    char *output = NULL;
     328    char *incoming = NULL;
     329    char *command = NULL;
    327330
    328331    /*@******************************* */
    329332
    330333    assert_string_is_neither_NULL_nor_zerolength(fname);
     334
    331335    asprintf(&command, "which %s 2> /dev/null", fname);
    332     asprintf(&incoming, call_program_and_get_last_line_of_output(command));
    333     paranoid_free(command);
    334 
    335     if (incoming[0] == '\0') {
     336    incoming = call_program_and_get_last_line_of_output(command);
     337    paranoid_free(command);
     338
     339    if (incoming == NULL) {
    336340        if (system("which file > /dev/null 2> /dev/null")) {
    337             paranoid_free(incoming);
    338341            return (NULL);      // forget it :)
    339342        }
     
    343346        paranoid_free(incoming);
    344347
    345         asprintf(&incoming,
    346                call_program_and_get_last_line_of_output(command));
     348        incoming = call_program_and_get_last_line_of_output(command);
    347349        paranoid_free(command);
    348350    }
    349     if (incoming[0] == '\0')    // yes, it is == '\0' twice, not once :)
     351    if (incoming == NULL)   // yes, it is == '\0' twice, not once :)
    350352    {
    351353        asprintf(&command, "dirname %s 2> /dev/null", incoming);
    352354        paranoid_free(incoming);
    353355
    354         asprintf(&incoming,
    355                call_program_and_get_last_line_of_output(command));
     356        incoming = call_program_and_get_last_line_of_output(command);
    356357        paranoid_free(command);
    357358    }
    358     strcpy(output, incoming);
    359     paranoid_free(incoming);
    360 
    361     if (output[0] != '\0' && does_file_exist(output)) {
    362         log_msg(4, "find_home_of_exe () --- Found %s at %s", fname,
    363                 output);
     359    output = incoming;
     360
     361    if (output != NULL && does_file_exist(output)) {
     362        log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, output);
    364363    } else {
    365         output[0] = '\0';
     364        paranoid_free(output);
    366365        log_msg(4, "find_home_of_exe() --- Could not find %s", fname);
    367366    }
    368     if (!output[0]) {
    369         return (NULL);
    370     } else {
    371         return (output);
    372     }
     367    return (output);
    373368}
    374369
     
    421416{
    422417
    423     /*@ buffers ***************************************************** */
    424     char *lastline;
    425     char *command;
    426     /*@ pointers **************************************************** */
    427     char *p;
    428 
    429     /*@ int's ******************************************************* */
     418    char *lastline = NULL;
     419    char *command = NULL;
     420    char *p = NULL;
    430421    int i;
    431422
    432     for (i = NOOF_ERR_LINES - 1;
     423    for (i = g_noof_log_lines - 1;
    433424         i >= 0 && !strstr(err_log_lines[i], "% Done")
    434425         && !strstr(err_log_lines[i], "% done"); i--);
     
    437428                "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'",
    438429                filename, '%');
    439         asprintf(&lastline,
    440                call_program_and_get_last_line_of_output(command));
     430        lastline = call_program_and_get_last_line_of_output(command);
    441431        paranoid_free(command);
    442         if (!lastline[0]) {
    443             paranoid_free(lastline);
     432        if (!lastline) {
    444433            return (0);
    445434        }
     
    477466{
    478467    /*@ buffers ***************************************************** */
    479     static char output[MAX_STR_LEN];
    480     static char *command;
    481     static char *tmp;
     468    char *output = NULL;
     469    char *command = NULL;
     470    char *tmp = NULL;
    482471
    483472    /*@ pointers **************************************************** */
    484473    FILE *fin;
     474    size_t n = 0;
    485475
    486476    /*@ end vars **************************************************** */
     
    491481        log_it(tmp);
    492482        paranoid_free(tmp);
    493 
    494         output[0] = '\0';
     483        asprintf(&output, "");
     484
    495485        return (output);
    496486    }
     
    499489    paranoid_free(command);
    500490
    501     (void) fgets(output, MAX_STR_LEN, fin);
     491    getline(&output, &n, fin);
    502492    paranoid_pclose(fin);
    503493    while (strlen(output) > 0 && output[strlen(output) - 1] < 32) {
     
    693683long size_of_partition_in_mountlist_K(char *tmpdir, char *dev)
    694684{
    695     char *command;
    696     char *sz_res;
    697     long file_len_K;
     685    char *command = NULL;
     686    char *sz_res = NULL;
     687    long file_len_K = 0L;
    698688
    699689    asprintf(&command,
     
    701691            dev, tmpdir);
    702692    log_it(command);
    703     asprintf(&sz_res, call_program_and_get_last_line_of_output(command));
     693    sz_res = call_program_and_get_last_line_of_output(command);
    704694    file_len_K = atol(sz_res);
    705695    log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K);
     
    717707long size_of_all_biggiefiles_K(struct s_bkpinfo *bkpinfo)
    718708{
    719     /*@ buffers ***************************************************** */
    720     char *fname;
    721     char *biggielist;
    722     char *comment;
    723     char *tmp;
    724     char *command;
     709    char *fname = NULL;
     710    char *biggielist = NULL;
     711    char *comment = NULL;
     712    char *tmp = NULL;
     713    char *command = NULL;
    725714
    726715    /*@ long ******************************************************** */
    727     long scratchL = 0;
    728     long file_len_K;
     716    long scratchL = 0L;
     717    long file_len_K = 0L;
    729718
    730719    /*@ pointers *************************************************** */
     
    734723    /*@ end vars *************************************************** */
    735724
    736     malloc_string(tmp);
    737     malloc_string(command);
    738725    log_it("Calculating size of all biggiefiles (in total)");
    739726    asprintf(&biggielist, "%s/biggielist.txt", bkpinfo->tmpdir);
     
    754741                        fatal_error("ntfsresize not found");
    755742                    }
    756                     sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);
     743                    asprintf(&command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);
    757744                    log_it("command = %s", command);
    758                     strcpy (tmp, call_program_and_get_last_line_of_output(command));
     745                    tmp = call_program_and_get_last_line_of_output(command);
     746                    paranoid_free(command);
     747
    759748                    log_it("res of it = %s", tmp);
    760749                    file_len_K = atoll(tmp) / 1024L;
     750                    paranoid_free(tmp);
    761751                } else {
    762752                    file_len_K = get_phys_size_of_drive(fname) * 1024L;
     
    787777    paranoid_fclose(fin);
    788778    log_it("Finished calculating total size of all biggiefiles");
    789     paranoid_free(tmp);
    790     paranoid_free(command);
    791779    return (scratchL);
    792780}
     
    803791    /*@ buffer ****************************************************** */
    804792    char *tmp = NULL;
    805     char *command;
     793    char *command = NULL;
    806794    long long llres;
    807795    size_t n = 0;
    808796    /*@ pointers **************************************************** */
    809     char *p;
    810     FILE *fin;
     797    char *p = NULL;
     798    FILE *fin = NULL;
    811799
    812800    /*@ end vars *************************************************** */
     
    10251013    paranoid_free(command);
    10261014
    1027     asprintf(&tmp,
    1028            call_program_and_get_last_line_of_output("which mondorestore"));
    1029     if (!tmp[0]) {
     1015    tmp = call_program_and_get_last_line_of_output("which mondorestore");
     1016    if (!tmp) {
    10301017        fatal_error
    10311018            ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?");
     
    10681055
    10691056    /*@ buffers ******** */
    1070     char *outfile;
    1071     char *nfs_dev;
    1072     char *nfs_mount;
    1073     char *nfs_client_ipaddr;
    1074     char *nfs_client_netmask;
    1075     char *nfs_client_broadcast;;
    1076     char *nfs_client_defgw;
    1077     char *nfs_server_ipaddr;
    1078     char *tmp;
    1079     char *command;
     1057    char *outfile = NULL;
     1058    char *nfs_dev = NULL;
     1059    char *nfs_mount = NULL;
     1060    char *nfs_client_ipaddr = NULL;
     1061    char *nfs_client_netmask = NULL;
     1062    char *nfs_client_broadcast = NULL;
     1063    char *nfs_client_defgw = NULL;
     1064    char *nfs_server_ipaddr = NULL;
     1065    char *tmp = NULL;
     1066    char *command = NULL;
    10801067
    10811068    /*@ pointers ***** */
     
    10991086    asprintf(&command,
    11001087            "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1");
    1101     asprintf(&nfs_dev, call_program_and_get_last_line_of_output(command));
     1088    nfs_dev = call_program_and_get_last_line_of_output(command);
    11021089    paranoid_free(command);
    11031090
    11041091    asprintf(&command,
    11051092            "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2");
    1106     asprintf(&nfs_client_ipaddr,
    1107            call_program_and_get_last_line_of_output(command));
     1093    nfs_client_ipaddr = call_program_and_get_last_line_of_output(command);
    11081094    paranoid_free(command);
    11091095
    11101096    asprintf(&command,
    11111097            "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2");
    1112     asprintf(&nfs_client_netmask,
    1113            call_program_and_get_last_line_of_output(command));
     1098    nfs_client_netmask = call_program_and_get_last_line_of_output(command);
    11141099    paranoid_free(command);
    11151100
    11161101    asprintf(&command,
    11171102            "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2");
    1118     strcpy(nfs_client_broadcast,
    1119            call_program_and_get_last_line_of_output(command));
    1120     sprintf(command,
     1103    nfs_client_broadcast = call_program_and_get_last_line_of_output(command);
     1104    paranoid_free(command);
     1105
     1106    asprintf(&command,
    11211107            "route -n | grep '^0.0.0.0' | awk '{print $2}'");
    1122     asprintf(&nfs_client_defgw,
    1123            call_program_and_get_last_line_of_output(command));
     1108    nfs_client_defgw = call_program_and_get_last_line_of_output(command);
    11241109    paranoid_free(command);
    11251110
     
    13171302    paranoid_free(tmp);
    13181303
    1319     asprintf(&do_not_compress_these, last_line_of_file(tmp));
     1304    do_not_compress_these = last_line_of_file(tmp);
    13201305    for (p = do_not_compress_these; p != NULL; p++) {
    13211306        asprintf(&tmp, p);
  • trunk/mondo/mondo/common/libmondo-fork.c

    r687 r688  
    1 /* libmondo-fork.c
    2    $Id$
    3 
    4 - subroutines for handling forking/pthreads/etc.
    5 
    6 
    7 01/20/2006
    8 - replaced partimagehack with ntfsclone
    9 
    10 06/20/2004
    11 - create fifo /var/log/partimagehack-debug.log and empty it
    12   to keep ramdisk from filling up
    13 
    14 04/13/2004
    15 - >= should be <= g_loglevel
    16 
    17 11/15/2003
    18 - changed a few []s to char*s
    19  
    20 10/12
    21 - rewrote partimagehack handling (multiple fifos, chunks, etc.)
    22 
    23 10/11
    24 - partimagehack now has debug level of N (set in my-stuff.h)
    25 
    26 10/08
    27 - call to partimagehack when restoring will now log errors to /var/log/....log
    28 
    29 10/06
    30 - cleaned up logging a bit
    31 
    32 09/30
    33 - line 735 - missing char* cmd in sprintf()
    34 
    35 09/28
    36 - added run_external_binary_with_percentage_indicator()
    37 - rewritten eval_call_to_make_ISO()
    38 
    39 09/18
    40 - call mkstemp instead of mktemp
    41 
    42 09/13
    43 - major NTFS hackage
    44 
    45 09/12
    46 - paranoid_system("rm -f /tmp/ *PARTIMAGE*") before calling partimagehack
    47 
    48 09/11
    49 - forward-ported unbroken feed_*_partimage() subroutines
    50   from early August 2003
    51 
    52 09/08
    53 - detect & use partimagehack if it exists
    54 
    55 09/05
    56 - finally finished partimagehack hack :)
    57 
    58 07/04
    59 - added subroutines to wrap around partimagehack
    60 
    61 04/27
    62 - don't echo (...res=%d...) at end of log_it()
    63   unnecessarily
    64 - replace newtFinished() and newtInit() with
    65   newtSuspend() and newtResume()
    66 
    67 04/24
    68 - added some assert()'s and log_OS_error()'s
    69 
    70 04/09
    71 - cleaned up run_program_and_log_output()
    72 
    73 04/07
    74 - cleaned up code a bit
    75 - let run_program_and_log_output() accept -1 (only log if _no error_)
    76 
    77 01/02/2003
    78 - in eval_call_to_make_ISO(), append output to MONDO_LOGFILE
    79   instead of a temporary stderr text file
    80 
    81 12/10
    82 - patch by Heiko Schlittermann to handle % chars in issue.net
    83 
    84 11/18
    85 - if mkisofs in eval_call_to_make_ISO() returns an error then return it,
    86   whether ISO was created or not
    87 
    88 10/30
    89 - if mkisofs in eval_call_to_make_ISO() returns an error then find out if
    90   the output (ISO) file has been created; if it has then return 0 anyway
    91 
    92 08/01 - 09/30
    93 - run_program_and_log_output() now takes boolean operator to specify
    94   whether it will log its activities in the event of _success_
    95 - system() now includes 2>/dev/null
    96 - enlarged some tmp[]'s
    97 - added run_program_and_log_to_screen() and run_program_and_log_output()
    98 
    99 07/24
    100 - created
    101 */
    102 
     1/* libmondo-fork.c - subroutines for handling forking/pthreads/etc.
     2 * $Id$
     3 */
    1034
    1045#include "my-stuff.h"
     
    11011#include "libmondo-tools-EXT.h"
    11112
    112 /*@unused@*/
    113 //static char cvsid[] = "$Id$";
    114 
    11513extern char *g_tmpfs_mountpt;
    11614extern t_bkptype g_backup_media_type;
     
    12321 * @param call The program to run.
    12422 * @return The last line of its output.
    125  * @note The returned value points to static storage that will be overwritten with each call.
     23 * @note The returned value should be freed by caller
    12624 */
    12725char *call_program_and_get_last_line_of_output(char *call)
    12826{
    129     /*@ buffers ***************************************************** */
    130     static char *result = NULL;
    131     char *tmp = NULL;
    132 
    133     /*@ pointers **************************************************** */
    134     FILE *fin;
    135 
     27    char *result = NULL;
     28    FILE *fin = NULL;
    13629    size_t n = 0;
    13730
    138     /*@******************************************************************** */
    139 
    14031    assert_string_is_neither_NULL_nor_zerolength(call);
     32
    14133    if ((fin = popen(call, "r"))) {
    142         for (getline(&tmp, &n, fin); !feof(fin);
    143              getline(&tmp, &n, fin)) {
    144             if (strlen(tmp) > 1) {
    145                 if (result != NULL) {
    146                     paranoid_free(result);
    147                 }
    148                 asprintf(&result, tmp);
    149             }
    150         }
     34        for (getline(&result, &n, fin); !feof(fin); getline(&result, &n, fin));
    15135        paranoid_pclose(fin);
    15236    } else {
    15337        log_OS_error("Unable to popen call");
    15438    }
    155     strip_spaces(result);
    156     paranoid_free(tmp);
    157     return (result);
     39    return(result);
    15840}
    15941
     
    425307    if (!(fin = popen(command, "r"))) {
    426308        log_OS_error("Unable to popen-in command");
    427         asprintf(&tmp, _("Failed utterly to call '%s'", command));
     309        asprintf(&tmp, _("Failed utterly to call '%s'"), command);
    428310        log_to_screen(tmp);
    429311        paranoid_free(tmp);
     
    648530{
    649531
    650     /*@ int *************************************************************** */
    651532    int res = 0;
    652533    int percentage = 0;
     
    655536    int last_pcno = 0;
    656537
    657     /*@ buffers *********************************************************** */
    658     char *command;
    659     char *tempfile;
    660     /*@ pointers ********************************************************** */
    661     FILE *pin;
     538    char *command = NULL;
     539    char *tempfile = NULL;
     540    FILE *pin = NULL;
    662541
    663542    assert_string_is_neither_NULL_nor_zerolength(cmd);
    664543
    665     asprintf(&tempfile,
    666            call_program_and_get_last_line_of_output
    667            ("mktemp -q /tmp/mondo.XXXXXXXX"));
     544    tempfile = call_program_and_get_last_line_of_output("mktemp -q /tmp/mondo.XXXXXXXX");
    668545    asprintf(&command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
    669546            tempfile);
  • trunk/mondo/mondo/common/libmondo-mountlist-EXT.h

    r59 r688  
    11/* libmondo-mountlist-EXT.h */
    22
    3 extern int evaluate_drive_within_mountlist(struct mountlist_itself
    4                                            *mountlist, char *drive,
    5                                            char *flaws_str);
    63extern int evaluate_mountlist(struct mountlist_itself *mountlist,
    74                              char *flaws_str_A, char *flaws_str_B,
     
    118extern int look_for_duplicate_mountpoints(struct mountlist_itself
    129                                          *mountlist, char *flaws_str);
    13 extern int look_for_weird_formats(struct mountlist_itself *mountlist,
    14                                   char *flaws_str);
    1510extern int make_list_of_drives_in_mountlist(struct mountlist_itself *,
    1611                                            struct list_of_disks *);
  • trunk/mondo/mondo/common/libmondo-mountlist.c

    r507 r688  
    6060
    6161    /*@ buffers ******************************************************** */
    62     char *tmp;
    63     char *device;
     62    char *tmp = NULL;
     63    char *tmp1 = NULL;
     64    char *device = NULL;
    6465    // BERLIOS : useless ? char *mountpoint;
    6566
     
    6970
    7071    /*@ pointers ******************************************************* */
    71     char *part_table_fmt;
     72    char *part_table_fmt = NULL;
    7273
    7374    /*@ initialize ***************************************************** */
    74     flaws_str[0] = '\0';
    7575    prev_part_no = 0;
    7676    // BERLIOS: tmp[0] = '\0';
     
    8181    if (physical_drive_size < 0) {
    8282        asprintf(&tmp, " %s does not exist.", drive);
    83         strcat(flaws_str, tmp);
     83        flaws_str = tmp;
    8484    } else {
    8585        asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size);
     86        flaws_str = NULL;
    8687    }
    8788    log_it(tmp);
     
    108109                asprintf(&tmp, " Can only have up to 'h' in disklabel.");
    109110                log_it(tmp);
    110                 strcat(flaws_str, tmp);
     111                if (flaws_str) {
     112                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     113                } else {
     114                    asprintf(&tmp1, "%s", tmp);
     115                }
     116                paranoid_free(flaws_str);
     117                flaws_str = tmp1;
    111118                paranoid_free(tmp);
    112119                res++;
     
    124131                if (!strstr(flaws_str, tmp)) {
    125132                    log_it(tmp);
    126                     strcat(flaws_str, tmp);
     133                    if (flaws_str) {
     134                        asprintf(&tmp1, "%s%s",flaws_str, tmp);
     135                    } else {
     136                        asprintf(&tmp1, "%s", tmp);
     137                    }
     138                    paranoid_free(flaws_str);
     139                    flaws_str = tmp1;
    127140                    res++;
    128141                }
     
    134147                asprintf(&tmp, " %s is tiny!", device);
    135148                log_it(tmp);
    136                 strcat(flaws_str, tmp);
     149                if (flaws_str) {
     150                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     151                } else {
     152                    asprintf(&tmp1, "%s", tmp);
     153                }
     154                paranoid_free(flaws_str);
     155                flaws_str = tmp1;
    137156                paranoid_free(tmp);
    138157                res++;
     
    147166                asprintf(&tmp, " %s has a weird mountpoint.", device);
    148167                log_it(tmp);
    149                 strcat(flaws_str, tmp);
     168                if (flaws_str) {
     169                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     170                } else {
     171                    asprintf(&tmp1, "%s", tmp);
     172                }
     173                paranoid_free(flaws_str);
     174                flaws_str = tmp1;
    150175                paranoid_free(tmp);
    151176                res++;
     
    155180                asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    156181                log_it(tmp);
    157                 strcat(flaws_str, tmp);
     182                if (flaws_str) {
     183                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     184                } else {
     185                    asprintf(&tmp1, "%s", tmp);
     186                }
     187                paranoid_free(flaws_str);
     188                flaws_str = tmp1;
    158189                paranoid_free(tmp);
    159190                res++;
     
    179210
    180211        if (((pos >= 0) || npos) && foundsome) {
    181             sprintf(flaws_str + strlen(flaws_str),
    182                     " %s has both DD and PC-style partitions.", drive);
     212            asprintf(&tmp, " %s has both DD and PC-style partitions.", drive);
     213            if (flaws_str) {
     214                asprintf(&tmp1, "%s%s",flaws_str, tmp);
     215            } else {
     216                asprintf(&tmp1, "%s", tmp);
     217            }
     218            paranoid_free(flaws_str);
     219            flaws_str = tmp1;
     220            paranoid_free(tmp);
    183221            return ++res;       // fatal error
    184222        }
     
    191229                    asprintf(&tmp, " Gap prior to %s.", device);
    192230                    log_it(tmp);
    193                     strcat(flaws_str, tmp);
     231                    if (flaws_str) {
     232                        asprintf(&tmp1, "%s%s",flaws_str, tmp);
     233                    } else {
     234                        asprintf(&tmp1, "%s", tmp);
     235                    }
     236                    paranoid_free(flaws_str);
     237                    flaws_str = tmp1;
    194238                    paranoid_free(tmp);
    195239                    res++;
     
    199243                             prev_part_no, curr_part_no);
    200244                    log_it(tmp);
    201                     strcat(flaws_str, tmp);
     245                    if (flaws_str) {
     246                        asprintf(&tmp1, "%s%s",flaws_str, tmp);
     247                    } else {
     248                        asprintf(&tmp1, "%s", tmp);
     249                    }
     250                    paranoid_free(flaws_str);
     251                    flaws_str = tmp1;
    202252                    paranoid_free(tmp);
    203253                    res++;
     
    211261                asprintf(&tmp, " Partition %ss4 is occupied.", drive);
    212262                log_it(tmp);
    213                 strcat(flaws_str, tmp);
     263                if (flaws_str) {
     264                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     265                } else {
     266                    asprintf(&tmp1, "%s", tmp);
     267                }
     268                paranoid_free(flaws_str);
     269                flaws_str = tmp1;
    214270                paranoid_free(tmp);
    215271                res++;
     
    227283                if (!strstr(flaws_str, tmp)) {
    228284                    log_it(tmp);
    229                     strcat(flaws_str, tmp);
     285                    if (flaws_str) {
     286                        asprintf(&tmp1, "%s%s",flaws_str, tmp);
     287                    } else {
     288                        asprintf(&tmp1, "%s", tmp);
     289                    }
     290                    paranoid_free(flaws_str);
     291                    flaws_str = tmp1;
    230292                    res++;
    231293                }
     
    237299                asprintf(&tmp, " %s is tiny!", device);
    238300                log_it(tmp);
    239                 strcat(flaws_str, tmp);
     301                if (flaws_str) {
     302                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     303                } else {
     304                    asprintf(&tmp1, "%s", tmp);
     305                }
     306                paranoid_free(flaws_str);
     307                flaws_str = tmp1;
    240308                paranoid_free(tmp);
    241309                res++;
     
    250318                asprintf(&tmp, " %s has a weird mountpoint.", device);
    251319                log_it(tmp);
    252                 strcat(flaws_str, tmp);
     320                if (flaws_str) {
     321                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     322                } else {
     323                    asprintf(&tmp1, "%s", tmp);
     324                }
     325                paranoid_free(flaws_str);
     326                flaws_str = tmp1;
    253327                paranoid_free(tmp);
    254328                res++;
     
    258332                asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    259333                log_it(tmp);
    260                 strcat(flaws_str, tmp);
     334                if (flaws_str) {
     335                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     336                } else {
     337                    asprintf(&tmp1, "%s", tmp);
     338                }
     339                paranoid_free(flaws_str);
     340                flaws_str = tmp1;
    261341                paranoid_free(tmp);
    262342                res++;
     
    278358                             " Can only have up to 'h' in disklabel.");
    279359                    log_it(tmp);
    280                     strcat(flaws_str, tmp);
     360                    if (flaws_str) {
     361                        asprintf(&tmp1, "%s%s",flaws_str, tmp);
     362                    } else {
     363                        asprintf(&tmp1, "%s", tmp);
     364                    }
     365                    paranoid_free(flaws_str);
     366                    flaws_str = tmp1;
    281367                    paranoid_free(tmp);
    282368                    res++;
     
    294380                    if (!strstr(flaws_str, tmp)) {
    295381                        log_it(tmp);
    296                         strcat(flaws_str, tmp);
     382                        if (flaws_str) {
     383                            asprintf(&tmp1, "%s%s",flaws_str, tmp);
     384                        } else {
     385                            asprintf(&tmp1, "%s", tmp);
     386                        }
     387                        paranoid_free(flaws_str);
     388                        flaws_str = tmp1;
    297389                        res++;
    298390                    }
     
    304396                    asprintf(&tmp, " %s is tiny!", device);
    305397                    log_it(tmp);
    306                     strcat(flaws_str, tmp);
     398                    if (flaws_str) {
     399                        asprintf(&tmp1, "%s%s",flaws_str, tmp);
     400                    } else {
     401                        asprintf(&tmp1, "%s", tmp);
     402                    }
     403                    paranoid_free(flaws_str);
     404                    flaws_str = tmp1;
    307405                    paranoid_free(tmp);
    308406                    res++;
     
    317415                    asprintf(&tmp, " %s has a weird mountpoint.", device);
    318416                    log_it(tmp);
    319                     strcat(flaws_str, tmp);
     417                    if (flaws_str) {
     418                        asprintf(&tmp1, "%s%s",flaws_str, tmp);
     419                    } else {
     420                        asprintf(&tmp1, "%s", tmp);
     421                    }
     422                    paranoid_free(flaws_str);
     423                    flaws_str = tmp1;
    320424                    paranoid_free(tmp);
    321425                    res++;
     
    326430                    asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    327431                    log_it(tmp);
    328                     strcat(flaws_str, tmp);
     432                    if (flaws_str) {
     433                        asprintf(&tmp1, "%s%s",flaws_str, tmp);
     434                    } else {
     435                        asprintf(&tmp1, "%s", tmp);
     436                    }
     437                    paranoid_free(flaws_str);
     438                    flaws_str = tmp1;
    329439                    paranoid_free(tmp);
    330440                    res++;
     
    347457                 amount_allocated - physical_drive_size, drive);
    348458        log_it(tmp);
    349         strcat(flaws_str, tmp);
     459        if (flaws_str) {
     460            asprintf(&tmp1, "%s%s",flaws_str, tmp);
     461        } else {
     462            asprintf(&tmp1, "%s", tmp);
     463        }
     464        paranoid_free(flaws_str);
     465        flaws_str = tmp1;
    350466        paranoid_free(tmp);
    351467        res++;
     
    354470                 physical_drive_size - amount_allocated, drive);
    355471        log_it(tmp);
    356         strcat(flaws_str, tmp);
     472        if (flaws_str) {
     473            asprintf(&tmp1, "%s%s",flaws_str, tmp);
     474        } else {
     475            asprintf(&tmp1, "%s", tmp);
     476        }
     477        paranoid_free(flaws_str);
     478        flaws_str = tmp1;
    357479        paranoid_free(tmp);
    358480    }
     
    391513    assert_string_is_neither_NULL_nor_zerolength(drive);
    392514    assert(mountlist != NULL);
    393     assert(flaws_str != NULL);
    394 
    395     flaws_str[0] = '\0';
     515    flaws_str = NULL;
     516
    396517    prev_part_no = 0;
    397518    // BERLIOS : useless ? tmp[0] = '\0';
     
    402523    if (physical_drive_size < 0) {
    403524        asprintf(&tmp, " %s does not exist.", drive);
    404         strcat(flaws_str, tmp);
     525        if (flaws_str) {
     526            asprintf(&tmp1, "%s%s",flaws_str, tmp);
     527        } else {
     528            asprintf(&tmp1, "%s", tmp);
     529        }
     530        paranoid_free(flaws_str);
     531        flaws_str = tmp1;
    405532        res++;
    406533        log_msg(1, tmp);
     
    421548        if (physical_drive_size < 0) {
    422549            asprintf(&tmp, " %s refers to non-existent hardware.", device);
    423             strcat(flaws_str, tmp);
     550            if (flaws_str) {
     551                asprintf(&tmp1, "%s%s",flaws_str, tmp);
     552            } else {
     553                asprintf(&tmp1, "%s", tmp);
     554            }
     555            paranoid_free(flaws_str);
     556            flaws_str = tmp1;
    424557            res++;
    425558            paranoid_free(tmp);
     
    432565                asprintf(&tmp, " Gap prior to %s.", device);
    433566                log_it(tmp);
    434                 strcat(flaws_str, tmp);
     567                if (flaws_str) {
     568                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     569                } else {
     570                    asprintf(&tmp1, "%s", tmp);
     571                }
     572                paranoid_free(flaws_str);
     573                flaws_str = tmp1;
    435574                paranoid_free(tmp);
    436575                res++;
     
    440579                         prev_part_no, curr_part_no);
    441580                log_it(tmp);
    442                 strcat(flaws_str, tmp);
     581                if (flaws_str) {
     582                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     583                } else {
     584                    asprintf(&tmp1, "%s", tmp);
     585                }
     586                paranoid_free(flaws_str);
     587                flaws_str = tmp1;
    443588                paranoid_free(tmp);
    444589                res++;
     
    452597            asprintf(&tmp, " Partition %s4 is occupied.", drive);
    453598            log_it(tmp);
    454             strcat(flaws_str, tmp);
     599            if (flaws_str) {
     600                asprintf(&tmp1, "%s%s",flaws_str, tmp);
     601            } else {
     602                asprintf(&tmp1, "%s", tmp);
     603            }
     604            paranoid_free(flaws_str);
     605            flaws_str = tmp1;
    455606            paranoid_free(tmp);
    456607            res++;
     
    470621            if (!strstr(flaws_str, tmp)) {
    471622                log_it(tmp);
    472                 strcat(flaws_str, tmp);
     623                if (flaws_str) {
     624                    asprintf(&tmp1, "%s%s",flaws_str, tmp);
     625                } else {
     626                    asprintf(&tmp1, "%s", tmp);
     627                }
     628                paranoid_free(flaws_str);
     629                flaws_str = tmp1;
    473630                res++;
    474631            }
     
    480637            asprintf(&tmp, " %s is tiny!", device);
    481638            log_it(tmp);
    482             strcat(flaws_str, tmp);
     639            if (flaws_str) {
     640                asprintf(&tmp1, "%s%s",flaws_str, tmp);
     641            } else {
     642                asprintf(&tmp1, "%s", tmp);
     643            }
     644            paranoid_free(flaws_str);
     645            flaws_str = tmp1;
    483646            paranoid_free(tmp);
    484647            res++;
     
    492655            asprintf(&tmp, " %s has a weird mountpoint.", device);
    493656            log_it(tmp);
    494             strcat(flaws_str, tmp);
     657            if (flaws_str) {
     658                asprintf(&tmp1, "%s%s",flaws_str, tmp);
     659            } else {
     660                asprintf(&tmp1, "%s", tmp);
     661            }
     662            paranoid_free(flaws_str);
     663            flaws_str = tmp1;
    495664            paranoid_free(tmp);
    496665            res++;
     
    500669            asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    501670            log_it(tmp);
    502             strcat(flaws_str, tmp);
     671            if (flaws_str) {
     672                asprintf(&tmp1, "%s%s",flaws_str, tmp);
     673            } else {
     674                asprintf(&tmp1, "%s", tmp);
     675            }
     676            paranoid_free(flaws_str);
     677            flaws_str = tmp1;
    503678            paranoid_free(tmp);
    504679            res++;
     
    515690                 amount_allocated - physical_drive_size, drive);
    516691        log_it(tmp);
    517         strcat(flaws_str, tmp);
     692        if (flaws_str) {
     693            asprintf(&tmp1, "%s%s",flaws_str, tmp);
     694        } else {
     695            asprintf(&tmp1, "%s", tmp);
     696        }
     697        paranoid_free(flaws_str);
     698        flaws_str = tmp1;
    518699        paranoid_free(tmp);
    519700        res++;
     
    522703                 physical_drive_size - amount_allocated, drive);
    523704        log_it(tmp);
    524         strcat(flaws_str, tmp);
     705        if (flaws_str) {
     706            asprintf(&tmp1, "%s%s",flaws_str, tmp);
     707        } else {
     708            asprintf(&tmp1, "%s", tmp);
     709        }
     710        paranoid_free(flaws_str);
     711        flaws_str = tmp1;
    525712        paranoid_free(tmp);
    526713    }
     
    582769            log_it(tmp);
    583770        } else {
    584             asprintf(&tmp, " ");
    585             // BERLIOS : tmp was NOT initialized ???
     771            // This function allocates tmp
    586772            if (!evaluate_drive_within_mountlist
    587773                (mountlist, drivelist->el[i].device, tmp)) {
     
    595781    }
    596782    res += look_for_duplicate_mountpoints(mountlist, flaws_str);
    597 /*  res+=look_for_weird_formats(mountlist,flaws_str); .. not necessary, now that we can check to see
    598  which formarts are actually _supported_ by the kernel */
    599     /* log_it(flaws_str); */
    600783    return (spread_flaws_across_three_lines
    601784            (flaws_str, flaws_str_A, flaws_str_B, flaws_str_C, res));
     
    650833
    651834    /*@ buffetr ********************************************************* */
    652     char *curr_mountpoint;
    653     char *tmp;
     835    char *curr_mountpoint = NULL;
     836    char *tmp = NULL;
     837    char *tmp1 = NULL;
    654838
    655839    assert(mountlist != NULL);
    656840    assert(flaws_str != NULL);
     841
    657842    for (currline = 0; currline < mountlist->entries; currline++) {
    658843        asprintf(&curr_mountpoint, mountlist->el[currline].mountpoint);
     
    670855            asprintf(&tmp, " %s %s's.", number_to_text(copies),
    671856                     curr_mountpoint);
    672             strcat(flaws_str, tmp);
    673857            log_it(tmp);
     858            asprintf(&tmp1, "%s%s",flaws_str, tmp);
     859            paranoid_free(flaws_str);
     860            flaws_str = tmp1;
    674861            paranoid_free(tmp);
    675862            res++;
    676863        }
    677864        paranoid_free(curr_mountpoint);
    678     }
    679     return (res);
    680 }
    681 
    682 
    683 /**
    684  * Look for strange formats. Does not respect /proc/filesystems.
    685  * @param mountlist The mountlist to check.
    686  * @param flaws_str The flaws string to append the results to.
    687  * @return The number of weird formats found, or 0 for success.
    688  * @bug Seems orphaned; please remove.
    689  */
    690 int
    691 look_for_weird_formats(struct mountlist_itself *mountlist, char *flaws_str)
    692 {
    693 
    694     /*@ int ************************************************************* */
    695     int i = 0;
    696     int res = 0;
    697 
    698     /*@ buffers ********************************************************* */
    699     char *tmp;
    700     char *format_sz;
    701 
    702     assert(mountlist != NULL);
    703     assert(flaws_str != NULL);
    704 
    705     for (i = 0; i < mountlist->entries; i++) {
    706         asprintf(&format_sz, " %s ", mountlist->el[i].format);
    707         if (!strstr(SANE_FORMATS, format_sz)
    708             && strcmp(mountlist->el[i].mountpoint, "image") != 0) {
    709             asprintf(&tmp, " %s has unknown format.",
    710                      mountlist->el[i].device);
    711             log_it(tmp);
    712             strcat(flaws_str, tmp);
    713             paranoid_free(tmp);
    714             res++;
    715         } else if ((!strcmp(mountlist->el[i].format, "swap")
    716                     && strcmp(mountlist->el[i].mountpoint, "swap")
    717                     && strcmp(mountlist->el[i].mountpoint, "none"))
    718                    || (strcmp(mountlist->el[i].format, "swap")
    719                        && !strcmp(mountlist->el[i].mountpoint, "swap")
    720                        && !strcmp(mountlist->el[i].mountpoint, "none"))) {
    721             asprintf(&tmp, " %s is half-swap.", mountlist->el[i].device);
    722             log_it(tmp);
    723             strcat(flaws_str, tmp);
    724             paranoid_free(tmp);
    725             res++;
    726         }
    727         paranoid_free(format_sz);
    728865    }
    729866    return (res);
  • trunk/mondo/mondo/common/libmondo-mountlist.h

    r59 r688  
    44
    55
    6 int evaluate_drive_within_mountlist(struct mountlist_itself *mountlist,
    7                                     char *drive, char *flaws_str);
    86int evaluate_mountlist(struct mountlist_itself *mountlist,
    97                       char *flaws_str_A, char *flaws_str_B,
     
    1311int look_for_duplicate_mountpoints(struct mountlist_itself *mountlist,
    1412                                   char *flaws_str);
    15 int look_for_weird_formats(struct mountlist_itself *mountlist,
    16                            char *flaws_str);
    1713int make_list_of_drives_in_mountlist(struct mountlist_itself *,
    1814                                     struct list_of_disks *);
  • trunk/mondo/mondo/common/libmondo-raid.c

    r672 r688  
    774774{
    775775    int cnt = 0;
    776     static char *argv[64];
     776    char *argv[64];
    777777    char **ap;
    778     char *line = (char *) malloc(MAX_STR_LEN);
    779     if (!line)
    780         errx(1,
    781              "unable to allocate %i bytes of memory for `char *line' at %s:%i",
    782              MAX_STR_LEN, __FILE__, __LINE__);
    783     (void) fgets(line, MAX_STR_LEN, f);
     778    char *line = NULL;
     779    size_t = 0;
     780    int lastpos = 0;
     781
     782    getline(&line, &n, f);
    784783    if (feof(f)) {
    785784        log_it("[GNVCL] Uh... I reached the EOF.");
    786         return 0;
    787     }
    788 
    789     for (ap = argv; (*ap = strsep(&line, " \t")) != NULL;)
     785        return NULL;
     786    }
     787
     788    for (ap = argv; (*ap = mr_strtok(line, " \t", &lastpos)) != NULL;)
    790789        if (**ap != '\0') {
    791790            if (++ap >= &argv[64])
  • trunk/mondo/mondo/common/libmondo-stream.c

    r687 r688  
    99 * Functions for writing data to/reading data from streams (tape, CD stream, etc.)
    1010 */
     11
     12#include <unistd.h>
    1113
    1214#include "my-stuff.h"
     
    2325#define EXTRA_TAPE_CHECKSUMS
    2426
    25 /*@unused@*/
    26 //static char cvsid[] = "$Id$";
    2727extern bool g_sigpipe;
    2828extern int g_tape_buffer_size_MB;
     
    119119    }
    120120    sleep(1);
    121     paranoid_system("sync");
     121    sync();
    122122    sleep(1);
    123123    paranoid_pclose(g_tape_stream);
     
    152152
    153153    sleep(1);
    154     paranoid_system("sync");
     154    sync();
    155155    sleep(1);
    156156    log_it("closeout_tape() -- entering");
     
    213213int find_tape_device_and_size(char *dev, char *siz)
    214214{
    215     char *tmp;
    216     char *command;
    217     char *cdr_exe;
    218     int res;
     215    char *tmp = NULL;
     216    char *tmp1 = NULL;
     217    char *command = NULL;
     218    char *cdr_exe = NULL;
     219    int res = 0;
    219220
    220221    log_to_screen("I am looking for your tape streamer. Please wait.");
    221     dev[0] = '\0';
     222    dev = NULL;
    222223    siz = NULL;
    223224    if (find_home_of_exe("cdrecord")) {
     
    228229    asprintf(&command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l",
    229230             cdr_exe);
    230     asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     231    tmp = call_program_and_get_last_line_of_output(command);
    231232    paranoid_free(command);
    232233
     
    234235        log_it
    235236            ("Either too few or too many tape streamers for me to detect...");
    236         strcpy(dev, VANILLA_SCSI_TAPE);
     237        asprintf(&dev, VANILLA_SCSI_TAPE"0");
    237238        paranoid_free(tmp);
    238239        paranoid_free(cdr_exe);
     
    244245             "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f2 | head -n1",
    245246             cdr_exe);
    246     asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     247    tmp = call_program_and_get_last_line_of_output(command);
    247248    paranoid_free(command);
    248249    if (strlen(tmp) < 2) {
     
    259260    paranoid_free(cdr_exe);
    260261
    261     asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     262    tmp = call_program_and_get_last_line_of_output(command);
    262263    paranoid_free(command);
    263     strcpy(dev, VANILLA_SCSI_TAPE);
    264     dev[strlen(dev) - 1] = '\0';
    265     strcat(dev, tmp);           // e.g. '/dev/st0' becomes '/dev/stN'
     264
     265    asprintf(&dev, VANILLA_SCSI_TAPE"%s", tmp);
    266266    paranoid_free(tmp);
    267267
    268     res = 0;
    269268    if (!mt_says_tape_exists(dev)) {
    270         strcpy(dev, ALT_TAPE);
     269        paranoid_free(dev);
     270
     271        asprintf(&dev, ALT_TAPE"%s", tmp);
    271272        if (!mt_says_tape_exists(dev)) {
    272273            log_it("Cannot openin %s", dev);
    273             strcpy(dev, "/dev/st0");
     274            paranoid_free(dev);
     275
     276            asprintf(&dev, VANILLA_SCSI_TAPE"0");
    274277            if (!mt_says_tape_exists(dev)) {
    275278                log_it("Cannot openin %s", dev);
    276                 strcpy(dev, "/dev/osst0");
     279                paranoid_free(dev);
     280
     281                asprintf(&dev, "/dev/osst0");
    277282                if (!mt_says_tape_exists(dev)) {
    278283                    res++;
     
    286291    log_it("At this point, dev = %s and res = %d", dev, res);
    287292
    288     asprintf(&tmp, call_program_and_get_last_line_of_output("\
     293    tmp = call_program_and_get_last_line_of_output("\
    289294cdrecord -scanbus 2> /dev/null | tr -s '\t' ' ' | \
    290295grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | \
    291 awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'"));
     296awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'");
    292297
    293298    if (mt_says_tape_exists(dev)) {
     
    296301        log_it("Turning %s", dev);
    297302        paranoid_free(tmp);
    298         asprintf(&tmp,
     303        asprintf(&tmp1,
    299304                 (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev);
    300         sprintf(dev, "/dev/os%s", tmp);
     305        paranoid_free(dev);
     306        asprintf(&dev, "/dev/os%s", tmp1);
     307        paranoid_free(tmp1);
     308
    301309        log_it("...into %s", dev);
    302310        if (mt_says_tape_exists(dev)) {
     
    12281236
    12291237    paranoid_pclose(g_tape_stream);
    1230     system("sync");
    1231     system("sync");
    1232     system("sync");
     1238    sync();
     1239    sync();
     1240    sync();
    12331241    log_it("Next tape requested.");
    12341242    insist_on_this_tape_number(g_current_media_number + 1); // will increment it, too
     
    12691277
    12701278    paranoid_pclose(g_tape_stream);
    1271     system("sync");
    1272     system("sync");
    1273     system("sync");
     1279    sync();
     1280    sync();
     1281    sync();
    12741282    log_it("New tape requested.");
    12751283    insist_on_this_tape_number(g_current_media_number + 1); // will increment g_current_media, too
  • trunk/mondo/mondo/common/libmondo-string.c

    r672 r688  
    3333 * @note If @p drive ends in a digit, then 'p' (on Linux) or 's' (on *BSD) is added before @p partno.
    3434 */
    35 char *build_partition_name(char *partition, const char *drive, int partno)
     35char *build_partition_name(const char *drive, int partno)
    3636{
    3737    char *p, *c;
    38 
    39     assert(partition != NULL);
     38    char *partition;
     39
    4040    assert_string_is_neither_NULL_nor_zerolength(drive);
    4141    assert(partno >= 0);
     
    537537
    538538    /*@ buffers **************************************************** */
    539     char *output;
    540     char *suffix;
     539    char *output = NULL;
     540    char *suffix = NULL;
    541541
    542542    /*@ end vars *************************************************** */
    543543
    544544    assert_string_is_neither_NULL_nor_zerolength(path);
    545     if (s[0] != '\0') {
     545
     546    if (s != NULL) {
    546547        asprintf(&suffix, ".%s", s);
    547548    } else {
    548         asprintf(&suffix, "%s", " ");
     549        asprintf(&suffix, "%s", "");
    549550    }
    550551    asprintf(&output, "%s/slice-%07ld.%05ld.dat%s", path, bigfileno,
  • 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);
  • trunk/mondo/mondo/common/libmondo-verify.c

    r507 r688  
    55 * Functions for verifying backups (booted from hard drive, not CD).
    66 */
     7
     8#include <unistd.h>
    79
    810#include "my-stuff.h"
     
    5961
    6062    asprintf(&afio_found_changes, "%s.afio", ignorefiles_fname);
    61     paranoid_system("sync");
     63    sync();
    6264
    6365/*  sprintf (command,
     
    193195{
    194196
    195     /*@ buffer ********************************************************** */
    196     char *tmp;
    197     char *mountpoint;
    198 //  char ca, cb;
    199     char *command;
    200     char *sz_exe;
     197    char *tmp = NULL;
     198    char *tmp1 = NULL;
     199    char *tmp2 = NULL;
     200    char *mountpoint = NULL;
     201    char *command = NULL;
     202    char *sz_exe = NULL;
    201203    static char *bufblkA = NULL;
    202204    static char *bufblkB = NULL;
    203205    const long maxbufsize = 65536L;
    204     long currsizA = 0;
    205     long currsizB = 0;
    206     long j;
    207 
    208     /*@ long ************************************************************ */
    209     long bigfile_num = 0;
     206    long currsizA = 0L;
     207    long currsizB = 0L;
     208    long j = 0L;
     209    long bigfile_num = 0L;
    210210    long slice_num = -1;
    211     int res;
     211    int res = 0;
    212212
    213213    static FILE *forig = NULL;
     
    215215    static long last_bigfile_num = -1;
    216216    static long last_slice_num = -1;
    217     FILE *pin;
    218     FILE *fin;
     217    FILE *pin = NULL;
     218    FILE *fin = NULL;
    219219    int retval = 0;
    220 //  long long outlen;
    221 
    222     malloc_string(sz_exe);
     220
    223221    if (!bufblkA) {
    224222        if (!(bufblkA = malloc(maxbufsize))) {
     
    251249    open_evalcall_form(tmp);
    252250    paranoid_free(tmp);
     251
    253252    iamhere("after vsbf");
    254253    asprintf(&mountpoint, "%s/archives", mtpt);
     
    263262        slice_num = last_slice_num + 1;
    264263    }
    265     while (does_file_exist
    266            (slice_fname
    267             (bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix))
    268            ||
    269            does_file_exist(slice_fname
    270                            (bigfile_num, slice_num, mountpoint, ""))) {
    271 // handle slices until end of CD
     264
     265    tmp = slice_fname(bigfile_num, slice_num, mountpoint, bkpinfo->zip_suffix);
     266    tmp1 = slice_fname(bigfile_num, slice_num, mountpoint, "");
     267    while (does_file_exist(tmp) || does_file_exist(tmp1)) {
     268        // handle slices until end of CD
    272269        if (slice_num == 0) {
    273270            log_msg(2, "ISO=%d  bigfile=%ld --START--",
    274271                    g_current_media_number, bigfile_num);
    275             if (!
    276                 (fin =
    277                  fopen(slice_fname(bigfile_num, slice_num, mountpoint, ""),
    278                        "r"))) {
     272            if (!(fin = fopen(tmp1,"r"))) {
    279273                log_msg(2, "Cannot open bigfile's info file");
    280274            } else {
     
    286280                paranoid_fclose(fin);
    287281            }
    288             asprintf(&tmp, "%s/%s", bkpinfo->restore_path,
     282            asprintf(&tmp2, "%s/%s", bkpinfo->restore_path,
    289283                     biggiestruct.filename);
    290             log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp);
    291             if (!(forig = fopen(tmp, "r"))) {
     284            log_msg(2, "Opening biggiefile #%ld - '%s'", bigfile_num, tmp2);
     285            if (!(forig = fopen(tmp2, "r"))) {
    292286                log_msg(2, "Failed to open bigfile. Darn.");
    293287                retval++;
    294288            }
    295             paranoid_free(tmp);
     289            paranoid_free(tmp2);
    296290
    297291            slice_num++;
    298         } else if (does_file_exist
    299                    (slice_fname(bigfile_num, slice_num, mountpoint, ""))) {
     292        } else if (does_file_exist(tmp1)) {
    300293            log_msg(2, "ISO=%d  bigfile=%ld ---END---",
    301294                    g_current_media_number, bigfile_num);
     
    307300                    g_current_media_number, bigfile_num, slice_num);
    308301            if (bkpinfo->compression_level > 0) {
    309                 asprintf(&command, "%s -dc %s 2>> %s", sz_exe,
    310                          slice_fname(bigfile_num, slice_num, mountpoint,
    311                                      bkpinfo->zip_suffix),
    312                          MONDO_LOGFILE);
     302                asprintf(&command, "%s -dc %s 2>> %s", sz_exe, tmp, MONDO_LOGFILE);
    313303            } else {
    314                 asprintf(&command, "cat %s",
    315                          slice_fname(bigfile_num, slice_num, mountpoint,
    316                                      bkpinfo->zip_suffix));
     304                asprintf(&command, "cat %s", tmp);
    317305            }
    318306            if ((pin = popen(command, "r"))) {
     
    356344        }
    357345    }
     346    paranoid_free(tmp);
     347    paranoid_free(tmp1);
    358348    paranoid_free(mountpoint);
    359349    paranoid_free(sz_exe);
     
    10721062
    10731063    /* find the final blocks */
    1074     paranoid_system("sync");
     1064    sync();
    10751065    sleep(2);
    10761066    closein_tape(bkpinfo);
  • trunk/mondo/mondo/common/libmondo-verify.h

    r687 r688  
    4242extern int openin_tape(struct s_bkpinfo *);
    4343extern void popup_and_OK(char *);
    44 extern bool popup_and_get_string(char *, char *, char *, int);
     44extern bool popup_and_get_string(char *, char *, char *);
    4545extern int read_file_from_tape_to_file(struct s_bkpinfo *, char *,
    4646                                       long long);
     
    8383extern long g_start_time, g_minimum_progress, g_maximum_progress,
    8484    g_current_progress, g_currentY;
    85 extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN];
    8685extern int g_current_media_number;
    8786
  • trunk/mondo/mondo/common/my-stuff.h

    r687 r688  
    145145
    146146#define SCREEN_LENGTH 25        ///< The default size of the screen.
    147 #define NOOF_ERR_LINES 6        ///< The number of lines of log output to keep at the bottom of the screen.
    148147#define ARBITRARY_MAXIMUM 2000  ///< The maximum number of items showing at once in the mountlist or filelist editor.
    149148#define MAX_TAPECATALOG_ENTRIES 8192    ///< The maximum number of entries in the tape catalog.
     
    335334
    336335/** @def VANILLA_SCSI_CDROM The first SCSI CD-ROM in the system (most likely to be the one to write to). */
    337 /** @def VANILLA_SCSI_TAPE  The first SCSI tape in the system (most likely to be the one towrite to. */
     336/** @def VANILLA_SCSI_TAPE  The SCSI tape radical on the system (most likely to be the one towrite to. */
    338337/** @def DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE A string whose presence in a device name indicates the
    339338 * inability to check this device for errors in the mountlist. */
     
    345344#ifdef __FreeBSD__
    346345#define VANILLA_SCSI_CDROM  "/dev/cd0"
    347 #define VANILLA_SCSI_TAPE   "/dev/sa0"
     346#define VANILLA_SCSI_TAPE   "/dev/sa"
    348347#define DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE  "/dev/vinum/"
    349348#define RAID_DEVICE_STUB    DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE
    350349#define SANE_FORMATS        "swap image msdosfs nfs ntfs raid lvm ffs ufs ext2fs"
    351 #define ALT_TAPE        "/dev/ast0"
     350#define ALT_TAPE        "/dev/ast"
    352351#define MKE2FS_OR_NEWFS "newfs"
    353352#define CP_BIN      "gcp"
    354353#else
    355354#define VANILLA_SCSI_CDROM  "/dev/scd0"
    356 #define VANILLA_SCSI_TAPE   "/dev/st0"
     355#define VANILLA_SCSI_TAPE   "/dev/st"
    357356#define DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE  "/dev/md"
    358357#define RAID_DEVICE_STUB    DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE
    359358#define SANE_FORMATS        "swap image vfat ext2 ext3 xfs vfs jfs reiserfs dos minix coda nfs ntfs hpfs raid lvm cifs"
    360 #define ALT_TAPE        "/dev/ht0"
     359#define ALT_TAPE        "/dev/ht"
    361360#define MKE2FS_OR_NEWFS "mke2fs"
    362361#define CP_BIN      "cp"
  • trunk/mondo/mondo/common/newt-specific-EXT.h

    r59 r688  
    1515extern void log_to_screen(const char *fmt, ...);
    1616extern void popup_and_OK(char *prompt);
    17 extern bool popup_and_get_string(char *title, char *b, char *output,
    18                                  int maxsize);
     17extern bool popup_and_get_string(char *title, char *b, char *output);
    1918extern bool popup_with_buttons(char *p, char *button1, char *button2);
    2019extern void refresh_log_screen();
  • trunk/mondo/mondo/common/newt-specific.c

    r588 r688  
    1313#define MAX_NEWT_COMMENT_LEN 200
    1414
    15 #if __cplusplus
    16 extern "C" {
    17 #endif
     15#include <unistd.h>
    1816
    1917#include "my-stuff.h"
     
    111109        if (g_text_mode) {
    112110            while (1) {
    113                 system("sync");
     111                sync();
    114112                printf
    115113                    ("---promptdialogYN---1--- %s\r\n---promptdialogYN---Q--- [yes] [no] ---\r\n--> ",
     
    130128                    return (FALSE);
    131129                } else {
    132                     system("sync");
     130                    sync();
    133131                    printf
    134132                        (_("Please enter either YES or NO (or yes or no, or y or n, or...)\n"));
     
    156154        assert_string_is_neither_NULL_nor_zerolength(prompt);
    157155        if (g_text_mode) {
    158             system("sync");
     156            sync();
    159157            printf
    160158                ("---promptdialogOKC---1--- %s\r\n---promptdialogOKC---Q--- [OK] [Cancel] ---\r\n--> ",
     
    279277        paranoid_system("killall mindi 2> /dev/null");
    280278        kill_anything_like_this("/mondo/do-not");
    281         kill_anything_like_this("tmp.mondo");
     279        kill_anything_like_this("mondo.tmp");
    282280        kill_anything_like_this("ntfsclone");
    283281        sync();
     
    291289        paranoid_free(tmp);
    292290
    293         if (g_erase_tmpdir_and_scratchdir[0]) {
     291        if (g_erase_tmpdir_and_scratchdir) {
    294292            run_program_and_log_output(g_erase_tmpdir_and_scratchdir, 5);
    295293        }
     
    339337    void
    340338     finish(int signal) {
    341         char *command;
    342         malloc_string(command);
     339        char *command = NULL;
    343340
    344341        /*  if (signal==0) { popup_and_OK("Please press <enter> to quit."); } */
     
    349346        chdir("/");
    350347        run_program_and_log_output("umount " MNT_CDROM, FALSE);
    351         run_program_and_log_output("rm -Rf /mondo.scratch.* /tmp.mondo.*",
     348        run_program_and_log_output("rm -Rf /mondo.scratch.* /mondo.tmp.*",
    352349                                   FALSE);
    353350        if (g_erase_tmpdir_and_scratchdir) {
     
    394391
    395392        /*@ buffers ********************************************************** */
    396         char *command;
    397         char *tmp;
     393        char *command = NULL;
     394        char *tmp = NULL;
    398395
    399396        /*@ pointers ********************************************************* */
    400         FILE *fin;
     397        FILE *fin = NULL;
    401398
    402399        /*@ int ************************************************************** */
    403400        int i = 0;
     401        size_t n = 0;
    404402
    405403        assert_string_is_neither_NULL_nor_zerolength(filename);
     
    420418        } else {
    421419            for (i = 0; i < g_noof_log_lines; i++) {
    422                 for (err_log_lines[i][0] = '\0';
    423                      strlen(err_log_lines[i]) < 2 && !feof(fin);) {
    424                     (void) fgets(err_log_lines[i], MAX_NEWT_COMMENT_LEN,
    425                                  fin);
     420                for (;
     421                    strlen(err_log_lines[i]) < 2 && !feof(fin);) {
     422                    getline(&(err_log_lines[i]), &n, fin);
    426423                    strip_spaces(err_log_lines[i]);
    427424                    if (!strncmp(err_log_lines[i], "root:", 5)) {
    428425                        asprintf(&tmp, "%s", err_log_lines[i] + 6);
    429                         strcpy(err_log_lines[i], tmp);
    430                         paranoid_free(tmp);
     426                        paranoid_free(err_log_lines[i]);
     427                        err_log_lines[i] = tmp;
    431428                    }
    432429                    if (feof(fin)) {
     
    456453
    457454        /*@ buffers ********************************************************** */
    458         char *output;
     455        char *output = NULL;
    459456
    460457
     
    472469
    473470        if (err_log_lines) {
     471            paranoid_free(&err_log_lines[0]);
    474472            for (i = 1; i < g_noof_log_lines; i++) {
    475                 strcpy(err_log_lines[i - 1],
    476                        "                                                                                ");
    477                 strcpy(err_log_lines[i - 1], err_log_lines[i]);
     473                err_log_lines[i - 1] = err_log_lines[i];
    478474            }
    479475        }
     
    487483        }
    488484        if (err_log_lines)
    489             strcpy(err_log_lines[g_noof_log_lines - 1], output);
     485            err_log_lines[g_noof_log_lines - 1] = output;
    490486        if (g_text_mode) {
    491487            printf("%s\n", output);
     
    493489            refresh_log_screen();
    494490        }
    495         paranoid_free(output);
    496     }
    497 
    498 
     491    }
    499492
    500493
     
    670663 * @param b The blurb (e.g. what you want the user to enter).
    671664 * @param output The string to put the user's answer in. It has to be freed by the caller
    672  * @param maxsize The size in bytes allocated to @p output.
    673665 * @return TRUE if the user pressed OK, FALSE if they pressed Cancel.
    674666 */
    675     bool popup_and_get_string(char *title, char *b, char *output,
    676                               int maxsize) {
     667    bool popup_and_get_string(char *title, char *b, char *output) {
    677668
    678669        /*@ newt ************************************************************ */
     
    685676
    686677        /*@ pointers ********************************************************* */
    687         char *entry_value;
     678        char *entry_value = NULL;
    688679
    689680        /*@ buffers ********************************************************** */
    690         char *blurb;
    691         char *original_contents;
     681        char *blurb = NULL;
    692682        size_t n = 0;
     683        bool ret = TRUE;
    693684
    694685        assert_string_is_neither_NULL_nor_zerolength(title);
     
    699690                ("---promptstring---1--- %s\r\n---promptstring---2--- %s\r\n---promptstring---Q---\r\n-->  ",
    700691                 title, b);
     692            paranoid_free(output);
    701693            (void) getline(&output, &n, stdin);
    702694            if (output[strlen(output) - 1] == '\n')
    703695                output[strlen(output) - 1] = '\0';
    704             return (TRUE);
     696            return (ret);
    705697        }
    706698        asprintf(&blurb, b);
    707699        text = newtTextboxReflowed(2, 1, blurb, 48, 5, 5, 0);
    708         original_contents = output;
    709700
    710701        type_here =
    711702            newtEntry(2, newtTextboxGetNumLines(text) + 2,
    712                       original_contents, 50,
    713 #ifdef __cplusplus
    714                       0, NEWT_FLAG_RETURNEXIT
    715 #else
    716                       (void *) &entry_value, NEWT_FLAG_RETURNEXIT
    717 #endif
     703                      output, 50,
     704                      &entry_value, NEWT_FLAG_RETURNEXIT
    718705            );
    719706        b_1 = newtButton(6, newtTextboxGetNumLines(text) + 4, _("  OK  "));
    720707        b_2 = newtButton(18, newtTextboxGetNumLines(text) + 4, _("Cancel"));
    721         //  newtOpenWindow (8, 5, 54, newtTextboxGetNumLines (text) + 9, title);
    722708        newtCenteredWindow(54, newtTextboxGetNumLines(text) + 9, title);
    723709        myForm = newtForm(NULL, NULL, 0);
     
    727713        newtPushHelpLine(blurb);
    728714        paranoid_free(blurb);
     715
    729716        b_res = newtRunForm(myForm);
    730         output = entry_value;
    731717        newtPopHelpLine();
     718        if (b_res == b_2) {
     719            ret = FALSE;
     720        } else {
     721            // Copy entry_value before destroying the form
     722            // clearing potentially output before
     723            paranoid_alloc(output,entry_value);
     724        }
    732725        newtFormDestroy(myForm);
    733726        newtPopWindow();
    734         if (b_res == b_2) {
    735             paranoid_free(output);
    736             output = original_contents;
    737             paranoid_free(original_contents);
    738             return (FALSE);
    739         } else {
    740             paranoid_free(original_contents);
    741             return (TRUE);
    742         }
     727        return(ret);
    743728    }
    744729
     
    846831        newtRefresh();
    847832        for (i = g_noof_log_lines - 1; i >= 0; i--) {
    848             err_log_lines[i][79] = '\0';
     833            //BERLIOS : removed for now, Think it's useless : err_log_lines[i][79] = '\0';
    849834            newtDrawRootText(0, i + g_noof_rows - 1 - g_noof_log_lines,
    850835                             err_log_lines[i]);
     
    884869
    885870        for (i = 0; i < g_noof_log_lines; i++) {
    886             err_log_lines[i] = (char *) malloc(MAX_NEWT_COMMENT_LEN);
    887             if (!err_log_lines[i]) {
    888                 fatal_error("Out of memory");
    889             }
    890         }
    891 
    892         for (i = 0; i < g_noof_log_lines; i++) {
    893             err_log_lines[i][0] = '\0';
     871            err_log_lines[i] = NULL;
    894872        }
    895873    }
     
    15751553
    15761554
    1577 #if __cplusplus
    1578 }                               /* extern "C" */
    1579 #endif
    1580 
    1581 
    15821555void wait_until_software_raids_are_prepped(char *mdstat_file,
    15831556                                           int wait_for_percentage);
  • trunk/mondo/mondo/common/newt-specific.h

    r59 r688  
    2121                        long max_val);
    2222void popup_and_OK(char *prompt);
    23 bool popup_and_get_string(char *title, char *b, char *output, int maxsize);
     23bool popup_and_get_string(char *title, char *b, char *output);
    2424bool popup_with_buttons(char *p, char *button1, char *button2);
    2525void refresh_log_screen();
Note: See TracChangeset for help on using the changeset viewer.