Changeset 688 in MondoRescue for trunk/mondo/mondo/common/libmondo-devices.c
- Timestamp:
- Jul 17, 2006, 3:44:46 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/common/libmondo-devices.c
r687 r688 1 /* $Id$ 1 /* 2 * $Id$ 2 3 * Subroutines for handling devices 3 4 */ … … 19 20 #include <sys/ioctl.h> 20 21 #include <sys/types.h> 22 #include <unistd.h> 21 23 #ifdef __FreeBSD__ 22 24 #define DKTYPENAMES … … 60 62 { 61 63 if (bkpinfo->media_device != NULL) { 62 paranoid_free(g_cdrom_drive_is_here); 63 asprintf(&g_cdrom_drive_is_here, bkpinfo->media_device); // just in case 64 paranoid_alloc(g_cdrom_drive_is_here, bkpinfo->media_device); // just in case 64 65 } 65 66 if (bkpinfo->media_device != NULL) { 66 paranoid_free(g_dvd_drive_is_here); 67 asprintf(&g_dvd_drive_is_here, bkpinfo->media_device); // just in case 67 paranoid_alloc(g_dvd_drive_is_here, bkpinfo->media_device); // just in case 68 68 } 69 69 } … … 320 320 char *incoming = NULL; 321 321 char *searchstr; 322 char *tmp; 322 323 323 324 /*@ ints ******************************************************* */ … … 332 333 assert_string_is_neither_NULL_nor_zerolength(drive); 333 334 assert(partno >= 0 && partno < 999); 334 335 malloc_string(searchstr);336 335 337 336 #ifdef __FreeBSD__ … … 353 352 paranoid_free(program); 354 353 355 (void) build_partition_name(searchstr, drive, partno); 356 strcat(searchstr, " "); 354 searchstr = build_partition_name(drive, partno); 355 asprintf(&tmp, "%s ", searchstr); 356 paranoid_free(searchstr); 357 357 358 for (res = 0; !res && getline(&incoming, &n, fin);) { 358 if (strstr(incoming, searchstr)) {359 if (strstr(incoming, tmp)) { 359 360 res = 1; 360 361 } … … 365 366 log_OS_error("Cannot pclose fin"); 366 367 } 367 paranoid_free( searchstr);368 paranoid_free(tmp); 368 369 return (res); 369 370 } … … 459 460 asprintf(&dev, g_cdrom_drive_is_here); 460 461 } else { 462 // find_cdrom_device allocates the string 461 463 dev = find_cdrom_device(FALSE); 462 464 } … … 468 470 469 471 if ((dev == NULL) || (! mount_CDROM_here(dev, mountpoint))) { 472 paranoid_free(dev); 470 473 if (!popup_and_get_string 471 (_("CD-ROM device"), _("Please enter your CD-ROM's /dev device"), 472 dev, MAX_STR_LEN / 4)) { 474 (_("CD-ROM device"), _("Please enter your CD-ROM's /dev device"), dev)) { 473 475 res = FALSE; 474 476 } else { … … 556 558 { 557 559 /*@ pointers **************************************************** */ 558 FILE *fin ;559 char *p ;560 char *q ;561 char *r ;560 FILE *fin = NULL; 561 char *p = NULL; 562 char *q = NULL; 563 char *r = NULL; 562 564 char *output = NULL; 563 565 size_t n = 0; … … 568 570 /*@ buffers ***************************************************** */ 569 571 char *tmp = NULL; 570 char *cdr_exe ;572 char *cdr_exe = NULL; 571 573 #ifndef __FreeBSD__ 572 574 char *phrase_two = NULL; 573 575 char *dvd_last_resort = NULL; 574 576 #endif 575 char *command ;576 char *mountpoint ;577 static char the_last_place_i_found_it[MAX_STR_LEN] = "";577 char *command = NULL; 578 char *mountpoint = NULL; 579 static char *the_last_place_i_found_it = NULL; 578 580 579 581 /*@ end vars **************************************************** */ … … 584 586 return(output); 585 587 } 586 if ( the_last_place_i_found_it[0] != '\0'&& !try_to_mount) {588 if ((the_last_place_i_found_it != NULL) && !try_to_mount) { 587 589 asprintf(&output, the_last_place_i_found_it); 588 590 log_msg(3, … … 834 836 } 835 837 log_msg(3, "(find_cdrom_device) --> '%s'", output); 836 strcpy(the_last_place_i_found_it, output);838 asprintf(&the_last_place_i_found_it, output); 837 839 paranoid_free(g_cdrom_drive_is_here); 838 840 asprintf(&g_cdrom_drive_is_here, output); … … 863 865 char *find_dvd_device() 864 866 { 865 char *tmp ;867 char *tmp = NULL; 866 868 int retval = 0, devno = -1; 867 869 char *output = NULL; … … 1008 1010 bool is_this_a_valid_disk_format(char *format) 1009 1011 { 1010 char *good_formats; 1011 char *command; 1012 char *format_sz; 1013 1014 FILE *pin; 1012 char *good_formats = NULL; 1013 char *command = NULL; 1014 char *tmp = NULL; 1015 char *format_sz = NULL; 1016 1017 FILE *pin = NULL; 1015 1018 bool retval; 1016 malloc_string(good_formats);1019 size_t n = 0; 1017 1020 assert_string_is_neither_NULL_nor_zerolength(format); 1018 1021 … … 1034 1037 retval = FALSE; 1035 1038 } else { 1036 strcpy(good_formats, " "); 1037 (void) fgets(good_formats + 1, MAX_STR_LEN, pin); 1039 getline(&good_formats, &n , pin); 1038 1040 if (pclose(pin)) { 1039 1041 log_OS_error("Cannot pclose good formats"); 1040 1042 } 1041 1043 strip_spaces(good_formats); 1042 strcat(good_formats, " swap lvm raid ntfs 7 "); // " ntfs 7 " -- um, cheating much? :) 1044 // " ntfs 7 " -- um, cheating much? :) 1045 asprintf(&tmp, " %s swap lvm raid ntfs 7 ",good_formats); 1046 paranoid_free(good_formats); 1047 good_formats = tmp; 1048 1043 1049 if (strstr(good_formats, format_sz)) { 1044 1050 retval = TRUE; … … 1046 1052 retval = FALSE; 1047 1053 } 1048 }1049 paranoid_free(good_formats);1054 paranoid_free(good_formats); 1055 } 1050 1056 paranoid_free(format_sz); 1051 1057 return (retval); … … 1141 1147 char *make_vn(char *fname) 1142 1148 { 1143 char *device ;1149 char *device = NULL; 1144 1150 char *mddevice = NULL; 1145 1151 char *command = NULL; … … 1224 1230 { 1225 1231 /*@ buffer ****************************************************** */ 1226 char *command ;1227 int retval ;1232 char *command = NULL; 1233 int retval = 0; 1228 1234 1229 1235 assert_string_is_neither_NULL_nor_zerolength(device); … … 1238 1244 1239 1245 #ifdef __FreeBSD__ 1240 char *dev ;1246 char *dev = NULL; 1241 1247 1242 1248 dev = make_vn(device)); … … 1361 1367 1362 1368 while (what_number_cd_is_this(bkpinfo) != cd_number_i_want) { 1363 paranoid_system("sync");1369 sync(); 1364 1370 if (is_this_device_mounted(MNT_CDROM)) { 1365 1371 res = … … 1383 1389 inject_device(bkpinfo->media_device); 1384 1390 } 1385 paranoid_system("sync");1391 sync(); 1386 1392 } 1387 1393 paranoid_free(request); … … 1410 1416 // archiving_to_media is FALSE if I'm being called by mondorestore 1411 1417 { 1412 char *tmp; 1418 char *tmp = NULL; 1419 char *tmp1 = NULL; 1420 char *tmp2 = NULL; 1413 1421 char *sz_size = NULL; 1414 char *command ;1415 char *comment ;1422 char *command = NULL; 1423 char *comment = NULL; 1416 1424 char *prompt = NULL; 1417 int i ;1418 FILE *fin ;1425 int i = 0; 1426 FILE *fin = NULL; 1419 1427 1420 1428 assert(bkpinfo != NULL); … … 1480 1488 media_descriptor_string(bkpinfo->backup_media_type)); 1481 1489 if (bkpinfo->backup_media_type == dvd) { 1482 paranoid_free(bkpinfo->media_device);1483 1490 bkpinfo->media_device = find_dvd_device(); 1484 1491 asprintf(&tmp, "1"); … … 1492 1499 } 1493 1500 if (bkpinfo->backup_media_type != dvd) { 1494 if (!popup_and_get_string(_("Speed"), comment, tmp , 4)) {1501 if (!popup_and_get_string(_("Speed"), comment, tmp)) { 1495 1502 log_to_screen(_("User has chosen not to backup the PC")); 1496 1503 finish(1); … … 1506 1513 media_descriptor_string(bkpinfo->backup_media_type)); 1507 1514 1508 if (!popup_and_get_string("Size", comment, sz_size , 5)) {1515 if (!popup_and_get_string("Size", comment, sz_size)) { 1509 1516 log_to_screen(_("User has chosen not to backup the PC")); 1510 1517 finish(1); … … 1515 1522 bkpinfo->media_size[i] = atoi(sz_size); 1516 1523 } 1524 paranoid_free(sz_size); 1525 1517 1526 if (bkpinfo->media_size[0] <= 0) { 1518 1527 log_to_screen(_("User has chosen not to backup the PC")); 1519 1528 finish(1); 1520 1529 } 1521 paranoid_free(sz_size);1522 1530 } 1523 1531 case cdstream: … … 1529 1537 || bkpinfo->backup_media_type == dvd) { 1530 1538 if (bkpinfo->media_device == NULL) { 1531 paranoid_alloc(bkpinfo->media_device, "/dev/cdrom");1539 asprintf(&bkpinfo->media_device, "/dev/cdrom"); 1532 1540 } // just for the heck of it :) 1533 1541 log_msg(1, "bkpinfo->media_device = %s", … … 1544 1552 backup_media_type)); 1545 1553 if (!popup_and_get_string 1546 (_("Device?"), comment, bkpinfo->media_device, 1547 MAX_STR_LEN / 4)) { 1554 (_("Device?"), comment, bkpinfo->media_device)) { 1548 1555 log_to_screen(_("User has chosen not to backup the PC")); 1549 1556 finish(1); … … 1555 1562 bkpinfo->media_device); 1556 1563 } else { 1557 paranoid_free(bkpinfo->media_device);1558 1564 bkpinfo->media_device = find_cdrw_device(); 1559 1565 if (bkpinfo->media_device != NULL) { … … 1571 1577 i = popup_and_get_string(_("Device node?"), 1572 1578 _("What is the SCSI node of your CD (re)writer, please?"), 1573 bkpinfo->media_device, 1574 MAX_STR_LEN / 4); 1579 bkpinfo->media_device); 1575 1580 } else { 1576 1581 i = popup_and_get_string(_("/dev entry?"), 1577 1582 _("What is the /dev entry of your CD (re)writer, please?"), 1578 bkpinfo->media_device, 1579 MAX_STR_LEN / 4); 1583 bkpinfo->media_device); 1580 1584 } 1581 1585 if (!i) { … … 1602 1606 if (find_tape_device_and_size(bkpinfo->media_device, sz_size)) { 1603 1607 log_msg(3, _("Ok, using vanilla scsi tape.")); 1604 paranoid_alloc(bkpinfo->media_device,VANILLA_SCSI_TAPE );1608 paranoid_alloc(bkpinfo->media_device,VANILLA_SCSI_TAPE"0" ); 1605 1609 if ((fin = fopen(bkpinfo->media_device, "r"))) { 1606 1610 paranoid_fclose(fin); … … 1630 1634 (_("Device name?"), 1631 1635 _("What is the /dev entry of your tape streamer?"), 1632 bkpinfo->media_device , MAX_STR_LEN / 4)) {1636 bkpinfo->media_device)) { 1633 1637 log_to_screen(_("User has chosen not to backup the PC")); 1634 1638 finish(1); … … 1642 1646 paranoid_free(tmp); 1643 1647 log_msg(4, "sz_size = %s", sz_size); 1644 sz_size[0] = '\0';1648 paranoid_free(sz_size); 1645 1649 bkpinfo->media_size[0] = 0; 1646 1650 log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]); … … 1677 1681 (_("NFS dir."), 1678 1682 _("Please enter path and directory where archives are stored remotely. (Mondo has taken a guess at the correct value. If it is incorrect, delete it and type the correct one.)"), 1679 bkpinfo->nfs_mount , MAX_STR_LEN / 4)) {1683 bkpinfo->nfs_mount)) { 1680 1684 log_to_screen(_("User has chosen not to backup the PC")); 1681 1685 finish(1); … … 1701 1705 asprintf(&comment, 1702 1706 _("How much data (in Megabytes) will each media store?")); 1703 if (!popup_and_get_string(_("Size"), comment, sz_size , 5)) {1707 if (!popup_and_get_string(_("Size"), comment, sz_size)) { 1704 1708 log_to_screen(_("User has chosen not to backup the PC")); 1705 1709 finish(1); … … 1718 1722 if (!popup_and_get_string 1719 1723 (_("NFS share"), _("Which remote NFS share should I mount?"), 1720 bkpinfo->nfs_mount , MAX_STR_LEN)) {1724 bkpinfo->nfs_mount)) { 1721 1725 log_to_screen(_("User has chosen not to backup the PC")); 1722 1726 finish(1); … … 1742 1746 finish(1); 1743 1747 } 1744 asprintf(&tmp, bkpinfo->nfs_remote_dir);1745 1748 if (!popup_and_get_string 1746 (_("Directory"), _("Which directory within that mountpoint?"), tmp, 1747 MAX_STR_LEN)) { 1749 (_("Directory"), _("Which directory within that mountpoint?"),bkpinfo->nfs_remote_dir)) { 1748 1750 log_to_screen(_("User has chosen not to backup the PC")); 1749 1751 finish(1); 1750 1752 } 1751 strcpy(bkpinfo->nfs_remote_dir, tmp); 1752 paranoid_free(tmp); 1753 1754 // check whether writable - we better remove surrounding spaces for this 1755 strip_spaces(bkpinfo->nfs_remote_dir); 1756 asprintf(&command, "echo hi > %s/%s/.dummy.txt", bkpinfo->isodir, 1753 1754 asprintf(&command, "echo hi > '%s/%s/.dummy.txt'", bkpinfo->isodir, 1757 1755 bkpinfo->nfs_remote_dir); 1758 1756 while (run_program_and_log_output(command, FALSE)) { 1759 paranoid_free(tmp);1760 paranoid_free(prompt);1761 asprintf(&tmp, bkpinfo->nfs_remote_dir);1762 1757 asprintf(&prompt, 1763 1758 _("Directory '%s' under mountpoint '%s' does not exist or is not writable. You can fix this or change the directory and retry or cancel the backup."), 1764 1759 bkpinfo->nfs_remote_dir, bkpinfo->isodir); 1765 1760 if (!popup_and_get_string 1766 (_("Directory"), prompt, tmp, MAX_STR_LEN)) {1761 (_("Directory"), prompt, bkpinfo->nfs_remote_dir)) { 1767 1762 log_to_screen(_("User has chosen not to backup the PC")); 1768 1763 finish(1); 1769 1764 } 1770 strcpy(bkpinfo->nfs_remote_dir, tmp);1771 // check whether writable - we better remove surrounding spaces for this */ 1772 strip_spaces(bkpinfo->nfs_remote_dir);1765 paranoid_free(prompt); 1766 1767 paranoid_free(command); 1773 1768 asprintf(&command, "echo hi > %s/%s/.dummy.txt", 1774 1769 bkpinfo->isodir, bkpinfo->nfs_remote_dir); 1775 1770 } 1776 1771 paranoid_free(command); 1777 paranoid_free(tmp);1778 paranoid_free(prompt);1779 1772 1780 1773 if (!popup_and_get_string 1781 1774 (_("Prefix."), 1782 1775 _("Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files"), 1783 bkpinfo->prefix , MAX_STR_LEN / 4)) {1776 bkpinfo->prefix)) { 1784 1777 log_to_screen(_("User has chosen not to backup the PC")); 1785 1778 finish(1); … … 1800 1793 (_("Storage dir."), 1801 1794 _("Please enter the full path that contains your ISO images. Example: /mnt/raid0_0"), 1802 bkpinfo->isodir , MAX_STR_LEN / 4)) {1795 bkpinfo->isodir)) { 1803 1796 log_to_screen(_("User has chosen not to backup the PC")); 1804 1797 finish(1); … … 1812 1805 if (!popup_and_get_string 1813 1806 (_("ISO size."), 1814 _("Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s or DVD's you plan to backup to."), 1815 sz_size, 16)) { 1807 _("Please enter how big you want each ISO image to be (in megabytes). This should be less than or equal to the size of the CD-R[W]'s or DVD's you plan to backup to."), sz_size)) { 1816 1808 log_to_screen(_("User has chosen not to backup the PC")); 1817 1809 finish(1); … … 1825 1817 (_("Prefix."), 1826 1818 _("Please enter the prefix that will be prepended to your ISO filename. Example: machine1 to obtain machine1-[1-9]*.iso files"), 1827 bkpinfo->prefix , MAX_STR_LEN / 4)) {1819 bkpinfo->prefix)) { 1828 1820 log_to_screen("User has chosen not to backup the PC"); 1829 1821 finish(1); … … 1844 1836 1845 1837 #ifdef __FreeBSD__ 1846 strcpy(bkpinfo->boot_device, 1847 call_program_and_get_last_line_of_output 1838 bkpinfo->boot_device = call_program_and_get_last_line_of_output 1848 1839 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/\\([0-9]\\).*/\\1/'")); 1849 1840 #else 1850 strcpy(bkpinfo->boot_device, 1851 call_program_and_get_last_line_of_output 1841 bkpinfo->boot_device = call_program_and_get_last_line_of_output 1852 1842 ("mount | grep ' / ' | head -1 | cut -d' ' -f1 | sed 's/[0-9].*//'")); 1853 1843 #endif … … 1860 1850 (_("Boot device"), 1861 1851 _("What is your boot device? (e.g. /dev/ad0)"), 1862 bkpinfo->boot_device , MAX_STR_LEN / 4)) {1852 bkpinfo->boot_device)) { 1863 1853 log_to_screen(_("User has chosen not to backup the PC")); 1864 1854 finish(1); … … 1869 1859 (_("Boot device"), 1870 1860 _("What is your boot device? (e.g. /dev/hda)"), 1871 bkpinfo->boot_device , MAX_STR_LEN / 4)) {1861 bkpinfo->boot_device)) { 1872 1862 log_to_screen(_("User has chosen not to backup the PC")); 1873 1863 finish(1); … … 1901 1891 } 1902 1892 bkpinfo->boot_loader = i; 1903 strcpy(bkpinfo->include_paths, "/");1893 asprintf(&bkpinfo->include_paths, "/"); 1904 1894 if (!popup_and_get_string 1905 1895 (_("Backup paths"), 1906 1896 _("Please enter paths which you want me to backup. The default is '/' (i.e. everything)."), 1907 bkpinfo->include_paths , MAX_STR_LEN)) {1897 bkpinfo->include_paths)) { 1908 1898 log_to_screen(_("User has chosen not to backup the PC")); 1909 1899 finish(1); 1910 1900 } 1901 1911 1902 tmp = list_of_NFS_mounts_only(); 1912 1903 if (strlen(tmp) > 2) { 1913 if (bkpinfo->exclude_paths[0]) { 1914 strcat(bkpinfo->exclude_paths, " "); 1915 } 1916 strncpy(bkpinfo->exclude_paths, tmp, MAX_STR_LEN); 1904 if (bkpinfo->exclude_paths != NULL) { 1905 tmp1 = bkpinfo->exclude_paths; 1906 asprintf(&bkpinfo->exclude_paths, "%s %s", tmp1, tmp); 1907 paranoid_free(tmp1); 1908 } else { 1909 bkpinfo->exclude_paths = tmp; 1910 } 1917 1911 } 1918 1912 paranoid_free(tmp); 1919 1913 // NTFS 1920 asprintf(&tmp, 1921 call_program_and_get_last_line_of_output 1922 ("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'")); 1914 tmp = call_program_and_get_last_line_of_output 1915 ("parted2fdisk -l | grep -i ntfs | awk '{ print $1};' | tr -s '\\n' ' ' | awk '{ print $0};'"); 1923 1916 if (strlen(tmp) > 2) { 1924 1917 if (!popup_and_get_string 1925 1918 (_("NTFS partitions"), 1926 1919 _("Please enter/confirm the NTFS partitions you wish to backup as well."), 1927 tmp , MAX_STR_LEN / 4)) {1920 tmp1)) { 1928 1921 log_to_screen(_("User has chosen not to backup the PC")); 1929 1922 finish(1); 1930 1923 } 1931 strncpy(bkpinfo->image_devs, tmp, MAX_STR_LEN / 4); 1924 if (bkpinfo->image_devs != NULL) { 1925 tmp2 = bkpinfo->image_devs; 1926 asprintf(&bkpinfo->image_devs, "%s %s", tmp2, tmp1); 1927 paranoid_free(tmp2); 1928 } else { 1929 bkpinfo->image_devs = tmp1; 1930 } 1931 paranoid_free(tmp1); 1932 1932 } 1933 1933 paranoid_free(tmp); … … 1936 1936 (_("Exclude paths"), 1937 1937 _("Please enter paths which you do NOT want to backup. Separate them with spaces. NB: /tmp and /proc are always excluded. :-) Just hit 'Enter' if you want to do a full system backup."), 1938 bkpinfo->exclude_paths , MAX_STR_LEN)) {1938 bkpinfo->exclude_paths)) { 1939 1939 log_to_screen(_("User has chosen not to backup the PC")); 1940 1940 finish(1); … … 2005 2005 * Get a space-separated list of NFS mounts. 2006 2006 * @return The list created. 2007 * @note The return value points to static data that will be overwritten with each call.2007 * @note The return value should be freed by caller 2008 2008 * @bug Even though we only want the mounts, the devices are still checked. 2009 2009 */ 2010 2010 char *list_of_NFS_mounts_only(void) 2011 2011 { 2012 char *exclude_these_devices; 2013 char *exclude_these_directories; 2014 char *result_sz; 2015 2016 asprintf(&exclude_these_directories, 2017 call_program_and_get_last_line_of_output 2012 return(call_program_and_get_last_line_of_output 2018 2013 ("mount -t coda,ncpfs,nfs,smbfs,cifs | tr -s '\t' ' ' | cut -d' ' -f3 | tr -s '\n' ' ' | awk '{print $0;}'")); 2014 /* BERLIOS : Useless 2019 2015 asprintf(&exclude_these_devices, 2020 2016 call_program_and_get_last_line_of_output 2021 2017 ("tr -s '\t' ' ' < /etc/fstab | grep -E '( (coda|ncpfs|nfs|smbfs|cifs) )' | cut -d' ' -f1 | tr -s '\n' ' ' | awk '{print $0;}'")); 2022 asprintf(&result_sz, "%s", exclude_these_directories); 2023 paranoid_free(exclude_these_devices); 2024 paranoid_free(exclude_these_directories); 2025 return (result_sz); 2018 */ 2026 2019 } 2027 2020 … … 2060 2053 void sensibly_set_tmpdir_and_scratchdir(struct s_bkpinfo *bkpinfo) 2061 2054 { 2062 char *tmp, *command, *sz; 2055 char *tmp = NULL; 2056 char *command = NULL; 2057 char *sz = NULL; 2058 int i = 0; 2063 2059 2064 2060 assert(bkpinfo != NULL); 2065 2061 2066 2062 #ifdef __FreeBSD__ 2067 asprintf(&tmp, 2068 call_program_and_get_last_line_of_output 2069 ("df -m -P -t nonfs,msdosfs,ntfs,smbfs,smb,cifs | tr -s '\t' ' ' | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'")); 2063 tmp = call_program_and_get_last_line_of_output 2064 ("df -m -P -t nonfs,msdosfs,ntfs,smbfs,smb,cifs | tr -s '\t' ' ' | grep -vE \"none|Filesystem\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"); 2070 2065 #else 2071 asprintf(&tmp, 2072 call_program_and_get_last_line_of_output 2073 ("df -m -P -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs | sed 's/ /devdev/' | tr -s '\t' ' ' | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'")); 2066 tmp = call_program_and_get_last_line_of_output 2067 ("df -m -P -x nfs -x vfat -x ntfs -x smbfs -x smb -x cifs | sed 's/ /devdev/' | tr -s '\t' ' ' | grep -vE \"none|Filesystem|/dev/shm\" | awk '{printf \"%s %s\\n\", $4, $6;}' | sort -n | tail -n1 | awk '{print $NF;}'"); 2074 2068 #endif 2075 2069 … … 2082 2076 fatal_error("I couldn't figure out the tempdir!"); 2083 2077 } 2084 sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%d", tmp,2085 (int) (random() % 32768));2078 i = (int) (random() % 32768); 2079 asprintf(&bkpinfo->tmpdir, "%s/mondo.tmp.%d", tmp, i); 2086 2080 log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir); 2087 2081 2088 sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, 2089 (int) (random() % 32768)); 2082 asprintf(&bkpinfo->scratchdir, "%s/mondo.scratch.%d", tmp, i); 2090 2083 log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir); 2091 2084 2092 sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,2085 asprintf(&g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir, 2093 2086 bkpinfo->scratchdir); 2094 2087 2095 asprintf(&command, "rm -Rf %s/ tmp.mondo.* %s/mondo.scratch.*", tmp, tmp);2088 asprintf(&command, "rm -Rf %s/mondo.tmp.* %s/mondo.scratch.*", tmp, tmp); 2096 2089 paranoid_free(tmp); 2097 2090 … … 2152 2145 { 2153 2146 int cd_number = -1; 2154 char *mountdev; 2155 char *tmp; 2147 char *mountdev = NULL; 2148 char *tmp = NULL; 2149 char *tmp1 = NULL; 2156 2150 2157 2151 assert(bkpinfo != NULL); … … 2159 2153 asprintf(&tmp, "mount | grep iso9660 | awk '{print $3;}'"); 2160 2154 2161 asprintf(&mountdev, "%s/archives/THIS-CD-NUMBER", call_program_and_get_last_line_of_output(tmp));2155 tmp1 = call_program_and_get_last_line_of_output(tmp); 2162 2156 paranoid_free(tmp); 2163 2157 2164 cd_number = atoi(last_line_of_file(mountdev)); 2158 asprintf(&mountdev, "%s/archives/THIS-CD-NUMBER", tmp1); 2159 paranoid_free(tmp1); 2160 2161 tmp = last_line_of_file(mountdev); 2162 cd_number = atoi(tmp); 2165 2163 paranoid_free(mountdev); 2164 paranoid_free(tmp); 2166 2165 2167 2166 return (cd_number); … … 2176 2175 (void)mount_CDROM_here(bkpinfo->media_device, MNT_CDROM); 2177 2176 } 2178 cd_number = 2179 atoi(last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER")); 2177 tmp = last_line_of_file(MNT_CDROM "/archives/THIS-CD-NUMBER"); 2178 cd_number = atoi(tmp); 2179 paranoid_free(tmp); 2180 2180 return (cd_number); 2181 2181 } … … 2191 2191 char *where_is_root_mounted() 2192 2192 { 2193 /*@ buffers **************** */2194 2193 char *tmp; 2195 2194 2196 2197 2195 #ifdef __FreeBSD__ 2198 asprintf(&tmp,call_program_and_get_last_line_of_output2199 ("mount | grep \" on / \" | cut -d' ' -f1") );2196 tmp = call_program_and_get_last_line_of_output 2197 ("mount | grep \" on / \" | cut -d' ' -f1"); 2200 2198 #else 2201 asprintf(&tmp,call_program_and_get_last_line_of_output2202 ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//") );2199 tmp = call_program_and_get_last_line_of_output 2200 ("mount | grep \" on / \" | cut -d' ' -f1 | sed s/[0-9]// | sed s/[0-9]//"); 2203 2201 if (strstr(tmp, "/dev/cciss/")) { 2204 2202 paranoid_free(tmp); 2205 asprintf(&tmp,call_program_and_get_last_line_of_output2206 ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1") );2203 tmp = call_program_and_get_last_line_of_output 2204 ("mount | grep \" on / \" | cut -d' ' -f1 | cut -dp -f1"); 2207 2205 } 2208 2206 if (strstr(tmp, "/dev/md")) { 2209 2207 paranoid_free(tmp); 2210 asprintf(&tmp, 2211 call_program_and_get_last_line_of_output 2212 ("mount | grep \" on / \" | cut -d' ' -f1")); 2208 tmp = call_program_and_get_last_line_of_output 2209 ("mount | grep \" on / \" | cut -d' ' -f1"); 2213 2210 } 2214 2211 #endif … … 2373 2370 char *resolve_softlinks_to_get_to_actual_device_file(char *incoming) 2374 2371 { 2375 char *output ;2376 char *command ;2377 char *curr_fname ;2378 char *scratch ;2379 char *tmp ;2380 char *p ;2372 char *output = NULL; 2373 char *command = NULL; 2374 char *curr_fname = NULL; 2375 char *scratch = NULL; 2376 char *tmp = NULL; 2377 char *p = NULL; 2381 2378 2382 2379 struct stat statbuf; … … 2391 2388 log_msg(1, "curr_fname = %s", curr_fname); 2392 2389 asprintf(&command, "file %s", curr_fname); 2393 asprintf(&tmp, call_program_and_get_last_line_of_output(command));2390 tmp = call_program_and_get_last_line_of_output(command); 2394 2391 paranoid_free(command); 2395 2392 … … 2400 2397 for (p = scratch; *p != '\0' && *p != '\''; p++); 2401 2398 *p = '\0'; 2402 log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, 2403 scratch); 2399 log_msg(0, "curr_fname %s --> '%s' --> %s", curr_fname, tmp, scratch); 2404 2400 paranoid_free(tmp); 2405 2401 … … 2439 2435 char *which_partition_format(const char *drive) 2440 2436 { 2441 char *output ;2442 char *tmp ;2443 char *command ;2444 char *fdisk ;2437 char *output = NULL; 2438 char *tmp = NULL; 2439 char *command = NULL; 2440 char *fdisk = NULL; 2445 2441 2446 2442 log_msg(0, "Looking for partition table format type"); … … 2450 2446 paranoid_free(fdisk); 2451 2447 2452 asprintf(&tmp, call_program_and_get_last_line_of_output(command));2448 tmp = call_program_and_get_last_line_of_output(command); 2453 2449 paranoid_free(command); 2454 2450
Note:
See TracChangeset
for help on using the changeset viewer.