Changeset 688 in MondoRescue for trunk/mondo/mondo/common/libmondo-files.c
- Timestamp:
- Jul 17, 2006, 3:44:46 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/common/libmondo-files.c
r687 r688 22 22 //static char cvsid[] = "$Id$"; 23 23 24 extern char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN];24 extern char **err_log_lines; 25 25 26 26 extern int g_currentY; … … 270 270 int figure_out_kernel_path_interactively_if_necessary(char *kernel) 271 271 { 272 char *tmp; 273 char *command; 274 275 if (!kernel[0]) { 276 strcpy(kernel, 277 call_program_and_get_last_line_of_output 272 char *tmp = NULL; 273 char *command = NULL; 274 275 if (kernel == NULL) { 276 kernel = call_program_and_get_last_line_of_output 278 277 ("mindi --findkernel 2> /dev/null")); 279 278 } 280 279 // If we didn't get anything back, check whether mindi raised a fatal error 281 if ( !kernel[0]) {280 if (kernel == NULL) { 282 281 asprintf(&command, "grep 'Fatal error' /var/log/mindi.log"); 283 asprintf(&tmp, call_program_and_get_last_line_of_output(command));282 tmp = call_program_and_get_last_line_of_output(command); 284 283 if (strlen(tmp) > 1) { 285 284 popup_and_OK(tmp); … … 289 288 paranoid_free(tmp); 290 289 } 291 log_it("Calling Mindi with kernel path of '%s'", kernel); 292 while (!kernel[0]) { 290 291 if (kernel != NULL) { 292 log_it("Calling Mindi with kernel path of '%s'", kernel); 293 } else { 294 log_it("Calling Mindi without kernel, so asking one"); 295 } 296 297 while (kernel == NULL) { 293 298 if (!ask_me_yes_or_no 294 299 (_("Kernel not found or invalid. Choose another?"))) { … … 298 303 (_("Kernel path"), 299 304 _("What is the full path and filename of your kernel, please?"), 300 kernel , MAX_STR_LEN / 4)) {305 kernel)) { 301 306 fatal_error 302 307 ("Kernel not found. Please specify with the '-k' flag."); 303 308 } 304 asprintf(&tmp, "User says kernel is at %s", kernel); 305 log_it(tmp); 306 paranoid_free(tmp); 309 log_it("User says kernel is at %s", kernel); 307 310 } 308 311 return (0); … … 322 325 { 323 326 /*@ buffers ********************* */ 324 static char output[MAX_STR_LEN];325 char *incoming ;326 char *command ;327 char *output = NULL; 328 char *incoming = NULL; 329 char *command = NULL; 327 330 328 331 /*@******************************* */ 329 332 330 333 assert_string_is_neither_NULL_nor_zerolength(fname); 334 331 335 asprintf(&command, "which %s 2> /dev/null", fname); 332 asprintf(&incoming, call_program_and_get_last_line_of_output(command));333 paranoid_free(command); 334 335 if (incoming [0] == '\0') {336 incoming = call_program_and_get_last_line_of_output(command); 337 paranoid_free(command); 338 339 if (incoming == NULL) { 336 340 if (system("which file > /dev/null 2> /dev/null")) { 337 paranoid_free(incoming);338 341 return (NULL); // forget it :) 339 342 } … … 343 346 paranoid_free(incoming); 344 347 345 asprintf(&incoming, 346 call_program_and_get_last_line_of_output(command)); 348 incoming = call_program_and_get_last_line_of_output(command); 347 349 paranoid_free(command); 348 350 } 349 if (incoming [0] == '\0') // yes, it is == '\0' twice, not once :)351 if (incoming == NULL) // yes, it is == '\0' twice, not once :) 350 352 { 351 353 asprintf(&command, "dirname %s 2> /dev/null", incoming); 352 354 paranoid_free(incoming); 353 355 354 asprintf(&incoming, 355 call_program_and_get_last_line_of_output(command)); 356 incoming = call_program_and_get_last_line_of_output(command); 356 357 paranoid_free(command); 357 358 } 358 strcpy(output, incoming); 359 paranoid_free(incoming); 360 361 if (output[0] != '\0' && does_file_exist(output)) { 362 log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, 363 output); 359 output = incoming; 360 361 if (output != NULL && does_file_exist(output)) { 362 log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, output); 364 363 } else { 365 output[0] = '\0';364 paranoid_free(output); 366 365 log_msg(4, "find_home_of_exe() --- Could not find %s", fname); 367 366 } 368 if (!output[0]) { 369 return (NULL); 370 } else { 371 return (output); 372 } 367 return (output); 373 368 } 374 369 … … 421 416 { 422 417 423 /*@ buffers ***************************************************** */ 424 char *lastline; 425 char *command; 426 /*@ pointers **************************************************** */ 427 char *p; 428 429 /*@ int's ******************************************************* */ 418 char *lastline = NULL; 419 char *command = NULL; 420 char *p = NULL; 430 421 int i; 431 422 432 for (i = NOOF_ERR_LINES- 1;423 for (i = g_noof_log_lines - 1; 433 424 i >= 0 && !strstr(err_log_lines[i], "% Done") 434 425 && !strstr(err_log_lines[i], "% done"); i--); … … 437 428 "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'", 438 429 filename, '%'); 439 asprintf(&lastline, 440 call_program_and_get_last_line_of_output(command)); 430 lastline = call_program_and_get_last_line_of_output(command); 441 431 paranoid_free(command); 442 if (!lastline[0]) { 443 paranoid_free(lastline); 432 if (!lastline) { 444 433 return (0); 445 434 } … … 477 466 { 478 467 /*@ buffers ***************************************************** */ 479 static char output[MAX_STR_LEN];480 static char *command;481 static char *tmp;468 char *output = NULL; 469 char *command = NULL; 470 char *tmp = NULL; 482 471 483 472 /*@ pointers **************************************************** */ 484 473 FILE *fin; 474 size_t n = 0; 485 475 486 476 /*@ end vars **************************************************** */ … … 491 481 log_it(tmp); 492 482 paranoid_free(tmp); 493 494 output[0] = '\0'; 483 asprintf(&output, ""); 484 495 485 return (output); 496 486 } … … 499 489 paranoid_free(command); 500 490 501 (void) fgets(output, MAX_STR_LEN, fin);491 getline(&output, &n, fin); 502 492 paranoid_pclose(fin); 503 493 while (strlen(output) > 0 && output[strlen(output) - 1] < 32) { … … 693 683 long size_of_partition_in_mountlist_K(char *tmpdir, char *dev) 694 684 { 695 char *command ;696 char *sz_res ;697 long file_len_K ;685 char *command = NULL; 686 char *sz_res = NULL; 687 long file_len_K = 0L; 698 688 699 689 asprintf(&command, … … 701 691 dev, tmpdir); 702 692 log_it(command); 703 asprintf(&sz_res, call_program_and_get_last_line_of_output(command));693 sz_res = call_program_and_get_last_line_of_output(command); 704 694 file_len_K = atol(sz_res); 705 695 log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K); … … 717 707 long size_of_all_biggiefiles_K(struct s_bkpinfo *bkpinfo) 718 708 { 719 /*@ buffers ***************************************************** */ 720 char *fname; 721 char *biggielist; 722 char *comment; 723 char *tmp; 724 char *command; 709 char *fname = NULL; 710 char *biggielist = NULL; 711 char *comment = NULL; 712 char *tmp = NULL; 713 char *command = NULL; 725 714 726 715 /*@ long ******************************************************** */ 727 long scratchL = 0 ;728 long file_len_K ;716 long scratchL = 0L; 717 long file_len_K = 0L; 729 718 730 719 /*@ pointers *************************************************** */ … … 734 723 /*@ end vars *************************************************** */ 735 724 736 malloc_string(tmp);737 malloc_string(command);738 725 log_it("Calculating size of all biggiefiles (in total)"); 739 726 asprintf(&biggielist, "%s/biggielist.txt", bkpinfo->tmpdir); … … 754 741 fatal_error("ntfsresize not found"); 755 742 } 756 sprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname);743 asprintf(&command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname); 757 744 log_it("command = %s", command); 758 strcpy (tmp, call_program_and_get_last_line_of_output(command)); 745 tmp = call_program_and_get_last_line_of_output(command); 746 paranoid_free(command); 747 759 748 log_it("res of it = %s", tmp); 760 749 file_len_K = atoll(tmp) / 1024L; 750 paranoid_free(tmp); 761 751 } else { 762 752 file_len_K = get_phys_size_of_drive(fname) * 1024L; … … 787 777 paranoid_fclose(fin); 788 778 log_it("Finished calculating total size of all biggiefiles"); 789 paranoid_free(tmp);790 paranoid_free(command);791 779 return (scratchL); 792 780 } … … 803 791 /*@ buffer ****************************************************** */ 804 792 char *tmp = NULL; 805 char *command ;793 char *command = NULL; 806 794 long long llres; 807 795 size_t n = 0; 808 796 /*@ pointers **************************************************** */ 809 char *p ;810 FILE *fin ;797 char *p = NULL; 798 FILE *fin = NULL; 811 799 812 800 /*@ end vars *************************************************** */ … … 1025 1013 paranoid_free(command); 1026 1014 1027 asprintf(&tmp, 1028 call_program_and_get_last_line_of_output("which mondorestore")); 1029 if (!tmp[0]) { 1015 tmp = call_program_and_get_last_line_of_output("which mondorestore"); 1016 if (!tmp) { 1030 1017 fatal_error 1031 1018 ("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?"); … … 1068 1055 1069 1056 /*@ buffers ******** */ 1070 char *outfile ;1071 char *nfs_dev ;1072 char *nfs_mount ;1073 char *nfs_client_ipaddr ;1074 char *nfs_client_netmask ;1075 char *nfs_client_broadcast ;;1076 char *nfs_client_defgw ;1077 char *nfs_server_ipaddr ;1078 char *tmp ;1079 char *command ;1057 char *outfile = NULL; 1058 char *nfs_dev = NULL; 1059 char *nfs_mount = NULL; 1060 char *nfs_client_ipaddr = NULL; 1061 char *nfs_client_netmask = NULL; 1062 char *nfs_client_broadcast = NULL; 1063 char *nfs_client_defgw = NULL; 1064 char *nfs_server_ipaddr = NULL; 1065 char *tmp = NULL; 1066 char *command = NULL; 1080 1067 1081 1068 /*@ pointers ***** */ … … 1099 1086 asprintf(&command, 1100 1087 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\n' | head -n1 | cut -d' ' -f1"); 1101 asprintf(&nfs_dev, call_program_and_get_last_line_of_output(command));1088 nfs_dev = call_program_and_get_last_line_of_output(command); 1102 1089 paranoid_free(command); 1103 1090 1104 1091 asprintf(&command, 1105 1092 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f7 | cut -d':' -f2"); 1106 asprintf(&nfs_client_ipaddr, 1107 call_program_and_get_last_line_of_output(command)); 1093 nfs_client_ipaddr = call_program_and_get_last_line_of_output(command); 1108 1094 paranoid_free(command); 1109 1095 1110 1096 asprintf(&command, 1111 1097 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f9 | cut -d':' -f2"); 1112 asprintf(&nfs_client_netmask, 1113 call_program_and_get_last_line_of_output(command)); 1098 nfs_client_netmask = call_program_and_get_last_line_of_output(command); 1114 1099 paranoid_free(command); 1115 1100 1116 1101 asprintf(&command, 1117 1102 "ifconfig | tr '\n' '#' | sed s/##// | tr '#' ' ' | tr '' '\\n' | head -n1 | tr -s '\t' ' ' | cut -d' ' -f8 | cut -d':' -f2"); 1118 strcpy(nfs_client_broadcast, 1119 call_program_and_get_last_line_of_output(command)); 1120 sprintf(command, 1103 nfs_client_broadcast = call_program_and_get_last_line_of_output(command); 1104 paranoid_free(command); 1105 1106 asprintf(&command, 1121 1107 "route -n | grep '^0.0.0.0' | awk '{print $2}'"); 1122 asprintf(&nfs_client_defgw, 1123 call_program_and_get_last_line_of_output(command)); 1108 nfs_client_defgw = call_program_and_get_last_line_of_output(command); 1124 1109 paranoid_free(command); 1125 1110 … … 1317 1302 paranoid_free(tmp); 1318 1303 1319 asprintf(&do_not_compress_these, last_line_of_file(tmp));1304 do_not_compress_these = last_line_of_file(tmp); 1320 1305 for (p = do_not_compress_these; p != NULL; p++) { 1321 1306 asprintf(&tmp, p);
Note:
See TracChangeset
for help on using the changeset viewer.