Ignore:
Timestamp:
Aug 18, 2009, 2:37:39 PM (15 years ago)
Author:
Bruno Cornec
Message:

r3331@localhost: bruno | 2009-08-06 01:34:32 +0200

  • bkpinfo->scratchdir is now dynamically allocated
  • mondoarchive tests made in text+newt env. Seems OK. Valgrind errors to be fixed
File:
1 edited

Legend:

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

    r2319 r2320  
    5656static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list);
    5757static int create_list_of_non_NFS_mounted_file_systems (void);
    58 static MOUNTED_FS_STRUCT *find_mount_point_in_list (char *mount_point);
    59 static MOUNTED_FS_STRUCT *find_device_in_list (char *device);
     58static MOUNTED_FS_STRUCT *find_mount_point_in_list (const char *mount_point);
     59static MOUNTED_FS_STRUCT *find_device_in_list (const char *device);
    6060
    6161/* Do we use extended attributes and acl ?
     
    124124    mr_free(tmp);
    125125
    126     sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir),
    127             "/mondo.scratch.%ld", random() % 32767);
     126    mr_strcat(bkpinfo->scratchdir, "/mondo.scratch.%ld", random() % 32767);
     127
    128128    mr_asprintf(&tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
    129129    paranoid_system(tmp);
     
    168168        bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p);
    169169    }
    170 //      bkpinfo->media_size[0] = bkpinfo->media_size[MAX_NOOF_MEDIA];
    171170    for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
    172171        if (bkpinfo->media_size[j] <= 0) {
     
    189188    while (DSFptr != NULL) {
    190189        DSFnext = DSFptr->next;
    191         paranoid_free(DSFptr);
     190        mr_free(DSFptr);
    192191        DSFptr = DSFnext;
    193192    }
     
    221220 * structure if it did.
    222221 */
    223 static MOUNTED_FS_STRUCT *find_device_in_list (char *device)
     222static MOUNTED_FS_STRUCT *find_device_in_list (const char *device)
    224223{
    225224    MOUNTED_FS_STRUCT *DSFptr = NULL;
     
    242241 * structure if it did.
    243242 */
    244 static MOUNTED_FS_STRUCT *find_mount_point_in_list (char *mount_point)
     243static MOUNTED_FS_STRUCT *find_mount_point_in_list (const char *mount_point)
    245244{
    246245    MOUNTED_FS_STRUCT *DSFptr = NULL;
     
    283282    log_msg(5, "Running: %s", command);
    284283    mr_asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
    285     paranoid_free(command);
     284    mr_free(command);
    286285
    287286    mount_cnt = atoi(mounted_file_system);
    288287    log_msg (5, "mount_cnt: %d", mount_cnt);
    289     paranoid_free(mounted_file_system);
     288    mr_free(mounted_file_system);
    290289
    291290    for (i=mount_cnt; i > 0; i--) {
     
    293292        log_msg(5, "Running: %s", command);
    294293        mr_asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
    295         paranoid_free(command);
     294        mr_free(command);
    296295
    297296        log_msg (5, "mounted_file_system: %s", mounted_file_system);
    298297        if ((token = strtok(mounted_file_system, token_chars)) == NULL) {
    299298            log_msg (4, "Could not get the list of mounted file systems");
    300             paranoid_free(mounted_file_system);
     299            mr_free(mounted_file_system);
    301300            mr_free(token);
    302301            return (1);
     
    315314            if ((token = strtok(NULL, token_chars)) == NULL) {
    316315                log_msg (5, "Ran out of entries on the mounted file systems list");
    317                 paranoid_free(mounted_file_system);
     316                mr_free(mounted_file_system);
    318317                mr_free(token);
    319318                return (1);
     
    324323            token = strtok(NULL, token_chars);
    325324        }
    326         paranoid_free(mounted_file_system);
     325        mr_free(mounted_file_system);
    327326    }
    328327    /********
     
    377376    log_msg(5, "  Executing: %s", command);
    378377    mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    379     paranoid_free(command);
     378    mr_free(command);
    380379
    381380    log_msg(5, "  Return value: %s", tmp);
    382381    c = atoi(tmp);
    383     paranoid_free(tmp);
     382    mr_free(tmp);
    384383
    385384    if (!c) {
     
    403402    log_msg(4, "Executing: %s", command);
    404403    mr_asprintf(&partition_list, "%s", call_program_and_get_last_line_of_output(command));
    405     paranoid_free(command);
     404    mr_free(command);
    406405    log_msg(4, "Partition list for %s: %s", dsf, partition_list);
    407406    if (!strlen(partition_list)) {
     
    419418        mr_free(token);
    420419    }
    421     paranoid_free(partition_list);
     420    mr_free(partition_list);
    422421 
    423422    /********
     
    457456        log_msg(4, "  Running: %s", command);
    458457        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    459         paranoid_free(command);
     458        mr_free(command);
     459
    460460        log_msg(4, "  Return value: %s", tmp);
    461461        c = strlen(tmp);
    462         paranoid_free(tmp);
     462        mr_free(tmp);
     463
    463464        if (c) {
    464465            log_msg(4, "It's swap. Ignoring partition %s", partitions[i]);
     
    468469        mr_asprintf(&command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
    469470        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    470         paranoid_free(command);
     471        mr_free(command);
     472
    471473        if (strlen(tmp)) {
    472474            log_msg(4, "  %s is mounted: %s", partitions[i], tmp);
    473475            if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) {
    474476                log_msg (4, "Can't find mount point %s in mounted file systems list", tmp);
    475                 paranoid_free(tmp);
     477                mr_free(tmp);
    476478                return (1);
    477479            }
    478480            DSFptr->check = 1;
    479             paranoid_free(tmp);
     481            mr_free(tmp);
    480482            continue;
    481483        }
    482         paranoid_free(tmp);
     484        mr_free(tmp);
    483485        /* It's not swap and it's not mounted. See if it's LVM */
    484486        log_msg(4, "  It's not mounted. Checking to see if it's LVM...");
     
    487489        log_msg(4, "  Running: %s", command);
    488490        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    489         paranoid_free(command);
     491        mr_free(command);
    490492        if (strlen(tmp)) {
    491493            log_msg(4, "  Partition ID: %s", tmp);
     
    496498                log_msg(4, "  Running: %s", command);
    497499                strcpy(VG, call_program_and_get_last_line_of_output(command));
    498                 paranoid_free(command);
     500                mr_free(command);
    499501                log_msg(4, "  Volume Group: %s", VG);
    500502                if (strlen(VG)) {
     
    504506                    log_msg(4, "  Running: %s", command);
    505507                    mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
    506                     paranoid_free(command);
     508                    mr_free(command);
    507509                    log_msg(4, "  VG %s mount_list: %s", VG, mount_list);
    508510                    lastpos = 0;
     
    511513                        if ((DSFptr = find_mount_point_in_list(token)) == NULL) {
    512514                            log_msg (4, "Can't find mount point %s in mounted file systems list", token);
    513                             paranoid_free(tmp);
     515                            mr_free(tmp);
    514516                            mr_free(token);
    515517                            return (1);
     
    522524                     * any of the Logical Volumes on the Volume Group.
    523525                     *******/
    524                     paranoid_free(mount_list);
     526                    mr_free(mount_list);
    525527                    mr_asprintf(&command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    526528                    log_msg (5, "Running: %s", command);
    527529                    mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
    528                     paranoid_free(command);
     530                    mr_free(command);
    529531                    log_msg(4, "  Software raid device list: %s", mount_list);
    530532                    lastpos = 0;
     
    532534                        mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
    533535                        log_msg (5, "Running: %s", command);
    534                         paranoid_free(tmp);
     536                        mr_free(tmp);
    535537                        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    536                         paranoid_free(command);
     538                        mr_free(command);
    537539                        log_msg(4, "Number of Software raid device: %s", tmp);
    538540                        if (atoi(tmp)) {
     
    540542                            if ((DSFptr = find_device_in_list(token)) == NULL) {
    541543                                log_msg (4, "Can't find device %s in mounted file systems list", token);
    542                                 paranoid_free(tmp);
     544                                mr_free(tmp);
    543545                                mr_free(token);
    544546                                return (1);
     
    548550                    }
    549551                    mr_free(token);
    550                     paranoid_free(mount_list);
     552                    mr_free(mount_list);
    551553                } else {
    552554                    log_msg (4, "Error finding Volume Group for partition %s", partitions[i]);
    553                     paranoid_free(tmp);
     555                    mr_free(tmp);
    554556                    return (1);
    555557                }
    556                 paranoid_free(tmp);
     558                mr_free(tmp);
    557559                continue;
    558560            }
     
    560562            log_msg (4, "Error finding partition type for the partition %s", partitions[i]);
    561563        }
    562         paranoid_free(tmp);
     564        mr_free(tmp);
    563565        /********
    564566         * It's not swap, mounted, or LVM. See if it's used in a software raid device.
     
    568570        log_msg(4, "  Running: %s", command);
    569571        mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    570         paranoid_free(command);
     572        mr_free(command);
    571573        if (!strlen(tmp)) {
    572574            log_msg(4, "  Partition %s is not used in a non-LVM software raid device", partitions[i]);
    573             paranoid_free(tmp);
     575            mr_free(tmp);
    574576            continue;
    575577        }
     
    579581        log_msg (5, "  Running: %s", command);
    580582        mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));
    581         paranoid_free(command);
     583        mr_free(command);
    582584        log_msg(4, "  Software raid device list: %s", mount_list);
    583585        /* Loop through the software raid device list to see if we can find the partition */
     
    586588            mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);
    587589            log_msg(4, "  Running: %s", command);
    588             paranoid_free(tmp);
     590            mr_free(tmp);
    589591            mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    590             paranoid_free(command);
     592            mr_free(command);
    591593            if (!atoi(tmp)) {
    592594                log_msg (4,"  Didn't find partition %s in software raid device %s", partitions[i], token);
     
    594596                if ((DSFptr = find_device_in_list(token)) == NULL) {
    595597                    log_msg (4, "Can't find device %s in mounted file systems list", token);
    596                     paranoid_free(tmp);
     598                    mr_free(tmp);
    597599                    mr_free(token);
    598600                    return (1);
     
    603605            mr_free(token);
    604606        }
    605         paranoid_free(tmp);
    606     }
    607     paranoid_free(partition_list);
    608     paranoid_free(mount_list);
     607        mr_free(tmp);
     608    }
     609    mr_free(partition_list);
     610    mr_free(mount_list);
    609611
    610612    /* Determine how much memory to allocate for included_dsf_list and excluded_dsf_list */
     
    753755
    754756    if (flag_set['I']) {
    755         if (bkpinfo->include_paths[0] == '-') {
     757        if (bkpinfo->include_paths && bkpinfo->include_paths[0] == '-') {
    756758            retval++;
    757759            log_to_screen("Please supply a sensible value with '-I'\n");
    758         }
    759         if (!strcmp(bkpinfo->include_paths, "/")) {
    760             log_msg(2, "'/' is pleonastic.");
    761760        }
    762761
     
    783782            }
    784783        }
    785         paranoid_free(tmp1);
     784        mr_free(tmp1);
    786785        while ((token = mr_strtok(flag_val['I'], token_chars, &lastpos)) != NULL) {
    787786            switch (get_dsf_mount_list(token, &mounted_on_dsf, &not_mounted_on_dsf)) {
     
    798797                log_to_screen("  %s\n", mounted_on_dsf);
    799798                mr_asprintf(&p, "/");
     799                mr_free(bkpinfo->include_paths);
    800800                bkpinfo->include_paths = p;
    801801                if (strlen(not_mounted_on_dsf)) {
     
    803803                    log_to_screen("Not archiving the following file systems:\n");
    804804                    log_to_screen("  %s\n", not_mounted_on_dsf);
    805                     mr_strcat(bkpinfo->exclude_paths, "%s ", not_mounted_on_dsf);
     805                    mr_strcat(bkpinfo->exclude_paths, " %s ", not_mounted_on_dsf);
    806806                }
    807807                break;
     
    837837        bkpinfo->make_filelist = FALSE;
    838838        mr_asprintf(&p, "%s", flag_val['J']);
     839        mr_free(bkpinfo->include_paths);
    839840        bkpinfo->include_paths = p;
    840841    }
     
    10891090
    10901091    if (flag_set['E']) {
    1091         if (bkpinfo->exclude_paths[0] == '-') {
     1092        if (bkpinfo->exclude_paths && bkpinfo->exclude_paths[0] == '-') {
    10921093            retval++;
    10931094            log_to_screen("Please supply a sensible value with '-E'\n");
    10941095        }
    1095         mr_strcat(bkpinfo->exclude_paths, " ");
    10961096        mr_asprintf(&tmp1, "%s", flag_val['E']);
    10971097
     
    11361136                    log_to_screen("  %s\n", mounted_on_dsf);
    11371137                    log_msg (5, "Adding to bkpinfo->exclude_paths due to -E option: %s", mounted_on_dsf);
    1138                     mr_strcat(bkpinfo->exclude_paths, "%s ", mounted_on_dsf);
    1139                     }
     1138                    mr_strcat(bkpinfo->exclude_paths, " %s ", mounted_on_dsf);
    11401139                }
    11411140                break;
     
    11461145            /* A device special file was not passed in. Process it as a path. */
    11471146            case -1:
    1148                 mr_strcat(bkpinfo->exclude_paths, "%s ", token);
     1147                mr_strcat(bkpinfo->exclude_paths, " %s ", token);
    11491148                break;
    11501149            }
     
    11641163    {
    11651164        mr_asprintf(&psz, "%s", list_of_NFS_mounts_only());
    1166         mr_strcat(bkpinfo->exclude_paths, "%s ", psz);
     1165        mr_strcat(bkpinfo->exclude_paths, " %s ", psz);
    11671166        mr_free(psz);
    11681167
     
    13001299
    13011300    if (flag_set['S']) {
    1302         sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'],
    1303                 random() % 32768);
     1301        mr_asprintf(&tmp1, "%s/mondo.scratch.%ld", flag_val['S'], random() % 32768);
     1302        mr_free(bkpinfo->scratchdir);
     1303        bkpinfo->scratchdir = tmp1;
    13041304    }
    13051305
     
    13761376        finish(0);
    13771377    }
     1378    mr_free(tmp);
    13781379
    13791380    if ((flag_set['L']) && (! bkpinfo->restore_data)) {
     
    14661467/* and finally... */
    14671468
    1468     paranoid_free(tmp);
    14691469    return (retval);
    14701470}
     
    15151515                mr_asprintf(&tmp, "Switch -%c previously defined as %s\n", opt, flag_val[opt]);
    15161516                log_to_screen(tmp);
    1517                 paranoid_free(tmp);
     1517                mr_free(tmp);
    15181518            } else {
    15191519                flag_set[opt] = TRUE;
     
    15311531                            mr_asprintf(&tmp, "-%c flag --- must be absolute path --- '%s' isn't absolute", opt, flag_val[opt]);
    15321532                            log_to_screen(tmp);
    1533                             paranoid_free(tmp);
     1533                            mr_free(tmp);
    15341534                            bad_switches = TRUE;
    15351535                        }
     
    15441544        mr_asprintf(&tmp, "Invalid arg -- %s\n", argv[i]);
    15451545        log_to_screen(tmp);
    1546         paranoid_free(tmp);
     1546        mr_free(tmp);
    15471547    }
    15481548    return (bad_switches);
     
    16071607    mr_strcat(tmp, " signal received from OS");
    16081608    log_to_screen(tmp);
    1609     paranoid_free(tmp);
     1609    mr_free(tmp);
    16101610
    16111611    log_to_screen(tmp2);
    1612     paranoid_free(tmp2);
     1612    mr_free(tmp2);
    16131613    if (sig == SIGABRT) {
    16141614        sleep(10);
Note: See TracChangeset for help on using the changeset viewer.