Ignore:
Timestamp:
Sep 10, 2009, 2:55:51 AM (15 years ago)
Author:
Bruno Cornec
Message:

call_program_and_get_last_line_of_output is now allocating memory and returning that string

File:
1 edited

Legend:

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

    r2382 r2383  
    264264    mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l");
    265265    log_msg(5, "Running: %s", command);
    266     mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
     266    mounted_file_system = call_program_and_get_last_line_of_output(command);
    267267    mr_free(command);
    268268
     
    274274        mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i);
    275275        log_msg(5, "Running: %s", command);
    276         mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
     276        mounted_file_system = call_program_and_get_last_line_of_output(command);
    277277        mr_free(command);
    278278
     
    333333    int c = 0;
    334334    int lastpos = 0;
    335     char VG[MAX_STR_LEN];
     335    char *VG = NULL;
    336336    char *tmp = NULL;
    337337    char *command = NULL;
     
    358358    mr_asprintf(command, "ls -al %s 2>/dev/null | wc -l", dsf);
    359359    log_msg(5, "  Executing: %s", command);
    360     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     360    tmp = call_program_and_get_last_line_of_output(command);
    361361    mr_free(command);
    362362
     
    384384    mr_asprintf(command, "parted2fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf);
    385385    log_msg(4, "Executing: %s", command);
    386     mr_asprintf(partition_list, "%s", call_program_and_get_last_line_of_output(command));
     386    partition_list = call_program_and_get_last_line_of_output(command);
    387387    mr_free(command);
    388388    log_msg(4, "Partition list for %s: %s", dsf, partition_list);
     
    438438          dsf, partitions[i]);
    439439        log_msg(4, "  Running: %s", command);
    440         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     440        tmp = call_program_and_get_last_line_of_output(command);
    441441        mr_free(command);
    442442
     
    451451        /* It's not swap. See if we can find the mount point from the mount command. */
    452452        mr_asprintf(command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
    453         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     453        tmp = call_program_and_get_last_line_of_output(command);
    454454        mr_free(command);
    455455
     
    471471        mr_asprintf(command, "parted2fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf, partitions[i]);
    472472        log_msg(4, "  Running: %s", command);
    473         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     473        tmp = call_program_and_get_last_line_of_output(command);
    474474        mr_free(command);
    475475        if (strlen(tmp)) {
     
    480480                mr_asprintf(command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
    481481                log_msg(4, "  Running: %s", command);
    482                 strcpy(VG, call_program_and_get_last_line_of_output(command));
     482                VG = call_program_and_get_last_line_of_output(command);
    483483                mr_free(command);
    484484                log_msg(4, "  Volume Group: %s", VG);
     
    488488                    mr_asprintf(command, "mount 2>/dev/null|grep -E \"/dev/mapper/%s-|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'", VG, VG);
    489489                    log_msg(4, "  Running: %s", command);
    490                     mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
     490                    mount_list = call_program_and_get_last_line_of_output(command);
    491491                    mr_free(command);
     492
    492493                    log_msg(4, "  VG %s mount_list: %s", VG, mount_list);
    493494                    lastpos = 0;
     
    498499                            mr_free(tmp);
    499500                            mr_free(token);
     501                            mr_free(VG);
    500502                            return (1);
    501503                        }
     
    510512                    mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    511513                    log_msg (5, "Running: %s", command);
    512                     mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
     514                    mount_list = call_program_and_get_last_line_of_output(command);
    513515                    mr_free(command);
    514516                    log_msg(4, "  Software raid device list: %s", mount_list);
     
    518520                        log_msg (5, "Running: %s", command);
    519521                        mr_free(tmp);
    520                         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     522
     523                        tmp = call_program_and_get_last_line_of_output(command);
    521524                        mr_free(command);
     525
    522526                        log_msg(4, "Number of Software raid device: %s", tmp);
    523527                        if (atoi(tmp)) {
     
    527531                                mr_free(tmp);
    528532                                mr_free(token);
     533                                mr_free(VG);
    529534                                return (1);
    530535                            }
     
    537542                    log_msg (4, "Error finding Volume Group for partition %s", partitions[i]);
    538543                    mr_free(tmp);
     544                    mr_free(VG);
    539545                    return (1);
    540546                }
    541547                mr_free(tmp);
     548                mr_free(VG);
    542549                continue;
    543550            }
     
    552559        mr_asprintf(command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);
    553560        log_msg(4, "  Running: %s", command);
    554         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     561        tmp = call_program_and_get_last_line_of_output(command);
    555562        mr_free(command);
    556563        if (!strlen(tmp)) {
     
    563570        mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    564571        log_msg (5, "  Running: %s", command);
    565         mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
     572        mount_list = call_program_and_get_last_line_of_output(command);
    566573        mr_free(command);
    567574        log_msg(4, "  Software raid device list: %s", mount_list);
     
    572579            log_msg(4, "  Running: %s", command);
    573580            mr_free(tmp);
    574             mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     581            tmp = call_program_and_get_last_line_of_output(command);
    575582            mr_free(command);
    576583            if (!atoi(tmp)) {
     
    10091016        mr_asprintf(tmp1, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_mount);
    10101017        mr_free(bkpinfo->isodir);
    1011         mr_asprintf(bkpinfo->isodir, "%s", call_program_and_get_last_line_of_output(tmp1));
     1018        bkpinfo->isodir = call_program_and_get_last_line_of_output(tmp1);
    10121019        mr_free(tmp1);
    10131020
     
    10271034                mr_asprintf(tmp1, "mount | grep -E \"^%s[/]* .*\" | cut -d' ' -f3", bkpinfo->netfs_mount);
    10281035                mr_free(bkpinfo->isodir);
    1029                 mr_asprintf(bkpinfo->isodir, "%s", call_program_and_get_last_line_of_output(tmp1));
     1036                bkpinfo->isodir = call_program_and_get_last_line_of_output(tmp1);
    10301037                mr_free(tmp1);
    10311038
Note: See TracChangeset for help on using the changeset viewer.