Changeset 3191 in MondoRescue for branches/3.2/mondo/src/common/libmondo-tools.c
- Timestamp:
- Sep 25, 2013, 8:55:45 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mondo/src/common/libmondo-tools.c
r3185 r3191 30 30 31 31 extern int g_tape_buffer_size_MB; 32 extern char *g_serial_string;33 32 extern bool g_text_mode; 34 33 extern int g_currentY; 35 34 extern int g_current_media_number; 36 35 extern char *MONDO_LOGFILE; 36 extern char *g_serial_string; 37 37 38 38 /* Reference to global bkpinfo */ … … 113 113 return; 114 114 } 115 #ifndef _XWIN116 115 if (!g_text_mode) 117 116 newtSuspend(); 118 #endif119 117 printf("ASSERTION FAILED: `%s'\n", exp); 120 118 printf("\tat %s:%d in %s\n\n", file, line, function); … … 163 161 getchar(); // skip \n 164 162 165 #ifndef _XWIN166 163 if (!g_text_mode) 167 164 newtResume(); 168 #endif169 165 } 170 166 … … 175 171 void clean_up_KDE_desktop_if_necessary(void) 176 172 { 177 char *tmp; 178 179 malloc_string(tmp); 180 strcpy(tmp, 181 "for i in `find /root /home -maxdepth 2 -type d -name Desktop`; do \ 182 file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; \ 183 awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } \ 184 else { print $0;};}' $file.old > $file ; fi ; done"); 173 char *tmp = NULL; 174 175 mr_asprintf(tmp, "for i in `find /root /home -maxdepth 2 -type d -name Desktop -maxdepth 2`; do file=$i/.directory; if [ -f \"$file\" ] ; then mv -f $file $file.old ; awk '{if (index($0, \"rootimagesmindi\")) { while (length($0)>2) { getline;} ; } else { print $0;};}' $file.old > $file ; fi ; done"); 185 176 run_program_and_log_output(tmp, 5); 186 paranoid_free(tmp);177 mr_free(tmp); 187 178 } 188 179 … … 232 223 double get_kernel_version(void) 233 224 { 234 char *p, tmp[200]; 225 char *p = NULL; 226 char *tmp = NULL; 235 227 double d; 236 228 #ifdef __FreeBSD__ … … 238 230 d = 5.2; // :-) 239 231 #else 240 strcpy(tmp, call_program_and_get_last_line_of_output("uname -r"));232 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("uname -r")); 241 233 p = strchr(tmp, '.'); 242 234 if (p) { … … 249 241 } 250 242 } 251 // log_msg(1, "tmp = '%s'", tmp);252 243 d = atof(tmp); 244 mr_free(tmp); 253 245 #endif 254 246 log_msg(1, "g_kernel_version = %f", d); … … 257 249 258 250 259 260 261 262 251 /** 263 252 * Get the current time. … … 268 257 return (long) time((void *) 0); 269 258 } 270 271 272 273 274 275 259 276 260 … … 368 352 char *mondo_mkisofs_sz = NULL; 369 353 char *command = NULL; 370 char *mtpt; 371 char *hostname; 354 char *hostname = NULL; 372 355 char *isofs_cmd = NULL; 373 356 char *ip_address = NULL; 374 357 int retval = 0; 375 358 char *colon; 376 char *cdr_exe ;359 char *cdr_exe = NULL; 377 360 char *tmp = NULL; 378 char call_before_iso_user[MAX_STR_LEN] = "\0"; 379 /* 380 long avm = 0; 381 int rdsiz_MB; 382 */ 361 char *p = NULL; 362 char *call_before_iso_user = NULL; 383 363 char *iso_dev = NULL; 384 364 char *iso_mnt = NULL; … … 387 367 388 368 assert(bkpinfo != NULL); 389 malloc_string(mtpt); 390 malloc_string(hostname); 391 malloc_string(cdr_exe); 369 392 370 bkpinfo->optimal_set_size = 393 371 (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) * … … 400 378 } 401 379 log_msg(1, "Tape"); 380 if (bkpinfo->media_device == NULL) { 381 return(1); 382 } 402 383 mr_asprintf(tmp, "mt -f %s status", bkpinfo->media_device); 403 384 log_msg(1, "tmp = '%s'", tmp); … … 429 410 strcpy(bkpinfo->zip_exe, "gzip"); 430 411 strcpy(bkpinfo->zip_suffix, "gz"); 412 } else if (bkpinfo->use_lzma) { 413 strcpy(bkpinfo->zip_exe, "lzma"); 414 strcpy(bkpinfo->zip_suffix, "lzma"); 431 415 } else if (bkpinfo->compression_level != 0) { 432 416 strcpy(bkpinfo->zip_exe, "bzip2"); … … 440 424 if (bkpinfo->backup_media_type == dvd) { 441 425 if (find_home_of_exe("growisofs")) { 442 strcpy(cdr_exe, "growisofs");426 mr_asprintf(cdr_exe, "growisofs"); 443 427 } // unlikely to be used 444 428 else { … … 462 446 } 463 447 #endif 464 else 465 { 448 else { 466 449 mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX); 467 450 } 468 451 if (bkpinfo->manual_cd_tray) { 469 paranoid_free(mondo_mkisofs_sz);470 452 fatal_error("Manual CD tray + DVD not supported yet."); 471 453 // -m isn't supported by growisofs, BTW... … … 475 457 mondo_mkisofs_sz, 476 458 "", bkpinfo->media_device); 477 paranoid_free(mondo_mkisofs_sz);478 }459 } 460 mr_free(mondo_mkisofs_sz); 479 461 if (getenv ("SUDO_COMMAND")) { 480 462 mr_asprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND"); … … 486 468 mr_free(command); 487 469 } 488 log_msg(2, "call_make_iso (DVD res) is ... %s", 489 bkpinfo->call_make_iso); 470 log_msg(2, "call_make_iso (DVD res) is ... %s", bkpinfo->call_make_iso); 490 471 } // end of DVD code 491 472 … … 504 485 } 505 486 if (find_home_of_exe("cdrecord")) { 506 strcpy(cdr_exe, "cdrecord");487 mr_asprintf(cdr_exe, "cdrecord"); 507 488 } else if (find_home_of_exe("dvdrecord")) { 508 strcpy(cdr_exe, "dvdrecord");489 mr_asprintf(cdr_exe, "dvdrecord"); 509 490 } else { 510 491 fatal_error("Please install either cdrecord or dvdrecord."); … … 544 525 mondo_mkisofs_sz, bkpinfo->tmpdir); 545 526 } else { 546 strncpy(call_before_iso_user, bkpinfo->call_before_iso, MAX_STR_LEN); 547 sprintf (bkpinfo->call_before_iso, 548 "( %s -o %s/"MONDO_TMPISOS" . 2>> _ERR_ ; %s )", 549 mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user); 527 mr_asprintf(call_before_iso_user, "%s", bkpinfo->call_before_iso); 528 sprintf(bkpinfo->call_before_iso, "( %s -o %s/"MONDO_TMPISOS" . 2>> _ERR_ ; %s )", mondo_mkisofs_sz, bkpinfo->tmpdir, call_before_iso_user); 529 mr_free(call_before_iso_user); 550 530 } 551 531 log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso); 552 sprintf(bkpinfo->call_make_iso, 553 "%s %s -v %s fs=4m dev=%s speed=%d %s/"MONDO_TMPISOS, 554 cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject", 555 extra_cdrom_params, bkpinfo->media_device, 556 bkpinfo->cdrw_speed, bkpinfo->tmpdir); 532 sprintf(bkpinfo->call_make_iso, "%s %s -v %s fs=4m dev=%s speed=%d %s/"MONDO_TMPISOS, cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject", extra_cdrom_params, bkpinfo->media_device, bkpinfo->cdrw_speed, bkpinfo->tmpdir); 557 533 } else { 558 sprintf(bkpinfo->call_make_iso, 559 "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -", 560 mondo_mkisofs_sz, cdr_exe, 561 (bkpinfo->please_dont_eject) ? " " : "-eject", 562 extra_cdrom_params, bkpinfo->media_device, 563 bkpinfo->cdrw_speed); 564 } 565 paranoid_free(mondo_mkisofs_sz); 566 paranoid_free(extra_cdrom_params); 534 sprintf(bkpinfo->call_make_iso, "%s . 2>> _ERR_ | %s %s %s fs=4m dev=%s speed=%d -", mondo_mkisofs_sz, cdr_exe, (bkpinfo->please_dont_eject) ? " " : "-eject", extra_cdrom_params, bkpinfo->media_device, bkpinfo->cdrw_speed); 535 } 536 mr_free(cdr_exe); 537 mr_free(mondo_mkisofs_sz); 538 mr_free(extra_cdrom_params); 567 539 } // end of CD code 568 540 … … 577 549 578 550 log_it("isodir = %s", bkpinfo->isodir); 579 mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1", 580 bkpinfo->isodir); 551 mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1", bkpinfo->isodir); 581 552 log_it("command = %s", command); 582 log_it("res of it = %s", call_program_and_get_last_line_of_output(command));583 553 mr_asprintf(iso_dev, "%s", call_program_and_get_last_line_of_output(command)); 554 log_it("res of it = %s", iso_dev); 584 555 mr_asprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir); 585 write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));556 write_one_liner_data_file(tmp, iso_dev); 586 557 mr_free(tmp); 587 558 mr_free(command); … … 591 562 592 563 log_it("command = %s", command); 593 log_it("res of it = %s", call_program_and_get_last_line_of_output(command));594 564 mr_asprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command)); 565 log_it("res of it = %s", iso_mnt); 595 566 mr_asprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir); 596 write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command));567 write_one_liner_data_file(tmp, iso_mnt); 597 568 mr_free(tmp); 598 569 mr_free(command); … … 612 583 } 613 584 } 585 mr_free(iso_mnt); 614 586 mr_free(iso_tmp); 615 mr_free(iso_mnt);616 587 617 588 mr_asprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir); … … 632 603 633 604 if (bkpinfo->backup_media_type == netfs) { 634 strcpy(hostname, bkpinfo->netfs_mount); 605 if (bkpinfo->netfs_mount) { 606 mr_asprintf(hostname, "%s", bkpinfo->netfs_mount); 607 } else { 608 log_it("netfs_mount is NULL"); 609 retval++; 610 mr_asprintf(hostname, ""); 611 } 635 612 colon = strchr(hostname, ':'); 636 613 if (!colon) { … … 651 628 } 652 629 if (!hent) { 653 log_it("Can't resolve Network mount (%s): %s", hostname, 654 hstrerror(h_errno)); 630 log_it("Can't resolve Network mount (%s): %s", hostname, hstrerror(h_errno)); 655 631 retval++; 656 632 } else { … … 658 634 mr_strcat(ip_address, strchr(bkpinfo->netfs_mount, ':')); 659 635 strcpy(bkpinfo->netfs_mount, ip_address); 660 paranoid_free(ip_address);636 mr_free(ip_address); 661 637 } 662 638 } 639 mr_free(hostname); 663 640 store_netfs_config(); 664 641 } … … 668 645 fprintf(stderr, "Type 'man mondoarchive' for help.\n"); 669 646 } 670 if (strlen(bkpinfo->tmpdir) < 2 || strlen(bkpinfo->scratchdir) < 2) { 671 log_it("tmpdir or scratchdir are blank/missing"); 672 retval++; 673 } 674 if (bkpinfo->include_paths[0] == '\0') { 675 // fatal_error ("Why no backup path?"); 676 strcpy(bkpinfo->include_paths, "/"); 677 } 678 chmod(bkpinfo->scratchdir, 0700); 647 if (bkpinfo->include_paths == NULL) { 648 mr_asprintf(bkpinfo->include_paths, "/"); 649 } 679 650 g_backup_media_type = bkpinfo->backup_media_type; 680 paranoid_free(mtpt);681 paranoid_free(hostname);682 paranoid_free(cdr_exe);683 651 return (retval); 684 652 } … … 704 672 if (bkpinfo->disaster_recovery) { 705 673 if (!does_nonMS_partition_exist()) { 706 fatal_error 707 ("I am in disaster recovery mode\nPlease don't run mondoarchive."); 674 fatal_error("I am in disaster recovery mode\nPlease don't run mondoarchive."); 708 675 } 709 676 } … … 713 680 paranoid_free(tmp); 714 681 if (find_and_store_mondoarchives_home(g_mondo_home)) { 715 fprintf(stderr, 716 "Cannot find Mondo's homedir. I think you have >1 'mondo' directory on your hard disk. Please delete the superfluous 'mondo' directories and try again\n"); 682 fprintf(stderr, "Cannot find Mondo's homedir. I think you have >1 'mondo' directory on your hard disk. Please delete the superfluous 'mondo' directories and try again\n"); 717 683 res++; 718 684 return (res); … … 723 689 } 724 690 g_current_media_number = 1; 725 bkpinfo->postnuke_tarball[0] = bkpinfo->netfs_mount[0] ='\0';691 bkpinfo->postnuke_tarball[0] = '\0'; 726 692 return (res); 727 693 } … … 772 738 if (p == NULL) { 773 739 log_it("Failed to create global tmp directory %s for Mondo.",tmp); 740 mr_free(tmp); 774 741 finish(-1); 775 742 } 743 mr_free(tmp); 744 776 745 strcpy(bkpinfo->tmpdir,p); 777 paranoid_free(tmp);746 log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir); 778 747 779 748 mr_asprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); … … 817 786 } 818 787 strcpy(bkpinfo->scratchdir,p); 788 log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir); 819 789 paranoid_free(tmp); 820 790 … … 832 802 { 833 803 int i; 834 835 log_msg(1, "Hi"); 804 log_msg(1, "Initializing bkpinfo"); 805 836 806 assert(bkpinfo != NULL); 837 807 memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo)); … … 847 817 bkpinfo->use_lzo = FALSE; 848 818 bkpinfo->use_gzip = FALSE; 849 bkpinfo-> do_not_compress_these[0] = '\0';819 bkpinfo->use_lzma = FALSE; 850 820 bkpinfo->verify_data = FALSE; 851 821 bkpinfo->backup_data = FALSE; … … 853 823 bkpinfo->use_star = FALSE; 854 824 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 855 bkpinfo->disaster_recovery = 856 (am_I_in_disaster_recovery_mode()? TRUE : FALSE); 825 826 /* We need tmpdir as early as possible for further function calls */ 827 bkpinfo->tmpdir = NULL; // Really setup after 828 setup_tmpdir(NULL); 829 setup_scratchdir(NULL); 830 831 bkpinfo->disaster_recovery = am_I_in_disaster_recovery_mode(); 857 832 if (bkpinfo->disaster_recovery) { 858 833 strcpy(bkpinfo->isodir, "/"); … … 861 836 } 862 837 strcpy(bkpinfo->prefix, STD_PREFIX); 863 setup_tmpdir(NULL);864 setup_scratchdir(NULL);865 866 838 bkpinfo->optimal_set_size = 0; 867 strcpy(bkpinfo->include_paths, "/");839 bkpinfo->backup_media_type = none; 868 840 bkpinfo->make_filelist = TRUE; // unless -J supplied to mondoarchive 869 bkpinfo->include_paths[0] = '\0'; 841 bkpinfo->exclude_paths = NULL; 842 bkpinfo->include_paths = NULL; 870 843 bkpinfo->exclude_devs = NULL; 871 844 bkpinfo->restore_path[0] = '\0'; … … 879 852 bkpinfo->netfs_user = NULL; 880 853 bkpinfo->netfs_remote_dir[0] = '\0'; 881 bkpinfo-> exclude_paths = NULL;854 bkpinfo->postnuke_tarball[0] = '\0'; 882 855 bkpinfo->subdir = NULL; 883 bkpinfo->postnuke_tarball[0] = '\0';884 856 bkpinfo->wipe_media_first = FALSE; 885 857 bkpinfo->differential = 0; … … 894 866 895 867 896 897 898 868 /** 899 869 * Get the remaining free space (in MB) on @p partition. … … 916 886 mr_free(command); 917 887 918 mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", 919 partition); 888 mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", partition); 920 889 mr_asprintf(out_sz, "%s", call_program_and_get_last_line_of_output(command)); 921 890 mr_free(command); … … 957 926 if (system("which mkfs.vfat 2> /dev/null 1> /dev/null") 958 927 && !system("which mkfs.msdos 2> /dev/null 1> /dev/null")) { 959 log_it 960 ("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand..."); 961 run_program_and_log_output 962 ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE); 963 } 964 mr_asprintf(tmp, "%s", 965 call_program_and_get_last_line_of_output 966 ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2")); 928 log_it("OK, you've got mkfs.msdos but not mkfs.vfat; time for the fairy to wave her magic wand..."); 929 run_program_and_log_output("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE); 930 } 931 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2")); 967 932 if (atol(tmp) < 35000) { 968 933 retval++; … … 970 935 } 971 936 if (atol(tmp) < 66000) { 972 log_to_screen 973 ("WARNING! You have very little RAM. Please upgrade to 64MB or more."); 937 log_to_screen("WARNING! You have very little RAM. Please upgrade to 64MB or more."); 974 938 } 975 939 mr_free(tmp); … … 1026 990 whine_if_not_found("cmp"); 1027 991 } 1028 run_program_and_log_output 1029 ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5); 1030 mr_asprintf(tmp, "%s", 1031 call_program_and_get_last_line_of_output 1032 ("mount | grep -E \"cdr(om|w)\"")); 992 run_program_and_log_output("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5); 993 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("mount | grep -E \"cdr(om|w)\"")); 1033 994 if (strcmp("", tmp)) { 1034 995 if (strstr(tmp, "autofs")) { … … 1104 1065 /*@ buffer ****************************************************** */ 1105 1066 char *command = NULL; 1106 char *tmp = NULL;1107 1067 1108 1068 /*@ end vars *************************************************** */ … … 1111 1071 assert_string_is_neither_NULL_nor_zerolength(label); 1112 1072 if (!does_file_exist(config_file)) { 1113 mr_asprintf(tmp, "(read_cfg_var) Cannot find %s config file", 1114 config_file); 1115 log_to_screen(tmp); 1116 mr_free(tmp); 1117 1073 log_to_screen("(read_cfg_var) Cannot find %s config file", config_file); 1118 1074 value[0] = '\0'; 1119 1075 return (1); … … 1127 1083 mr_free(command); 1128 1084 1085 log_msg(4, "Configuration item %s is %s", label, value); 1129 1086 if (strlen(value) == 0) { 1130 1087 return (1); … … 1242 1199 * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it. 1243 1200 */ 1244 void mount_boot_if_necessary() 1245 { 1201 void mount_boot_if_necessary() { 1246 1202 char *tmp = NULL; 1247 1203 char *command = NULL; … … 1251 1207 g_boot_mountpt[0] = '\0'; 1252 1208 log_msg(4, "Done. Great. Seeting command to something"); 1253 mr_asprintf(command, "%s", 1254 "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1"); 1209 mr_asprintf(command, "%s", "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1"); 1255 1210 log_msg(4, "Cool. Command = '%s'", command); 1256 1211 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); … … 1258 1213 1259 1214 log_msg(4, "tmp = '%s'", tmp); 1260 if (tmp[0]) { 1261 log_it("/boot is at %s according to /etc/fstab", tmp); 1262 mr_asprintf(command, "mount | grep -Ew '/boot'"); 1263 mr_free(tmp); 1264 mr_asprintf(tmp, call_program_and_get_last_line_of_output(command)); 1265 mr_free(command); 1266 1267 if (!strcmp(tmp,"")) { 1268 if (((strstr(tmp, "LABEL=") != NULL) || (strstr(tmp,"UUID=")) != NULL)) { 1269 if (!run_program_and_log_output("mount /boot", 5)) { 1270 strcpy(g_boot_mountpt, "/boot"); 1271 log_msg(1, "Mounted /boot"); 1272 } else { 1273 log_it("...ignored cos it's a label or uuid :-)"); 1215 log_it("/boot is at %s according to /etc/fstab", tmp); 1216 mr_asprintf(command, "mount | grep -Ew '/boot'"); 1217 mr_free(tmp); 1218 1219 mr_asprintf(tmp, call_program_and_get_last_line_of_output(command)); 1220 mr_free(command); 1221 1222 if (!strcmp(tmp,"")) { 1223 if ((strstr(tmp, "LABEL=") != NULL) || (strstr(tmp,"UUID=") != NULL)) { 1224 if (!run_program_and_log_output("mount /boot", 5)) { 1225 strcpy(g_boot_mountpt, "/boot"); 1226 log_msg(1, "Mounted /boot"); 1227 } else { 1228 log_it("...ignored cos it's a label or uuid :-)"); 1229 } 1230 } else { 1231 mr_asprintf(command, "mount | grep -E '^%s'", tmp); 1232 log_msg(3, "command = %s", command); 1233 if (run_program_and_log_output(command, 5)) { 1234 strcpy(g_boot_mountpt, tmp); 1235 mr_free(tmp); 1236 log_it("%s (your /boot partition) is not mounted. I'll mount it before backing up", g_boot_mountpt); 1237 1238 mr_asprintf(tmp, "mount %s", g_boot_mountpt); 1239 if (run_program_and_log_output(tmp, 5)) { 1240 g_boot_mountpt[0] = '\0'; 1241 log_msg(1, "Plan B"); 1242 if (!run_program_and_log_output("mount /boot", 5)) { 1243 strcpy(g_boot_mountpt, "/boot"); 1244 log_msg(1, "Plan B worked"); 1245 } else { 1246 log_msg(1, 1247 "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition."); 1248 } 1274 1249 } 1275 } else {1276 mr_asprintf(command, "mount | grep -E '^%s'", tmp);1277 log_msg(3, "command = %s", command);1278 if (run_program_and_log_output(command, 5)) {1279 strcpy(g_boot_mountpt, tmp);1280 mr_free(tmp);1281 mr_asprintf(tmp,1282 "%s (your /boot partition) is not mounted. I'll mount it before backing up",1283 g_boot_mountpt);1284 log_it(tmp);1285 mr_free(tmp);1286 1287 mr_asprintf(tmp, "mount %s", g_boot_mountpt);1288 if (run_program_and_log_output(tmp, 5)) {1289 g_boot_mountpt[0] = '\0';1290 log_msg(1, "Plan B");1291 if (!run_program_and_log_output("mount /boot", 5)) {1292 strcpy(g_boot_mountpt, "/boot");1293 log_msg(1, "Plan B worked");1294 } else {1295 log_msg(1,1296 "Plan B failed. Unable to mount /boot for backup purposes. This probably means /boot is mounted already, or doesn't have its own partition.");1297 }1298 }1299 mr_free(tmp);1300 }1301 mr_free(command);1302 1250 } 1303 } 1304 } 1251 mr_free(command); 1252 } 1253 } 1254 mr_free(tmp); 1305 1255 log_msg(1, "Ended sub"); 1306 1256 } … … 1340 1290 char *command = NULL; 1341 1291 char *tempfile = NULL; 1342 char *tmp = NULL;1343 1292 1344 1293 … … 1348 1297 assert(value != NULL); 1349 1298 if (!does_file_exist(config_file)) { 1350 mr_asprintf(tmp, "(write_cfg_file) Cannot find %s config file", 1351 config_file); 1352 log_to_screen(tmp); 1353 mr_free(tmp); 1299 log_to_screen("(write_cfg_file) Cannot find %s config file", config_file); 1354 1300 return (1); 1355 1301 } 1356 1302 mr_asprintf(tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir); 1357 1303 if (does_file_exist(config_file)) { 1358 mr_asprintf(command, "grep -vE '^%s .*$' %s > %s", 1359 label, config_file, tempfile); 1304 mr_asprintf(command, "grep -vE '^%s .*$' %s > %s", label, config_file, tempfile); 1360 1305 paranoid_system(command); 1361 1306 mr_free(command); … … 1378 1323 * information to the logfile. 1379 1324 */ 1380 void standard_log_debug_msg(int debug_level, const char *szFile, 1381 const char *szFunction, int nLine, 1382 const char *fmt, ...) 1383 { 1325 void standard_log_debug_msg(int debug_level, const char *szFile, const char *szFunction, int nLine, const char *fmt, ...) { 1326 1384 1327 va_list args; 1385 int i;1386 1328 static int depth = 0; 1387 1329 FILE *fout; … … 1396 1338 if (!(fout = fopen(MONDO_LOGFILE, "a"))) { 1397 1339 return; 1398 } // fatal_error("Failed to openout to logfile - sheesh..."); }1340 } 1399 1341 1400 1342 // add tabs to distinguish log levels 1401 1343 if (debug_level > 0) { 1402 for (i = 1; i < debug_level; i++) 1403 fprintf(fout, "\t"); 1344 fprintf(fout, "DBG%d: ", debug_level); 1404 1345 if (getpid() == g_main_pid) 1405 1346 fprintf(fout, "[Main] %s->%s#%d: ", szFile, szFunction, nLine); … … 1408 1349 else 1409 1350 fprintf(fout, "[TH=%d] %s->%s#%d: ", getpid(), szFile, szFunction, nLine); 1351 } else { 1352 fprintf(fout, "INFO: "); 1410 1353 } 1411 1354 va_start(args, fmt); … … 1413 1356 va_end(args); 1414 1357 1415 // do not slow down the progran if standard debug level1416 // must be enabled: if no flush, the log won't be up-to-date if there1417 // is a segfault1418 //if (g_dwDebugLevel != 1)1419 1420 1358 fprintf(fout, "\n"); 1421 1359 paranoid_fclose(fout); … … 1430 1368 ...) = standard_log_debug_msg; 1431 1369 1432 1433 /**1434 * If @p y, malloc @p x, else free @p x.1435 * @bug This function seems orphaned. Please remove.1436 */1437 #define do_alloc_or_free_depending(x,y) { if(y) {x=malloc(MAX_STR_LEN);} else {paranoid_free(x);} }1438 1370 1439 1371 /** … … 1446 1378 malloc_string(g_boot_mountpt); 1447 1379 malloc_string(g_mondo_home); 1448 /*1449 malloc_string(g_tmpfs_mountpt);1450 */1451 1380 malloc_string(g_serial_string); 1452 1381 malloc_string(g_magicdev_command); … … 1454 1383 paranoid_free(g_boot_mountpt); 1455 1384 paranoid_free(g_mondo_home); 1456 /*1457 paranoid_free(g_tmpfs_mountpt);1458 */1459 paranoid_free(g_serial_string);1460 1385 paranoid_free(g_magicdev_command); 1461 1386 1462 } 1463 1464 /* 1465 char**list_of_arrays[] = { 1466 &g_boot_mountpt, 1467 &g_mondo_home, 1468 &g_tmpfs_mountpt, 1469 &g_serial_string, 1470 &g_magicdev_command, 1471 NULL}; 1472 1473 char**ppcurr; 1474 int i; 1475 1476 for(i=0;list_of_arrays[i];i++) 1477 { 1478 log_msg(5, "Allocating %d", i); 1479 ppcurr = list_of_arrays[i]; 1480 if (mal) 1481 { *ppcurr = malloc(MAX_STR_LEN); } 1482 else 1483 { 1484 if (*ppcurr) 1485 { 1486 free(*ppcurr); 1487 } 1488 } 1489 } 1490 log_msg(5, "Returning"); 1491 */ 1387 mr_free(g_serial_string); 1388 } 1492 1389 } 1493 1390 … … 1518 1415 void stop_magicdev_if_necessary() 1519 1416 { 1520 strcpy(g_magicdev_command, 1521 call_program_and_get_last_line_of_output 1522 ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99")); 1417 strcpy(g_magicdev_command, call_program_and_get_last_line_of_output("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99")); 1523 1418 if (g_magicdev_command[0]) { 1524 1419 log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
Note:
See TracChangeset
for help on using the changeset viewer.