Changeset 3192 in MondoRescue for branches/3.0/mondo/src/common/libmondo-tools.c
- Timestamp:
- Sep 25, 2013, 9:03:25 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.0/mondo/src/common/libmondo-tools.c
r3188 r3192 30 30 31 31 extern int g_tape_buffer_size_MB; 32 extern char *g_serial_string; 32 33 extern bool g_text_mode; 33 34 extern int g_currentY; 34 35 extern int g_current_media_number; 35 36 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 _XWIN 115 116 if (!g_text_mode) 116 117 newtSuspend(); 118 #endif 117 119 printf("ASSERTION FAILED: `%s'\n", exp); 118 120 printf("\tat %s:%d in %s\n\n", file, line, function); … … 161 163 getchar(); // skip \n 162 164 165 #ifndef _XWIN 163 166 if (!g_text_mode) 164 167 newtResume(); 168 #endif 165 169 } 166 170 … … 171 175 void clean_up_KDE_desktop_if_necessary(void) 172 176 { 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"); 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"); 176 185 run_program_and_log_output(tmp, 5); 177 mr_free(tmp);186 paranoid_free(tmp); 178 187 } 179 188 … … 223 232 double get_kernel_version(void) 224 233 { 225 char *p = NULL; 226 char *tmp = NULL; 234 char *p, tmp[200]; 227 235 double d; 228 236 #ifdef __FreeBSD__ … … 230 238 d = 5.2; // :-) 231 239 #else 232 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("uname -r"));240 strcpy(tmp, call_program_and_get_last_line_of_output("uname -r")); 233 241 p = strchr(tmp, '.'); 234 242 if (p) { … … 241 249 } 242 250 } 251 // log_msg(1, "tmp = '%s'", tmp); 243 252 d = atof(tmp); 244 mr_free(tmp);245 253 #endif 246 254 log_msg(1, "g_kernel_version = %f", d); … … 249 257 250 258 259 260 261 251 262 /** 252 263 * Get the current time. … … 257 268 return (long) time((void *) 0); 258 269 } 270 271 272 273 274 259 275 260 276 … … 352 368 char *mondo_mkisofs_sz = NULL; 353 369 char *command = NULL; 354 char *hostname = NULL; 370 char *mtpt; 371 char *hostname; 355 372 char *isofs_cmd = NULL; 356 373 char *ip_address = NULL; 357 374 int retval = 0; 358 375 char *colon; 359 char *cdr_exe = NULL;376 char *cdr_exe; 360 377 char *tmp = NULL; 361 char *p = NULL; 362 char *call_before_iso_user = NULL; 378 char call_before_iso_user[MAX_STR_LEN] = "\0"; 379 /* 380 long avm = 0; 381 int rdsiz_MB; 382 */ 363 383 char *iso_dev = NULL; 364 384 char *iso_mnt = NULL; … … 367 387 368 388 assert(bkpinfo != NULL); 369 389 malloc_string(mtpt); 390 malloc_string(hostname); 391 malloc_string(cdr_exe); 370 392 bkpinfo->optimal_set_size = 371 393 (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) * … … 378 400 } 379 401 log_msg(1, "Tape"); 380 if (bkpinfo->media_device == NULL) {381 return(1);382 }383 402 mr_asprintf(tmp, "mt -f %s status", bkpinfo->media_device); 384 403 log_msg(1, "tmp = '%s'", tmp); … … 410 429 strcpy(bkpinfo->zip_exe, "gzip"); 411 430 strcpy(bkpinfo->zip_suffix, "gz"); 412 } else if (bkpinfo->use_lzma) {413 strcpy(bkpinfo->zip_exe, "lzma");414 strcpy(bkpinfo->zip_suffix, "lzma");415 431 } else if (bkpinfo->compression_level != 0) { 416 432 strcpy(bkpinfo->zip_exe, "bzip2"); … … 424 440 if (bkpinfo->backup_media_type == dvd) { 425 441 if (find_home_of_exe("growisofs")) { 426 mr_asprintf(cdr_exe, "growisofs");442 strcpy(cdr_exe, "growisofs"); 427 443 } // unlikely to be used 428 444 else { … … 446 462 } 447 463 #endif 448 else { 464 else 465 { 449 466 mr_asprintf(mondo_mkisofs_sz, MONDO_GROWISOFS_REGULAR_SYSLINUX); 450 467 } 451 468 if (bkpinfo->manual_cd_tray) { 469 paranoid_free(mondo_mkisofs_sz); 452 470 fatal_error("Manual CD tray + DVD not supported yet."); 453 471 // -m isn't supported by growisofs, BTW... … … 457 475 mondo_mkisofs_sz, 458 476 "", bkpinfo->media_device); 459 }460 mr_free(mondo_mkisofs_sz);477 paranoid_free(mondo_mkisofs_sz); 478 } 461 479 if (getenv ("SUDO_COMMAND")) { 462 480 mr_asprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND"); … … 468 486 mr_free(command); 469 487 } 470 log_msg(2, "call_make_iso (DVD res) is ... %s", bkpinfo->call_make_iso); 488 log_msg(2, "call_make_iso (DVD res) is ... %s", 489 bkpinfo->call_make_iso); 471 490 } // end of DVD code 472 491 … … 485 504 } 486 505 if (find_home_of_exe("cdrecord")) { 487 mr_asprintf(cdr_exe, "cdrecord");506 strcpy(cdr_exe, "cdrecord"); 488 507 } else if (find_home_of_exe("dvdrecord")) { 489 mr_asprintf(cdr_exe, "dvdrecord");508 strcpy(cdr_exe, "dvdrecord"); 490 509 } else { 491 510 fatal_error("Please install either cdrecord or dvdrecord."); … … 525 544 mondo_mkisofs_sz, bkpinfo->tmpdir); 526 545 } else { 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); 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); 530 550 } 531 551 log_it("bkpinfo->call_before_iso = %s", bkpinfo->call_before_iso); 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); 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); 533 557 } else { 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); 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); 539 567 } // end of CD code 540 568 … … 549 577 550 578 log_it("isodir = %s", bkpinfo->isodir); 551 mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1", bkpinfo->isodir); 579 mr_asprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1", 580 bkpinfo->isodir); 552 581 log_it("command = %s", command); 582 log_it("res of it = %s", call_program_and_get_last_line_of_output(command)); 553 583 mr_asprintf(iso_dev, "%s", call_program_and_get_last_line_of_output(command)); 554 log_it("res of it = %s", iso_dev);555 584 mr_asprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir); 556 write_one_liner_data_file(tmp, iso_dev);585 write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command)); 557 586 mr_free(tmp); 558 587 mr_free(command); … … 562 591 563 592 log_it("command = %s", command); 593 log_it("res of it = %s", call_program_and_get_last_line_of_output(command)); 564 594 mr_asprintf(iso_mnt, "%s", call_program_and_get_last_line_of_output(command)); 565 log_it("res of it = %s", iso_mnt);566 595 mr_asprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir); 567 write_one_liner_data_file(tmp, iso_mnt);596 write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command)); 568 597 mr_free(tmp); 569 598 mr_free(command); … … 583 612 } 584 613 } 614 mr_free(iso_tmp); 585 615 mr_free(iso_mnt); 586 mr_free(iso_tmp);587 616 588 617 mr_asprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir); … … 603 632 604 633 if (bkpinfo->backup_media_type == netfs) { 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 } 634 strcpy(hostname, bkpinfo->netfs_mount); 612 635 colon = strchr(hostname, ':'); 613 636 if (!colon) { … … 628 651 } 629 652 if (!hent) { 630 log_it("Can't resolve Network mount (%s): %s", hostname, hstrerror(h_errno)); 653 log_it("Can't resolve Network mount (%s): %s", hostname, 654 hstrerror(h_errno)); 631 655 retval++; 632 656 } else { … … 634 658 mr_strcat(ip_address, strchr(bkpinfo->netfs_mount, ':')); 635 659 strcpy(bkpinfo->netfs_mount, ip_address); 636 mr_free(ip_address);660 paranoid_free(ip_address); 637 661 } 638 662 } 639 mr_free(hostname);640 663 store_netfs_config(); 641 664 } … … 645 668 fprintf(stderr, "Type 'man mondoarchive' for help.\n"); 646 669 } 647 if (bkpinfo->include_paths == NULL) { 648 mr_asprintf(bkpinfo->include_paths, "/"); 649 } 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); 650 679 g_backup_media_type = bkpinfo->backup_media_type; 680 paranoid_free(mtpt); 681 paranoid_free(hostname); 682 paranoid_free(cdr_exe); 651 683 return (retval); 652 684 } … … 672 704 if (bkpinfo->disaster_recovery) { 673 705 if (!does_nonMS_partition_exist()) { 674 fatal_error("I am in disaster recovery mode\nPlease don't run mondoarchive."); 706 fatal_error 707 ("I am in disaster recovery mode\nPlease don't run mondoarchive."); 675 708 } 676 709 } … … 680 713 paranoid_free(tmp); 681 714 if (find_and_store_mondoarchives_home(g_mondo_home)) { 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"); 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"); 683 717 res++; 684 718 return (res); … … 689 723 } 690 724 g_current_media_number = 1; 691 bkpinfo->postnuke_tarball[0] = '\0';725 bkpinfo->postnuke_tarball[0] = bkpinfo->netfs_mount[0] = '\0'; 692 726 return (res); 693 727 } … … 738 772 if (p == NULL) { 739 773 log_it("Failed to create global tmp directory %s for Mondo.",tmp); 740 mr_free(tmp);741 774 finish(-1); 742 775 } 743 mr_free(tmp);744 745 776 strcpy(bkpinfo->tmpdir,p); 746 log_it("bkpinfo->tmpdir is being set to %s", bkpinfo->tmpdir);777 paranoid_free(tmp); 747 778 748 779 mr_asprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); … … 786 817 } 787 818 strcpy(bkpinfo->scratchdir,p); 788 log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);789 819 paranoid_free(tmp); 790 820 … … 802 832 { 803 833 int i; 804 log_msg(1, "Initializing bkpinfo"); 805 834 835 log_msg(1, "Hi"); 806 836 assert(bkpinfo != NULL); 807 837 memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo)); … … 817 847 bkpinfo->use_lzo = FALSE; 818 848 bkpinfo->use_gzip = FALSE; 819 bkpinfo-> use_lzma = FALSE;849 bkpinfo->do_not_compress_these[0] = '\0'; 820 850 bkpinfo->verify_data = FALSE; 821 851 bkpinfo->backup_data = FALSE; … … 823 853 bkpinfo->use_star = FALSE; 824 854 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 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(); 855 bkpinfo->disaster_recovery = 856 (am_I_in_disaster_recovery_mode()? TRUE : FALSE); 832 857 if (bkpinfo->disaster_recovery) { 833 858 strcpy(bkpinfo->isodir, "/"); … … 836 861 } 837 862 strcpy(bkpinfo->prefix, STD_PREFIX); 863 setup_tmpdir(NULL); 864 setup_scratchdir(NULL); 865 838 866 bkpinfo->optimal_set_size = 0; 839 bkpinfo->backup_media_type = none;867 strcpy(bkpinfo->include_paths, "/"); 840 868 bkpinfo->make_filelist = TRUE; // unless -J supplied to mondoarchive 841 bkpinfo->exclude_paths = NULL; 842 bkpinfo->include_paths = NULL; 869 bkpinfo->include_paths[0] = '\0'; 843 870 bkpinfo->exclude_devs = NULL; 844 871 bkpinfo->restore_path[0] = '\0'; … … 852 879 bkpinfo->netfs_user = NULL; 853 880 bkpinfo->netfs_remote_dir[0] = '\0'; 881 bkpinfo->exclude_paths = NULL; 882 bkpinfo->subdir = NULL; 854 883 bkpinfo->postnuke_tarball[0] = '\0'; 855 bkpinfo->subdir = NULL;856 884 bkpinfo->wipe_media_first = FALSE; 857 885 bkpinfo->differential = 0; … … 866 894 867 895 896 897 868 898 /** 869 899 * Get the remaining free space (in MB) on @p partition. … … 886 916 mr_free(command); 887 917 888 mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", partition); 918 mr_asprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", 919 partition); 889 920 mr_asprintf(out_sz, "%s", call_program_and_get_last_line_of_output(command)); 890 921 mr_free(command); … … 926 957 if (system("which mkfs.vfat 2> /dev/null 1> /dev/null") 927 958 && !system("which mkfs.msdos 2> /dev/null 1> /dev/null")) { 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")); 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")); 932 967 if (atol(tmp) < 35000) { 933 968 retval++; … … 935 970 } 936 971 if (atol(tmp) < 66000) { 937 log_to_screen("WARNING! You have very little RAM. Please upgrade to 64MB or more."); 972 log_to_screen 973 ("WARNING! You have very little RAM. Please upgrade to 64MB or more."); 938 974 } 939 975 mr_free(tmp); … … 990 1026 whine_if_not_found("cmp"); 991 1027 } 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)\"")); 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)\"")); 994 1033 if (strcmp("", tmp)) { 995 1034 if (strstr(tmp, "autofs")) { … … 1065 1104 /*@ buffer ****************************************************** */ 1066 1105 char *command = NULL; 1106 char *tmp = NULL; 1067 1107 1068 1108 /*@ end vars *************************************************** */ … … 1071 1111 assert_string_is_neither_NULL_nor_zerolength(label); 1072 1112 if (!does_file_exist(config_file)) { 1073 log_to_screen("(read_cfg_var) Cannot find %s config file", 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 1074 1118 value[0] = '\0'; 1075 1119 return (1); … … 1083 1127 mr_free(command); 1084 1128 1085 log_msg(4, "Configuration item %s is %s", label, value);1086 1129 if (strlen(value) == 0) { 1087 1130 return (1); … … 1199 1242 * If this is a distribution like Gentoo that doesn't keep /boot mounted, mount it. 1200 1243 */ 1201 void mount_boot_if_necessary() { 1244 void mount_boot_if_necessary() 1245 { 1202 1246 char *tmp = NULL; 1203 1247 char *command = NULL; … … 1207 1251 g_boot_mountpt[0] = '\0'; 1208 1252 log_msg(4, "Done. Great. Seeting command to something"); 1209 mr_asprintf(command, "%s", "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1"); 1253 mr_asprintf(command, "%s", 1254 "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1"); 1210 1255 log_msg(4, "Cool. Command = '%s'", command); 1211 1256 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output(command)); … … 1213 1258 1214 1259 log_msg(4, "tmp = '%s'", tmp); 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"); 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 :-)"); 1274 } 1227 1275 } else { 1228 log_it("...ignored cos it's a label or uuid :-)"); 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); 1229 1302 } 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 } 1249 } 1250 } 1251 mr_free(command); 1252 } 1253 } 1254 mr_free(tmp); 1303 } 1304 } 1255 1305 log_msg(1, "Ended sub"); 1256 1306 } … … 1290 1340 char *command = NULL; 1291 1341 char *tempfile = NULL; 1342 char *tmp = NULL; 1292 1343 1293 1344 … … 1297 1348 assert(value != NULL); 1298 1349 if (!does_file_exist(config_file)) { 1299 log_to_screen("(write_cfg_file) Cannot find %s config file", 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); 1300 1354 return (1); 1301 1355 } 1302 1356 mr_asprintf(tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir); 1303 1357 if (does_file_exist(config_file)) { 1304 mr_asprintf(command, "grep -vE '^%s .*$' %s > %s", label, config_file, tempfile); 1358 mr_asprintf(command, "grep -vE '^%s .*$' %s > %s", 1359 label, config_file, tempfile); 1305 1360 paranoid_system(command); 1306 1361 mr_free(command); … … 1323 1378 * information to the logfile. 1324 1379 */ 1325 void standard_log_debug_msg(int debug_level, const char *szFile, const char *szFunction, int nLine, const char *fmt, ...) { 1326 1380 void standard_log_debug_msg(int debug_level, const char *szFile, 1381 const char *szFunction, int nLine, 1382 const char *fmt, ...) 1383 { 1327 1384 va_list args; 1385 int i; 1328 1386 static int depth = 0; 1329 1387 FILE *fout; … … 1338 1396 if (!(fout = fopen(MONDO_LOGFILE, "a"))) { 1339 1397 return; 1340 } 1398 } // fatal_error("Failed to openout to logfile - sheesh..."); } 1341 1399 1342 1400 // add tabs to distinguish log levels 1343 1401 if (debug_level > 0) { 1344 fprintf(fout, "DBG%d: ", debug_level); 1402 for (i = 1; i < debug_level; i++) 1403 fprintf(fout, "\t"); 1345 1404 if (getpid() == g_main_pid) 1346 1405 fprintf(fout, "[Main] %s->%s#%d: ", szFile, szFunction, nLine); … … 1349 1408 else 1350 1409 fprintf(fout, "[TH=%d] %s->%s#%d: ", getpid(), szFile, szFunction, nLine); 1351 } else {1352 fprintf(fout, "INFO: ");1353 1410 } 1354 1411 va_start(args, fmt); … … 1356 1413 va_end(args); 1357 1414 1415 // do not slow down the progran if standard debug level 1416 // must be enabled: if no flush, the log won't be up-to-date if there 1417 // is a segfault 1418 //if (g_dwDebugLevel != 1) 1419 1358 1420 fprintf(fout, "\n"); 1359 1421 paranoid_fclose(fout); … … 1368 1430 ...) = standard_log_debug_msg; 1369 1431 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);} } 1370 1438 1371 1439 /** … … 1378 1446 malloc_string(g_boot_mountpt); 1379 1447 malloc_string(g_mondo_home); 1448 /* 1449 malloc_string(g_tmpfs_mountpt); 1450 */ 1380 1451 malloc_string(g_serial_string); 1381 1452 malloc_string(g_magicdev_command); … … 1383 1454 paranoid_free(g_boot_mountpt); 1384 1455 paranoid_free(g_mondo_home); 1456 /* 1457 paranoid_free(g_tmpfs_mountpt); 1458 */ 1459 paranoid_free(g_serial_string); 1385 1460 paranoid_free(g_magicdev_command); 1386 1461 1387 mr_free(g_serial_string); 1388 } 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 */ 1389 1492 } 1390 1493 … … 1415 1518 void stop_magicdev_if_necessary() 1416 1519 { 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")); 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")); 1418 1523 if (g_magicdev_command[0]) { 1419 1524 log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command);
Note:
See TracChangeset
for help on using the changeset viewer.