Changeset 2320 in MondoRescue for branches/2.2.10/mondo/src/common/libmondo-cli.c
- Timestamp:
- Aug 18, 2009, 2:37:39 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/common/libmondo-cli.c
r2319 r2320 56 56 static int get_dsf_mount_list (const char *dsf, char **included_dsf_list, char **excluded_dsf_list); 57 57 static int create_list_of_non_NFS_mounted_file_systems (void); 58 static MOUNTED_FS_STRUCT *find_mount_point_in_list (c har *mount_point);59 static MOUNTED_FS_STRUCT *find_device_in_list (c har *device);58 static MOUNTED_FS_STRUCT *find_mount_point_in_list (const char *mount_point); 59 static MOUNTED_FS_STRUCT *find_device_in_list (const char *device); 60 60 61 61 /* Do we use extended attributes and acl ? … … 124 124 mr_free(tmp); 125 125 126 sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir),127 "/mondo.scratch.%ld", random() % 32767); 126 mr_strcat(bkpinfo->scratchdir, "/mondo.scratch.%ld", random() % 32767); 127 128 128 mr_asprintf(&tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir); 129 129 paranoid_system(tmp); … … 168 168 bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p); 169 169 } 170 // bkpinfo->media_size[0] = bkpinfo->media_size[MAX_NOOF_MEDIA];171 170 for (j = 1; j <= MAX_NOOF_MEDIA; j++) { 172 171 if (bkpinfo->media_size[j] <= 0) { … … 189 188 while (DSFptr != NULL) { 190 189 DSFnext = DSFptr->next; 191 paranoid_free(DSFptr);190 mr_free(DSFptr); 192 191 DSFptr = DSFnext; 193 192 } … … 221 220 * structure if it did. 222 221 */ 223 static MOUNTED_FS_STRUCT *find_device_in_list (c har *device)222 static MOUNTED_FS_STRUCT *find_device_in_list (const char *device) 224 223 { 225 224 MOUNTED_FS_STRUCT *DSFptr = NULL; … … 242 241 * structure if it did. 243 242 */ 244 static MOUNTED_FS_STRUCT *find_mount_point_in_list (c har *mount_point)243 static MOUNTED_FS_STRUCT *find_mount_point_in_list (const char *mount_point) 245 244 { 246 245 MOUNTED_FS_STRUCT *DSFptr = NULL; … … 283 282 log_msg(5, "Running: %s", command); 284 283 mr_asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command)); 285 paranoid_free(command);284 mr_free(command); 286 285 287 286 mount_cnt = atoi(mounted_file_system); 288 287 log_msg (5, "mount_cnt: %d", mount_cnt); 289 paranoid_free(mounted_file_system);288 mr_free(mounted_file_system); 290 289 291 290 for (i=mount_cnt; i > 0; i--) { … … 293 292 log_msg(5, "Running: %s", command); 294 293 mr_asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command)); 295 paranoid_free(command);294 mr_free(command); 296 295 297 296 log_msg (5, "mounted_file_system: %s", mounted_file_system); 298 297 if ((token = strtok(mounted_file_system, token_chars)) == NULL) { 299 298 log_msg (4, "Could not get the list of mounted file systems"); 300 paranoid_free(mounted_file_system);299 mr_free(mounted_file_system); 301 300 mr_free(token); 302 301 return (1); … … 315 314 if ((token = strtok(NULL, token_chars)) == NULL) { 316 315 log_msg (5, "Ran out of entries on the mounted file systems list"); 317 paranoid_free(mounted_file_system);316 mr_free(mounted_file_system); 318 317 mr_free(token); 319 318 return (1); … … 324 323 token = strtok(NULL, token_chars); 325 324 } 326 paranoid_free(mounted_file_system);325 mr_free(mounted_file_system); 327 326 } 328 327 /******** … … 377 376 log_msg(5, " Executing: %s", command); 378 377 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 379 paranoid_free(command);378 mr_free(command); 380 379 381 380 log_msg(5, " Return value: %s", tmp); 382 381 c = atoi(tmp); 383 paranoid_free(tmp);382 mr_free(tmp); 384 383 385 384 if (!c) { … … 403 402 log_msg(4, "Executing: %s", command); 404 403 mr_asprintf(&partition_list, "%s", call_program_and_get_last_line_of_output(command)); 405 paranoid_free(command);404 mr_free(command); 406 405 log_msg(4, "Partition list for %s: %s", dsf, partition_list); 407 406 if (!strlen(partition_list)) { … … 419 418 mr_free(token); 420 419 } 421 paranoid_free(partition_list);420 mr_free(partition_list); 422 421 423 422 /******** … … 457 456 log_msg(4, " Running: %s", command); 458 457 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 459 paranoid_free(command); 458 mr_free(command); 459 460 460 log_msg(4, " Return value: %s", tmp); 461 461 c = strlen(tmp); 462 paranoid_free(tmp); 462 mr_free(tmp); 463 463 464 if (c) { 464 465 log_msg(4, "It's swap. Ignoring partition %s", partitions[i]); … … 468 469 mr_asprintf(&command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]); 469 470 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 470 paranoid_free(command); 471 mr_free(command); 472 471 473 if (strlen(tmp)) { 472 474 log_msg(4, " %s is mounted: %s", partitions[i], tmp); 473 475 if ((DSFptr = find_mount_point_in_list(tmp)) == NULL) { 474 476 log_msg (4, "Can't find mount point %s in mounted file systems list", tmp); 475 paranoid_free(tmp);477 mr_free(tmp); 476 478 return (1); 477 479 } 478 480 DSFptr->check = 1; 479 paranoid_free(tmp);481 mr_free(tmp); 480 482 continue; 481 483 } 482 paranoid_free(tmp);484 mr_free(tmp); 483 485 /* It's not swap and it's not mounted. See if it's LVM */ 484 486 log_msg(4, " It's not mounted. Checking to see if it's LVM..."); … … 487 489 log_msg(4, " Running: %s", command); 488 490 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 489 paranoid_free(command);491 mr_free(command); 490 492 if (strlen(tmp)) { 491 493 log_msg(4, " Partition ID: %s", tmp); … … 496 498 log_msg(4, " Running: %s", command); 497 499 strcpy(VG, call_program_and_get_last_line_of_output(command)); 498 paranoid_free(command);500 mr_free(command); 499 501 log_msg(4, " Volume Group: %s", VG); 500 502 if (strlen(VG)) { … … 504 506 log_msg(4, " Running: %s", command); 505 507 mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command)); 506 paranoid_free(command);508 mr_free(command); 507 509 log_msg(4, " VG %s mount_list: %s", VG, mount_list); 508 510 lastpos = 0; … … 511 513 if ((DSFptr = find_mount_point_in_list(token)) == NULL) { 512 514 log_msg (4, "Can't find mount point %s in mounted file systems list", token); 513 paranoid_free(tmp);515 mr_free(tmp); 514 516 mr_free(token); 515 517 return (1); … … 522 524 * any of the Logical Volumes on the Volume Group. 523 525 *******/ 524 paranoid_free(mount_list);526 mr_free(mount_list); 525 527 mr_asprintf(&command, "%s", "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); 526 528 log_msg (5, "Running: %s", command); 527 529 mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command)); 528 paranoid_free(command);530 mr_free(command); 529 531 log_msg(4, " Software raid device list: %s", mount_list); 530 532 lastpos = 0; … … 532 534 mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG); 533 535 log_msg (5, "Running: %s", command); 534 paranoid_free(tmp);536 mr_free(tmp); 535 537 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 536 paranoid_free(command);538 mr_free(command); 537 539 log_msg(4, "Number of Software raid device: %s", tmp); 538 540 if (atoi(tmp)) { … … 540 542 if ((DSFptr = find_device_in_list(token)) == NULL) { 541 543 log_msg (4, "Can't find device %s in mounted file systems list", token); 542 paranoid_free(tmp);544 mr_free(tmp); 543 545 mr_free(token); 544 546 return (1); … … 548 550 } 549 551 mr_free(token); 550 paranoid_free(mount_list);552 mr_free(mount_list); 551 553 } else { 552 554 log_msg (4, "Error finding Volume Group for partition %s", partitions[i]); 553 paranoid_free(tmp);555 mr_free(tmp); 554 556 return (1); 555 557 } 556 paranoid_free(tmp);558 mr_free(tmp); 557 559 continue; 558 560 } … … 560 562 log_msg (4, "Error finding partition type for the partition %s", partitions[i]); 561 563 } 562 paranoid_free(tmp);564 mr_free(tmp); 563 565 /******** 564 566 * It's not swap, mounted, or LVM. See if it's used in a software raid device. … … 568 570 log_msg(4, " Running: %s", command); 569 571 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 570 paranoid_free(command);572 mr_free(command); 571 573 if (!strlen(tmp)) { 572 574 log_msg(4, " Partition %s is not used in a non-LVM software raid device", partitions[i]); 573 paranoid_free(tmp);575 mr_free(tmp); 574 576 continue; 575 577 } … … 579 581 log_msg (5, " Running: %s", command); 580 582 mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command)); 581 paranoid_free(command);583 mr_free(command); 582 584 log_msg(4, " Software raid device list: %s", mount_list); 583 585 /* Loop through the software raid device list to see if we can find the partition */ … … 586 588 mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp); 587 589 log_msg(4, " Running: %s", command); 588 paranoid_free(tmp);590 mr_free(tmp); 589 591 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 590 paranoid_free(command);592 mr_free(command); 591 593 if (!atoi(tmp)) { 592 594 log_msg (4," Didn't find partition %s in software raid device %s", partitions[i], token); … … 594 596 if ((DSFptr = find_device_in_list(token)) == NULL) { 595 597 log_msg (4, "Can't find device %s in mounted file systems list", token); 596 paranoid_free(tmp);598 mr_free(tmp); 597 599 mr_free(token); 598 600 return (1); … … 603 605 mr_free(token); 604 606 } 605 paranoid_free(tmp);606 } 607 paranoid_free(partition_list);608 paranoid_free(mount_list);607 mr_free(tmp); 608 } 609 mr_free(partition_list); 610 mr_free(mount_list); 609 611 610 612 /* Determine how much memory to allocate for included_dsf_list and excluded_dsf_list */ … … 753 755 754 756 if (flag_set['I']) { 755 if (bkpinfo->include_paths [0] == '-') {757 if (bkpinfo->include_paths && bkpinfo->include_paths[0] == '-') { 756 758 retval++; 757 759 log_to_screen("Please supply a sensible value with '-I'\n"); 758 }759 if (!strcmp(bkpinfo->include_paths, "/")) {760 log_msg(2, "'/' is pleonastic.");761 760 } 762 761 … … 783 782 } 784 783 } 785 paranoid_free(tmp1);784 mr_free(tmp1); 786 785 while ((token = mr_strtok(flag_val['I'], token_chars, &lastpos)) != NULL) { 787 786 switch (get_dsf_mount_list(token, &mounted_on_dsf, ¬_mounted_on_dsf)) { … … 798 797 log_to_screen(" %s\n", mounted_on_dsf); 799 798 mr_asprintf(&p, "/"); 799 mr_free(bkpinfo->include_paths); 800 800 bkpinfo->include_paths = p; 801 801 if (strlen(not_mounted_on_dsf)) { … … 803 803 log_to_screen("Not archiving the following file systems:\n"); 804 804 log_to_screen(" %s\n", not_mounted_on_dsf); 805 mr_strcat(bkpinfo->exclude_paths, " %s ", not_mounted_on_dsf);805 mr_strcat(bkpinfo->exclude_paths, " %s ", not_mounted_on_dsf); 806 806 } 807 807 break; … … 837 837 bkpinfo->make_filelist = FALSE; 838 838 mr_asprintf(&p, "%s", flag_val['J']); 839 mr_free(bkpinfo->include_paths); 839 840 bkpinfo->include_paths = p; 840 841 } … … 1089 1090 1090 1091 if (flag_set['E']) { 1091 if (bkpinfo->exclude_paths [0] == '-') {1092 if (bkpinfo->exclude_paths && bkpinfo->exclude_paths[0] == '-') { 1092 1093 retval++; 1093 1094 log_to_screen("Please supply a sensible value with '-E'\n"); 1094 1095 } 1095 mr_strcat(bkpinfo->exclude_paths, " ");1096 1096 mr_asprintf(&tmp1, "%s", flag_val['E']); 1097 1097 … … 1136 1136 log_to_screen(" %s\n", mounted_on_dsf); 1137 1137 log_msg (5, "Adding to bkpinfo->exclude_paths due to -E option: %s", mounted_on_dsf); 1138 mr_strcat(bkpinfo->exclude_paths, "%s ", mounted_on_dsf); 1139 } 1138 mr_strcat(bkpinfo->exclude_paths, " %s ", mounted_on_dsf); 1140 1139 } 1141 1140 break; … … 1146 1145 /* A device special file was not passed in. Process it as a path. */ 1147 1146 case -1: 1148 mr_strcat(bkpinfo->exclude_paths, " %s ", token);1147 mr_strcat(bkpinfo->exclude_paths, " %s ", token); 1149 1148 break; 1150 1149 } … … 1164 1163 { 1165 1164 mr_asprintf(&psz, "%s", list_of_NFS_mounts_only()); 1166 mr_strcat(bkpinfo->exclude_paths, " %s ", psz);1165 mr_strcat(bkpinfo->exclude_paths, " %s ", psz); 1167 1166 mr_free(psz); 1168 1167 … … 1300 1299 1301 1300 if (flag_set['S']) { 1302 sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'], 1303 random() % 32768); 1301 mr_asprintf(&tmp1, "%s/mondo.scratch.%ld", flag_val['S'], random() % 32768); 1302 mr_free(bkpinfo->scratchdir); 1303 bkpinfo->scratchdir = tmp1; 1304 1304 } 1305 1305 … … 1376 1376 finish(0); 1377 1377 } 1378 mr_free(tmp); 1378 1379 1379 1380 if ((flag_set['L']) && (! bkpinfo->restore_data)) { … … 1466 1467 /* and finally... */ 1467 1468 1468 paranoid_free(tmp);1469 1469 return (retval); 1470 1470 } … … 1515 1515 mr_asprintf(&tmp, "Switch -%c previously defined as %s\n", opt, flag_val[opt]); 1516 1516 log_to_screen(tmp); 1517 paranoid_free(tmp);1517 mr_free(tmp); 1518 1518 } else { 1519 1519 flag_set[opt] = TRUE; … … 1531 1531 mr_asprintf(&tmp, "-%c flag --- must be absolute path --- '%s' isn't absolute", opt, flag_val[opt]); 1532 1532 log_to_screen(tmp); 1533 paranoid_free(tmp);1533 mr_free(tmp); 1534 1534 bad_switches = TRUE; 1535 1535 } … … 1544 1544 mr_asprintf(&tmp, "Invalid arg -- %s\n", argv[i]); 1545 1545 log_to_screen(tmp); 1546 paranoid_free(tmp);1546 mr_free(tmp); 1547 1547 } 1548 1548 return (bad_switches); … … 1607 1607 mr_strcat(tmp, " signal received from OS"); 1608 1608 log_to_screen(tmp); 1609 paranoid_free(tmp);1609 mr_free(tmp); 1610 1610 1611 1611 log_to_screen(tmp2); 1612 paranoid_free(tmp2);1612 mr_free(tmp2); 1613 1613 if (sig == SIGABRT) { 1614 1614 sleep(10);
Note:
See TracChangeset
for help on using the changeset viewer.