Changeset 3610 in MondoRescue for branches/3.2/mondo/src/common/libmondo-devices.c
- Timestamp:
- Nov 5, 2016, 6:12:23 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mondo/src/common/libmondo-devices.c
r3604 r3610 135 135 bool is_this_a_ramdisk = FALSE; 136 136 137 mr_asprintf(tmp, "%s", where_is_root_mounted());137 tmp = where_is_root_mounted(); 138 138 log_msg(0, "root is mounted at %s", tmp); 139 139 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); … … 544 544 if (find_home_of_exe(cdr_exe)) { 545 545 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); 547 547 mr_free(command); 548 548 } … … 550 550 mr_free(tmp); 551 551 mr_free(cdr_exe); 552 return 1;552 return (1); 553 553 } else { 554 554 strcpy(cdrw_device, tmp); … … 754 754 } 755 755 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); 757 757 if (system(tmp) == 0) { 758 758 log_msg(4, "%s is not right. It's being SCSI-emulated. Continuing.", output); … … 847 847 848 848 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); 850 850 mr_free(command); 851 851 … … 883 883 } 884 884 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"); 886 886 log_msg(5, "tmp = '%s'", tmp); 887 887 if (!tmp[0]) { 888 888 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"); 890 890 } 891 891 if (tmp[0]) { … … 1153 1153 { 1154 1154 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; 1157 1158 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) { 1159 1162 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); 1162 1166 if (vndev > 10) { 1167 mr_free(tmp); 1168 mr_free(mddevice); 1169 mr_free(command); 1163 1170 return NULL; 1164 1171 } … … 1166 1173 while (system(command)); 1167 1174 } else { 1168 sprintf(command, "mdconfig -a -t vnode -f %s", fname);1175 mr_asprintf(command, "mdconfig -a -t vnode -f %s", fname); 1169 1176 mddevice = call_program_and_get_last_line_of_output(command); 1170 1177 if (!strstr(mddevice, "md")) { 1178 mr_free(tmp); 1179 mr_free(command); 1180 mr_free(mddevice); 1171 1181 return NULL; 1172 1182 } 1173 1183 } 1184 mr_free(tmp); 1185 mr_free(command); 1174 1186 sprintf(device, "/dev/%s", mddevice); 1187 mr_free(mddevice); 1175 1188 return device; 1176 1189 } … … 1189 1202 { 1190 1203 char *command = NULL; 1204 char *tmp = NULL; 1191 1205 int res = 0; 1192 1206 … … 1195 1209 } 1196 1210 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) { 1198 1213 mr_asprintf(command, "vnconfig -d %s", dname); 1199 1214 } else { 1200 1215 mr_asprintf(command, "mdconfig -d -u %s", dname); 1201 1216 } 1217 mr_free(tmp); 1202 1218 res = system(command); 1203 1219 mr_free(command); … … 1632 1648 mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l"); 1633 1649 log_msg(5, "Running: %s", command); 1634 m r_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); 1635 1651 mr_free(command); 1636 1652 … … 1642 1658 mr_asprintf(command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i); 1643 1659 log_msg(5, "Running: %s", command); 1644 m r_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); 1645 1661 mr_free(command); 1646 1662 … … 1722 1738 mr_asprintf(command, "ls -al %s 2>/dev/null | wc -l", dsf); 1723 1739 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); 1725 1741 mr_free(command); 1726 1742 … … 1748 1764 mr_asprintf(command, "mr-parted2fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf); 1749 1765 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); 1751 1767 mr_free(command); 1752 1768 log_msg(4, "Partition list for %s: %s", dsf, partition_list); … … 1814 1830 mr_asprintf(command, "mr-parted2fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", ndsf, partitions[i]); 1815 1831 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); 1817 1833 mr_free(command); 1818 1834 … … 1828 1844 /* It's not swap. See if we can find the mount point from the mount command. */ 1829 1845 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); 1831 1847 mr_free(command); 1832 1848 … … 1850 1866 mr_asprintf(command, "pvdisplay -c %s 2> /dev/null", partitions[i]); 1851 1867 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); 1853 1869 mr_free(command); 1854 1870 … … 1858 1874 mr_asprintf(command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]); 1859 1875 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); 1861 1877 mr_free(command); 1862 1878 … … 1867 1883 mr_asprintf(command, "mount 2>/dev/null|grep -E \"/dev/mapper/%s|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'", VG, VG); 1868 1884 log_msg(5, " Running: %s", command); 1869 m r_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); 1870 1886 mr_free(command); 1871 1887 … … 1891 1907 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); 1892 1908 log_msg (5, "Running: %s", command); 1893 m r_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); 1894 1910 mr_free(command); 1895 1911 log_msg(4, " Software raid device list: %s", mount_list); … … 1899 1915 log_msg (5, "Running: %s", command); 1900 1916 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); 1902 1918 mr_free(command); 1903 1919 log_msg(4, "Number of Software raid device: %s", tmp); … … 1934 1950 mr_asprintf(command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]); 1935 1951 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); 1937 1953 mr_free(command); 1938 1954 … … 1947 1963 mr_asprintf(command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); 1948 1964 log_msg (5, " Running: %s", command); 1949 m r_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); 1950 1966 mr_free(command); 1951 1967 … … 1957 1973 log_msg(4, " Running: %s", command); 1958 1974 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); 1960 1976 mr_free(command); 1961 1977 … … 2196 2212 */ 2197 2213 #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"); 2199 2215 #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"); 2201 2217 #endif 2202 2218 … … 2432 2448 /* Initiate bkpinfo netfs_mount path from running environment if not already done */ 2433 2449 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"); 2435 2451 } 2436 2452 #ifdef __FreeBSD__ … … 2472 2488 } 2473 2489 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); 2475 2493 mr_free(command); 2476 2494 … … 2535 2553 /* Initiate bkpinfo isodir path from running environment if mount already done */ 2536 2554 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); 2538 2558 } else { 2539 2559 // Why netfsdir ? … … 2641 2661 mr_free(bkpinfo->boot_device); 2642 2662 #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/'"); 2644 2664 #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].*//'"); 2646 2666 #endif 2647 2667 i = which_boot_loader(bkpinfo->boot_device); … … 2706 2726 mr_free(tmp); 2707 2727 // 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); 2709 2731 if (strlen(tmp1) > 2) { 2710 2732 if (!popup_and_get_string("NTFS partitions", "Please enter/confirm the NTFS partitions you wish to backup as well.", tmp1, MAX_STR_LEN / 4)) { … … 2884 2906 * Get a |-separated list of NETFS mounts. 2885 2907 * @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 2887 2910 * @bug Even though we only want the mounts, the devices are still checked. 2888 2911 */ … … 2891 2914 char *exclude_these_directories = NULL; 2892 2915 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;}'"); 2894 2917 log_msg(9,"list_of_NETFS_mounts_only returns %s",exclude_these_directories); 2895 2918 return(exclude_these_directories); … … 2988 3011 // log_it("Asking what_number_cd_is_this"); 2989 3012 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); 2993 3016 cd_number = atoi(last_line_of_file(mountdev)); 2994 paranoid_free(mountdev); 2995 paranoid_free(tmp); 3017 mr_free(mountdev); 2996 3018 2997 3019 return (cd_number); … … 3011 3033 } 3012 3034 } 3013 paranoid_free(mountdev);3035 mr_free(mountdev); 3014 3036 3015 3037 cd_number = atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER")); … … 3021 3043 * Find out what device is mounted as root (/). 3022 3044 * @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 3024 3047 * @bug A bit of a misnomer; it's actually finding out the root device. 3025 3048 * The mountpoint (where it's mounted) will obviously be '/'. … … 3028 3051 3029 3052 /*@ buffers **************** */ 3030 static char tmp[MAX_STR_LEN]; 3031 3053 char *tmp = NULL; 3032 3054 3033 3055 #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"); 3035 3057 #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]//"); 3037 3059 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"); 3039 3062 } 3040 3063 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"); 3042 3066 } 3043 3067 #endif … … 3131 3155 assert(which_device != NULL); 3132 3156 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); 3134 3159 log_it("list_drives_cmd = %s", list_drives_cmd); 3135 3160 mr_free(tmp); 3136 3161 if (!(pdrives = popen(list_drives_cmd, "r"))) { 3137 3162 log_OS_error("Unable to open list of drives"); … … 3276 3301 log_msg(1, "curr_fname = %s", curr_fname); 3277 3302 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); 3279 3304 mr_free(command); 3280 3305 for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' '; … … 3318 3343 char *output = NULL; 3319 3344 char *command = NULL; 3345 3320 3346 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); 3322 3348 mr_free(command); 3323 3349
Note:
See TracChangeset
for help on using the changeset viewer.