Changeset 688 in MondoRescue for trunk/mondo/mondo/common/libmondo-tools.c
- Timestamp:
- Jul 17, 2006, 3:44:46 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/common/libmondo-tools.c
r687 r688 218 218 d = 5.2; // :-) 219 219 #else 220 asprintf(&tmp, call_program_and_get_last_line_of_output("uname -r"));220 tmp = call_program_and_get_last_line_of_output("uname -r"); 221 221 p = strchr(tmp, '.'); 222 222 if (p) { … … 390 390 rdsiz_MB = PPCFG_RAMDISK_SIZE + g_tape_buffer_size_MB; 391 391 #ifdef __FreeBSD__ 392 asprintf(&tmp, 393 call_program_and_get_last_line_of_output 394 ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6")); 392 tmp = call_program_and_get_last_line_of_output 393 ("vmstat | tail -1 | tr -s ' ' | cut -d' ' -f6"); 395 394 avm += atol(tmp); 396 395 paranoid_free(tmp); 397 asprintf(&tmp, 398 call_program_and_get_last_line_of_output 399 ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc")); 396 tmp = call_program_and_get_last_line_of_output 397 ("swapinfo | grep -v Device | tr -s ' ' | cut -d' ' -f4 | tr '\n' '+' | sed 's/+$//' | bc"); 400 398 avm += atol(tmp); 401 399 paranoid_free(tmp); … … 403 401 g_tmpfs_mountpt); 404 402 #else 405 asprintf(&tmp, 406 call_program_and_get_last_line_of_output 407 ("free | grep \":\" | tr -s ' ' '\t' | cut -f2 | head -n1")); 403 tmp = call_program_and_get_last_line_of_output 404 ("free | grep \":\" | tr -s ' ' '\t' | cut -f2 | head -n1"); 408 405 avm += atol(tmp); 409 406 paranoid_free(tmp); … … 478 475 if (getenv ("SUDO_COMMAND")) { 479 476 asprintf(&command, "strings `which growisofs` | grep -c SUDO_COMMAND"); 480 if (!strcmp(call_program_and_get_last_line_of_output(command), "1")) { 477 tmp = call_program_and_get_last_line_of_output(command); 478 if (!strcmp(tmp, "1")) { 481 479 popup_and_OK("Fatal Error: Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details."); 482 480 fatal_error("Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details."); 483 481 } 482 paranoid_free(tmp); 484 483 paranoid_free(command); 485 484 } … … 574 573 bkpinfo->isodir); 575 574 log_it("command = %s", command); 576 asprintf(&tmp, call_program_and_get_last_line_of_output(command));575 tmp = call_program_and_get_last_line_of_output(command); 577 576 paranoid_free(command); 578 577 log_it("res of it = %s", tmp); … … 585 584 paranoid_free(tmp); 586 585 log_it("command = %s", command); 587 asprintf(&tmp, call_program_and_get_last_line_of_output(command));586 tmp = call_program_and_get_last_line_of_output(command); 588 587 paranoid_free(command); 589 588 log_it("res of it = %s", tmp); … … 704 703 } 705 704 g_current_media_number = 1; 706 bkpinfo->postnuke_tarball[0] = bkpinfo->nfs_mount[0] = '\0'; 705 bkpinfo->postnuke_tarball = NULL; 706 bkpinfo->nfs_mount = NULL; 707 707 return (res); 708 708 } … … 717 717 void reset_bkpinfo(struct s_bkpinfo *bkpinfo) 718 718 { 719 int i ;719 int i = 0; 720 720 721 721 log_msg(1, "Hi"); 722 722 723 assert(bkpinfo != NULL); 724 /* BERLIOS : Useless 723 725 memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo)); 726 */ 727 724 728 bkpinfo->manual_cd_tray = FALSE; 725 729 bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE; 726 paranoid_free(bkpinfo->media_device); 730 bkpinfo->boot_loader = '\0'; 731 727 732 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 728 733 bkpinfo->media_size[i] = -1; 729 734 } 730 bkpinfo->boot_loader = '\0'; 731 bkpinfo->boot_device[0] = '\0'; 732 bkpinfo->zip_exe[0] = '\0'; 733 bkpinfo->zip_suffix[0] = '\0'; 734 bkpinfo->restore_path[0] = '\0'; 735 736 paranoid_free(bkpinfo->media_device); 737 paranoid_free(bkpinfo->boot_device); 738 paranoid_free(bkpinfo->zip_exe); 739 paranoid_free(bkpinfo->zip_suffix); 740 paranoid_free(bkpinfo->restore_path); 735 741 bkpinfo->use_lzo = FALSE; 736 bkpinfo->do_not_compress_these[0] = '\0';742 paranoid_free(bkpinfo->do_not_compress_these); 737 743 bkpinfo->verify_data = FALSE; 738 744 bkpinfo->backup_data = FALSE; … … 741 747 (am_I_in_disaster_recovery_mode()? TRUE : FALSE); 742 748 if (bkpinfo->disaster_recovery) { 743 strcpy(bkpinfo->isodir, "/");749 paranoid_alloc(bkpinfo->isodir, "/"); 744 750 } else { 745 strcpy(bkpinfo->isodir, "/var/cache/mondo/iso");746 } 747 strcpy(bkpinfo->prefix, STD_PREFIX);748 749 bkpinfo->scratchdir[0] = '\0';751 paranoid_alloc(bkpinfo->isodir, "/var/cache/mondo/iso"); 752 } 753 paranoid_alloc(bkpinfo->prefix, STD_PREFIX); 754 755 paranoid_free(bkpinfo->scratchdir); 750 756 bkpinfo->make_filelist = TRUE; // unless -J supplied to mondoarchive 751 sprintf(bkpinfo->tmpdir, "/tmp/tmpfs/mondo.tmp.%d", (int) (random() % 32768)); // for mondorestore 757 paranoid_free(bkpinfo->tmpdir); 758 asprintf(&bkpinfo->tmpdir, "/tmp/tmpfs/mondo.tmp.%d", (int) (random() % 32768)); // for mondorestore 752 759 bkpinfo->optimal_set_size = 0; 753 760 bkpinfo->backup_media_type = none; 754 strcpy(bkpinfo->include_paths, "/");755 bkpinfo->exclude_paths[0] = '\0';756 bkpinfo->call_before_iso[0] = '\0';757 bkpinfo->call_make_iso[0] = '\0';758 bkpinfo->call_burn_iso[0] = '\0';759 bkpinfo->call_after_iso[0] = '\0';760 bkpinfo->image_devs[0] = '\0';761 bkpinfo->postnuke_tarball[0] = '\0';762 bkpinfo->kernel_path[0] = '\0';763 bkpinfo->nfs_mount[0] = '\0';764 bkpinfo->nfs_remote_dir[0] = '\0';761 paranoid_alloc(bkpinfo->include_paths, "/"); 762 paranoid_free(bkpinfo->exclude_paths); 763 paranoid_free(bkpinfo->call_before_iso); 764 paranoid_free(bkpinfo->call_make_iso); 765 paranoid_free(bkpinfo->call_burn_iso); 766 paranoid_free(bkpinfo->call_after_iso); 767 paranoid_free(bkpinfo->image_devs); 768 paranoid_free(bkpinfo->postnuke_tarball); 769 paranoid_free(bkpinfo->kernel_path); 770 paranoid_free(bkpinfo->nfs_mount); 771 paranoid_free(bkpinfo->nfs_remote_dir); 765 772 bkpinfo->wipe_media_first = FALSE; 766 773 bkpinfo->differential = FALSE; … … 773 780 774 781 775 776 777 782 /** 778 783 * Get the remaining free space (in MB) on @p partition. … … 782 787 long free_space_on_given_partition(char *partition) 783 788 { 784 char *command, *out_sz; 789 char *command = NULL; 790 char *out_sz = NULL; 785 791 long res; 786 792 … … 795 801 asprintf(&command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", 796 802 partition); 797 asprintf(&out_sz, call_program_and_get_last_line_of_output(command));803 out_sz = call_program_and_get_last_line_of_output(command); 798 804 paranoid_free(command); 799 805 if (strlen(out_sz) == 0) { … … 840 846 ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE); 841 847 } 842 asprintf(&tmp, 843 call_program_and_get_last_line_of_output 844 ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2")); 848 tmp = call_program_and_get_last_line_of_output 849 ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2"); 845 850 if (atol(tmp) < 35000) { 846 851 retval++; … … 928 933 run_program_and_log_output 929 934 ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5); 930 asprintf(&tmp, 931 call_program_and_get_last_line_of_output 932 ("mount | grep -E \"cdr(om|w)\"")); 935 tmp = call_program_and_get_last_line_of_output("mount | grep -E \"cdr(om|w)\""); 933 936 if (strcmp("", tmp)) { 934 937 if (strstr(tmp, "autofs")) { … … 1021 1024 { 1022 1025 /*@ buffer ****************************************************** */ 1023 char *command ;1024 char *tmp ;1026 char *command = NULL; 1027 char *tmp = NULL; 1025 1028 1026 1029 /*@ end vars *************************************************** */ … … 1028 1031 assert_string_is_neither_NULL_nor_zerolength(config_file); 1029 1032 assert_string_is_neither_NULL_nor_zerolength(label); 1033 1030 1034 if (!does_file_exist(config_file)) { 1031 1035 asprintf(&tmp, "(read_cfg_var) Cannot find %s config file", … … 1033 1037 log_to_screen(tmp); 1034 1038 paranoid_free(tmp); 1035 value [0] = '\0';1039 value = NULL; 1036 1040 return (1); 1037 1041 } else if (strstr(value, "/dev/") && strstr(value, "t0") … … 1043 1047 asprintf(&command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5", 1044 1048 label, config_file); 1045 strcpy(value, call_program_and_get_last_line_of_output(command));1049 value = call_program_and_get_last_line_of_output(command); 1046 1050 paranoid_free(command); 1047 1051 if (strlen(value) == 0) { … … 1052 1056 } 1053 1057 } 1054 1055 1058 1056 1059 … … 1101 1104 "grep -v \":\" /etc/fstab | grep -vx \"#.*\" | grep -w \"/boot\" | tr -s ' ' '\t' | cut -f1 | head -n1"); 1102 1105 log_msg(4, "Cool. Command = '%s'", command); 1103 asprintf(&tmp, call_program_and_get_last_line_of_output(command));1106 tmp = call_program_and_get_last_line_of_output(command); 1104 1107 paranoid_free(command); 1105 1108 1106 1109 log_msg(4, "tmp = '%s'", tmp); 1107 if (tmp [0]) {1110 if (tmp) { 1108 1111 log_it("/boot is at %s according to /etc/fstab", tmp); 1109 1112 if (strstr(tmp, "LABEL=")) { … … 1199 1202 return (1); 1200 1203 } 1201 asprintf(&tempfile, 1202 call_program_and_get_last_line_of_output 1203 ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX")); 1204 tempfile = call_program_and_get_last_line_of_output 1205 ("mktemp -q /tmp/mojo-jojo.blah.XXXXXX"); 1204 1206 if (does_file_exist(config_file)) { 1205 1207 asprintf(&command, "grep -vx '%s .*' %s > %s", … … 1228 1230 if (mal) { 1229 1231 iamhere("Malloc'ing globals"); 1230 malloc_string(g_erase_tmpdir_and_scratchdir);1232 g_erase_tmpdir_and_scratchdir = NULL; 1231 1233 malloc_string(g_serial_string); 1232 malloc_string(g_magicdev_command);1233 1234 } else { 1234 1235 iamhere("Freeing globals"); … … 1268 1269 void stop_magicdev_if_necessary() 1269 1270 { 1270 strcpy(g_magicdev_command, 1271 call_program_and_get_last_line_of_output 1272 ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99")); 1273 if (g_magicdev_command[0]) { 1271 g_magicdev_command = call_program_and_get_last_line_of_output 1272 ("ps ax | grep -w magicdev | grep -v grep | tr -s '\t' ' '| cut -d' ' -f6-99"); 1273 if (g_magicdev_command) { 1274 1274 log_msg(1, "g_magicdev_command = '%s'", g_magicdev_command); 1275 1275 paranoid_system("killall magicdev"); … … 1283 1283 void restart_magicdev_if_necessary() 1284 1284 { 1285 char *tmp ;1286 1287 if ( g_magicdev_command && g_magicdev_command[0]) {1285 char *tmp = NULL; 1286 1287 if (!g_magicdev_command) { 1288 1288 asprintf(&tmp, "%s &", g_magicdev_command); 1289 1289 paranoid_system(tmp);
Note:
See TracChangeset
for help on using the changeset viewer.