Changeset 3185 in MondoRescue for branches/3.0/mondo/src/common/libmondo-tools.c
- Timestamp:
- Sep 20, 2013, 2:29:57 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.0/mondo/src/common/libmondo-tools.c
r3154 r3185 224 224 225 225 uname(&utsn); 226 mr_asprintf( &tmp, "%s", utsn.machine);226 mr_asprintf(tmp, "%s", utsn.machine); 227 227 return (tmp); 228 228 } … … 400 400 } 401 401 log_msg(1, "Tape"); 402 mr_asprintf( &tmp, "mt -f %s status", bkpinfo->media_device);402 mr_asprintf(tmp, "mt -f %s status", bkpinfo->media_device); 403 403 log_msg(1, "tmp = '%s'", tmp); 404 404 if (run_program_and_log_output(tmp, 3)) { … … 446 446 } 447 447 if (bkpinfo->nonbootable_backup) { 448 mr_asprintf( &mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT);448 mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_NONBOOT); 449 449 } else if 450 450 #ifdef __FreeBSD__ … … 455 455 #ifdef __IA64__ 456 456 { 457 mr_asprintf( &mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO);457 mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_ELILO); 458 458 } 459 459 #else 460 460 { 461 mr_asprintf( &mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO);461 mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_LILO); 462 462 } 463 463 #endif 464 464 else 465 465 { 466 mr_asprintf( &mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX);466 mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX); 467 467 } 468 468 if (bkpinfo->manual_cd_tray) { … … 478 478 } 479 479 if (getenv ("SUDO_COMMAND")) { 480 mr_asprintf( &command, "strings `which growisofs` | grep -c SUDO_COMMAND");480 mr_asprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND"); 481 481 if (!strcmp(call_program_and_get_last_line_of_output(command), "1")) { 482 482 mr_free(command); … … 494 494 || bkpinfo->backup_media_type == cdr) { 495 495 if (!bkpinfo->manual_cd_tray) { 496 mr_asprintf( &extra_cdrom_params, "-waiti ");496 mr_asprintf(extra_cdrom_params, "-waiti "); 497 497 } 498 498 if (bkpinfo->backup_media_type == cdrw) { 499 mr_asprintf( &extra_cdrom_params, "blank=fast ");499 mr_asprintf(extra_cdrom_params, "blank=fast "); 500 500 } 501 501 if (extra_cdrom_params == NULL) { 502 502 // If not initialized earlier, do it now 503 mr_asprintf( &extra_cdrom_params, " ");503 mr_asprintf(extra_cdrom_params, " "); 504 504 } 505 505 if (find_home_of_exe("cdrecord")) { … … 511 511 } 512 512 if (find_home_of_exe("genisoimage")) { 513 mr_asprintf( &isofs_cmd, "%s", MONDO_GENISOIMAGE_CMD);513 mr_asprintf(isofs_cmd, "%s", MONDO_GENISOIMAGE_CMD); 514 514 } else { 515 mr_asprintf( &isofs_cmd, "%s", MONDO_MKISOFS_CMD);515 mr_asprintf(isofs_cmd, "%s", MONDO_MKISOFS_CMD); 516 516 } 517 517 if (bkpinfo->nonbootable_backup) { 518 mr_asprintf( &mondo_mkisofs_sz, "%s%s", isofs_cmd, MONDO_MKISOFS);518 mr_asprintf(mondo_mkisofs_sz, "%s%s", isofs_cmd, MONDO_MKISOFS); 519 519 } else if 520 520 #ifdef __FreeBSD__ … … 525 525 #ifdef __IA64__ 526 526 { 527 mr_asprintf( &mondo_mkisofs_sz, "%s%s -V _CD#_", isofs_cmd, MONDO_MKISOFS_REGULAR_ELILO);527 mr_asprintf(mondo_mkisofs_sz, "%s%s -V _CD#_", isofs_cmd, MONDO_MKISOFS_REGULAR_ELILO); 528 528 } 529 529 #else 530 530 { 531 mr_asprintf( &mondo_mkisofs_sz, "%s%s -V _CD#_", isofs_cmd, MONDO_MKISOFS_REGULAR_LILO);531 mr_asprintf(mondo_mkisofs_sz, "%s%s -V _CD#_", isofs_cmd, MONDO_MKISOFS_REGULAR_LILO); 532 532 } 533 533 #endif 534 534 else 535 535 { 536 mr_asprintf( &mondo_mkisofs_sz, "%s%s -V _CD#_", isofs_cmd, MONDO_MKISOFS_REGULAR_SYSLINUX);536 mr_asprintf(mondo_mkisofs_sz, "%s%s -V _CD#_", isofs_cmd, MONDO_MKISOFS_REGULAR_SYSLINUX); 537 537 } 538 538 mr_free(isofs_cmd); … … 577 577 578 578 log_it("isodir = %s", bkpinfo->isodir); 579 mr_asprintf( &command, "df -P %s | tail -n1 | cut -d' ' -f1",579 mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1", 580 580 bkpinfo->isodir); 581 581 log_it("command = %s", command); 582 582 log_it("res of it = %s", call_program_and_get_last_line_of_output(command)); 583 mr_asprintf( &iso_dev, "%s", call_program_and_get_last_line_of_output(command));584 mr_asprintf( &tmp, "%s/ISO-DEV", bkpinfo->tmpdir);583 mr_asprintf(iso_dev, "%s", call_program_and_get_last_line_of_output(command)); 584 mr_asprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir); 585 585 write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command)); 586 586 mr_free(tmp); 587 587 mr_free(command); 588 588 589 mr_asprintf( &command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", iso_dev);589 mr_asprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", iso_dev); 590 590 mr_free(iso_dev); 591 591 592 592 log_it("command = %s", command); 593 593 log_it("res of it = %s", call_program_and_get_last_line_of_output(command)); 594 mr_asprintf( &iso_mnt, "%s", call_program_and_get_last_line_of_output(command));595 mr_asprintf( &tmp, "%s/ISO-MNT", bkpinfo->tmpdir);594 mr_asprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command)); 595 mr_asprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir); 596 596 write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command)); 597 597 mr_free(tmp); … … 599 599 600 600 log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt)); 601 mr_asprintf( &iso_tmp, "%s", bkpinfo->isodir);601 mr_asprintf(iso_tmp, "%s", bkpinfo->isodir); 602 602 if (strlen(iso_tmp) < strlen(iso_mnt)) { 603 mr_asprintf( &iso_path, "%s", "");603 mr_asprintf(iso_path, "%s", ""); 604 604 } else { 605 605 // If iso_mnt is only / then iso_path is the full dir 606 606 // (the formula bellow doesn't work in this case) 607 607 if (strcmp(iso_mnt, "/") == 0) { 608 mr_asprintf( &iso_path, "%s", iso_tmp);608 mr_asprintf(iso_path, "%s", iso_tmp); 609 609 // else it's a part of iso_tmp 610 610 } else { 611 mr_asprintf( &iso_path, "%s", iso_tmp + strlen(iso_mnt));611 mr_asprintf(iso_path, "%s", iso_tmp + strlen(iso_mnt)); 612 612 } 613 613 } … … 615 615 mr_free(iso_mnt); 616 616 617 mr_asprintf( &tmp, "%s/ISODIR", bkpinfo->tmpdir);617 mr_asprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir); 618 618 write_one_liner_data_file(tmp, iso_path); 619 619 mr_free(tmp); … … 622 622 mr_free(iso_path); 623 623 624 mr_asprintf( &tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir);624 mr_asprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir); 625 625 write_one_liner_data_file(tmp, bkpinfo->prefix); 626 626 mr_free(tmp); … … 646 646 colon++; 647 647 hent = gethostbyname(colon); 648 mr_asprintf( &(bkpinfo->netfs_user),"%s", hostname);648 mr_asprintf(bkpinfo->netfs_user,"%s", hostname); 649 649 } else { 650 650 hent = gethostbyname(hostname); … … 655 655 retval++; 656 656 } else { 657 mr_asprintf( &ip_address, "%s", inet_ntoa((struct in_addr) *((struct in_addr *) hent->h_addr)));657 mr_asprintf(ip_address, "%s", inet_ntoa((struct in_addr) *((struct in_addr *) hent->h_addr))); 658 658 mr_strcat(ip_address, strchr(bkpinfo->netfs_mount, ':')); 659 659 strcpy(bkpinfo->netfs_mount, ip_address); … … 709 709 } 710 710 711 mr_asprintf( &tmp,"rm -Rf %s/changed.files*",MONDO_CACHE);711 mr_asprintf(tmp,"rm -Rf %s/changed.files*",MONDO_CACHE); 712 712 run_program_and_log_output(tmp, FALSE); 713 713 paranoid_free(tmp); … … 750 750 if (strstr(bkpinfo->tmpdir,"mondo.tmp.") != NULL) { 751 751 log_it("Purging old tmpdir %s", bkpinfo->tmpdir); 752 mr_asprintf( &tmp,"rm -Rf %s",bkpinfo->tmpdir);752 mr_asprintf(tmp,"rm -Rf %s",bkpinfo->tmpdir); 753 753 } else { 754 754 log_it("Purging old tmpdir %s/mondo.tmp.*", bkpinfo->tmpdir); 755 mr_asprintf( &tmp,"rm -Rf %s/mondo.tmp.*",bkpinfo->tmpdir);755 mr_asprintf(tmp,"rm -Rf %s/mondo.tmp.*",bkpinfo->tmpdir); 756 756 } 757 757 paranoid_system(tmp); … … 761 761 /* Always take in account arg first, then env, then default */ 762 762 if (path != NULL) { 763 mr_asprintf( &tmp, "%s/mondo.tmp.XXXXXX", path);763 mr_asprintf(tmp, "%s/mondo.tmp.XXXXXX", path); 764 764 } else if (getenv("TMPDIR")) { 765 mr_asprintf( &tmp, "%s/mondo.tmp.XXXXXX", getenv("TMPDIR"));765 mr_asprintf(tmp, "%s/mondo.tmp.XXXXXX", getenv("TMPDIR")); 766 766 } else if (getenv("MRTMP")) { 767 mr_asprintf( &tmp, "%s/mondo.tmp.XXXXXX", getenv("MRTMP"));767 mr_asprintf(tmp, "%s/mondo.tmp.XXXXXX", getenv("MRTMP")); 768 768 } else { 769 mr_asprintf( &tmp, "/tmp/mondo.tmp.XXXXXX");769 mr_asprintf(tmp, "/tmp/mondo.tmp.XXXXXX"); 770 770 } 771 771 p = mkdtemp(tmp); … … 777 777 paranoid_free(tmp); 778 778 779 mr_asprintf( &tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);779 mr_asprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); 780 780 paranoid_system(tmp); 781 781 mr_free(tmp); … … 794 794 if (strstr(bkpinfo->scratchdir,"mondo.scratch.") != NULL) { 795 795 log_it("Purging old scratchdir %s", bkpinfo->scratchdir); 796 mr_asprintf( &tmp,"rm -Rf %s",bkpinfo->scratchdir);796 mr_asprintf(tmp,"rm -Rf %s",bkpinfo->scratchdir); 797 797 } else { 798 798 log_it("Purging old scratchdir %s/mondo.scratch.*", bkpinfo->scratchdir); 799 mr_asprintf( &tmp,"rm -Rf %s/mondo.scratch.*",bkpinfo->scratchdir);799 mr_asprintf(tmp,"rm -Rf %s/mondo.scratch.*",bkpinfo->scratchdir); 800 800 } 801 801 paranoid_system(tmp); … … 805 805 /* Always take in account arg first, then env, then default */ 806 806 if (path != NULL) { 807 mr_asprintf( &tmp, "%s/mondo.scratch.XXXXXX", path);807 mr_asprintf(tmp, "%s/mondo.scratch.XXXXXX", path); 808 808 } else if (getenv("MRSCRATCH")) { 809 mr_asprintf( &tmp, "%s/mondo.scratch.XXXXXX", getenv("MRSCRATCH"));809 mr_asprintf(tmp, "%s/mondo.scratch.XXXXXX", getenv("MRSCRATCH")); 810 810 } else { 811 mr_asprintf( &tmp, "/tmp/mondo.scratch.XXXXXX");811 mr_asprintf(tmp, "/tmp/mondo.scratch.XXXXXX"); 812 812 } 813 813 p = mkdtemp(tmp); … … 819 819 paranoid_free(tmp); 820 820 821 mr_asprintf( &tmp, "mkdir -p %s", bkpinfo->scratchdir);821 mr_asprintf(tmp, "mkdir -p %s", bkpinfo->scratchdir); 822 822 paranoid_system(tmp); 823 823 mr_free(tmp); … … 909 909 assert_string_is_neither_NULL_nor_zerolength(partition); 910 910 911 mr_asprintf( &command, "df -m -P %s 1> /dev/null 2> /dev/null", partition);911 mr_asprintf(command, "df -m -P %s 1> /dev/null 2> /dev/null", partition); 912 912 if (system(command)) { 913 913 mr_free(command); … … 916 916 mr_free(command); 917 917 918 mr_asprintf( &command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4",918 mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", 919 919 partition); 920 mr_asprintf( &out_sz, "%s", call_program_and_get_last_line_of_output(command));920 mr_asprintf(out_sz, "%s", call_program_and_get_last_line_of_output(command)); 921 921 mr_free(command); 922 922 … … 962 962 ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE); 963 963 } 964 mr_asprintf( &tmp, "%s",964 mr_asprintf(tmp, "%s", 965 965 call_program_and_get_last_line_of_output 966 966 ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2")); … … 1028 1028 run_program_and_log_output 1029 1029 ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5); 1030 mr_asprintf( &tmp, "%s",1030 mr_asprintf(tmp, "%s", 1031 1031 call_program_and_get_last_line_of_output 1032 1032 ("mount | grep -E \"cdr(om|w)\"")); … … 1063 1063 fatal_error("Please reinstall Mondo and Mindi."); 1064 1064 } 1065 mr_asprintf( &tmp, "mindi --makemountlist %s/mountlist.txt.test", bkpinfo->tmpdir);1065 mr_asprintf(tmp, "mindi --makemountlist %s/mountlist.txt.test", bkpinfo->tmpdir); 1066 1066 if (run_program_and_log_output(tmp, 5)) { 1067 1067 mr_free(tmp); 1068 mr_asprintf( &tmp, "mindi --makemountlist %s/mountlist.txt.test failed for some reason.", bkpinfo->tmpdir);1068 mr_asprintf(tmp, "mindi --makemountlist %s/mountlist.txt.test failed for some reason.", bkpinfo->tmpdir); 1069 1069 log_to_screen(tmp); 1070 1070 log_to_screen … … 1111 1111 assert_string_is_neither_NULL_nor_zerolength(label); 1112 1112 if (!does_file_exist(config_file)) { 1113 mr_asprintf( &tmp, "(read_cfg_var) Cannot find %s config file",1113 mr_asprintf(tmp, "(read_cfg_var) Cannot find %s config file", 1114 1114 config_file); 1115 1115 log_to_screen(tmp); … … 1122 1122 return (0); 1123 1123 } else { 1124 mr_asprintf( &command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5",1124 mr_asprintf(command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5", 1125 1125 label, config_file); 1126 1126 strcpy(value, call_program_and_get_last_line_of_output(command)); … … 1206 1206 log_msg(3, "%s --- autofs detected", g_autofs_exe); 1207 1207 // FIXME -- only disable it if it's running --- sprintf(tmp, "%s status", autofs_exe); 1208 mr_asprintf( &tmp, "%s stop", g_autofs_exe);1208 mr_asprintf(tmp, "%s stop", g_autofs_exe); 1209 1209 if (run_program_and_log_output(tmp, 2)) { 1210 1210 log_it("Failed to stop autofs - I assume it wasn't running"); … … 1228 1228 return; 1229 1229 } 1230 mr_asprintf( &tmp, "%s start", g_autofs_exe);1230 mr_asprintf(tmp, "%s start", g_autofs_exe); 1231 1231 if (run_program_and_log_output(tmp, 2)) { 1232 1232 log_it("Failed to start autofs"); … … 1251 1251 g_boot_mountpt[0] = '\0'; 1252 1252 log_msg(4, "Done. Great. Seeting command to something"); 1253 mr_asprintf( &command, "%s",1253 mr_asprintf(command, "%s", 1254 1254 "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1"); 1255 1255 log_msg(4, "Cool. Command = '%s'", command); 1256 mr_asprintf( &tmp, "%s", call_program_and_get_last_line_of_output(command));1256 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); 1257 1257 mr_free(command); 1258 1258 … … 1260 1260 if (tmp[0]) { 1261 1261 log_it("/boot is at %s according to /etc/fstab", tmp); 1262 mr_asprintf( &command, "mount | grep -Ew '/boot'");1262 mr_asprintf(command, "mount | grep -Ew '/boot'"); 1263 1263 mr_free(tmp); 1264 mr_asprintf( &tmp, call_program_and_get_last_line_of_output(command));1264 mr_asprintf(tmp, call_program_and_get_last_line_of_output(command)); 1265 1265 mr_free(command); 1266 1266 … … 1274 1274 } 1275 1275 } else { 1276 mr_asprintf( &command, "mount | grep -E '^%s'", tmp);1276 mr_asprintf(command, "mount | grep -E '^%s'", tmp); 1277 1277 log_msg(3, "command = %s", command); 1278 1278 if (run_program_and_log_output(command, 5)) { 1279 1279 strcpy(g_boot_mountpt, tmp); 1280 1280 mr_free(tmp); 1281 mr_asprintf( &tmp,1281 mr_asprintf(tmp, 1282 1282 "%s (your /boot partition) is not mounted. I'll mount it before backing up", 1283 1283 g_boot_mountpt); … … 1285 1285 mr_free(tmp); 1286 1286 1287 mr_asprintf( &tmp, "mount %s", g_boot_mountpt);1287 mr_asprintf(tmp, "mount %s", g_boot_mountpt); 1288 1288 if (run_program_and_log_output(tmp, 5)) { 1289 1289 g_boot_mountpt[0] = '\0'; … … 1316 1316 log_msg(3, "starting"); 1317 1317 if (g_boot_mountpt[0]) { 1318 mr_asprintf( &tmp, "umount %s", g_boot_mountpt);1318 mr_asprintf(tmp, "umount %s", g_boot_mountpt); 1319 1319 if (run_program_and_log_output(tmp, 5)) { 1320 1320 log_it("WARNING - unable to unmount /boot"); … … 1348 1348 assert(value != NULL); 1349 1349 if (!does_file_exist(config_file)) { 1350 mr_asprintf( &tmp, "(write_cfg_file) Cannot find %s config file",1350 mr_asprintf(tmp, "(write_cfg_file) Cannot find %s config file", 1351 1351 config_file); 1352 1352 log_to_screen(tmp); … … 1354 1354 return (1); 1355 1355 } 1356 mr_asprintf( &tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir);1356 mr_asprintf(tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir); 1357 1357 if (does_file_exist(config_file)) { 1358 mr_asprintf( &command, "grep -vE '^%s .*$' %s > %s",1358 mr_asprintf(command, "grep -vE '^%s .*$' %s > %s", 1359 1359 label, config_file, tempfile); 1360 1360 paranoid_system(command); 1361 1361 mr_free(command); 1362 1362 } 1363 mr_asprintf( &command, "echo \"%s %s\" >> %s", label, value, tempfile);1363 mr_asprintf(command, "echo \"%s %s\" >> %s", label, value, tempfile); 1364 1364 paranoid_system(command); 1365 1365 mr_free(command); 1366 1366 1367 mr_asprintf( &command, "mv -f %s %s", tempfile, config_file);1367 mr_asprintf(command, "mv -f %s %s", tempfile, config_file); 1368 1368 paranoid_system(command); 1369 1369 mr_free(command); … … 1536 1536 1537 1537 if (g_magicdev_command && g_magicdev_command[0]) { 1538 mr_asprintf( &tmp, "%s &", g_magicdev_command);1538 mr_asprintf(tmp, "%s &", g_magicdev_command); 1539 1539 paranoid_system(tmp); 1540 1540 mr_free(tmp);
Note:
See TracChangeset
for help on using the changeset viewer.