Changeset 2331 in MondoRescue for branches/2.2.10/mondo/src/common/libmondo-files.c
- Timestamp:
- Aug 18, 2009, 3:25:29 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/common/libmondo-files.c
r2328 r2331 317 317 * @return The full path to the executable, or "" if it does not exist, or NULL if @c file could not be found. 318 318 * @note The returned string points to static storage that will be overwritten with each call. 319 * @bug The checks with @c file and @c dirname seem pointless. If @c incomingis "", then you're calling319 * @bug The checks with @c file and @c dirname seem pointless. If @c output is "", then you're calling 320 320 * <tt>dirname 2\>/dev/null</tt> or <tt>file 2\>/dev/null | cut -d':' -f1 2\>/dev/null</tt>, which basically amounts 321 321 * to nothing. … … 324 324 { 325 325 /*@ buffers ********************* */ 326 static char output[MAX_STR_LEN]; 327 char *incoming; 326 char *output = NULL; 328 327 char *command = NULL; 329 328 330 malloc_string(incoming);331 incoming[0] = '\0';332 329 /*@******************************* */ 333 330 334 331 assert_string_is_neither_NULL_nor_zerolength(fname); 335 332 mr_asprintf(command, "which %s 2> /dev/null", fname); 336 strcpy(incoming, call_program_and_get_last_line_of_output(command));337 mr_free(command); 338 if ( incoming[0] == '\0') {333 mr_asprintf(output, "%s", call_program_and_get_last_line_of_output(command)); 334 mr_free(command); 335 if (output[0] == '\0') { 339 336 if (system("which file > /dev/null 2> /dev/null")) { 340 paranoid_free(incoming); 341 output[0] = '\0'; 337 mr_free(output); 342 338 return (NULL); // forget it :) 343 339 } 344 mr_asprintf(command, "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", incoming); 345 strcpy(incoming, call_program_and_get_last_line_of_output(command)); 340 mr_asprintf(command, "file %s 2> /dev/null | cut -d':' -f1 2> /dev/null", output); 341 mr_free(output); 342 mr_asprintf(output, "%s", call_program_and_get_last_line_of_output(command)); 346 343 mr_free(command); 347 344 } 348 if ( incoming[0] == '\0') // yes, it is == '\0' twice, not once :)349 {350 mr_ asprintf(command, "dirname %s 2> /dev/null", incoming);351 strcpy(incoming, call_program_and_get_last_line_of_output(command));345 if (output[0] == '\0') { 346 mr_asprintf(command, "dirname %s 2> /dev/null", output); 347 mr_free(output); 348 mr_asprintf(output, "%s", call_program_and_get_last_line_of_output(command)); 352 349 mr_free(command); 353 350 } 354 strcpy(output, incoming); 351 355 352 if (output[0] != '\0' && does_file_exist(output)) { 356 log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, 357 incoming); 353 log_msg(4, "find_home_of_exe () --- Found %s at %s", fname, output); 358 354 } else { 359 output[0] = '\0';355 mr_free(output); 360 356 log_msg(4, "find_home_of_exe() --- Could not find %s", fname); 361 357 } 362 paranoid_free(incoming); 363 if (!output[0]) { 364 return (NULL); 365 } else { 366 return (output); 367 } 358 return (output); 368 359 } 369 360 … … 427 418 428 419 /*@ buffers ***************************************************** */ 429 char lastline[MAX_STR_LEN];420 char *lastline = NULL; 430 421 char *command = NULL; 431 422 /*@ pointers **************************************************** */ … … 440 431 if (i < 0) { 441 432 mr_asprintf(command, "tail -n3 %s | grep -Fi \"%c\" | tail -n1 | awk '{print $0;}'", filename, '%'); 442 strcpy(lastline, call_program_and_get_last_line_of_output(command));433 mr_asprintf(lastline, "%s", call_program_and_get_last_line_of_output(command)); 443 434 mr_free(command); 444 435 if (!lastline[0]) { 436 mr_free(lastline); 445 437 return (0); 446 438 } 447 439 } else { 448 strcpy(lastline, err_log_lines[i]);440 mr_asprintf(lastline, "%s", err_log_lines[i]); 449 441 } 450 442 … … 454 446 } 455 447 if (!p) { 448 mr_free(lastline); 456 449 return (0); 457 450 } … … 461 454 p++; 462 455 } 456 mr_free(lastline); 457 463 458 i = atoi(p); 464 465 459 return (i); 466 460 } … … 550 544 char stub_fname[1000]; 551 545 char curr_fname[1000]; 552 char curr_cksum[1000];546 char *curr_cksum = NULL; 553 547 char *tmp = NULL; 554 548 … … 589 583 mr_free(tmp); 590 584 591 strcpy(curr_cksum, calc_file_ugly_minichecksum(curr_fname));585 mr_asprintf(curr_cksum, "%s", calc_file_ugly_minichecksum(curr_fname)); 592 586 fprintf(fout, "%s\t%s\n", curr_fname, curr_cksum); 587 mr_free(curr_cksum); 588 593 589 if (counter++ > 12) { 594 590 current_time = get_time(); … … 719 715 char *command = NULL; 720 716 char *mountlist = NULL; 721 char sz_res[MAX_STR_LEN];717 char *sz_res = NULL; 722 718 long file_len_K; 723 719 … … 727 723 728 724 log_it(command); 729 strcpy(sz_res, call_program_and_get_last_line_of_output(command));725 mr_asprintf(sz_res, "%s", call_program_and_get_last_line_of_output(command)); 730 726 file_len_K = atol(sz_res); 731 727 log_msg(4, "%s --> %s --> %ld", command, sz_res, file_len_K); 728 mr_free(sz_res); 732 729 mr_free(command); 733 730 … … 745 742 char *fname; 746 743 char *biggielist = NULL; 747 char *comment = NULL;748 744 char *tmp = NULL; 749 745 char *command = NULL; … … 752 748 long scratchL = 0; 753 749 long file_len_K; 754 755 int res = 0;756 750 757 751 /*@ pointers *************************************************** */ … … 778 772 if (0 == strncmp(fname, "/dev/", 5)) { 779 773 if (is_dev_an_NTFS_dev(fname)) { 780 if ( !find_home_of_exe("ntfsresize")) { 774 tmp = find_home_of_exe("ntfsresize"); 775 if (!tmp) { 776 mr_free(tmp); 781 777 fatal_error("ntfsresize not found"); 782 778 } 779 mr_free(tmp); 780 783 781 mr_asprintf(command, "ntfsresize --force --info %s|grep '^You might resize at '|cut -d' ' -f5", fname); 784 782 log_it("command = %s", command); … … 1005 1003 /*@ Char buffers ** */ 1006 1004 char *command = NULL; 1007 char tmp[MAX_STR_LEN];1005 char *tmp = NULL; 1008 1006 int res = 0; 1009 1007 1010 mvaddstr_and_log_it(g_currentY, 0, 1011 "Copying Mondo's core files to the scratch directory"); 1008 mvaddstr_and_log_it(g_currentY, 0, "Copying Mondo's core files to the scratch directory"); 1012 1009 1013 1010 log_msg(4, "g_mondo_home='%s'", g_mondo_home); … … 1033 1030 } 1034 1031 1035 strcpy(tmp, 1036 call_program_and_get_last_line_of_output("which mondorestore")); 1032 mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("which mondorestore")); 1037 1033 if (!tmp[0]) { 1038 fatal_error1039 1034 mr_free(tmp); 1035 fatal_error("'which mondorestore' returned null. Where's your mondorestore? `which` can't find it. That's odd. Did you install mondorestore?"); 1040 1036 } 1041 1037 mr_asprintf(command, "cp -f %s %s", tmp, bkpinfo->tmpdir); 1038 mr_free(tmp); 1039 1042 1040 res = run_program_and_log_output(command, FALSE); 1043 1041 mr_free(command); … … 1270 1268 1271 1269 /** 1272 * Get the last suffix of @p instr.1273 * If @p instr was "httpd.log.gz", we would return "gz".1274 * @param instr The filename to get the suffix of.1275 * @return The suffix (without a dot), or "" if none.1276 * @note The returned string points to static storage that will be overwritten with each call.1277 */1278 char *sz_last_suffix(char *instr)1279 {1280 static char outstr[MAX_STR_LEN];1281 char *p;1282 1283 p = strrchr(instr, '.');1284 if (!p) {1285 outstr[0] = '\0';1286 } else {1287 strcpy(outstr, p);1288 }1289 return (outstr);1290 }1291 1292 1293 /**1294 1270 * Determine whether a file is compressed. This is done 1295 1271 * by reading through the "do-not-compress-these" file distributed with Mondo. … … 1299 1275 bool is_this_file_compressed(char *filename) 1300 1276 { 1301 char do_not_compress_these[MAX_STR_LEN];1277 char *do_not_compress_these = NULL; 1302 1278 char *tmp = NULL; 1303 1279 char *p; … … 1315 1291 } 1316 1292 /* BERLIOS: This is just plain WRONG !! */ 1317 strcpy(do_not_compress_these,last_line_of_file(tmp));1293 mr_asprintf(do_not_compress_these, "%s", last_line_of_file(tmp)); 1318 1294 mr_free(tmp); 1319 1295 … … 1325 1301 if (!strcmp(q, tmp)) { 1326 1302 mr_free(tmp); 1303 mr_free(do_not_compress_these); 1327 1304 return (TRUE); 1328 1305 } … … 1332 1309 mr_free(tmp); 1333 1310 } 1311 mr_free(do_not_compress_these); 1334 1312 return (FALSE); 1335 1313 }
Note:
See TracChangeset
for help on using the changeset viewer.