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-devices.c

    r2382 r2383  
    525525    if (tmp1) {
    526526        mr_asprintf(command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep CD | cut -d' ' -f2 | head -n1", cdr_exe);
    527         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     527        tmp = call_program_and_get_last_line_of_output(command);
    528528        mr_free(command);
    529529    }
     
    805805
    806806    log_msg(1, "command=%s", command);
    807     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     807    tmp = call_program_and_get_last_line_of_output(command);
    808808    mr_free(command);
    809809
     
    833833    }
    834834
    835     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("dvdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1"));
     835    tmp = call_program_and_get_last_line_of_output("dvdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1");
    836836    log_msg(5, "tmp = '%s'", tmp);
    837837    if (!tmp[0])
    838838        mr_free(tmp);
    839         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output ("cdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1")
    840             );
     839        tmp = call_program_and_get_last_line_of_output("cdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1");
    841840    if (tmp[0]) {
    842841        devno = atoi(tmp) - 1;
     
    10971096    char *mddevice = (char *) malloc(32);
    10981097    char command[MAX_STR_LEN];
     1098    char *tmp = NULL;
    10991099    int vndev = 2;
    1100     if (atoi
    1101         (call_program_and_get_last_line_of_output
    1102          ("/sbin/sysctl -n kern.osreldate")) < 500000) {
     1100    int i = 2;
     1101
     1102    tmp = call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate"));
     1103    i = atoi(tmp);
     1104    mr_free(tmp);
     1105
     1106    if (i < 500000) {
    11031107        do {
    11041108            sprintf(mddevice, "vn%ic", vndev++);
     
    11331137{
    11341138    char *command = NULL;
     1139    char *tmp = NULL;
    11351140    int res = 0;
     1141    int i = 0;
    11361142
    11371143    if (strncmp(dname, "/dev/", 5) == 0) {
     
    11391145    }
    11401146
    1141     if (atoi
    1142         (call_program_and_get_last_line_of_output
    1143          ("/sbin/sysctl -n kern.osreldate")) < 500000) {
     1147    tmp = call_program_and_get_last_line_of_output("/sbin/sysctl -n kern.osreldate"));
     1148    i = atoi(tmp);
     1149    mr_free(tmp);
     1150
     1151    if (i < 500000) {
    11441152        mr_asprintf(command, "vnconfig -d %s", dname);
    11451153    } else {
     
    16531661        /* Initiate bkpinfo netfs_mount path from running environment if not already done */
    16541662        if (bkpinfo->netfs_mount == NULL) {
    1655             mr_asprintf(bkpinfo->netfs_mount, "%s", call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1"));
     1663            bkpinfo->netfs_mount = call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1");
    16561664        }
    16571665#ifdef __FreeBSD__
     
    16821690            mr_asprintf(command, "mount | grep \"%s \" | cut -d' ' -f3", bkpinfo->netfs_mount);
    16831691            mr_free(bkpinfo->isodir);
    1684             mr_asprintf(bkpinfo->isodir, "%s", call_program_and_get_last_line_of_output(command));
     1692            bkpinfo->isodir = call_program_and_get_last_line_of_output(command);
    16851693            mr_free(command);
    16861694
     
    17221730        mr_free(bkpinfo->isodir);
    17231731        if (is_this_device_mounted(bkpinfo->netfs_mount)) {
    1724             mr_asprintf(bkpinfo->isodir, "%s", call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f3 | head -n1"));
     1732            bkpinfo->isodir = call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f3 | head -n1");
    17251733
    17261734        } else {
     
    18271835#ifdef __FreeBSD__
    18281836#define EXAMPLEBD   "/dev/ad0"
    1829         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/'"));
     1837        bkpinfo->boot_device = call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'");
    18301838#else
    18311839#define EXAMPLEBD   "/dev/hda"
    1832         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].*//'"));
     1840        bkpinfo->boot_device = call_program_and_get_last_line_of_output("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'");
    18331841#endif
    18341842        i = which_boot_loader(bkpinfo->boot_device);
     
    18871895        mr_free(tmp);
    18881896// NTFS
    1889         mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'"));
     1897        tmp = call_program_and_get_last_line_of_output("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'");
    18901898        if (strlen(tmp) > 2) {
    18911899            p = popup_and_get_string("NTFS partitions", "Please enter/confirm the NTFS partitions you wish to backup as well.", tmp);
     
    20302038
    20312039    mr_asprintf(exclude_these_directories,"%s",list_of_NETFS_mounts_only());
    2032     mr_asprintf(exclude_these_devices,"%s", call_program_and_get_last_line_of_output("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|sshfs|nfs|nfs4|smbfs|cifs|afs|gfs|ocfs|ocfs2|mvfs|nsspool|nsvol) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'"));
     2040    exclude_these_devices = call_program_and_get_last_line_of_output("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|sshfs|nfs|nfs4|smbfs|cifs|afs|gfs|ocfs|ocfs2|mvfs|nsspool|nsvol) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'");
    20332041    snprintf(result_sz, 1023, "%s %s", exclude_these_directories, exclude_these_devices);
    20342042    mr_free(exclude_these_devices);
     
    20512059    static char result_sz[512];
    20522060
    2053     mr_asprintf(exclude_these_directories,"%s", call_program_and_get_last_line_of_output("mount -t coda,ncpfs,fuse.sshfs,nfs,nfs4,smbfs,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'"));
     2061    exclude_these_directories = call_program_and_get_last_line_of_output("mount -t coda,ncpfs,fuse.sshfs,nfs,nfs4,smbfs,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'");
    20542062    snprintf(result_sz, 511, "%s", exclude_these_directories);
    20552063    mr_free(exclude_these_directories);
     
    21032111
    21042112#ifdef __FreeBSD__
    2105     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -t nonfs,msdosfs,ntfs,ntfs-3g,smbfs,smb,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"));
     2113    tmp = call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -t nonfs,msdosfs,ntfs,ntfs-3g,smbfs,smb,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'");
    21062114#else
    2107     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -x nfs -x nfs4 -x fuse.sshfs -x vfat -x ntfs -x ntfs-3g -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 -n | tail -n1 | awk '{print $NF;}'"));
     2115    tmp = call_program_and_get_last_line_of_output("LANGUAGE=C df -m -P -x nfs -x nfs4 -x fuse.sshfs -x vfat -x ntfs -x ntfs-3g -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 -n | tail -n1 | awk '{print $NF;}'");
    21082116#endif
    21092117
     
    21992207    if (g_ISO_restore_mode) {
    22002208        mr_asprintf(tmp, "mount | grep iso9660 | awk '{print $3;}'");
    2201         mr_asprintf(mountdev, "%s%s", call_program_and_get_last_line_of_output(tmp), "/archives/THIS-CD-NUMBER");
     2209        mountdev = call_program_and_get_last_line_of_output(tmp);
     2210        mr_strcat(mountdev, "/archives/THIS-CD-NUMBER");
    22022211        mr_free(tmp);
    22032212
     
    22522261
    22532262#ifdef __FreeBSD__
    2254     mr_asprintf(output, "%s", call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1"));
     2263    output = call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1");
    22552264#else
    2256     mr_asprintf(output, "%s", call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1 | sed 's/[0-9]//' | sed 's/[0-9]//'"));
     2265    output = call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1 | sed 's/[0-9]//' | sed 's/[0-9]//'");
    22572266    if (strstr(output, "/dev/cciss/")) {
    22582267        mr_free(output);
    2259         mr_asprintf(output, "%s", call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1 | cut -dp -f1"));
     2268        output = call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1 | cut -dp -f1");
    22602269    }
    22612270    if (strstr(output, "/dev/md")) {
    22622271        mr_free(output);
    2263         mr_asprintf(output, "%s", call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1"));
     2272        output = call_program_and_get_last_line_of_output("mount | grep ' on / ' | cut -d' ' -f1");
    22642273    }
    22652274#endif
     
    24992508            log_msg(1, "curr_fname = %s", curr_fname);
    25002509            mr_asprintf(command, "file %s", curr_fname);
    2501             mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     2510            tmp = call_program_and_get_last_line_of_output(command);
    25022511            mr_free(command);
    25032512            for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' '; p--);
     
    25502559    mr_free(fdisk);
    25512560
    2552     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command));
     2561    tmp = call_program_and_get_last_line_of_output(command);
    25532562    mr_free(command);
    25542563
Note: See TracChangeset for help on using the changeset viewer.