Ignore:
Timestamp:
Nov 5, 2016, 6:12:23 PM (7 years ago)
Author:
Bruno Cornec
Message:
  • Change interfaces for the call_program_and_get_last_line_of_output and where_is_root_mounted(now return dynamically allocated string)
  • removes useless function store_netfs_config
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mondo/src/common/libmondo-devices.c

    r3604 r3610  
    135135    bool is_this_a_ramdisk = FALSE;
    136136
    137     mr_asprintf(tmp, "%s", where_is_root_mounted());
     137    tmp = where_is_root_mounted();
    138138    log_msg(0, "root is mounted at %s", tmp);
    139139    log_msg(0, "That doesn't mean %s is the root partition. It's just a debugging message. Relax. It's part of am_I_in_disaster_recovery_mode().", tmp);
     
    544544    if (find_home_of_exe(cdr_exe)) {
    545545        mr_asprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -E '[D|C][V|D]' | cut -d' ' -f2 | head -n1", cdr_exe);
    546         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     546        tmp = call_program_and_get_last_line_of_output(command);
    547547        mr_free(command);
    548548    }
     
    550550        mr_free(tmp);
    551551        mr_free(cdr_exe);
    552         return 1;
     552        return (1);
    553553    } else {
    554554        strcpy(cdrw_device, tmp);
     
    754754    }
    755755    if (found_it) {
    756         sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", strrchr(output, '/') + 1);
     756        sprintf(tmp, "grep \"%s=ide-scsi\" "CMDLINE" &> /dev/null", strrchr(output, '/') + 1);
    757757        if (system(tmp) == 0) {
    758758            log_msg(4, "%s is not right. It's being SCSI-emulated. Continuing.", output);
     
    847847
    848848    log_msg(1, "command=%s", command);
    849     mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output(command));
     849    tmp1 = call_program_and_get_last_line_of_output(command);
    850850    mr_free(command);
    851851
     
    883883    }
    884884
    885     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("dvdrecord -scanbus 2> /dev/null | grep -E '\)\ \'' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1"));
     885    tmp = call_program_and_get_last_line_of_output("dvdrecord -scanbus 2> /dev/null | grep -E '\)\ \'' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1");
    886886    log_msg(5, "tmp = '%s'", tmp);
    887887    if (!tmp[0]) {
    888888        mr_free(tmp);
    889         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("cdrecord -scanbus 2> /dev/null | grep -E '\)\ \'' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1"));
     889        tmp = call_program_and_get_last_line_of_output("cdrecord -scanbus 2> /dev/null | grep -E '\)\ \'' | grep -n '' | grep -E '[D|C][V|D]' | cut -d':' -f1");
    890890    }
    891891    if (tmp[0]) {
     
    11531153{
    11541154    char *device = (char *) malloc(MAX_STR_LEN);
    1155     char *mddevice = (char *) malloc(32);
    1156     char command[MAX_STR_LEN];
     1155    char *mddevice = NULL;
     1156    char *command = NULL;
     1157    char *tmp = NULL;
    11571158    int vndev = 2;
    1158     if (atoi(call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate")) < 500000) {
     1159
     1160    tmp = call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate");
     1161    if (atoi(tmp) < 500000) {
    11591162        do {
    1160             sprintf(mddevice, "vn%ic", vndev++);
    1161             sprintf(command, "vnconfig %s %s", mddevice, fname);
     1163            mr_asprintf(mddevice, "vn%ic", vndev++);
     1164            mr_free(command);
     1165            mr_asprintf(command, "vnconfig %s %s", mddevice, fname);
    11621166            if (vndev > 10) {
     1167                mr_free(tmp);
     1168                mr_free(mddevice);
     1169                mr_free(command);
    11631170                return NULL;
    11641171            }
     
    11661173        while (system(command));
    11671174    } else {
    1168         sprintf(command, "mdconfig -a -t vnode -f %s", fname);
     1175        mr_asprintf(command, "mdconfig -a -t vnode -f %s", fname);
    11691176        mddevice = call_program_and_get_last_line_of_output(command);
    11701177        if (!strstr(mddevice, "md")) {
     1178            mr_free(tmp);
     1179            mr_free(command);
     1180            mr_free(mddevice);
    11711181            return NULL;
    11721182        }
    11731183    }
     1184    mr_free(tmp);
     1185    mr_free(command);
    11741186    sprintf(device, "/dev/%s", mddevice);
     1187    mr_free(mddevice);
    11751188    return device;
    11761189}
     
    11891202{
    11901203    char *command = NULL;
     1204    char *tmp = NULL;
    11911205    int res = 0;
    11921206
     
    11951209    }
    11961210
    1197     if (atoi(call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate")) < 500000) {
     1211    tmp = call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate");
     1212    if (atoi(tmp) < 500000) {
    11981213        mr_asprintf(command, "vnconfig -d %s", dname);
    11991214    } else {
    12001215        mr_asprintf(command, "mdconfig -d -u %s", dname);
    12011216    }
     1217    mr_free(tmp);
    12021218    res = system(command);
    12031219    mr_free(command);
     
    16321648    mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l");
    16331649    log_msg(5, "Running: %s", command);
    1634     mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
     1650    mounted_file_system = call_program_and_get_last_line_of_output(command);
    16351651    mr_free(command);
    16361652
     
    16421658        mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i);
    16431659        log_msg(5, "Running: %s", command);
    1644         mr_asprintf(mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));
     1660        mounted_file_system = call_program_and_get_last_line_of_output(command);
    16451661        mr_free(command);
    16461662
     
    17221738    mr_asprintf(command, "ls -al %s 2>/dev/null | wc -l", dsf);
    17231739    log_msg(5, "  Executing: %s", command);
    1724     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     1740    tmp = call_program_and_get_last_line_of_output(command);
    17251741    mr_free(command);
    17261742
     
    17481764    mr_asprintf(command, "mr-parted2fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf);
    17491765    log_msg(5, "Executing: %s", command);
    1750     mr_asprintf(partition_list, "%s", call_program_and_get_last_line_of_output(command));
     1766    partition_list = call_program_and_get_last_line_of_output(command);
    17511767    mr_free(command);
    17521768    log_msg(4, "Partition list for %s: %s", dsf, partition_list);
     
    18141830        mr_asprintf(command, "mr-parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", ndsf, partitions[i]);
    18151831        log_msg(5, "  Running: %s", command);
    1816         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     1832        tmp = call_program_and_get_last_line_of_output(command);
    18171833        mr_free(command);
    18181834
     
    18281844        /* It's not swap. See if we can find the mount point from the mount command. */
    18291845        mr_asprintf(command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);
    1830         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     1846        tmp = call_program_and_get_last_line_of_output(command);
    18311847        mr_free(command);
    18321848
     
    18501866        mr_asprintf(command, "pvdisplay -c %s 2> /dev/null", partitions[i]);
    18511867        log_msg(5, "  Running: %s", command);
    1852         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     1868        tmp = call_program_and_get_last_line_of_output(command);
    18531869        mr_free(command);
    18541870
     
    18581874            mr_asprintf(command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);
    18591875            log_msg(5, "  Running: %s", command);
    1860             mr_asprintf(VG, "%s", call_program_and_get_last_line_of_output(command));
     1876            VG = call_program_and_get_last_line_of_output(command);
    18611877            mr_free(command);
    18621878
     
    18671883                mr_asprintf(command, "mount 2>/dev/null|grep -E \"/dev/mapper/%s|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'", VG, VG);
    18681884                log_msg(5, "  Running: %s", command);
    1869                 mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
     1885                mount_list = call_program_and_get_last_line_of_output(command);
    18701886                mr_free(command);
    18711887
     
    18911907                mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    18921908                log_msg (5, "Running: %s", command);
    1893                 mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
     1909                mount_list = call_program_and_get_last_line_of_output(command);
    18941910                mr_free(command);
    18951911                log_msg(4, "  Software raid device list: %s", mount_list);
     
    18991915                    log_msg (5, "Running: %s", command);
    19001916                    mr_free(tmp);
    1901                     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     1917                    tmp = call_program_and_get_last_line_of_output(command);
    19021918                    mr_free(command);
    19031919                    log_msg(4, "Number of Software raid device: %s", tmp);
     
    19341950        mr_asprintf(command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);
    19351951        log_msg(4, "  Running: %s", command);
    1936         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     1952        tmp = call_program_and_get_last_line_of_output(command);
    19371953        mr_free(command);
    19381954
     
    19471963        mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'");
    19481964        log_msg (5, "  Running: %s", command);
    1949         mr_asprintf(mount_list, "%s", call_program_and_get_last_line_of_output(command));
     1965        mount_list = call_program_and_get_last_line_of_output(command);
    19501966        mr_free(command);
    19511967
     
    19571973            log_msg(4, "  Running: %s", command);
    19581974            mr_free(tmp);
    1959             mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     1975            tmp = call_program_and_get_last_line_of_output(command);
    19601976            mr_free(command);
    19611977
     
    21962212         */
    21972213#ifdef __FreeBSD__
    2198         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("df -m -P -t nonfs,msdosfs,ntfs,ntfs-3g,vmhgfs,smbfs,smb,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -nr | awk '{print $NF;}' | while read x ; do test -w $x && echo $x && break ; done"));
     2214        tmp = call_program_and_get_last_line_of_output("df -m -P -t nonfs,msdosfs,ntfs,ntfs-3g,vmhgfs,smbfs,smb,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -nr | awk '{print $NF;}' | while read x ; do test -w $x && echo $x && break ; done");
    21992215#else
    2200         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("df -m -P -x nfs -x nfs4 -x fuse.sshfs -x fuse -x vfat -x ntfs -x ntfs-3g -x vmhgfs -x smbfs -x smb -x cifs -x afs -x gfs -x ocfs -x ocfs2 -x mvfs -x nsspool -x nssvol -x iso9660 | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -nr | awk '{print $NF;}' | while read x ; do test -w $x && echo $x && break ; done"));
     2216        tmp = call_program_and_get_last_line_of_output("df -m -P -x nfs -x nfs4 -x fuse.sshfs -x fuse -x vfat -x ntfs -x ntfs-3g -x vmhgfs -x smbfs -x smb -x cifs -x afs -x gfs -x ocfs -x ocfs2 -x mvfs -x nsspool -x nssvol -x iso9660 | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -nr | awk '{print $NF;}' | while read x ; do test -w $x && echo $x && break ; done");
    22012217#endif
    22022218
     
    24322448        /* Initiate bkpinfo netfs_mount path from running environment if not already done */
    24332449        if (bkpinfo->netfs_mount == NULL) {
    2434             mr_asprintf(bkpinfo->netfs_mount, "%s", call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1"));
     2450            bkpinfo->netfs_mount = call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1");
    24352451        }
    24362452#ifdef __FreeBSD__
     
    24722488            }
    24732489            mr_asprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", tmp1);
    2474             strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(command));
     2490            tmp = call_program_and_get_last_line_of_output(command);
     2491            strcpy(bkpinfo->isodir, tmp);
     2492            mr_free(tmp);
    24752493            mr_free(command);
    24762494
     
    25352553        /* Initiate bkpinfo isodir path from running environment if mount already done */
    25362554        if (is_this_device_mounted(bkpinfo->netfs_mount)) {
    2537             strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f3 | head -n1"));
     2555            tmp = call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f3 | head -n1");
     2556            strcpy(bkpinfo->isodir, tmp);
     2557            mr_free(tmp);
    25382558        } else {
    25392559            // Why netfsdir ?
     
    26412661        mr_free(bkpinfo->boot_device);
    26422662#ifdef __FreeBSD__
    2643         mr_asprintf(bkpinfo->boot_device, "%s", call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'"));
     2663        bkpinfo->boot_device = call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'");
    26442664#else
    2645         mr_asprintf(bkpinfo->boot_device, "%s", call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'"));
     2665        bkpinfo->boot_device = call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'");
    26462666#endif
    26472667        i = which_boot_loader(bkpinfo->boot_device);
     
    27062726        mr_free(tmp);
    27072727// NTFS
    2708         strcpy(tmp1, call_program_and_get_last_line_of_output("mr-parted2fdisk -l 2>/dev/null | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'"));
     2728        tmp = call_program_and_get_last_line_of_output("mr-parted2fdisk -l 2>/dev/null | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'");
     2729        strncpy(tmp1, tmp, MAX_STR_LEN / 4);
     2730        mr_free(tmp);
    27092731        if (strlen(tmp1) > 2) {
    27102732            if (!popup_and_get_string("NTFS partitions", "Please enter/confirm the NTFS partitions you wish to backup as well.", tmp1, MAX_STR_LEN / 4)) {
     
    28842906 * Get a |-separated list of NETFS mounts.
    28852907 * @return The list created.
    2886  * @note The return value points to allocated string that needs to be freed
     2908 * @note The return value points to allocated string that needs to be freed by
     2909 * caller
    28872910 * @bug Even though we only want the mounts, the devices are still checked.
    28882911 */
     
    28912914    char *exclude_these_directories = NULL;
    28922915
    2893     mr_asprintf(exclude_these_directories,"%s", call_program_and_get_last_line_of_output("mount -t coda,ncpfs,fuse.sshfs,nfs,nfs4,vmhgfs,smbfs,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' '|' | awk '{print $0;}'"));
     2916    exclude_these_directories = call_program_and_get_last_line_of_output("mount -t coda,ncpfs,fuse.sshfs,nfs,nfs4,vmhgfs,smbfs,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' '|' | awk '{print $0;}'");
    28942917    log_msg(9,"list_of_NETFS_mounts_only returns %s",exclude_these_directories);
    28952918    return(exclude_these_directories);
     
    29883011//  log_it("Asking what_number_cd_is_this");
    29893012    if (g_ISO_restore_mode) {
    2990         mr_asprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'");
    2991 
    2992         mr_asprintf(mountdev, "%s%s", call_program_and_get_last_line_of_output(tmp), "/archives/THIS-CD-NUMBER");
     3013        tmp = call_program_and_get_last_line_of_output("mount | grep iso9660 | awk '{print $3;}'");
     3014        mr_asprintf(mountdev, "%s%s", tmp, "/archives/THIS-CD-NUMBER");
     3015        mr_free(tmp);
    29933016        cd_number = atoi(last_line_of_file(mountdev));
    2994         paranoid_free(mountdev);
    2995         paranoid_free(tmp);
     3017        mr_free(mountdev);
    29963018
    29973019        return (cd_number);
     
    30113033        }
    30123034    }
    3013     paranoid_free(mountdev);
     3035    mr_free(mountdev);
    30143036
    30153037    cd_number = atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"));
     
    30213043 * Find out what device is mounted as root (/).
    30223044 * @return Root device.
    3023  * @note The returned string points to static storage and will be overwritten with every call.
     3045 * @note The returned string points to storage that needs to be freed by
     3046 * caller
    30243047 * @bug A bit of a misnomer; it's actually finding out the root device.
    30253048 * The mountpoint (where it's mounted) will obviously be '/'.
     
    30283051
    30293052/*@ buffers **************** */
    3030 static char tmp[MAX_STR_LEN];
    3031 
     3053char *tmp = NULL;
    30323054
    30333055#ifdef __FreeBSD__
    3034     strcpy(tmp, call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1"));
     3056    tmp = call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1");
    30353057#else
    3036     strcpy(tmp, call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//"));
     3058    tmp = call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//");
    30373059    if (strstr(tmp, "/dev/cciss/")) {
    3038         strcpy(tmp, call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1"));
     3060        mr_free(tmp);
     3061        tmp = call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1");
    30393062    }
    30403063    if (strstr(tmp, "/dev/md")) {
    3041         strcpy(tmp, call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1"));
     3064        mr_free(tmp);
     3065        tmp = call_program_and_get_last_line_of_output("mount | grep \" on / \" | cut -d' ' -f1");
    30423066    }
    30433067#endif
     
    31313155    assert(which_device != NULL);
    31323156
    3133     mr_asprintf(list_drives_cmd, "mr-parted2fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", where_is_root_mounted());
     3157    tmp = where_is_root_mounted();
     3158    mr_asprintf(list_drives_cmd, "mr-parted2fdisk -l 2>/dev/null | grep \"/dev/.*:\" | tr -s ':' ' ' | tr -s ' ' '\n' | grep /dev/; echo %s", tmp);
    31343159    log_it("list_drives_cmd = %s", list_drives_cmd);
    3135 
     3160    mr_free(tmp);
    31363161    if (!(pdrives = popen(list_drives_cmd, "r"))) {
    31373162        log_OS_error("Unable to open list of drives");
     
    32763301            log_msg(1, "curr_fname = %s", curr_fname);
    32773302            mr_asprintf(command, "file %s", curr_fname);
    3278             mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     3303            tmp = call_program_and_get_last_line_of_output(command);
    32793304            mr_free(command);
    32803305            for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' ';
     
    33183343    char *output = NULL;
    33193344    char *command = NULL;
     3345
    33203346    mr_asprintf(command, "mr-disk-type %s", drive);
    3321     mr_asprintf(output, "%s", call_program_and_get_last_line_of_output(command));
     3347    output = call_program_and_get_last_line_of_output(command);
    33223348    mr_free(command);
    33233349
Note: See TracChangeset for help on using the changeset viewer.