Changeset 2022


Ignore:
Timestamp:
Sep 23, 2008, 2:14:56 AM (11 years ago)
Author:
bruno
Message:
  • DSF patch modified to so that get_dsf_mount_list only deal with one path passed as param
  • -E and -I options are working again. DSF not fully tested, but no more issue (Fix #274)
  • Fix some complier warnings
Location:
branches/2.2.7/mondo/src
Files:
3 edited

Legend:

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

    r2011 r2022  
    166166#include "libmondo-cli-EXT.h"
    167167#include "libmondo.h"
     168#include "mr_string.h"
    168169
    169170extern int g_loglevel;
     
    413414{
    414415    int i = 0;
     416    int lastpos = 0;
    415417    int mount_cnt = 0;
    416418    char *mounted_file_system = NULL;
     
    449451            return (1);
    450452        }
    451         paranoid_free(mounted_file_system);
    452453        log_msg (5, "token: %s", token);
    453454        while (token != NULL) {
     
    460461            if ((token = strtok(NULL, token_chars)) == NULL) {
    461462                log_msg (5, "Ran out of entries on the mounted file systems list");
     463                paranoid_free(mounted_file_system);
    462464                return (1);
    463465            }
     
    466468            token = strtok(NULL, token_chars);
    467469        }
     470        paranoid_free(mounted_file_system);
    468471    }
    469472    /********
     
    491494    int i = 0;
    492495    int c = 0;
    493     int dsf_cnt = 0;
    494     int num_dsf = 0;
     496    int lastpos = 0;
    495497    char VG[MAX_STR_LEN];
    496498    char *tmp = NULL;
     
    498500    char *partition_list = NULL;
    499501    char partitions[64][MAX_STR_LEN];
    500     char dsf_list[16][MAX_STR_LEN];
    501502    char *mount_list = NULL;
    502503    char *token = NULL;
    503     char *DSF = NULL;
    504504    char token_chars[] =" \t\r\f\a\0";
    505505    MOUNTED_FS_STRUCT *DSFptr = NULL;
    506506
    507     malloc_string(DSF);
    508507    memset((char *)partitions, 0, sizeof(partitions));
    509     memset((char *)dsf_list, 0, sizeof(dsf_list));
    510 
    511     num_dsf = 0;
    512     log_msg(5, "DSF's: %s", dsf);
    513     strcpy(DSF, dsf);
    514     token = strtok(DSF, token_chars);
    515     while (token != NULL) {
    516         log_msg (5, " dsf: %s", token);
    517         strcpy(dsf_list[num_dsf], token);
    518         /********
    519         * See if a device special file was passed in (i.e. it must start with /dev/
    520         ********/
    521         if (strncmp(dsf_list[num_dsf], "/dev/", 5)) {
    522             log_msg (5, "%s does not start with /dev/ and (probably) is not a  device special file", dsf_list[num_dsf]);
    523             return (-1);
    524         }
    525         log_msg(5, "  %s looks like a device special file", dsf_list[num_dsf]);
    526         /* Verify that the dsf exists */
    527         asprintf(&command, "ls -al %s 2>/dev/null | wc -l", dsf_list[num_dsf]);
    528         log_msg(5, "  Executing: %s", command);
    529         asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    530         paranoid_free(command);
    531         log_msg(5, "  Return value: %s", tmp);
    532         c = atoi(tmp);
    533         paranoid_free(tmp);
    534         if (!c) {
    535             log_to_screen("Cannot find device special file %s", dsf_list[num_dsf]);
    536             return (1);
    537         }
    538         log_msg(5, "  %s device special file exists", dsf_list[dsf_cnt]);
    539         num_dsf++;
    540         token = strtok(NULL, token_chars);
    541     }
    542     paranoid_free(DSF);
    543     log_msg (5, " num_dsf: %d", num_dsf);
     508
     509    log_msg(5, "dsf: %s", dsf);
     510   
     511    /********
     512    * See if a device special file was passed in (i.e. it must start with /dev/
     513    ********/
     514    if (strncmp(dsf, "/dev/", 5)) {
     515        log_msg (5, "%s does not start with /dev/ and (probably) is not a  device special file", dsf);
     516        return (-1);
     517    }
     518    log_msg(5, "  %s looks like a device special file", dsf);
     519    /* Verify that the dsf exists */
     520    asprintf(&command, "ls -al %s 2>/dev/null | wc -l", dsf);
     521    log_msg(5, "  Executing: %s", command);
     522    asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     523    paranoid_free(command);
     524
     525    log_msg(5, "  Return value: %s", tmp);
     526    c = atoi(tmp);
     527    paranoid_free(tmp);
     528
     529    if (!c) {
     530        log_to_screen("Cannot find device special file %s", dsf);
     531        return (1);
     532    }
     533    log_msg(5, "  %s device special file exists", dsf);
    544534   
    545535    /* Get a list of the mounted file systems */
     
    548538        return (1);
    549539    }
    550     /* Loop throught each dsf */
    551     for (dsf_cnt=0; dsf_cnt < num_dsf; dsf_cnt++) {
    552         log_msg (5, "Processing dsf: %s", dsf_list[dsf_cnt]);
     540    log_msg (5, "Processing dsf: %s", dsf);
     541    /********
     542    * Get a list of the dsf's partitions. There could be no partitions on the disk
     543    * or a dsf of a partition was passed in (e.g. /dev/sda1 instead of /dev/sda).
     544    * Either way, it's an error.
     545    ********/
     546    asprintf(&command,
     547      "fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf);
     548    log_msg(4, "Executing: %s", command);
     549    asprintf(&partition_list, call_program_and_get_last_line_of_output(command));
     550    paranoid_free(command);
     551    log_msg(4, "Partition list for %s: %s", dsf, partition_list);
     552    if (!strlen(partition_list)) {
     553        /* There were no partitions on the disk */
     554        log_msg(4, "Cannot find any partitions on device special file %s", dsf);
     555        return (-2);
     556    }
     557
     558    /* Fill the partition list */
     559    i = 0;
     560    lastpos = 0;
     561    while (token = mr_strtok(partition_list, token_chars, &lastpos)) {
     562        log_msg (5, "Found partition: %s", token);
     563        strcpy(partitions[i++], token);
     564    }
     565    paranoid_free(partition_list);
     566 
     567    /********
     568     * At this point, we have a list of all of the partitions on the dsf. Now try to
     569     * see which partitions have a file system on them.
     570     *
     571     * Loop through each partition on the disk and:
     572     *
     573     * - If the partition is swap, it ignores it.
     574     *
     575     * - If the partition is mounted (e.g. /dev/sda1 is mounted on /boot), it adds an entry
     576     *  to the linked list, copies to it the device name and mount point, and sets check == 1.
     577     *
     578     * - If the partition is part of a Volume Group that has Logical Volumes mounted, it adds
     579     *  an entry to the linked list for each mounted Logical Volume in that Volume Group, copying
     580     *  to it the device name and mount point, and sets check == 1. Note that if the Volume Group
     581     *  contains more than one disk, it will still add the entry even if the Logical Volume's
     582     *  extents are not on the dsf that was passed in to the function. For example, Volume Group
     583     *  VolGroup00 contains the disks /dev/sda1 and /dev/sdb1, and the Logical Volumes LogVol01,
     584     *  which is mounted on /var and has all of its extents on /dev/sda1, and LogVol02, which is
     585     *  mounted as /usr and has all of its extents on /dev/sdb1. If you pass /dev/sda into the
     586     *  function, both /var and /usr will be archived even though /usr is actually on/dev/sdb.
     587     *
     588     * - If the partition is part of a Volume Group that has Logical Volumes used in a mounted
     589     *  software raid device, it adds an entry to the linked list, copies to it the software raid
     590     *  device name and mount point, and sets check == 1.
     591     *
     592     * - If the partition is part of a mounted software raid device, it adds an entry to the linked
     593     *  list, copies to it the software raid device name and mount point, and sets check == 1.
     594     *
     595     ********/
     596    for (i=0; strlen(partitions[i]); i++) {
     597        log_msg(4, "Processing partition: %s", partitions[i]);
     598        /* See if it's swap. If it is, ignore it. */
     599        asprintf(&command,
     600          "fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'",
     601          dsf, partitions[i]);
     602        log_msg(4, "  Running: %s", command);
     603        asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     604        paranoid_free(command);
     605        log_msg(4, "  Return value: %s", tmp);
     606        c = strlen(tmp);
     607        paranoid_free(tmp);
     608        if (c) {
     609            log_msg(4, "It's swap. Ignoring partition %s", partitions[i]);
     610            continue;
     611        }
     612        /* It's not swap. See if we can find the mount point from the mount command. */
     613        asprintf(&command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
     614        asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     615        paranoid_free(command);
     616        if (strlen(tmp)) {
     617            log_msg(4, "  %s is mounted: %s", partitions[i], tmp);
     618            if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) {
     619                log_msg (4, "Can't find mount point %s in mounted file systems list", tmp);
     620                paranoid_free(tmp);
     621                return (1);
     622            }
     623            DSFptr->check = 1;
     624            paranoid_free(tmp);
     625            continue;
     626        }
     627        paranoid_free(tmp);
     628        /* It's not swap and it's not mounted. See if it's LVM */
     629        log_msg(4, "  It's not mounted. Checking to see if it's LVM...");
     630        /* Get the partition ID; 8e for LVM */
     631        asprintf(&command, "fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf, partitions[i]);
     632        log_msg(4, "  Running: %s", command);
     633        asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     634        paranoid_free(command);
     635        if (strlen(tmp)) {
     636            log_msg(4, "  Partition ID: %s", tmp);
     637            if (!strcasecmp(tmp, "8e")) {
     638                /* It's LVM: Find the VG it's in */
     639                log_msg(4, "  It's LVM: Find the VG it's in...");
     640                asprintf(&command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
     641                log_msg(4, "  Running: %s", command);
     642                strcpy(VG, call_program_and_get_last_line_of_output(command));
     643                paranoid_free(command);
     644                log_msg(4, "  Volume Group: %s", VG);
     645                if (strlen(VG)) {
     646                    /* Found the Volume Group. Now find all of the VG's mount points */
     647                    log_msg(4, "  Found the Volume Group. Now find all of the VG's mount points");
     648                    asprintf(&command,
     649                      "mount 2>/dev/null|grep -E \"/dev/mapper/%s-|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'",
     650                      VG, VG);
     651                    log_msg(4, "  Running: %s", command);
     652                    asprintf(&mount_list, call_program_and_get_last_line_of_output(command));
     653                    paranoid_free(command);
     654                    log_msg(4, "  VG %s mount_list: %s", VG, mount_list);
     655                    lastpos = 0;
     656                    while (token = mr_strtok(mount_list, token_chars, &lastpos)) {
     657                        log_msg (5, "mount point token: %s", token);
     658                        if ((DSFptr = find_mount_point_in_list(token)) == NULL) {
     659                            log_msg (4, "Can't find mount point %s in mounted file systems list", token);
     660                            paranoid_free(tmp);
     661                            return (1);
     662                        }
     663                        DSFptr->check = 1;
     664                    }
     665                    /********
     666                     * Now we want to see if there are any software raid devices using
     667                     * any of the Logical Volumes on the Volume Group.
     668                     *******/
     669                    paranoid_free(mount_list);
     670                    asprintf(&command, "%s",
     671                        "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
     672                    log_msg (5, "Running: %s", command);
     673                    asprintf(&mount_list, call_program_and_get_last_line_of_output(command));
     674                    paranoid_free(command);
     675                    log_msg(4, "  Software raid device list: %s", mount_list);   
     676                    lastpos = 0;
     677                    while (token = mr_strtok(mount_list, token_chars, &lastpos)) {
     678                        asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
     679                        log_msg (5, "Running: %s", command);
     680                        paranoid_free(tmp);
     681                        asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
     682                        paranoid_free(command);
     683                        log_msg(4, "Number of Software raid device: %s", tmp);
     684                        if (atoi(tmp)) {
     685                            /* This device is on our disk */
     686                            if ((DSFptr = find_device_in_list(token)) == NULL) {
     687                                log_msg (4, "Can't find device %s in mounted file systems list", token);
     688                                paranoid_free(tmp);
     689                                return (1);
     690                            }
     691                            DSFptr->check = 1;
     692                        }
     693                    }
     694                    paranoid_free(mount_list);
     695                } else {
     696                    log_msg (4, "Error finding Volume Group for partition %s", partitions[i]);
     697                    paranoid_free(tmp);
     698                    return (1);
     699                }
     700                paranoid_free(tmp);
     701                continue;
     702            }
     703        } else {
     704            log_msg (4, "Error finding partition type for the partition %s", partitions[i]);
     705        }
     706        paranoid_free(tmp);
    553707        /********
    554         * Get a list of the dsf's partitions. There could be no partitions on the disk
    555         * or a dsf of a partition was passed in (e.g. /dev/sda1 instead of /dev/sda).
    556         * Either way, it's an error.
    557         ********/
    558         asprintf(&command,
    559           "fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf_list[dsf_cnt]);
    560         log_msg(4, "Executing: %s", command);
    561         asprintf(&partition_list, call_program_and_get_last_line_of_output(command));
     708         * It's not swap, mounted, or LVM. See if it's used in a software raid device.
     709         ********/
     710        log_msg (5, "It's not swap, mounted, or LVM. See if it's used in a software raid device.");
     711        asprintf(&command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);
     712        log_msg(4, "  Running: %s", command);
     713        asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    562714        paranoid_free(command);
    563         log_msg(4, "Partition list for %s: %s", dsf_list[dsf_cnt], partition_list);
    564         if (!strlen(partition_list)) {
    565             /* There were no partitions on the disk */
    566             log_msg(4, "Cannot find any partitions on device special file %s", dsf_list[dsf_cnt]);
    567             return (-2);
    568         }
    569 
    570         /* Fill the partition list */
    571         i = 0;
    572         token = strtok(partition_list, token_chars);
    573         while (token != NULL) {
    574             log_msg (5, "Found partition: %s", token);
    575             strcpy(partitions[i++], token);
    576             token = strtok(NULL, token_chars);
    577         }
    578         paranoid_free(partition_list);
    579  
    580         /********
    581          * At this point, we have a list of all of the partitions on the dsf. Now try to
    582          * see which partitions have a file system on them.
    583          *
    584          * Loop through each partition on the disk and:
    585          *
    586          * - If the partition is swap, it ignores it.
    587          *
    588          * - If the partition is mounted (e.g. /dev/sda1 is mounted on /boot), it adds an entry
    589          *  to the linked list, copies to it the device name and mount point, and sets check == 1.
    590          *
    591          * - If the partition is part of a Volume Group that has Logical Volumes mounted, it adds
    592          *  an entry to the linked list for each mounted Logical Volume in that Volume Group, copying
    593          *  to it the device name and mount point, and sets check == 1. Note that if the Volume Group
    594          *  contains more than one disk, it will still add the entry even if the Logical Volume's
    595          *  extents are not on the dsf that was passed in to the function. For example, Volume Group
    596          *  VolGroup00 contains the disks /dev/sda1 and /dev/sdb1, and the Logical Volumes LogVol01,
    597          *  which is mounted on /var and has all of its extents on /dev/sda1, and LogVol02, which is
    598          *  mounted as /usr and has all of its extents on /dev/sdb1. If you pass /dev/sda into the
    599          *  function, both /var and /usr will be archived even though /usr is actually on/dev/sdb.
    600          *
    601          * - If the partition is part of a Volume Group that has Logical Volumes used in a mounted
    602          *  software raid device, it adds an entry to the linked list, copies to it the software raid
    603          *  device name and mount point, and sets check == 1.
    604          *
    605          * - If the partition is part of a mounted software raid device, it adds an entry to the linked
    606          *  list, copies to it the software raid device name and mount point, and sets check == 1.
    607          *
    608          ********/
    609         for (i=0; strlen(partitions[i]); i++) {
    610             log_msg(4, "Processing partition: %s", partitions[i]);
    611             /* See if it's swap. If it is, ignore it. */
    612             asprintf(&command,
    613               "fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'",
    614               dsf_list[dsf_cnt], partitions[i]);
     715        if (!strlen(tmp)) {
     716            log_msg(4, "  Partition %s is not used in a non-LVM software raid device", partitions[i]);
     717            paranoid_free(tmp);
     718            continue;
     719        }
     720        log_msg (5, "  UUID: %s", tmp);
     721        /* Get the Software raid device list */
     722        asprintf(&command, "%s",
     723         "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
     724        log_msg (5, "  Running: %s", command);
     725        asprintf(&mount_list, call_program_and_get_last_line_of_output(command));
     726        paranoid_free(command);
     727        log_msg(4, "  Software raid device list: %s", mount_list);   
     728        /* Loop through the software raid device list to see if we can find the partition */
     729        lastpos = 0;
     730        while (token = mr_strtok(mount_list, token_chars, &lastpos)) {
     731            asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);
    615732            log_msg(4, "  Running: %s", command);
     733            paranoid_free(tmp);
    616734            asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    617735            paranoid_free(command);
    618             log_msg(4, "  Return value: %s", tmp);
    619             c = strlen(tmp);
    620             paranoid_free(tmp);
    621             if (c) {
    622                 log_msg(4, "It's swap. Ignoring partition %s", partitions[i]);
    623                 continue;
    624             }
    625             /* It's not swap. See if we can find the mount point from the mount command. */
    626             asprintf(&command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
    627             asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    628             paranoid_free(command);
    629             if (strlen(tmp)) {
    630                 log_msg(4, "  %s is mounted: %s", partitions[i], tmp);
    631                 if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) {
    632                     log_msg (4, "Can't find mount point %s in mounted file systems list", tmp);
     736            if (!atoi(tmp)) {
     737                log_msg (4,"  Didn't find partition %s in software raid device %s", partitions[i], token);
     738            } else {
     739                if ((DSFptr = find_device_in_list(token)) == NULL) {
     740                    log_msg (4, "Can't find device %s in mounted file systems list", token);
    633741                    paranoid_free(tmp);
    634742                    return (1);
    635743                }
    636744                DSFptr->check = 1;
    637                 paranoid_free(tmp);
    638                 continue;
    639             }
    640             paranoid_free(tmp);
    641             /* It's not swap and it's not mounted. See if it's LVM */
    642             log_msg(4, "  It's not mounted. Checking to see if it's LVM...");
    643             /* Get the partition ID; 8e for LVM */
    644             asprintf(&command, "fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf_list[dsf_cnt], partitions[i]);
    645             log_msg(4, "  Running: %s", command);
    646             asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    647             paranoid_free(command);
    648             if (strlen(tmp)) {
    649                 log_msg(4, "  Partition ID: %s", tmp);
    650                 if (!strcasecmp(tmp, "8e")) {
    651                     /* It's LVM: Find the VG it's in */
    652                     log_msg(4, "  It's LVM: Find the VG it's in...");
    653                     asprintf(&command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
    654                     log_msg(4, "  Running: %s", command);
    655                     strcpy(VG, call_program_and_get_last_line_of_output(command));
    656                     paranoid_free(command);
    657                     log_msg(4, "  Volume Group: %s", VG);
    658                     if (strlen(VG)) {
    659                         /* Found the Volume Group. Now find all of the VG's mount points */
    660                         log_msg(4, "  Found the Volume Group. Now find all of the VG's mount points");
    661                         asprintf(&command,
    662                           "mount 2>/dev/null|grep -E \"/dev/mapper/%s-|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'",
    663                           VG, VG);
    664                         log_msg(4, "  Running: %s", command);
    665                         asprintf(&mount_list, call_program_and_get_last_line_of_output(command));
    666                         paranoid_free(command);
    667                         log_msg(4, "  VG %s mount_list: %s", VG, mount_list);
    668                         token = strtok(mount_list, token_chars);
    669                         while (token != NULL) {
    670                             log_msg (5, "mount point token: %s", token);
    671                             if ((DSFptr = find_mount_point_in_list(token)) == NULL) {
    672                                 log_msg (4, "Can't find mount point %s in mounted file systems list", token);
    673                                 paranoid_free(tmp);
    674                                 return (1);
    675                             }
    676                             DSFptr->check = 1;
    677                             token = strtok(NULL, token_chars);
    678                         }
    679                         /********
    680                          * Now we want to see if there are any software raid devices using
    681                          * any of the Logical Volumes on the Volume Group.
    682                          *******/
    683                         paranoid_free(mount_list);
    684                         asprintf(&command, "%s",
    685                             "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    686                         log_msg (5, "Running: %s", command);
    687                         asprintf(&mount_list, call_program_and_get_last_line_of_output(command));
    688                         paranoid_free(command);
    689                         log_msg(4, "  Software raid device list: %s", mount_list);   
    690                         token = strtok(mount_list, token_chars);
    691                         while (token != NULL) {
    692                             asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);
    693                             log_msg (5, "Running: %s", command);
    694                             paranoid_free(tmp);
    695                             asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    696                             paranoid_free(command);
    697                             log_msg(4, "Number of Software raid device: %s", tmp);
    698                             if (atoi(tmp)) {
    699                                 /* This device is on our disk */
    700                                 if ((DSFptr = find_device_in_list(token)) == NULL) {
    701                                     log_msg (4, "Can't find device %s in mounted file systems list", token);
    702                                     paranoid_free(tmp);
    703                                     return (1);
    704                                 }
    705                                 DSFptr->check = 1;
    706                             }
    707                             token = strtok(NULL, token_chars);
    708                         }
    709                         paranoid_free(mount_list);
    710                     } else {
    711                         log_msg (4, "Error finding Volume Group for partition %s", partitions[i]);
    712                         paranoid_free(tmp);
    713                         return (1);
    714                     }
    715                     paranoid_free(tmp);
    716                     continue;
    717                 }
    718             } else {
    719                 log_msg (4, "Error finding partition type for the partition %s", partitions[i]);
    720             }
    721             paranoid_free(tmp);
    722             /********
    723              * It's not swap, mounted, or LVM. See if it's used in a software raid device.
    724              ********/
    725             log_msg (5, "It's not swap, mounted, or LVM. See if it's used in a software raid device.");
    726             asprintf(&command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);
    727             log_msg(4, "  Running: %s", command);
    728             asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    729             paranoid_free(command);
    730             if (!strlen(tmp)) {
    731                 log_msg(4, "  Partition %s is not used in a non-LVM software raid device", partitions[i]);
    732                 paranoid_free(tmp);
    733                 continue;
    734             }
    735             log_msg (5, "  UUID: %s", tmp);
    736             /* Get the Software raid device list */
    737             asprintf(&command, "%s",
    738              "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    739             log_msg (5, "  Running: %s", command);
    740             asprintf(&mount_list, call_program_and_get_last_line_of_output(command));
    741             paranoid_free(command);
    742             log_msg(4, "  Software raid device list: %s", mount_list);   
    743             /* Loop through the software raid device list to see if we can find the partition */
    744             token = strtok(mount_list, token_chars);
    745             while (token != NULL) {
    746                 asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);
    747                 log_msg(4, "  Running: %s", command);
    748                 paranoid_free(tmp);
    749                 asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    750                 paranoid_free(command);
    751                 if (!atoi(tmp)) {
    752                     log_msg (4,"  Didn't find partition %s in software raid device %s", partitions[i], token);
    753                 } else {
    754                     if ((DSFptr = find_device_in_list(token)) == NULL) {
    755                         log_msg (4, "Can't find device %s in mounted file systems list", token);
    756                         paranoid_free(tmp);
    757                         return (1);
    758                     }
    759                     DSFptr->check = 1;
    760                     break;
    761                 }
    762                 token = strtok(NULL, token_chars);
    763             }
    764             paranoid_free(tmp);
    765         }
     745                break;
     746            }
     747        }
     748        paranoid_free(tmp);
    766749    }
    767750    paranoid_free(partition_list);
     
    819802    int retval = 0;
    820803    int percent = 0;
     804    int lastpos = 0;
    821805
    822806    /*@ buffers ** */
    823     char *tmp;
    824     char *tmp1;
    825     char *psz;
    826     char *p;
    827     char *q;
     807    char *tmp = NULL;
     808    char *tmp1 = NULL;
     809    char *psz = NULL;
     810    char *p = NULL;
     811    char *q = NULL;
     812    char *token = NULL;
    828813    char *mounted_on_dsf = NULL;
    829814    char *not_mounted_on_dsf = NULL;
     815    char token_chars[] =" \t\r\f\a\0";
    830816
    831817    long itbs = 0L;
     
    910896
    911897    if (flag_set['I']) {
     898        if (bkpinfo->include_paths[0] == '-') {
     899            retval++;
     900            log_to_screen("Please supply a sensible value with '-I'\n");
     901        }
    912902        if (!strcmp(bkpinfo->include_paths, "/")) {
    913903            log_msg(2, "'/' is pleonastic.");
     
    917907            strcat(bkpinfo->include_paths, " ");
    918908        }
    919         switch (get_dsf_mount_list(flag_val['I'], &mounted_on_dsf, &not_mounted_on_dsf)) {
     909       
     910        asprintf(&tmp1, flag_val['I']);
     911        p = tmp1;
     912        q = tmp1;
     913
     914        /* Cut the flag_val['I'] in parts containing all paths to test them */
     915        while (p != NULL) {
     916            q = strchr(p, ' ');
     917            if (q != NULL) {
     918                *q = '\0';
     919                if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
     920                    log_msg(1, "ERROR ! %s doesn't exist", p);
     921                    fatal_error("ERROR ! You specified a directory to include which doesn't exist");
     922                }
     923                p = q+1 ;
     924            } else {
     925                if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
     926                    log_msg(1, "ERROR ! %s doesn't exist", p);
     927                    fatal_error("ERROR ! You specified a directory to include which doesn't exist");
     928                }
     929                p = NULL;
     930            }
     931        }
     932        paranoid_free(tmp1);
     933        while (token = mr_strtok(flag_val['I'], token_chars, &lastpos)) {
     934            switch (get_dsf_mount_list(token, &mounted_on_dsf, &not_mounted_on_dsf)) {
    920935            /* It's a dsf but not a whole disk dsf */
    921936            case -2:
    922                 log_to_screen("Could %s be a partition instead of a whole disk device special file?\n", flag_val['I']);
     937                log_to_screen("Could %s be a partition instead of a whole disk device special file?\n Ignored.", token);
    923938                break;
    924939            /* Fatal error; exit */
     
    927942            /* Everything is OK; process to archive data */
    928943            case 0:
    929                 log_to_screen("Archiving only the following file systems on %s:\n", flag_val['I']);
     944                log_to_screen("Archiving only the following file systems on %s:\n", token);
    930945                log_to_screen("  %s\n", mounted_on_dsf);
    931946                strcpy(bkpinfo->include_paths, "/");
     
    940955            /* A device special file was not passed in. Process it as a path. */
    941956            case -1:
    942 
    943                 p = tmp1;
    944                 q = tmp1;
    945 
    946                 /* Cut the flag_val['I'] in parts containing all paths to test them */
    947                 while (p != NULL) {
    948                     q = strchr(p, ' ');
    949                     if (q != NULL) {
    950                         *q = '\0';
    951                         if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
    952                             log_msg(1, "ERROR ! %s doesn't exist", p);
    953                             fatal_error("ERROR ! You specified a directory to include which doesn't exist");
    954                         }
    955                         p = q+1 ;
    956                     } else {
    957                         if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
    958                             log_msg(1, "ERROR ! %s doesn't exist", p);
    959                             fatal_error("ERROR ! You specified a directory to include which doesn't exist");
    960                         }
    961                         p = NULL;
    962                     }
    963                 }
    964                 paranoid_free(tmp1);
    965                 strncpy(bkpinfo->include_paths + strlen(bkpinfo->include_paths),
    966                     flag_val['I'],
    967                     4*MAX_STR_LEN - strlen(bkpinfo->include_paths));
    968                 if (bkpinfo->include_paths[0] == '-') {
    969                     retval++;
    970                     log_to_screen("Please supply a sensible value with '-I'\n");
    971                 }
     957                    strcat(bkpinfo->include_paths, token);
     958                    strcat(bkpinfo->include_paths, " ");
    972959                break;
    973960            }
    974             log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
    975             log_msg(4, "Finished with the -I option");
     961        }
     962        log_msg(1, "include_paths is now '%s'", bkpinfo->include_paths);
     963        if (bkpinfo->exclude_paths != NULL) {
     964            log_msg(1, "exclude_paths is now '%s'", bkpinfo->exclude_paths);
     965        }
     966        log_msg(4, "Finished with the -I option");
    976967    }
    977968
     
    12091200
    12101201    if (flag_set['E']) {
     1202        if (bkpinfo->exclude_paths[0] == '-') {
     1203            retval++;
     1204            log_to_screen("Please supply a sensible value with '-E'\n");
     1205        }
    12111206        if (bkpinfo->exclude_paths[0]) {
    12121207            strcat(bkpinfo->exclude_paths, " ");
     
    12141209        asprintf(&tmp1, flag_val['E']);
    12151210
    1216         switch (get_dsf_mount_list(flag_val['E'], &mounted_on_dsf, &not_mounted_on_dsf)) {
     1211        p = tmp1;
     1212        q = tmp1;
     1213
     1214        /* Cut the flag_val['E'] in parts containing all paths to test them */
     1215        while (p != NULL) {
     1216            q = strchr(p, ' ');
     1217            if (q != NULL) {
     1218                *q = '\0';
     1219                /* Fix bug 14 where ending / cause a problem later
     1220                * so handled here for the moment */
     1221                q--;
     1222                if (*q == '/') {
     1223                    *q = '\0';
     1224                }
     1225                q++;
     1226                /* End of bug fix */
     1227                if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
     1228                    log_msg(1, "WARNING ! %s doesn't exist", p);
     1229                }
     1230                p = q+1 ;
     1231            } else {
     1232                if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
     1233                    log_msg(1, "WARNING ! %s doesn't exist", p);
     1234                }
     1235                p = NULL;
     1236            }
     1237        }
     1238        paranoid_free(tmp1);
     1239        lastpos = 0;
     1240        while (token = mr_strtok(flag_val['E'], token_chars, &lastpos)) {
     1241            switch (get_dsf_mount_list(token, &mounted_on_dsf, &not_mounted_on_dsf)) {
    12171242            /* Fatal error; exit */
    12181243            case 1:
    1219                 fatal_error ("Error processing -I option");
     1244                fatal_error ("Error processing -E option");
    12201245            /* Everything is OK; proceed to archive data */
    12211246            case 0:
    12221247                if (strlen(mounted_on_dsf)) {
    1223                     log_to_screen("Excluding the following file systems on %s:\n", flag_val['E']);
     1248                    log_to_screen("Excluding the following file systems on %s:\n", token);
    12241249                    log_to_screen("  %s\n", mounted_on_dsf);
    12251250                    log_msg (5, "Adding to bkpinfo->exclude_paths due to -E option: %s", mounted_on_dsf);
    12261251                    strcat(bkpinfo->exclude_paths, mounted_on_dsf);
    1227                     strcat(bkpinfo->exclude_paths, "");
     1252                    strcat(bkpinfo->exclude_paths, " ");
    12281253                }
    12291254                break;
    12301255            /* It's a dsf but not a whole disk dsf */
    12311256            case -2:
     1257                log_to_screen("Could %s be a partition instead of a whole disk device special file?\nIgnored.", token);
    12321258                break;
    12331259            /* A device special file was not passed in. Process it as a path. */
    12341260            case -1:
    1235                 p = tmp1;
    1236                 q = tmp1;
    1237 
    1238                 /* Cut the flag_val['E'] in parts containing all paths to test them */
    1239                 while (p != NULL) {
    1240                     q = strchr(p, ' ');
    1241                     if (q != NULL) {
    1242                         *q = '\0';
    1243                         /* Fix bug 14 where ending / cause a problem later
    1244                         * so handled here for the moment */
    1245                         q--;
    1246                         if (*q == '/') {
    1247                             *q = '\0';
    1248                         }
    1249                         q++;
    1250                         /* End of bug fix */
    1251                         if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
    1252                             log_msg(1, "WARNING ! %s doesn't exist", p);
    1253                         }
    1254                         p = q+1 ;
    1255                     } else {
    1256                         if ((stat(p, &buf) != 0) && (! bkpinfo->restore_data)) {
    1257                             log_msg(1, "WARNING ! %s doesn't exist", p);
    1258                         }
    1259                         p = NULL;
    1260                     }
    1261                 }
    1262                 paranoid_free(tmp1);
    1263                 strncpy(bkpinfo->exclude_paths + strlen(bkpinfo->exclude_paths),
    1264                     flag_val['E'],
    1265                     4*MAX_STR_LEN - strlen(bkpinfo->exclude_paths));
    1266             }
    1267             log_msg(4, "Exclude path from -E: %s", bkpinfo->exclude_paths);
     1261                    strcat(bkpinfo->exclude_paths, token);
     1262                    strcat(bkpinfo->exclude_paths, " ");
     1263            break;
     1264            }
     1265        }
     1266        log_msg(1, "exclude_paths is now '%s'", bkpinfo->exclude_paths);
     1267        log_msg(4, "Finished with the -E option");
    12681268    }
    12691269
  • branches/2.2.7/mondo/src/mondorestore/mondo-rstr-tools.c

    r1996 r2022  
    170170extern void kill_anything_like_this(char *str);
    171171extern int skip_obdr(void);
     172extern int set_tape_block_size_with_mt(long internal_tape_block_size);
    172173
    173174/**
  • branches/2.2.7/mondo/src/mondorestore/mondorestore.c

    r1999 r2022  
    908908    char *old_restpath;
    909909
    910     struct mountlist_itself *mountlist;
     910    struct mountlist_itself *mountlist = NULL;
    911911//  static
    912     struct raidlist_itself *raidlist;
    913     struct s_node *filelist;
     912    struct raidlist_itself *raidlist = NULL;
     913    struct s_node *filelist = NULL;
    914914
    915915    log_msg(1, "restore_to_live_filesystem() - starting");
Note: See TracChangeset for help on using the changeset viewer.