Changeset 2262 in MondoRescue
- Timestamp:
- Jul 12, 2009, 2:04:30 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/common/libmondo-tools.c
r2241 r2262 414 414 char *extra_cdrom_params = NULL; 415 415 char *mondo_mkisofs_sz = NULL; 416 char *command ;416 char *command = NULL; 417 417 char *mtpt; 418 418 char *hostname; … … 421 421 char *colon; 422 422 char *cdr_exe; 423 char *tmp ;423 char *tmp = NULL; 424 424 char call_before_iso_user[MAX_STR_LEN] = "\0"; 425 425 /* … … 427 427 int rdsiz_MB; 428 428 */ 429 char *iso_dev ;430 char *iso_mnt ;431 char *iso_tmp ;432 char *iso_path ;429 char *iso_dev = NULL; 430 char *iso_mnt = NULL; 431 char *iso_tmp = NULL; 432 char *iso_path = NULL; 433 433 434 434 assert(bkpinfo != NULL); 435 malloc_string(command);436 435 malloc_string(mtpt); 437 436 malloc_string(hostname); 438 437 malloc_string(cdr_exe); 439 malloc_string(tmp);440 malloc_string(iso_dev);441 malloc_string(iso_mnt);442 malloc_string(iso_tmp);443 malloc_string(iso_path);444 438 bkpinfo->optimal_set_size = 445 439 (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type) ? 16 : 16) * … … 449 443 if (bkpinfo->backup_media_type == tape) { 450 444 log_msg(1, "Bar"); 451 sprintf(tmp, "mt -f %s status", bkpinfo->media_device);445 mr_asprintf(&tmp, "mt -f %s status", bkpinfo->media_device); 452 446 log_msg(1, "tmp = '%s'", tmp); 453 447 if (run_program_and_log_output(tmp, 3)) { 448 mr_free(tmp); 454 449 fatal_error 455 450 ("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."); 456 451 } 452 mr_free(tmp); 457 453 } 458 454 make_hole_for_dir(bkpinfo->scratchdir); … … 526 522 } 527 523 if (getenv ("SUDO_COMMAND")) { 528 sprintf(command, "strings `which growisofs` | grep -c SUDO_COMMAND");524 mr_asprintf(&command, "strings `which growisofs` | grep -c SUDO_COMMAND"); 529 525 if (!strcmp(call_program_and_get_last_line_of_output(command), "1")) { 526 mr_free(command); 530 527 popup_and_OK("Fatal Error: Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details."); 531 528 fatal_error("Can't write DVDs as sudo because growisofs doesn't support this - see the growisofs manpage for details."); 532 529 } 530 mr_free(command); 533 531 } 534 532 log_msg(2, "call_make_iso (DVD res) is ... %s", … … 602 600 } // end of CD code 603 601 604 /*605 if (bkpinfo->backup_data && bkpinfo->backup_media_type == tape)606 {607 sprintf (tmp,608 "dd if=/dev/zero of=%s bs=%ld count=32 2> /dev/null",609 bkpinfo->media_device, bkpinfo->internal_tape_block_size);610 if (system(tmp))611 {612 retval++;613 fprintf (stderr,614 "Cannot write to tape device. Is the tape set read-only?\n");615 }616 } // end of tape code617 */618 619 620 602 if (bkpinfo->backup_media_type == iso) { 621 603 … … 628 610 629 611 log_it("isodir = %s", bkpinfo->isodir); 630 sprintf(command, "df -P %s | tail -n1 | cut -d' ' -f1",612 mr_asprintf(&command, "df -P %s | tail -n1 | cut -d' ' -f1", 631 613 bkpinfo->isodir); 632 614 log_it("command = %s", command); 633 log_it("res of it = %s", 634 call_program_and_get_last_line_of_output(command)); 635 sprintf(iso_dev, "%s", 636 call_program_and_get_last_line_of_output(command)); 637 sprintf(tmp, "%s/ISO-DEV", bkpinfo->tmpdir); 638 write_one_liner_data_file(tmp, 639 call_program_and_get_last_line_of_output 640 (command)); 641 642 sprintf(command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", 643 iso_dev); 615 log_it("res of it = %s", call_program_and_get_last_line_of_output(command)); 616 mr_asprintf(&iso_dev, "%s", call_program_and_get_last_line_of_output(command)); 617 mr_asprintf(&tmp, "%s/ISO-DEV", bkpinfo->tmpdir); 618 write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command)); 619 mr_free(tmp); 620 mr_free(command); 621 622 mr_asprintf(&command, "mount | grep -w %s | tail -n1 | cut -d' ' -f3", iso_dev); 623 mr_free(iso_dev); 624 644 625 log_it("command = %s", command); 645 log_it("res of it = %s", 646 call_program_and_get_last_line_of_output(command)); 647 sprintf(iso_mnt, "%s", 648 call_program_and_get_last_line_of_output(command)); 649 sprintf(tmp, "%s/ISO-MNT", bkpinfo->tmpdir); 650 write_one_liner_data_file(tmp, 651 call_program_and_get_last_line_of_output 652 (command)); 626 log_it("res of it = %s", call_program_and_get_last_line_of_output(command)); 627 mr_asprintf(&iso_mnt, "%s", call_program_and_get_last_line_of_output(command)); 628 mr_asprintf(&tmp, "%s/ISO-MNT", bkpinfo->tmpdir); 629 write_one_liner_data_file(tmp, call_program_and_get_last_line_of_output(command)); 630 mr_free(tmp); 631 mr_free(command); 632 653 633 log_it("isomnt: %s, %d", iso_mnt, strlen(iso_mnt)); 654 sprintf(iso_tmp, "%s", bkpinfo->isodir);634 mr_asprintf(&iso_tmp, "%s", bkpinfo->isodir); 655 635 if (strlen(iso_tmp) < strlen(iso_mnt)) { 656 iso_path[0] = '\0';636 mr_asprintf(&iso_path, "%s", ""); 657 637 } else { 658 sprintf(iso_path, "%s", iso_tmp + strlen(iso_mnt)); 659 } 660 sprintf(tmp, "%s/ISODIR", bkpinfo->tmpdir); 638 mr_asprintf(&iso_path, "%s", iso_tmp + strlen(iso_mnt)); 639 } 640 mr_free(iso_tmp); 641 642 mr_asprintf(&tmp, "%s/ISODIR", bkpinfo->tmpdir); 661 643 write_one_liner_data_file(tmp, iso_path); 644 mr_free(tmp); 645 662 646 log_it("isodir: %s", iso_path); 663 sprintf(tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir); 647 mr_free(iso_path); 648 649 mr_asprintf(&tmp, "%s/ISO-PREFIX", bkpinfo->tmpdir); 664 650 write_one_liner_data_file(tmp, bkpinfo->prefix); 651 mr_free(tmp); 652 665 653 log_it("iso-prefix: %s", bkpinfo->prefix); 666 654 … … 710 698 g_backup_media_type = bkpinfo->backup_media_type; 711 699 paranoid_free(mtpt); 712 paranoid_free(command);713 700 paranoid_free(hostname); 714 701 paranoid_free(cdr_exe); 715 paranoid_free(tmp);716 paranoid_free(iso_dev);717 paranoid_free(iso_mnt);718 paranoid_free(iso_tmp);719 paranoid_free(iso_path);720 702 return (retval); 721 703 } … … 872 854 long free_space_on_given_partition(char *partition) 873 855 { 874 char command[MAX_STR_LEN], out_sz[MAX_STR_LEN]; 856 char *out_sz = NULL; 857 char *command = NULL; 875 858 long res; 876 859 877 860 assert_string_is_neither_NULL_nor_zerolength(partition); 878 861 879 sprintf(command, "df -m -P %s 1> /dev/null 2> /dev/null", partition);862 mr_asprintf(&command, "df -m -P %s 1> /dev/null 2> /dev/null", partition); 880 863 if (system(command)) { 864 mr_free(command); 881 865 return (-1); 882 866 } // partition does not exist 883 sprintf(command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", 867 mr_free(command); 868 869 mr_asprintf(&command, "df -m -P %s | tail -n1 | tr -s ' ' '\t' | cut -f4", 884 870 partition); 885 strcpy(out_sz, call_program_and_get_last_line_of_output(command)); 871 mr_asprintf(&out_sz, "%s", call_program_and_get_last_line_of_output(command)); 872 mr_free(command); 873 886 874 if (strlen(out_sz) == 0) { 875 mr_free(out_sz); 887 876 return (-1); 888 877 } // error within df, probably 889 878 res = atol(out_sz); 879 mr_free(out_sz); 890 880 return (res); 891 881 } … … 908 898 909 899 /*@ buffers ************ */ 910 char tmp[MAX_STR_LEN]; 911 // char command[MAX_STR_LEN]; 900 char *tmp = NULL; 912 901 913 902 /*@ int's *************** */ … … 924 913 ("ln -sf `which mkfs.msdos` /sbin/mkfs.vfat", FALSE); 925 914 } 926 strcpy(tmp,915 mr_asprintf(&tmp, "%s", 927 916 call_program_and_get_last_line_of_output 928 917 ("free | grep Mem | head -n1 | tr -s ' ' '\t' | cut -f2")); … … 935 924 ("WARNING! You have very little RAM. Please upgrade to 64MB or more."); 936 925 } 926 mr_free(tmp); 937 927 #endif 938 928 … … 996 986 run_program_and_log_output 997 987 ("umount `mount | grep cdr | cut -d' ' -f3 | tr '\n' ' '`", 5); 998 strcpy(tmp,988 mr_asprintf(&tmp, "%s", 999 989 call_program_and_get_last_line_of_output 1000 990 ("mount | grep -E \"cdr(om|w)\"")); … … 1011 1001 if (run_program_and_log_output("uname -a | grep Knoppix", 5)) { 1012 1002 retval++; 1013 fatal_error 1014 ("Your CD-ROM drive is mounted. Please unmount it."); 1015 } 1016 } 1003 mr_free(tmp); 1004 fatal_error("Your CD-ROM drive is mounted. Please unmount it."); 1005 } 1006 } 1007 mr_free(tmp); 1017 1008 1018 1009 run_program_and_log_output("cat /etc/fstab", 5); … … 1030 1021 fatal_error("Please reinstall Mondo and Mindi."); 1031 1022 } 1032 sprintf(tmp, "mindi --makemountlist %s/mountlist.txt.test", bkpinfo->tmpdir);1023 mr_asprintf(&tmp, "mindi --makemountlist %s/mountlist.txt.test", bkpinfo->tmpdir); 1033 1024 if (run_program_and_log_output(tmp, 5)) { 1034 sprintf(tmp, "mindi --makemountlist %s/mountlist.txt.test failed for some reason.", bkpinfo->tmpdir); 1025 mr_free(tmp); 1026 mr_asprintf(&tmp, "mindi --makemountlist %s/mountlist.txt.test failed for some reason.", bkpinfo->tmpdir); 1035 1027 log_to_screen(tmp); 1036 1028 log_to_screen … … 1042 1034 retval++; 1043 1035 } 1036 mr_free(tmp); 1044 1037 1045 1038 if (!run_program_and_log_output("parted2fdisk -l | grep -i raid", 1) … … 1068 1061 { 1069 1062 /*@ buffer ****************************************************** */ 1070 char command[MAX_STR_LEN * 2];1071 char tmp[MAX_STR_LEN];1063 char *command = NULL; 1064 char *tmp = NULL; 1072 1065 1073 1066 /*@ end vars *************************************************** */ … … 1076 1069 assert_string_is_neither_NULL_nor_zerolength(label); 1077 1070 if (!does_file_exist(config_file)) { 1078 sprintf(tmp, "(read_cfg_var) Cannot find %s config file",1071 mr_asprintf(&tmp, "(read_cfg_var) Cannot find %s config file", 1079 1072 config_file); 1080 1073 log_to_screen(tmp); 1074 mr_free(tmp); 1075 1081 1076 value[0] = '\0'; 1082 1077 return (1); … … 1085 1080 return (0); 1086 1081 } else { 1087 sprintf(command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5",1082 mr_asprintf(&command, "grep '%s .*' %s| cut -d' ' -f2,3,4,5", 1088 1083 label, config_file); 1089 1084 strcpy(value, call_program_and_get_last_line_of_output(command)); 1085 mr_free(command); 1086 1090 1087 if (strlen(value) == 0) { 1091 1088 return (1); … … 1153 1150 void stop_autofs_if_necessary() 1154 1151 { 1155 char tmp[MAX_STR_LEN];1152 char *tmp = NULL; 1156 1153 1157 1154 g_autofs_exe[0] = '\0'; … … 1166 1163 } else { 1167 1164 log_msg(3, "%s --- autofs detected", g_autofs_exe); 1168 // FIXME -- only disable it if it's running --- sprintf(tmp, "%s status", autofs_exe);1169 sprintf(tmp, "%s stop", g_autofs_exe);1165 // FIXME -- only disable it if it's running --- sprintf(tmp, "%s status", autofs_exe); 1166 mr_asprintf(&tmp, "%s stop", g_autofs_exe); 1170 1167 if (run_program_and_log_output(tmp, 2)) { 1171 1168 log_it("Failed to stop autofs - I assume it wasn't running"); … … 1174 1171 log_it("Stopped autofs OK"); 1175 1172 } 1173 mr_free(tmp); 1176 1174 } 1177 1175 } … … 1182 1180 void restart_autofs_if_necessary() 1183 1181 { 1184 char tmp[MAX_STR_LEN];1182 char *tmp = NULL; 1185 1183 1186 1184 if (!g_autofs_stopped || !g_autofs_exe[0]) { … … 1188 1186 return; 1189 1187 } 1190 sprintf(tmp, "%s start", g_autofs_exe);1188 mr_asprintf(&tmp, "%s start", g_autofs_exe); 1191 1189 if (run_program_and_log_output(tmp, 2)) { 1192 1190 log_it("Failed to start autofs"); … … 1195 1193 log_it("Started autofs OK"); 1196 1194 } 1195 mr_free(tmp); 1197 1196 } 1198 1197 … … 1203 1202 void mount_boot_if_necessary() 1204 1203 { 1205 char tmp[MAX_STR_LEN];1206 char command[MAX_STR_LEN];1204 char *tmp = NULL; 1205 char *command = NULL; 1207 1206 1208 1207 log_msg(1, "Started sub"); … … 1210 1209 g_boot_mountpt[0] = '\0'; 1211 1210 log_msg(4, "Done. Great. Seeting command to something"); 1212 strcpy(command,1211 mr_asprintf(&command, "%s", 1213 1212 "grep -v \":\" /etc/fstab | grep -vE '^#.*$' | grep -E \"[ ]/boot[ ]\" | tr -s ' ' '\t' | cut -f1 | head -n1"); 1214 1213 log_msg(4, "Cool. Command = '%s'", command); 1215 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 1214 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 1215 mr_free(command); 1216 1216 1217 log_msg(4, "tmp = '%s'", tmp); 1217 1218 if (tmp[0]) { 1218 1219 log_it("/boot is at %s according to /etc/fstab", tmp); 1219 strcpy(command, "mount | grep -Ew '/boot'"); 1220 strcpy(tmp, call_program_and_get_last_line_of_output(command)); 1220 mr_asprintf(&command, "mount | grep -Ew '/boot'"); 1221 mr_free(tmp); 1222 mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command)); 1223 mr_free(command); 1224 1221 1225 if (!strcmp(tmp,"")) { 1222 1226 if ((strstr(tmp, "LABEL=") || strstr(tmp,"UUID="))) { … … 1228 1232 } 1229 1233 } else { 1230 sprintf(command, "mount | grep -E '^%s'", tmp);1234 mr_asprintf(&command, "mount | grep -E '^%s'", tmp); 1231 1235 log_msg(3, "command = %s", command); 1232 1236 if (run_program_and_log_output(command, 5)) { 1233 1237 strcpy(g_boot_mountpt, tmp); 1234 sprintf(tmp, 1238 mr_free(tmp); 1239 mr_asprintf(&tmp, 1235 1240 "%s (your /boot partition) is not mounted. I'll mount it before backing up", 1236 1241 g_boot_mountpt); 1237 1242 log_it(tmp); 1238 sprintf(tmp, "mount %s", g_boot_mountpt); 1243 mr_free(tmp); 1244 1245 mr_asprintf(&tmp, "mount %s", g_boot_mountpt); 1239 1246 if (run_program_and_log_output(tmp, 5)) { 1240 1247 g_boot_mountpt[0] = '\0'; … … 1248 1255 } 1249 1256 } 1257 mr_free(tmp); 1250 1258 } 1259 mr_free(command); 1251 1260 } 1252 1261 } … … 1261 1270 void unmount_boot_if_necessary() 1262 1271 { 1263 char tmp[MAX_STR_LEN];1272 char *tmp = NULL; 1264 1273 1265 1274 log_msg(3, "starting"); 1266 1275 if (g_boot_mountpt[0]) { 1267 sprintf(tmp, "umount %s", g_boot_mountpt);1276 mr_asprintf(&tmp, "umount %s", g_boot_mountpt); 1268 1277 if (run_program_and_log_output(tmp, 5)) { 1269 1278 log_it("WARNING - unable to unmount /boot"); 1270 1279 } 1280 mr_free(tmp); 1271 1281 } 1272 1282 log_msg(3, "leaving"); … … 1286 1296 { 1287 1297 /*@ buffers ***************************************************** */ 1288 char command[MAX_STR_LEN * 2];1289 char tempfile[MAX_STR_LEN];1290 char tmp[MAX_STR_LEN];1298 char *command = NULL; 1299 char *tempfile = NULL; 1300 char *tmp = NULL; 1291 1301 1292 1302 … … 1296 1306 assert(value != NULL); 1297 1307 if (!does_file_exist(config_file)) { 1298 sprintf(tmp, "(write_cfg_file) Cannot find %s config file",1308 mr_asprintf(&tmp, "(write_cfg_file) Cannot find %s config file", 1299 1309 config_file); 1300 1310 log_to_screen(tmp); 1311 mr_free(tmp); 1301 1312 return (1); 1302 1313 } 1303 sprintf(tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir);1314 mr_asprintf(&tempfile, "%s/mojo-jojo.blah", bkpinfo->tmpdir); 1304 1315 if (does_file_exist(config_file)) { 1305 sprintf(command, "grep -vE '^%s .*$' %s > %s",1316 mr_sprintf(&command, "grep -vE '^%s .*$' %s > %s", 1306 1317 label, config_file, tempfile); 1307 1318 paranoid_system(command); 1308 } 1309 sprintf(command, "echo \"%s %s\" >> %s", label, value, tempfile); 1319 mr_free(command); 1320 } 1321 mr_asprintf(&command, "echo \"%s %s\" >> %s", label, value, tempfile); 1310 1322 paranoid_system(command); 1311 sprintf(command, "mv -f %s %s", tempfile, config_file); 1323 mr_free(command); 1324 1325 mr_asprintf(&command, "mv -f %s %s", tempfile, config_file); 1312 1326 paranoid_system(command); 1327 mr_free(command); 1313 1328 unlink(tempfile); 1329 mr_free(tempfile); 1314 1330 return (0); 1315 1331 } … … 1475 1491 void restart_magicdev_if_necessary() 1476 1492 { 1477 char *tmp; 1478 1479 malloc_string(tmp); 1493 char *tmp = NULL; 1494 1480 1495 if (g_magicdev_command && g_magicdev_command[0]) { 1481 sprintf(tmp, "%s &", g_magicdev_command);1496 mr_asprintf(&tmp, "%s &", g_magicdev_command); 1482 1497 paranoid_system(tmp); 1483 }1484 paranoid_free(tmp);1498 mr_free(tmp); 1499 } 1485 1500 } 1486 1501
Note:
See TracChangeset
for help on using the changeset viewer.