Changeset 2518 in MondoRescue
- Timestamp:
- Jan 4, 2010, 7:42:06 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mondo/src/common/libmondo-tools.c
r2506 r2518 368 368 char *extra_cdrom_params = NULL; 369 369 char *mondo_mkisofs_sz = NULL; 370 char *command ;370 char *command = NULL; 371 371 char *mtpt; 372 372 char *hostname; … … 375 375 char *colon; 376 376 char *cdr_exe; 377 char *tmp ;377 char *tmp = NULL; 378 378 char call_before_iso_user[MAX_STR_LEN] = "\0"; 379 379 /* … … 381 381 int rdsiz_MB; 382 382 */ 383 char *iso_dev ;384 char *iso_mnt ;385 char *iso_tmp ;386 char *iso_path ;383 char *iso_dev = NULL; 384 char *iso_mnt = NULL; 385 char *iso_tmp = NULL; 386 char *iso_path = NULL; 387 387 388 388 assert(bkpinfo != NULL); 389 malloc_string(command);390 389 malloc_string(mtpt); 391 390 malloc_string(hostname); 392 391 malloc_string(cdr_exe); 393 malloc_string(tmp);394 malloc_string(iso_dev);395 malloc_string(iso_mnt);396 malloc_string(iso_tmp);397 malloc_string(iso_path);398 392 bkpinfo->optimal_set_size = 399 393 (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) * … … 403 397 if (bkpinfo->backup_media_type == tape) { 404 398 log_msg(1, "Bar"); 405 sprintf(tmp, "mt -f %s status", bkpinfo->media_device);399 mr_asprintf(&tmp, "mt -f %s status", bkpinfo->media_device); 406 400 log_msg(1, "tmp = '%s'", tmp); 407 401 if (run_program_and_log_output(tmp, 3)) { 402 mr_free(tmp); 408 403 fatal_error 409 404 ("Unable to open tape device. If you haven't specified it with -d, do so. If you already have, check your parameter. I think it's wrong."); 410 405 } 406 mr_free(tmp); 411 407 } 412 408 make_hole_for_dir(bkpinfo->scratchdir); … … 480 476 } 481 477 if (getenv ("SUDO_COMMAND")) { 482 sprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND");478 mr_asprintf(&command, "strings `which growisofs` | grep -c SUDO_COMMAND"); 483 479 if (!strcmp(call_program_and_get_last_line_of_output(command), "1")) { 480 mr_free(command); 484 481 popup_and_OK("Fatal Error: Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details."); 485 482 fatal_error("Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details."); 486 483 } 484 mr_free(command); 487 485 } 488 486 log_msg(2, "call_make_iso (DVD res) is ... %s", … … 556 554 } // end of CD code 557 555 558 /*559 if (bkpinfo->backup_data && bkpinfo->backup_media_type == tape)560 {561 sprintf (tmp,562 "dd if=/dev/zero of=%s bs=%ld count=32 2> /dev/null",563 bkpinfo->media_device, bkpinfo->internal_tape_block_size);564 if (system(tmp))565 {566 retval++;567 fprintf (stderr,568 "Cannot write to tape device. Is the tape set read-only?\n");569 }570 } // end of tape code571 */572 573 574 556 if (bkpinfo->backup_media_type == iso) { 575 557 … … 582 564 583 565 log_it("isodir = %s", bkpinfo->isodir); 584 sprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1",566 mr_asprintf(&command, "df -P %s | tail -n1 | cut -d' ' -f1", 585 567 bkpinfo->isodir); 586 568 log_it("command = %s", command); 587 log_it("res of it = %s", 588 call_program_and_get_last_line_of_output(command)); 589 sprintf(iso_dev, "%s", 590 call_program_and_get_last_line_of_output(command)); 591 sprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir); 592 write_one_liner_data_file(tmp, 593 call_program_and_get_last_line_of_output 594 (command)); 595 596 sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", 597 iso_dev); 569 log_it("res of it = %s", call_program_and_get_last_line_of_output(command)); 570 mr_asprintf(&iso_dev, "%s", call_program_and_get_last_line_of_output(command)); 571 mr_asprintf(&tmp, "%s/ISO-DEV", bkpinfo->tmpdir); 572 write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command)); 573 mr_free(tmp); 574 mr_free(command); 575 576 mr_asprintf(&command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", iso_dev); 577 mr_free(iso_dev); 578 598 579 log_it("command = %s", command); 599 log_it("res of it = %s", 600 call_program_and_get_last_line_of_output(command)); 601 sprintf(iso_mnt, "%s", 602 call_program_and_get_last_line_of_output(command)); 603 sprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir); 604 write_one_liner_data_file(tmp, 605 call_program_and_get_last_line_of_output 606 (command)); 580 log_it("res of it = %s", call_program_and_get_last_line_of_output(command)); 581 mr_asprintf(&iso_mnt, "%s", call_program_and_get_last_line_of_output(command)); 582 mr_asprintf(&tmp, "%s/ISO-MNT", bkpinfo->tmpdir); 583 write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command)); 584 mr_free(tmp); 585 mr_free(command); 586 607 587 log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt)); 608 sprintf(iso_tmp, "%s", bkpinfo->isodir);588 mr_asprintf(&iso_tmp, "%s", bkpinfo->isodir); 609 589 if (strlen(iso_tmp) < strlen(iso_mnt)) { 610 iso_path[0] = '\0';590 mr_asprintf(&iso_path, "%s", ""); 611 591 } else { 612 // If iso_mnt is only / then iso_path is the full dir 613 // (the formula bellow doesn't work in this case) 614 if (strcmp(iso_mnt, "/") == 0) { 615 sprintf(iso_path, "%s", iso_tmp); 616 // else it's a part of iso_tmp 617 } else { 618 sprintf(iso_path, "%s", iso_tmp + strlen(iso_mnt)); 619 } 620 } 621 sprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir); 592 mr_asprintf(&iso_path, "%s", iso_tmp + strlen(iso_mnt)); 593 } 594 mr_free(iso_tmp); 595 596 mr_asprintf(&tmp, "%s/ISODIR", bkpinfo->tmpdir); 622 597 write_one_liner_data_file(tmp, iso_path); 598 mr_free(tmp); 599 623 600 log_it("isodir: %s", iso_path); 624 sprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir); 601 mr_free(iso_path); 602 603 mr_asprintf(&tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir); 625 604 write_one_liner_data_file(tmp, bkpinfo->prefix); 605 mr_free(tmp); 606 626 607 log_it("iso-prefix: %s", bkpinfo->prefix); 627 608 … … 669 650 g_backup_media_type = bkpinfo->backup_media_type; 670 651 paranoid_free(mtpt); 671 paranoid_free(command);672 652 paranoid_free(hostname); 673 653 paranoid_free(cdr_exe); 674 paranoid_free(tmp);675 paranoid_free(iso_dev);676 paranoid_free(iso_mnt);677 paranoid_free(iso_tmp);678 paranoid_free(iso_path);679 654 return (retval); 680 655 } … … 834 809 long free_space_on_given_partition(char *partition) 835 810 { 836 char command[MAX_STR_LEN], out_sz[MAX_STR_LEN]; 811 char *out_sz = NULL; 812 char *command = NULL; 837 813 long res; 838 814 839 815 assert_string_is_neither_NULL_nor_zerolength(partition); 840 816 841 sprintf(command, "df -m -P %s 1> /dev/null 2> /dev/null", partition);817 mr_asprintf(&command, "df -m -P %s 1> /dev/null 2> /dev/null", partition); 842 818 if (system(command)) { 819 mr_free(command); 843 820 return (-1); 844 821 } // partition does not exist 845 sprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", 822 mr_free(command); 823 824 mr_asprintf(&command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", 846 825 partition); 847 strcpy(out_sz, call_program_and_get_last_line_of_output(command)); 826 mr_asprintf(&out_sz, "%s", call_program_and_get_last_line_of_output(command)); 827 mr_free(command); 828 848 829 if (strlen(out_sz) == 0) { 830 mr_free(out_sz); 849 831 return (-1); 850 832 } // error within df, probably 851 833 res = atol(out_sz); 834 mr_free(out_sz); 852 835 return (res); 853 836 } … … 870 853 871 854 /*@ buffers ************ */ 872 char tmp[MAX_STR_LEN]; 873 // char command[MAX_STR_LEN]; 855 char *tmp = NULL; 874 856 875 857 /*@ int's *************** */ … … 886 868 ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE); 887 869 } 888 strcpy(tmp,870 mr_asprintf(&tmp, "%s", 889 871 call_program_and_get_last_line_of_output 890 872 ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2")); … … 897 879 ("WARNING! You have very little RAM. Please upgrade to 64MB or more."); 898 880 } 881 mr_free(tmp); 899 882 #endif 900 883 … … 958 941 run_program_and_log_output 959 942 ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5); 960 strcpy(tmp,943 mr_asprintf(&tmp, "%s", 961 944 call_program_and_get_last_line_of_output 962 945 ("mount | grep -E \"cdr(om|w)\"")); … … 973 956 if (run_program_and_log_output("uname -a | grep Knoppix", 5)) { 974 957 retval++; 975 fatal_error 976 ("Your CD-ROM drive is mounted. Please unmount it."); 977 } 978 } 958 mr_free(tmp); 959 fatal_error("Your CD-ROM drive is mounted. Please unmount it."); 960 } 961 } 962 mr_free(tmp); 979 963 980 964 run_program_and_log_output("cat /etc/fstab", 5); … … 992 976 fatal_error("Please reinstall Mondo and Mindi."); 993 977 } 994 sprintf(tmp, "mindi --makemountlist %s/mountlist.txt.test", bkpinfo->tmpdir);978 mr_asprintf(&tmp, "mindi --makemountlist %s/mountlist.txt.test", bkpinfo->tmpdir); 995 979 if (run_program_and_log_output(tmp, 5)) { 996 sprintf(tmp, "mindi --makemountlist %s/mountlist.txt.test failed for some reason.", bkpinfo->tmpdir); 980 mr_free(tmp); 981 mr_asprintf(&tmp, "mindi --makemountlist %s/mountlist.txt.test failed for some reason.", bkpinfo->tmpdir); 997 982 log_to_screen(tmp); 998 983 log_to_screen … … 1004 989 retval++; 1005 990 } 991 mr_free(tmp); 1006 992 1007 993 if (!run_program_and_log_output("parted2fdisk -l | grep -i raid", 1) … … 1030 1016 { 1031 1017 /*@ buffer ****************************************************** */ 1032 char command[MAX_STR_LEN * 2];1033 char tmp[MAX_STR_LEN];1018 char *command = NULL; 1019 char *tmp = NULL; 1034 1020 1035 1021 /*@ end vars *************************************************** */ … … 1038 1024 assert_string_is_neither_NULL_nor_zerolength(label); 1039 1025 if (!does_file_exist(config_file)) { 1040 sprintf(tmp, "(read_cfg_var) Cannot find %s config file",1026 mr_asprintf(&tmp, "(read_cfg_var) Cannot find %s config file", 1041 1027 config_file); 1042 1028 log_to_screen(tmp); 1029 mr_free(tmp); 1030 1043 1031 value[0] = '\0'; 1044 1032 return (1); … … 1047 1035 return (0); 1048 1036 } else { 1049 sprintf(command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5",1037 mr_asprintf(&command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5", 1050 1038 label, config_file); 1051 1039 strcpy(value, call_program_and_get_last_line_of_output(command)); 1040 mr_free(command); 1041 1052 1042 if (strlen(value) == 0) { 1053 1043 return (1); … … 1115 1105 void stop_autofs_if_necessary() 1116 1106 { 1117 char tmp[MAX_STR_LEN];1107 char *tmp = NULL; 1118 1108 1119 1109 g_autofs_exe[0] = '\0'; … … 1128 1118 } else { 1129 1119 log_msg(3, "%s --- autofs detected", g_autofs_exe); 1130 // FIXME -- only disable it if it's running --- sprintf(tmp, "%s status", autofs_exe);1131 sprintf(tmp, "%s stop", g_autofs_exe);1120 // FIXME -- only disable it if it's running --- sprintf(tmp, "%s status", autofs_exe); 1121 mr_asprintf(&tmp, "%s stop", g_autofs_exe); 1132 1122 if (run_program_and_log_output(tmp, 2)) { 1133 1123 log_it("Failed to stop autofs - I assume it wasn't running"); … … 1136 1126 log_it("Stopped autofs OK"); 1137 1127 } 1128 mr_free(tmp); 1138 1129 } 1139 1130 } … … 1144 1135 void restart_autofs_if_necessary() 1145 1136 { 1146 char tmp[MAX_STR_LEN];1137 char *tmp = NULL; 1147 1138 1148 1139 if (!g_autofs_stopped || !g_autofs_exe[0]) { … … 1150 1141 return; 1151 1142 } 1152 sprintf(tmp, "%s start", g_autofs_exe);1143 mr_asprintf(&tmp, "%s start", g_autofs_exe); 1153 1144 if (run_program_and_log_output(tmp, 2)) { 1154 1145 log_it("Failed to start autofs"); … … 1157 1148 log_it("Started autofs OK"); 1158 1149 } 1150 mr_free(tmp); 1159 1151 } 1160 1152 … … 1165 1157 void mount_boot_if_necessary() 1166 1158 { 1167 char tmp[MAX_STR_LEN];1168 char command[MAX_STR_LEN];1159 char *tmp = NULL; 1160 char *command = NULL; 1169 1161 1170 1162 log_msg(1, "Started sub"); … … 1172 1164 g_boot_mountpt[0] = '\0'; 1173 1165 log_msg(4, "Done. Great. Seeting command to something"); 1174 strcpy(command,1166 mr_asprintf(&command, "%s", 1175 1167 "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1"); 1176 1168 log_msg(4, "Cool. Command = '%s'", command); 1177 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 1169 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 1170 mr_free(command); 1171 1178 1172 log_msg(4, "tmp = '%s'", tmp); 1179 1173 if (tmp[0]) { 1180 1174 log_it("/boot is at %s according to /etc/fstab", tmp); 1181 strcpy(command, "mount | grep -Ew '/boot'"); 1182 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 1175 mr_asprintf(&command, "mount | grep -Ew '/boot'"); 1176 mr_free(tmp); 1177 mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command)); 1178 mr_free(command); 1179 1183 1180 if (!strcmp(tmp,"")) { 1184 1181 if ((strstr(tmp, "LABEL=") || strstr(tmp,"UUID="))) { … … 1190 1187 } 1191 1188 } else { 1192 sprintf(command, "mount | grep -E '^%s'", tmp);1189 mr_asprintf(&command, "mount | grep -E '^%s'", tmp); 1193 1190 log_msg(3, "command = %s", command); 1194 1191 if (run_program_and_log_output(command, 5)) { 1195 1192 strcpy(g_boot_mountpt, tmp); 1196 sprintf(tmp, 1193 mr_free(tmp); 1194 mr_asprintf(&tmp, 1197 1195 "%s (your /boot partition) is not mounted. I'll mount it before backing up", 1198 1196 g_boot_mountpt); 1199 1197 log_it(tmp); 1200 sprintf(tmp, "mount %s", g_boot_mountpt); 1198 mr_free(tmp); 1199 1200 mr_asprintf(&tmp, "mount %s", g_boot_mountpt); 1201 1201 if (run_program_and_log_output(tmp, 5)) { 1202 1202 g_boot_mountpt[0] = '\0'; … … 1210 1210 } 1211 1211 } 1212 mr_free(tmp); 1212 1213 } 1214 mr_free(command); 1213 1215 } 1214 1216 } … … 1223 1225 void unmount_boot_if_necessary() 1224 1226 { 1225 char tmp[MAX_STR_LEN];1227 char *tmp = NULL; 1226 1228 1227 1229 log_msg(3, "starting"); 1228 1230 if (g_boot_mountpt[0]) { 1229 sprintf(tmp, "umount %s", g_boot_mountpt);1231 mr_asprintf(&tmp, "umount %s", g_boot_mountpt); 1230 1232 if (run_program_and_log_output(tmp, 5)) { 1231 1233 log_it("WARNING - unable to unmount /boot"); 1232 1234 } 1235 mr_free(tmp); 1233 1236 } 1234 1237 log_msg(3, "leaving"); … … 1248 1251 { 1249 1252 /*@ buffers ***************************************************** */ 1250 char command[MAX_STR_LEN * 2];1251 char tempfile[MAX_STR_LEN];1252 char tmp[MAX_STR_LEN];1253 char *command = NULL; 1254 char *tempfile = NULL; 1255 char *tmp = NULL; 1253 1256 1254 1257 … … 1258 1261 assert(value != NULL); 1259 1262 if (!does_file_exist(config_file)) { 1260 sprintf(tmp, "(write_cfg_file) Cannot find %s config file",1263 mr_asprintf(&tmp, "(write_cfg_file) Cannot find %s config file", 1261 1264 config_file); 1262 1265 log_to_screen(tmp); 1266 mr_free(tmp); 1263 1267 return (1); 1264 1268 } 1265 sprintf(tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir);1269 mr_asprintf(&tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir); 1266 1270 if (does_file_exist(config_file)) { 1267 sprintf(command, "grep -vE '^%s .*$' %s > %s",1271 mr_sprintf(&command, "grep -vE '^%s .*$' %s > %s", 1268 1272 label, config_file, tempfile); 1269 1273 paranoid_system(command); 1270 } 1271 sprintf(command, "echo \"%s %s\" >> %s", label, value, tempfile); 1274 mr_free(command); 1275 } 1276 mr_asprintf(&command, "echo \"%s %s\" >> %s", label, value, tempfile); 1272 1277 paranoid_system(command); 1273 sprintf(command, "mv -f %s %s", tempfile, config_file); 1278 mr_free(command); 1279 1280 mr_asprintf(&command, "mv -f %s %s", tempfile, config_file); 1274 1281 paranoid_system(command); 1282 mr_free(command); 1275 1283 unlink(tempfile); 1284 mr_free(tempfile); 1276 1285 return (0); 1277 1286 } … … 1437 1446 void restart_magicdev_if_necessary() 1438 1447 { 1439 char *tmp; 1440 1441 malloc_string(tmp); 1448 char *tmp = NULL; 1449 1442 1450 if (g_magicdev_command && g_magicdev_command[0]) { 1443 sprintf(tmp, "%s &", g_magicdev_command);1451 mr_asprintf(&tmp, "%s &", g_magicdev_command); 1444 1452 paranoid_system(tmp); 1445 }1446 paranoid_free(tmp);1453 mr_free(tmp); 1454 } 1447 1455 } 1448 1456
Note:
See TracChangeset
for help on using the changeset viewer.