Changeset 2323 in MondoRescue for branches/2.2.10/mondo/src/common/libmondo-tools.c
- Timestamp:
- Aug 18, 2009, 3:05:43 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/common/libmondo-tools.c
r2322 r2323 219 219 220 220 uname(&utsn); 221 mr_asprintf( &tmp, "%s", utsn.machine);221 mr_asprintf(tmp, "%s", utsn.machine); 222 222 return (tmp); 223 223 } … … 449 449 if (bkpinfo->backup_media_type == tape) { 450 450 log_msg(1, "Bar"); 451 mr_asprintf( &tmp, "mt -f %s status", bkpinfo->media_device);451 mr_asprintf(tmp, "mt -f %s status", bkpinfo->media_device); 452 452 log_msg(1, "tmp = '%s'", tmp); 453 453 if (run_program_and_log_output(tmp, 3)) { … … 501 501 } 502 502 if (bkpinfo->nonbootable_backup) { 503 mr_asprintf( &mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);503 mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT); 504 504 } else if 505 505 #ifdef __FreeBSD__ … … 510 510 #ifdef __IA64__ 511 511 { 512 mr_asprintf( &mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);512 mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO); 513 513 } 514 514 #else 515 515 { 516 mr_asprintf( &mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);516 mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO); 517 517 } 518 518 #endif 519 519 else 520 520 { 521 mr_asprintf( &mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);521 mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX); 522 522 } 523 523 if (bkpinfo->manual_cd_tray) { … … 533 533 } 534 534 if (getenv ("SUDO_COMMAND")) { 535 mr_asprintf( &command, "strings `which growisofs` | grep -c SUDO_COMMAND");535 mr_asprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND"); 536 536 if (!strcmp(call_program_and_get_last_line_of_output(command), "1")) { 537 537 mr_free(command); … … 549 549 || bkpinfo->backup_media_type == cdr) { 550 550 if (!bkpinfo->manual_cd_tray) { 551 mr_asprintf( &extra_cdrom_params, "-waiti ");551 mr_asprintf(extra_cdrom_params, "-waiti "); 552 552 } 553 553 if (bkpinfo->backup_media_type == cdrw) { 554 mr_asprintf( &extra_cdrom_params, "blank=fast ");554 mr_asprintf(extra_cdrom_params, "blank=fast "); 555 555 } 556 556 if (find_home_of_exe("cdrecord")) { … … 562 562 } 563 563 if (bkpinfo->nonbootable_backup) { 564 mr_asprintf( &mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT);564 mr_asprintf(mondo_mkisofs_sz, MONDO_MKISOFS_NONBOOT); 565 565 } else if 566 566 #ifdef __FreeBSD__ … … 571 571 #ifdef __IA64__ 572 572 { 573 mr_asprintf( &mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO);573 mr_asprintf(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_ELILO); 574 574 } 575 575 #else 576 576 { 577 mr_asprintf( &mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO);577 mr_asprintf(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_LILO); 578 578 } 579 579 #endif 580 580 else 581 581 { 582 mr_asprintf( &mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX);582 mr_asprintf(mondo_mkisofs_sz, MONDO_MKISOFS_REGULAR_SYSLINUX); 583 583 } 584 584 if (bkpinfo->manual_cd_tray) { … … 621 621 622 622 log_it("isodir = %s", bkpinfo->isodir); 623 mr_asprintf( &command, "df -P %s | tail -n1 | cut -d' ' -f1", bkpinfo->isodir);623 mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1", bkpinfo->isodir); 624 624 log_it("command = %s", command); 625 625 log_it("res of it = %s", call_program_and_get_last_line_of_output(command)); 626 mr_asprintf( &iso_dev, "%s", call_program_and_get_last_line_of_output(command));627 mr_asprintf( &tmp, "%s/ISO-DEV", bkpinfo->tmpdir);626 mr_asprintf(iso_dev, "%s", call_program_and_get_last_line_of_output(command)); 627 mr_asprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir); 628 628 write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command)); 629 629 mr_free(tmp); 630 630 mr_free(command); 631 631 632 mr_asprintf( &command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", iso_dev);632 mr_asprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", iso_dev); 633 633 mr_free(iso_dev); 634 634 635 635 log_it("command = %s", command); 636 636 log_it("res of it = %s", call_program_and_get_last_line_of_output(command)); 637 mr_asprintf( &iso_mnt, "%s", call_program_and_get_last_line_of_output(command));638 mr_asprintf( &tmp, "%s/ISO-MNT", bkpinfo->tmpdir);637 mr_asprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command)); 638 mr_asprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir); 639 639 write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command)); 640 640 mr_free(tmp); … … 642 642 643 643 log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt)); 644 mr_asprintf( &iso_tmp, "%s", bkpinfo->isodir);644 mr_asprintf(iso_tmp, "%s", bkpinfo->isodir); 645 645 if (strlen(iso_tmp) < strlen(iso_mnt)) { 646 mr_asprintf( &iso_path, "%s", "");646 mr_asprintf(iso_path, "%s", ""); 647 647 } else { 648 mr_asprintf( &iso_path, "%s", iso_tmp + strlen(iso_mnt));648 mr_asprintf(iso_path, "%s", iso_tmp + strlen(iso_mnt)); 649 649 } 650 650 mr_free(iso_tmp); 651 651 652 mr_asprintf( &tmp, "%s/ISODIR", bkpinfo->tmpdir);652 mr_asprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir); 653 653 write_one_liner_data_file(tmp, iso_path); 654 654 mr_free(tmp); … … 657 657 mr_free(iso_path); 658 658 659 mr_asprintf( &tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);659 mr_asprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir); 660 660 write_one_liner_data_file(tmp, bkpinfo->prefix); 661 661 mr_free(tmp); … … 682 682 retval++; 683 683 } else { 684 mr_asprintf( &ip_address, "%s", inet_ntoa((struct in_addr) *((struct in_addr *) hent->h_addr)));684 mr_asprintf(ip_address, "%s", inet_ntoa((struct in_addr) *((struct in_addr *) hent->h_addr))); 685 685 mr_strcat(ip_address, strchr(bkpinfo->nfs_mount, ':')); 686 686 strcpy(bkpinfo->nfs_mount, ip_address); … … 696 696 } 697 697 if (bkpinfo->include_paths == NULL) { 698 mr_asprintf( &p, "/");698 mr_asprintf(p, "/"); 699 699 bkpinfo->include_paths = p; 700 700 } … … 732 732 733 733 unlink(MONDO_TRACEFILE); 734 mr_asprintf( &tmp,"rm -Rf %s/changed.files*",MONDO_CACHE);734 mr_asprintf(tmp,"rm -Rf %s/changed.files*",MONDO_CACHE); 735 735 run_program_and_log_output(tmp, FALSE); 736 736 paranoid_free(tmp); … … 758 758 /* purging a potential old tmpdir */ 759 759 log_it("Purging old tmpdir %s", bkpinfo->tmpdir); 760 mr_asprintf( &tmp,"rm -Rf %s",bkpinfo->tmpdir);760 mr_asprintf(tmp,"rm -Rf %s",bkpinfo->tmpdir); 761 761 mr_free(bkpinfo->tmpdir); 762 762 (void)system(tmp); … … 765 765 766 766 if (path != NULL) { 767 mr_asprintf( &tmp, "%s/mondo.tmp.XXXXXX", path);767 mr_asprintf(tmp, "%s/mondo.tmp.XXXXXX", path); 768 768 } else if (getenv("TMPDIR")) { 769 mr_asprintf( &tmp, "%s/mondo.tmp.XXXXXX", getenv("TMPDIR"));769 mr_asprintf(tmp, "%s/mondo.tmp.XXXXXX", getenv("TMPDIR")); 770 770 } else if (getenv("TMP")) { 771 mr_asprintf( &tmp, "%s/mondo.tmp.XXXXXX", getenv("TMP"));771 mr_asprintf(tmp, "%s/mondo.tmp.XXXXXX", getenv("TMP")); 772 772 } else { 773 mr_asprintf( &tmp, "/tmp/mondo.tmp.XXXXXX");773 mr_asprintf(tmp, "/tmp/mondo.tmp.XXXXXX"); 774 774 } 775 775 p = mkdtemp(tmp); … … 821 821 bkpinfo->use_lzo = FALSE; 822 822 bkpinfo->use_gzip = FALSE; 823 bkpinfo->do_not_compress_these[0] = '\0';824 823 bkpinfo->verify_data = FALSE; 825 824 bkpinfo->backup_data = FALSE; … … 829 828 bkpinfo->disaster_recovery = (am_I_in_disaster_recovery_mode()? TRUE : FALSE); 830 829 if (bkpinfo->disaster_recovery) { 831 strcpy(bkpinfo->isodir, "/");830 mr_asprintf(p, "%s", "/"); 832 831 } else { 833 strcpy(bkpinfo->isodir, MONDO_CACHE); 834 } 835 mr_asprintf(&p, "%s", STD_PREFIX); 832 mr_asprintf(p, "%s", MONDO_CACHE); 833 } 834 bkpinfo->isodir = p; 835 mr_asprintf(p, "%s", STD_PREFIX); 836 836 bkpinfo->prefix = p; 837 837 bkpinfo->scratchdir = NULL; … … 882 882 assert_string_is_neither_NULL_nor_zerolength(partition); 883 883 884 mr_asprintf( &command, "df -m -P %s 1> /dev/null 2> /dev/null", partition);884 mr_asprintf(command, "df -m -P %s 1> /dev/null 2> /dev/null", partition); 885 885 if (system(command)) { 886 886 mr_free(command); … … 889 889 mr_free(command); 890 890 891 mr_asprintf( &command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4",891 mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", 892 892 partition); 893 mr_asprintf( &out_sz, "%s", call_program_and_get_last_line_of_output(command));893 mr_asprintf(out_sz, "%s", call_program_and_get_last_line_of_output(command)); 894 894 mr_free(command); 895 895 … … 935 935 ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE); 936 936 } 937 mr_asprintf( &tmp, "%s", call_program_and_get_last_line_of_output("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"));937 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2")); 938 938 if (atol(tmp) < 35000) { 939 939 retval++; … … 1006 1006 run_program_and_log_output 1007 1007 ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5); 1008 mr_asprintf( &tmp, "%s", call_program_and_get_last_line_of_output("mount | grep -E \"cdr(om|w)\""));1008 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("mount | grep -E \"cdr(om|w)\"")); 1009 1009 if (strcmp("", tmp)) { 1010 1010 if (strstr(tmp, "autofs")) { … … 1039 1039 fatal_error("Please reinstall Mondo and Mindi."); 1040 1040 } 1041 mr_asprintf( &tmp, "mindi --makemountlist %s/mountlist.txt.test", bkpinfo->tmpdir);1041 mr_asprintf(tmp, "mindi --makemountlist %s/mountlist.txt.test", bkpinfo->tmpdir); 1042 1042 if (run_program_and_log_output(tmp, 5)) { 1043 1043 mr_free(tmp); 1044 mr_asprintf( &tmp, "mindi --makemountlist %s/mountlist.txt.test failed for some reason.", bkpinfo->tmpdir);1044 mr_asprintf(tmp, "mindi --makemountlist %s/mountlist.txt.test failed for some reason.", bkpinfo->tmpdir); 1045 1045 log_to_screen(tmp); 1046 1046 log_to_screen … … 1087 1087 assert_string_is_neither_NULL_nor_zerolength(label); 1088 1088 if (!does_file_exist(config_file)) { 1089 mr_asprintf( &tmp, "(read_cfg_var) Cannot find %s config file", config_file);1089 mr_asprintf(tmp, "(read_cfg_var) Cannot find %s config file", config_file); 1090 1090 log_to_screen(tmp); 1091 1091 mr_free(tmp); … … 1097 1097 return (0); 1098 1098 } else { 1099 mr_asprintf( &command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5", label, config_file);1099 mr_asprintf(command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5", label, config_file); 1100 1100 strcpy(value, call_program_and_get_last_line_of_output(command)); 1101 1101 mr_free(command); … … 1180 1180 log_msg(3, "%s --- autofs detected", g_autofs_exe); 1181 1181 // FIXME -- only disable it if it's running --- sprintf(tmp, "%s status", autofs_exe); 1182 mr_asprintf( &tmp, "%s stop", g_autofs_exe);1182 mr_asprintf(tmp, "%s stop", g_autofs_exe); 1183 1183 if (run_program_and_log_output(tmp, 2)) { 1184 1184 log_it("Failed to stop autofs - I assume it wasn't running"); … … 1202 1202 return; 1203 1203 } 1204 mr_asprintf( &tmp, "%s start", g_autofs_exe);1204 mr_asprintf(tmp, "%s start", g_autofs_exe); 1205 1205 if (run_program_and_log_output(tmp, 2)) { 1206 1206 log_it("Failed to start autofs"); … … 1225 1225 g_boot_mountpt[0] = '\0'; 1226 1226 log_msg(4, "Done. Great. Seeting command to something"); 1227 mr_asprintf( &command, "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1");1227 mr_asprintf(command, "%s", "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1"); 1228 1228 log_msg(4, "Cool. Command = '%s'", command); 1229 mr_asprintf( &tmp, "%s", call_program_and_get_last_line_of_output(command));1229 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1230 1230 mr_free(command); 1231 1231 … … 1233 1233 if (tmp[0]) { 1234 1234 log_it("/boot is at %s according to /etc/fstab", tmp); 1235 mr_asprintf( &command, "mount | grep -Ew '/boot'");1235 mr_asprintf(command, "mount | grep -Ew '/boot'"); 1236 1236 mr_free(tmp); 1237 mr_asprintf( &tmp, "%s", call_program_and_get_last_line_of_output(command));1237 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1238 1238 mr_free(command); 1239 1239 … … 1247 1247 } 1248 1248 } else { 1249 mr_asprintf( &command, "mount | grep -E '^%s'", tmp);1249 mr_asprintf(command, "mount | grep -E '^%s'", tmp); 1250 1250 log_msg(3, "command = %s", command); 1251 1251 if (run_program_and_log_output(command, 5)) { 1252 1252 strcpy(g_boot_mountpt, tmp); 1253 1253 mr_free(tmp); 1254 mr_asprintf( &tmp, "%s (your /boot partition) is not mounted. I'll mount it before backing up", g_boot_mountpt);1254 mr_asprintf(tmp, "%s (your /boot partition) is not mounted. I'll mount it before backing up", g_boot_mountpt); 1255 1255 log_it(tmp); 1256 1256 mr_free(tmp); 1257 1257 1258 mr_asprintf( &tmp, "mount %s", g_boot_mountpt);1258 mr_asprintf(tmp, "mount %s", g_boot_mountpt); 1259 1259 if (run_program_and_log_output(tmp, 5)) { 1260 1260 g_boot_mountpt[0] = '\0'; … … 1287 1287 log_msg(3, "starting"); 1288 1288 if (g_boot_mountpt[0]) { 1289 mr_asprintf( &tmp, "umount %s", g_boot_mountpt);1289 mr_asprintf(tmp, "umount %s", g_boot_mountpt); 1290 1290 if (run_program_and_log_output(tmp, 5)) { 1291 1291 log_it("WARNING - unable to unmount /boot"); … … 1319 1319 assert(value != NULL); 1320 1320 if (!does_file_exist(config_file)) { 1321 mr_asprintf( &tmp, "(write_cfg_file) Cannot find %s config file", config_file);1321 mr_asprintf(tmp, "(write_cfg_file) Cannot find %s config file", config_file); 1322 1322 log_to_screen(tmp); 1323 1323 mr_free(tmp); 1324 1324 return (1); 1325 1325 } 1326 mr_asprintf( &tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir);1326 mr_asprintf(tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir); 1327 1327 if (does_file_exist(config_file)) { 1328 mr_asprintf( &command, "grep -vE '^%s .*$' %s > %s", label, config_file, tempfile);1328 mr_asprintf(command, "grep -vE '^%s .*$' %s > %s", label, config_file, tempfile); 1329 1329 paranoid_system(command); 1330 1330 mr_free(command); 1331 1331 } 1332 mr_asprintf( &command, "echo \"%s %s\" >> %s", label, value, tempfile);1332 mr_asprintf(command, "echo \"%s %s\" >> %s", label, value, tempfile); 1333 1333 paranoid_system(command); 1334 1334 mr_free(command); 1335 1335 1336 mr_asprintf( &command, "mv -f %s %s", tempfile, config_file);1336 mr_asprintf(command, "mv -f %s %s", tempfile, config_file); 1337 1337 paranoid_system(command); 1338 1338 mr_free(command); … … 1463 1463 1464 1464 if (g_magicdev_command && g_magicdev_command[0]) { 1465 mr_asprintf( &tmp, "%s &", g_magicdev_command);1465 mr_asprintf(tmp, "%s &", g_magicdev_command); 1466 1466 paranoid_system(tmp); 1467 1467 mr_free(tmp);
Note:
See TracChangeset
for help on using the changeset viewer.