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

r3336@localhost: bruno | 2009-08-11 16:32:36 +0200

  • bkpinfo->media_device, bkpinfo->nfs_remote_dir, and bkpinfo->nfs_mount are now dynamically allocated
  • new interfaces for find_cdrom_device(), find_tape_device_and_size(), find_dvd_device(), find_cdrw_device(), set_dev_to_this_if_rx_OK() and read_cfg_var() which allocate the string now returned
  • Better differentiation between ISO and NFS iso file names construction
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.10/mondo/src/common/libmondo-tools.c

    r2324 r2325  
    419419    char *p = NULL;
    420420    char call_before_iso_user[MAX_STR_LEN] = "\0";
    421     /*
    422     long avm = 0;
    423     int rdsiz_MB;
    424     */
    425421    char *iso_dev = NULL;
    426422    char *iso_mnt = NULL;
     
    449445    if (bkpinfo->backup_media_type == tape) {
    450446        log_msg(1, "Bar");
     447        if (bkpinfo->media_device == NULL) {
     448            return(1);
     449        }
    451450        mr_asprintf(tmp, "mt -f %s status", bkpinfo->media_device);
    452451        log_msg(1, "tmp = '%s'", tmp);
     
    526525            // -m isn't supported by growisofs, BTW...
    527526        } else {
     527            if (bkpinfo->media_device == NULL) {
     528                return(1);
     529            }
    528530            sprintf(bkpinfo->call_make_iso,
    529531                    "%s %s -Z %s . 2>> _ERR_",
     
    594596            }
    595597            log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso);
     598            if (bkpinfo->media_device == NULL) {
     599                return(1);
     600            }
    596601            sprintf(bkpinfo->call_make_iso,
    597602                    "%s %s -v %s fs=4m dev=%s speed=%d %s/"MONDO_TMPISOS,
     
    667672
    668673    if (bkpinfo->backup_media_type == nfs) {
    669         strcpy(hostname, bkpinfo->nfs_mount);
     674        if (bkpinfo->nfs_mount) {
     675            strcpy(hostname, bkpinfo->nfs_mount);
     676        } else {
     677            log_it("nfs_mount is NULL");
     678            retval++;
     679            strcpy(hostname, "");
     680        }
    670681        colon = strchr(hostname, ':');
    671682        if (!colon) {
     
    678689            hent = gethostbyname(hostname);
    679690            if (!hent) {
    680                 log_it("Can't resolve NFS mount (%s): %s", hostname,
    681                        hstrerror(h_errno));
     691                log_it("Can't resolve NFS mount (%s): %s", hostname, hstrerror(h_errno));
    682692                retval++;
    683693            } else {
    684694                mr_asprintf(ip_address, "%s", inet_ntoa((struct in_addr) *((struct in_addr *) hent->h_addr)));
    685695                mr_strcat(ip_address, strchr(bkpinfo->nfs_mount, ':'));
    686                 strcpy(bkpinfo->nfs_mount, ip_address);
    687                 paranoid_free(ip_address);
     696                mr_free(bkpinfo->nfs_mount);
     697                bkpinfo->nfs_mount = ip_address;
    688698            }
    689699        }
     
    746756    }
    747757    g_current_media_number = 1;
    748     bkpinfo->postnuke_tarball[0] = bkpinfo->nfs_mount[0] = '\0';
     758    bkpinfo->postnuke_tarball[0] = '\0';
    749759    return (res);
    750760}
     
    787797void mr_free_bkpinfo() {
    788798
     799    mr_free(bkpinfo->media_device);
     800    mr_free(bkpinfo->isodir);
     801    mr_free(bkpinfo->prefix);
    789802    mr_free(bkpinfo->scratchdir);
    790803    mr_free(bkpinfo->tmpdir);
    791804    mr_free(bkpinfo->include_paths);
    792805    mr_free(bkpinfo->exclude_paths);
     806    mr_free(bkpinfo->nfs_mount);
     807    mr_free(bkpinfo->nfs_remote_dir);
    793808    mr_free(bkpinfo->nfs_user);
    794809
     
    804819{
    805820    int i;
    806     char *p = NULL;
    807 
    808821    log_msg(1, "Hi");
    809822
    810823    /* Initialized in same order as in the structure declaration to detect errors more easily */
    811     bkpinfo->media_device[0] = '\0';
     824    bkpinfo->media_device = NULL;
    812825    for (i = 0; i <= MAX_NOOF_MEDIA; i++) {
    813826        bkpinfo->media_size[i] = -1;
     
    846859    bkpinfo->call_after_iso[0] = '\0';
    847860    bkpinfo->kernel_path[0] = '\0';
    848     bkpinfo->nfs_mount[0] = '\0';
    849     bkpinfo->nfs_remote_dir[0] = '\0';
     861    bkpinfo->nfs_mount = NULL;
     862    bkpinfo->nfs_remote_dir = NULL;
    850863    bkpinfo->nfs_user = NULL;
    851864    bkpinfo->postnuke_tarball[0] = '\0';
     
    10721085 * @return 0 for success, 1 for failure.
    10731086 */
    1074 int read_cfg_var(char *config_file, char *label, char *value)
     1087char *read_cfg_var(char *config_file, char *label)
    10751088{
    10761089    /*@ buffer ****************************************************** */
    10771090    char *command = NULL;
     1091    char *value = NULL;
    10781092
    10791093    /*@ end vars *************************************************** */
     
    10831097    if (!does_file_exist(config_file)) {
    10841098        log_to_screen("(read_cfg_var) Cannot find %s config file", config_file);
    1085         value[0] = '\0';
    1086         return (1);
     1099        return (NULL);
     1100        /* BERLIOS: not sure the sage of this one ?
    10871101    } else if ((value != NULL) && (strstr(value, "/dev/") && strstr(value, "t0") && !strcmp(label, "media-dev"))) {
    10881102        log_msg(2, "FYI, I can't read new value for %s - already got %s", label, value);
    10891103        return (0);
     1104        */
    10901105    } else {
    10911106        mr_asprintf(command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5", label, config_file);
    1092         strcpy(value, call_program_and_get_last_line_of_output(command));
     1107        mr_asprintf(value, "%s", call_program_and_get_last_line_of_output(command));
    10931108        mr_free(command);
    10941109
    10951110        if (strlen(value) == 0) {
    1096             return (1);
     1111            return (NULL);
    10971112        } else {
    1098             return (0);
     1113            return (value);
    10991114        }
    11001115    }
Note: See TracChangeset for help on using the changeset viewer.