Changeset 2214 in MondoRescue for branches/2.2.9/mondo/src/common/libmondo-devices.c
- Timestamp:
- Jun 3, 2009, 7:10:28 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mondo/src/common/libmondo-devices.c
r2211 r2214 107 107 bool am_I_in_disaster_recovery_mode(void) 108 108 { 109 char *tmp, *comment; 109 char *tmp = NULL; 110 char *comment; 110 111 bool is_this_a_ramdisk = FALSE; 111 112 112 malloc_string(tmp);113 113 malloc_string(comment); 114 strcpy(tmp, where_is_root_mounted());114 mr_asprintf(&tmp, "%s", where_is_root_mounted()); 115 115 sprintf(comment, "root is mounted at %s\n", tmp); 116 116 log_msg(0, comment); … … 133 133 } 134 134 #endif 135 mr_free(tmp); 135 136 136 137 if (is_this_a_ramdisk) { … … 144 145 is_this_a_ramdisk = TRUE; 145 146 } 146 paranoid_free(tmp);147 147 paranoid_free(comment); 148 148 log_msg(1, "Is this a ramdisk? result = %d", is_this_a_ramdisk); … … 513 513 /*@ buffers ************************ */ 514 514 char *comment; 515 char *tmp ;516 char *cdr_exe ;515 char *tmp = NULL; 516 char *cdr_exe = NULL; 517 517 char *command; 518 518 519 519 malloc_string(comment); 520 malloc_string(tmp);521 malloc_string(cdr_exe);522 520 malloc_string(command); 523 521 if (g_cdrw_drive_is_here[0]) { … … 525 523 log_msg(3, "Been there, done that. Returning %s", cdrw_device); 526 524 paranoid_free(comment); 527 paranoid_free(tmp);528 paranoid_free(cdr_exe);529 525 paranoid_free(command); 530 526 return (0); … … 534 530 "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?"); 535 531 paranoid_free(comment); 536 paranoid_free(tmp);537 paranoid_free(cdr_exe);538 532 paranoid_free(command); 539 533 return (1); … … 541 535 run_program_and_log_output("insmod ide-scsi", -1); 542 536 if (find_home_of_exe("cdrecord")) { 543 strcpy(cdr_exe, "cdrecord");537 mr_asprintf(&cdr_exe, "cdrecord"); 544 538 } else { 545 strcpy(cdr_exe, "dvdrecord"); 546 } 547 tmp[0] = '\0'; 539 mr_asprintf(&cdr_exe, "dvdrecord"); 540 } 548 541 if (find_home_of_exe(cdr_exe)) { 549 542 sprintf(command, 550 543 "%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", 551 544 cdr_exe); 552 strcpy(tmp, call_program_and_get_last_line_of_output(command));553 } 554 if ( strlen(tmp) < 2) {545 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 546 } 547 if ((tmp == NULL) || (strlen(tmp) < 2)) { 555 548 paranoid_free(comment); 556 paranoid_free(tmp);557 paranoid_free(cdr_exe);549 mr_free(tmp); 550 mr_free(cdr_exe); 558 551 paranoid_free(command); 559 552 return 1; … … 564 557 strcpy(g_cdrw_drive_is_here, cdrw_device); 565 558 paranoid_free(comment); 566 paranoid_free(tmp);567 paranoid_free(cdr_exe);559 mr_free(tmp); 560 mr_free(cdr_exe); 568 561 paranoid_free(command); 569 562 return (0); … … 597 590 /*@ buffers ***************************************************** */ 598 591 char *tmp; 599 char *cdr_exe; 592 char *tmp1 = NULL; 593 char *cdr_exe = NULL; 600 594 char *phrase_one; 601 595 char *phrase_two; … … 607 601 /*@ intialize *************************************************** */ 608 602 malloc_string(tmp); 609 malloc_string(cdr_exe);610 603 malloc_string(phrase_one); 611 604 malloc_string(phrase_two); … … 640 633 641 634 if (find_home_of_exe("cdrecord")) { 642 strcpy(cdr_exe, "cdrecord");635 mr_asprintf(&cdr_exe, "cdrecord"); 643 636 } else { 644 strcpy(cdr_exe, "dvdrecord");637 mr_asprintf(&cdr_exe, "dvdrecord"); 645 638 } 646 639 tmp[0] = '\0'; … … 663 656 log_msg(4, "command=%s", command); 664 657 log_OS_error("Cannot popen command"); 658 mr_free(cdr_exe); 665 659 return (1); 666 660 } … … 862 856 cdr_exe, g_cdrw_drive_is_here); 863 857 log_msg(1, "command=%s", command); 864 strcpy(tmp, call_program_and_get_last_line_of_output(command));865 if ( tmp[0]) {866 strcpy(output, tmp );858 mr_asprintf(&tmp1, "%s", call_program_and_get_last_line_of_output(command)); 859 if (strlen(tmp1) > 0) { 860 strcpy(output, tmp1); 867 861 log_msg(4, "Finally found it at %s", output); 868 862 retval = 0; 869 goto end_of_find_cdrom_device;870 863 } else { 871 864 log_msg(4, "Still couldn't find it."); 872 865 retval = 1; 873 goto end_of_find_cdrom_device; 874 } 866 } 867 mr_free(tmp1); 868 875 869 end_of_find_cdrom_device: 876 870 paranoid_free(tmp); 877 paranoid_free(cdr_exe);871 mr_free(cdr_exe); 878 872 paranoid_free(phrase_one); 879 873 paranoid_free(phrase_two); … … 1103 1097 /*@ buffers ***************************************************** */ 1104 1098 char *incoming; 1105 char *device_with_tab ;1106 char *device_with_space ;1107 char *tmp ;1108 int retval = 0;1099 char *device_with_tab = NULL; 1100 char *device_with_space = NULL; 1101 char *tmp = NULL; 1102 bool retval = FALSE; 1109 1103 1110 1104 #ifdef __FreeBSD__ … … 1117 1111 1118 1112 malloc_string(incoming); 1119 malloc_string(device_with_tab);1120 malloc_string(device_with_space);1121 malloc_string(tmp);1122 1113 assert(device_raw != NULL); 1123 1114 // assert_string_is_neither_NULL_nor_zerolength(device_raw); … … 1125 1116 log_msg(1, "%s needs to have a '/' prefixed - I'll do it", 1126 1117 device_raw); 1127 sprintf(tmp, "/%s", device_raw);1118 mr_asprintf(&tmp, "/%s", device_raw); 1128 1119 } else { 1129 strcpy(tmp, device_raw);1120 mr_asprintf(&tmp, "%s", device_raw); 1130 1121 } 1131 1122 log_msg(1, "Is %s mounted?", tmp); … … 1133 1124 log_msg(1, 1134 1125 "I don't know how the heck /proc made it into the mountlist. I'll ignore it."); 1135 return (0); 1136 } 1137 sprintf(device_with_tab, "%s\t", tmp); 1138 sprintf(device_with_space, "%s ", tmp); 1126 mr_free(tmp); 1127 return(FALSE); 1128 } 1129 mr_asprintf(&device_with_tab, "%s\t", tmp); 1130 mr_asprintf(&device_with_space, "%s ", tmp); 1131 mr_free(tmp); 1139 1132 1140 1133 if (!(fin = popen("mount", "r"))) { 1141 1134 log_OS_error("Cannot popen 'mount'"); 1142 return 1135 return(FALSE); 1143 1136 } 1144 1137 for ((void)fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin); … … 1148 1141 { 1149 1142 paranoid_pclose(fin); 1150 retval = 1; 1151 goto end_of_func; 1152 } 1153 } 1143 paranoid_free(incoming); 1144 return(TRUE); 1145 } 1146 } 1147 mr_free(device_with_tab); 1148 mr_free(device_with_space); 1154 1149 paranoid_pclose(fin); 1155 sprintf(tmp, "%s | grep -E \"^%s\" > /dev/null 2> /dev/null",1150 mr_asprintf(&tmp, "%s | grep -E \"^%s\" > /dev/null 2> /dev/null", 1156 1151 SWAPLIST_COMMAND, device_with_space); 1157 1152 log_msg(4, "tmp (command) = '%s'", tmp); 1158 1153 if (!system(tmp)) { 1159 retval = 1; 1160 goto end_of_func; 1161 } 1162 end_of_func: 1154 retval = TRUE; 1155 } 1156 mr_free(tmp); 1163 1157 paranoid_free(incoming); 1164 paranoid_free(device_with_tab); 1165 paranoid_free(device_with_space); 1166 paranoid_free(tmp); 1167 return (retval); 1158 return(retval); 1168 1159 } 1169 1160 … … 1245 1236 /*@ buffer ****************************************************** */ 1246 1237 char *command; 1247 char *dev;1248 1238 int retval; 1249 1239 1250 1240 malloc_string(command); 1251 malloc_string(dev);1252 1241 assert_string_is_neither_NULL_nor_zerolength(device); 1253 1242 assert_string_is_neither_NULL_nor_zerolength(mountpoint); … … 1256 1245 if (isdigit(device[0])) { 1257 1246 return(1); 1258 } else {1259 strcpy(dev, device);1260 1247 } 1261 1248 log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device, … … 1276 1263 1277 1264 paranoid_free(command); 1278 paranoid_free(dev);1279 1265 return (retval); 1280 1266 } … … 1482 1468 // archiving_to_media is FALSE if I'm being called by mondorestore 1483 1469 { 1484 char *tmp ;1470 char *tmp = NULL; 1485 1471 char *tmp1 = NULL; 1486 1472 char *sz_size; … … 1491 1477 FILE *fin; 1492 1478 1493 malloc_string(tmp);1494 1479 malloc_string(sz_size); 1495 1480 malloc_string(command); … … 1553 1538 if (bkpinfo->backup_media_type == dvd) { 1554 1539 find_dvd_device(bkpinfo->media_device, FALSE); 1555 strcpy(tmp, "1");1540 mr_asprintf(&tmp, "1"); 1556 1541 sprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4482 MB 1557 1542 log_msg(1, "Setting to DVD defaults"); 1558 1543 } else { 1559 1544 strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM); 1560 strcpy(tmp, "4");1545 mr_asprintf(&tmp, "4"); 1561 1546 strcpy(sz_size, "650"); 1562 1547 log_msg(1, "Setting to CD defaults"); … … 1569 1554 } 1570 1555 bkpinfo->cdrw_speed = atoi(tmp); // if DVD then this shouldn't ever be used anyway :) 1556 mr_free(tmp); 1557 1571 1558 sprintf(comment, 1572 1559 "How much data (in Megabytes) will each %s store?", … … 1620 1607 if (bkpinfo->media_device[0]) { 1621 1608 if (bkpinfo->backup_media_type == usb) { 1622 sprintf(tmp,1609 mr_asprintf(&tmp, 1623 1610 "I think your %s media corresponds to %s. Is this correct?", 1624 1611 media_descriptor_string(bkpinfo->backup_media_type), 1625 1612 bkpinfo->media_device); 1626 1613 } else { 1627 sprintf(tmp,1614 mr_asprintf(&tmp, 1628 1615 "I think I've found your %s burner at SCSI node %s. Is this correct? (Say no if you have an IDE burner and you are running a 2.6 kernel. You will then be prompted for further details.)", 1629 1616 media_descriptor_string(bkpinfo->backup_media_type), … … 1633 1620 bkpinfo->media_device[0] = '\0'; 1634 1621 } 1622 mr_free(tmp); 1635 1623 } 1636 1624 if (!bkpinfo->media_device[0]) { … … 1691 1679 } 1692 1680 } 1693 sprintf(tmp,1694 "I think I've found your tape streamer at %s; am I right on the money?",1695 bkpinfo->media_device);1696 1681 } 1697 1682 if (bkpinfo->media_device[0]) { 1698 sprintf(tmp,1683 mr_asprintf(&tmp, 1699 1684 "I think I've found your tape streamer at %s; am I right on the money?", 1700 1685 bkpinfo->media_device); … … 1702 1687 bkpinfo->media_device[0] = '\0'; 1703 1688 } 1689 mr_free(tmp); 1704 1690 } 1705 1691 if (!bkpinfo->media_device[0]) { … … 1712 1698 } 1713 1699 } 1714 sprintf(tmp, "ls -l %s", bkpinfo->media_device);1700 mr_asprintf(&tmp, "ls -l %s", bkpinfo->media_device); 1715 1701 if (run_program_and_log_output(tmp, FALSE)) { 1716 1702 log_to_screen("User has not specified a valid /dev entry"); 1717 1703 finish(1); 1718 1704 } 1705 mr_free(tmp); 1719 1706 log_msg(4, "sz_size = %s", sz_size); 1720 1707 sz_size[0] = '\0'; 1721 /* 1722 if ((size_sz[0]=='\0' || atol(size_sz)==0) && archiving_to_media) 1723 { 1724 if (!popup_and_get_string("Tape size", "How much COMPRESSED data will one of your tape cartridges hold? (e.g. 4GB for 4 gigabytes)", size_sz, 16)) 1725 { log_to_screen("User has chosen not to backup the PC"); finish(1); } 1726 } 1727 */ 1708 1728 1709 bkpinfo->use_obdr = ask_me_yes_or_no 1729 1710 ("Do you want to activate OBDR support for your tapes ?"); … … 1829 1810 sprintf(command, "mkdir -p %s", bkpinfo->isodir); 1830 1811 run_program_and_log_output(command, 5); 1831 sprintf(tmp, "mount -t nfs -o nolock %s %s", bkpinfo->nfs_mount,1812 mr_asprintf(&tmp, "mount -t nfs -o nolock %s %s", bkpinfo->nfs_mount, 1832 1813 bkpinfo->isodir); 1833 1814 run_program_and_log_output(tmp, 3); 1815 mr_free(tmp); 1816 1834 1817 malloc_string(g_selfmounted_isodir); 1835 1818 strcpy(g_selfmounted_isodir, bkpinfo->isodir); … … 1840 1823 finish(1); 1841 1824 } 1842 strcpy(tmp, bkpinfo->nfs_remote_dir);1825 mr_asprintf(&tmp, bkpinfo->nfs_remote_dir); 1843 1826 if (!popup_and_get_string 1844 1827 ("Directory", "Which directory within that mountpoint?", tmp, … … 1848 1831 } 1849 1832 strcpy(bkpinfo->nfs_remote_dir, tmp); 1833 mr_free(tmp); 1834 1850 1835 // check whether writable - we better remove surrounding spaces for this 1851 1836 strip_spaces(bkpinfo->nfs_remote_dir); … … 1981 1966 finish(1); 1982 1967 } 1983 strcpy(tmp, list_of_NFS_mounts_only());1968 mr_asprintf(&tmp, "%s", list_of_NFS_mounts_only()); 1984 1969 if (strlen(tmp) > 2) { 1985 1970 if (bkpinfo->exclude_paths[0]) { … … 1988 1973 strncpy(bkpinfo->exclude_paths, tmp, MAX_STR_LEN); 1989 1974 } 1975 mr_free(tmp); 1990 1976 // NTFS 1991 strcpy(tmp,1977 mr_asprintf(&tmp, "%s", 1992 1978 call_program_and_get_last_line_of_output 1993 1979 ("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'")); … … 2002 1988 strncpy(bkpinfo->image_devs, tmp, MAX_STR_LEN / 4); 2003 1989 } 1990 mr_free(tmp); 2004 1991 2005 1992 … … 2047 2034 #else 2048 2035 if (bkpinfo->backup_media_type == nfs) { 2049 sprintf(tmp, "mount | grep \"%s\" | cut -d' ' -f3",2050 bkpinfo->nfs_mount);2051 // strcpy(bkpinfo->isodir, call_program_and_get_last_line_of_output(tmp));2052 2036 log_msg(3, "I think the NFS mount is mounted at %s", 2053 2037 bkpinfo->isodir); … … 2078 2062 } 2079 2063 } 2080 paranoid_free(tmp);2081 2064 paranoid_free(sz_size); 2082 2065 paranoid_free(command); … … 2100 2083 char *list_of_NFS_devices_and_mounts(void) 2101 2084 { 2102 char *exclude_these_devices ;2103 char *exclude_these_directories ;2085 char *exclude_these_devices = NULL; 2086 char *exclude_these_directories = NULL; 2104 2087 static char result_sz[1024]; 2105 2088 2106 malloc_string(exclude_these_devices); 2107 malloc_string(exclude_these_directories); 2108 strcpy(exclude_these_directories,list_of_NFS_mounts_only()); 2109 strcpy(exclude_these_devices, 2089 mr_asprintf(exclude_these_directories,"%s",list_of_NFS_mounts_only()); 2090 mr_asprintf(exclude_these_devices,"%s", 2110 2091 call_program_and_get_last_line_of_output 2111 2092 ("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|nfs|nfs4|smbfs|cifs|afs|gfs|ocfs|ocfs2|mvfs|nsspool|nsvol) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'")); 2112 s printf(result_sz, "%s %s", exclude_these_directories,2113 exclude_these_devices );2114 paranoid_free(exclude_these_devices);2115 paranoid_free(exclude_these_directories);2093 snprintf(result_sz, "%s %s", exclude_these_directories, 2094 exclude_these_devices, 1023); 2095 mr_free(exclude_these_devices); 2096 mr_free(exclude_these_directories); 2116 2097 return (result_sz); 2117 2098 } … … 2128 2109 char *list_of_NFS_mounts_only(void) 2129 2110 { 2130 char *exclude_these_directories ;2111 char *exclude_these_directories = NULL; 2131 2112 static char result_sz[512]; 2132 2113 2133 malloc_string(exclude_these_directories); 2134 strcpy(exclude_these_directories, 2114 mr_asprintf(&exclude_these_directories,"%s", 2135 2115 call_program_and_get_last_line_of_output 2136 2116 ("mount -t coda,ncpfs,nfs,nfs4,smbfs,cifs,afs,gfs,ocfs,ocfs2,mvfs,nsspool,nssvol | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'")); 2137 s printf(result_sz, "%s", exclude_these_directories);2138 paranoid_free(exclude_these_directories);2117 snprintf(result_sz, "%s", exclude_these_directories, 511); 2118 mr_free(exclude_these_directories); 2139 2119 return (result_sz); 2140 2120 } … … 2183 2163 { 2184 2164 char *tmp = NULL; 2185 char *command, *sz; 2186 2187 malloc_string(command); 2188 malloc_string(sz); 2165 char *command = NULL; 2166 char *sz = NULL; 2167 2189 2168 assert(bkpinfo != NULL); 2190 2169 … … 2200 2179 2201 2180 if (tmp[0] != '/') { 2202 strcpy(sz, tmp);2181 mr_asprintf(&sz, tmp); 2203 2182 paranoid_free(tmp); 2204 2183 mr_asprintf(&tmp, "/%s", sz); 2184 mr_free(sz); 2205 2185 } 2206 2186 if (!tmp[0]) { … … 2214 2194 log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir); 2215 2195 2216 sprintf(command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp);2196 mr_asprintf(&command, "rm -Rf %s/tmp.mondo.* %s/mondo.scratch.*", tmp, tmp); 2217 2197 paranoid_free(tmp); 2218 2198 2219 2199 paranoid_system(command); 2220 paranoid_free(command); 2221 paranoid_free(sz); 2200 mr_free(command); 2222 2201 } 2223 2202 … … 2559 2538 char *command; 2560 2539 char *curr_fname; 2561 char *scratch ;2562 char *tmp ;2540 char *scratch = NULL; 2541 char *tmp = NULL; 2563 2542 char *p; 2564 2543 2565 2544 struct stat statbuf; 2566 2545 command = malloc(1000); 2567 malloc_string(tmp);2568 malloc_string(scratch);2569 2546 malloc_string(curr_fname); 2570 2547 if (!does_file_exist(incoming)) { … … 2578 2555 log_msg(1, "curr_fname = %s", curr_fname); 2579 2556 sprintf(command, "file %s", curr_fname); 2580 strcpy(tmp, call_program_and_get_last_line_of_output(command));2557 mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command)); 2581 2558 for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' '; 2582 2559 p--); 2583 2560 p++; 2584 strcpy(scratch, p);2561 mr_asprintf(&scratch, p); 2585 2562 for (p = scratch; *p != '\0' && *p != '\''; p++); 2586 2563 *p = '\0'; 2587 log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, 2588 scratch); 2564 log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, scratch); 2565 mr_free(tmp); 2566 2589 2567 if (scratch[0] == '/') { 2590 2568 strcpy(curr_fname, scratch); // copy whole thing because it's an absolute softlink … … 2599 2577 strcpy(p, scratch); 2600 2578 } 2579 mr_free(scratch); 2601 2580 lstat(curr_fname, &statbuf); 2602 2581 } … … 2606 2585 paranoid_free(command); 2607 2586 paranoid_free(curr_fname); 2608 paranoid_free(tmp);2609 2587 return (output); 2610 2588 } … … 2619 2597 { 2620 2598 static char output[4]; 2621 char *tmp ;2599 char *tmp = NULL; 2622 2600 char *command; 2623 2601 char *fdisk; … … 2625 2603 struct stat buf; 2626 2604 #endif 2627 malloc_string(tmp);2628 2605 malloc_string(command); 2629 2606 malloc_string(fdisk); … … 2632 2609 log_msg(1, "Using %s", fdisk); 2633 2610 sprintf(command, "%s -l %s | grep 'EFI GPT'", fdisk, drive); 2634 strcpy(tmp, call_program_and_get_last_line_of_output(command));2611 mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command)); 2635 2612 if (strstr(tmp, "GPT") == NULL) { 2636 2613 strcpy(output, "MBR"); … … 2638 2615 strcpy(output, "GPT"); 2639 2616 } 2617 mr_free(tmp); 2618 2640 2619 log_msg(0, "Found %s partition table format type", output); 2641 2620 paranoid_free(command); 2642 paranoid_free(tmp);2643 2621 paranoid_free(fdisk); 2644 2622 return (output);
Note:
See TracChangeset
for help on using the changeset viewer.