Changeset 146 in MondoRescue for trunk/mondo/mondo/mondoarchive/mondo-cli.c


Ignore:
Timestamp:
Dec 1, 2005, 10:00:14 AM (18 years ago)
Author:
bcornec
Message:

MONDO_LOGFILE used each time now
memory management on libmondo-devices.c
some splint improvements

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/mondoarchive/mondo-cli.c

    r142 r146  
    367367
    368368    long itbs;
    369 
    370     malloc_string(tmp);
    371     malloc_string(psz);
    372369
    373370    assert(bkpinfo != NULL);
     
    532529        }
    533530        flag_set['d'] = TRUE;
    534         sprintf(tmp,
     531        paranoid_free(tmp); // allocation from find_tape_device_and_size
     532
     533        asprintf(&tmp,
    535534                "You didn't specify a tape streamer device. I'm assuming %s",
    536535                flag_val['d']);
    537536        log_to_screen(tmp);
     537        paranoid_free(tmp);
    538538        percent = 0;
    539539    }
     
    616616            strncpy(bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN);
    617617        }
    618         sprintf(tmp, "mount | grep -x \"%s .*\" | cut -d' ' -f3",
     618        asprintf(&tmp, "mount | grep -x \"%s .*\" | cut -d' ' -f3",
    619619                bkpinfo->nfs_mount);
    620620        strncpy(bkpinfo->isodir,
    621621                call_program_and_get_last_line_of_output(tmp),
    622622                MAX_STR_LEN / 4);
     623        paranoid_free(tmp);
     624
    623625        if (strlen(bkpinfo->isodir) < 3) {
    624626            retval++;
     
    670672    if (flag_set['N'])          // exclude NFS mounts & devices
    671673    {
    672 //      strncpy(psz, list_of_NFS_devices_and_mounts(), MAX_STR_LEN);
    673         strncpy(psz, list_of_NFS_mounts_only(), MAX_STR_LEN);
     674        psz = list_of_NFS_mounts_only();
    674675        if (bkpinfo->exclude_paths[0]) {
    675676            strncat(bkpinfo->exclude_paths, " ", MAX_STR_LEN);
    676677        }
    677678        strncat(bkpinfo->exclude_paths, psz, MAX_STR_LEN);
     679        paranoid_free(psz);
     680
    678681        log_msg(3, "-N means we're now excluding %s",
    679682                bkpinfo->exclude_paths);
     
    684687    }
    685688    if (flag_set['b']) {
    686         strcpy(psz, flag_val['b']);
     689        asprintf(&psz, flag_val['b']);
    687690        log_msg(1, "psz = '%s'", psz);
    688691        if (psz[strlen(psz) - 1] == 'k') {
     
    692695            itbs = atol(psz);
    693696        }
     697        paranoid_free(psz);
     698
    694699        log_msg(1, "'%s' --> %ld", flag_val['b'], itbs);
    695700        log_msg(1, "Internal tape block size is now %ld bytes", itbs);
     
    725730            && !does_file_exist(bkpinfo->kernel_path)) {
    726731            retval++;
    727             sprintf(tmp,
     732            asprintf(&tmp,
    728733                    "You specified kernel '%s', which does not exist\n",
    729734                    bkpinfo->kernel_path);
    730735            log_to_screen(tmp);
     736            paranoid_free(tmp);
    731737        }
    732738    }
     
    739745        if (flag_set['i']) {
    740746            strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4);
    741             sprintf(tmp, "ls -l %s", bkpinfo->isodir);
     747            asprintf(&tmp, "ls -l %s", bkpinfo->isodir);
    742748            if (run_program_and_log_output(tmp, FALSE)) {
    743749                fatal_error
    744750                    ("output folder does not exist - please create it");
    745751            }
     752            paranoid_free(tmp);
    746753        } else if (flag_set['n']) {
    747754            strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN);
     
    753760
    754761    if (flag_set['n']) {
    755         sprintf(tmp, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir,
     762        asprintf(&tmp, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir,
    756763                bkpinfo->nfs_remote_dir);
    757764        if (run_program_and_log_output(tmp, FALSE)) {
    758765            retval++;
    759             sprintf(tmp,
     766            paranoid_free(tmp);
     767            asprintf(&tmp,
    760768                    "Are you sure directory '%s' exists in remote dir '%s'?\nIf so, do you have rights to write to it?\n",
    761769                    bkpinfo->nfs_remote_dir, bkpinfo->nfs_mount);
    762770            log_to_screen(tmp);
    763771        }
     772        paranoid_free(tmp);
    764773    }
    765774
     
    802811        sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%ld", flag_val['T'],
    803812                random() % 32768);
    804         sprintf(tmp, "touch %s/.foo.dat", flag_val['T']);
     813        asprintf(&tmp, "touch %s/.foo.dat", flag_val['T']);
    805814        if (run_program_and_log_output(tmp, 1)) {
    806815            retval++;
     
    809818            fatal_error("I cannot write to the tempdir you specified.");
    810819        }
    811         sprintf(tmp, "ln -sf %s/.foo.dat %s/.bar.dat", flag_val['T'],
     820        paranoid_free(tmp);
     821
     822        asprintf(&tmp, "ln -sf %s/.foo.dat %s/.bar.dat", flag_val['T'],
    812823                flag_val['T']);
    813824        if (run_program_and_log_output(tmp, 1)) {
     
    817828            fatal_error("I cannot write to the tempdir you specified.");
    818829        }
     830        paranoid_free(tmp);
    819831    }
    820832    if (flag_set['A']) {
     
    851863    }
    852864    if (flag_set['f']) {
    853         strncpy(bkpinfo->boot_device,
    854                 resolve_softlinks_to_get_to_actual_device_file(flag_val
    855                                                                ['f']),
     865        tmp = resolve_softlinks_to_get_to_actual_device_file(flag_val['f']);
     866        strncpy(bkpinfo->boot_device, tmp,
    856867                MAX_STR_LEN / 4);
    857868    }
    858     if (flag_set['P']) {
    859         strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN);
    860     }
    861869    if (flag_set['Q']) {
     870        if (tmp == NULL) {
     871            printf("-f option required when using -Q\n");
     872            finish(-1);
     873        }
    862874        i = which_boot_loader(tmp);
    863875        log_msg(3, "boot loader is %c, residing at %s", i, tmp);
    864876        printf("boot loader is %c, residing at %s\n", i, tmp);
    865877        finish(0);
     878    }
     879    paranoid_free(tmp);
     880
     881    if (flag_set['P']) {
     882        strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN);
    866883    }
    867884    if (flag_set['L']) {
     
    928945/* and finally... */
    929946
    930     paranoid_free(tmp);
    931     paranoid_free(psz);
    932947    return (retval);
    933948}
Note: See TracChangeset for help on using the changeset viewer.