Changeset 2211 in MondoRescue for branches/2.2.9/mondo/src/common/libmondo-cli.c
- Timestamp:
- Jun 3, 2009, 7:10:19 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mondo/src/common/libmondo-cli.c
r2202 r2211 12 12 #include <pthread.h> 13 13 #include "my-stuff.h" 14 #include "mr_mem.h" 15 #include "mr_string.h" 14 16 #include "mondostructures.h" 15 17 #include "libmondo-cli-EXT.h" 16 18 #include "libmondo.h" 17 #include "mr_string.h"18 19 19 20 extern int g_loglevel; … … 278 279 ********/ 279 280 /* Get the number of mounted file systems ((those that start with "/dev/" */ 280 asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l");281 mr_asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $0}}'|wc -l"); 281 282 log_msg(5, "Running: %s", command); 282 asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));283 mr_asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command)); 283 284 paranoid_free(command); 284 285 … … 288 289 289 290 for (i=mount_cnt; i > 0; i--) { 290 asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i);291 mr_asprintf(&command, "mount 2>/dev/null | awk '{if($1 ~ \"^/dev/\"){print $1,$3}}'|head -n %d", i); 291 292 log_msg(5, "Running: %s", command); 292 asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command));293 mr_asprintf(&mounted_file_system, "%s", call_program_and_get_last_line_of_output(command)); 293 294 paranoid_free(command); 294 295 … … 366 367 log_msg(5, " %s looks like a device special file", dsf); 367 368 /* Verify that the dsf exists */ 368 asprintf(&command, "ls -al %s 2>/dev/null | wc -l", dsf);369 mr_asprintf(&command, "ls -al %s 2>/dev/null | wc -l", dsf); 369 370 log_msg(5, " Executing: %s", command); 370 asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));371 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 371 372 paranoid_free(command); 372 373 … … 392 393 * Either way, it's an error. 393 394 ********/ 394 asprintf(&command,395 mr_asprintf(&command, 395 396 "fdisk -l %s 2>/dev/null|grep -E \"^/dev/\"|awk '{printf(\"%%s \", $1)}END{print \"\"}'", dsf); 396 397 log_msg(4, "Executing: %s", command); 397 asprintf(&partition_list, "%s", call_program_and_get_last_line_of_output(command));398 mr_asprintf(&partition_list, "%s", call_program_and_get_last_line_of_output(command)); 398 399 paranoid_free(command); 399 400 log_msg(4, "Partition list for %s: %s", dsf, partition_list); … … 445 446 log_msg(4, "Processing partition: %s", partitions[i]); 446 447 /* See if it's swap. If it is, ignore it. */ 447 asprintf(&command,448 mr_asprintf(&command, 448 449 "fdisk -l %s 2>/dev/null | awk '{if(($1==\"%s\")&&(toupper($0) ~ \"SWAP\")){print $1;exit}}'", 449 450 dsf, partitions[i]); 450 451 log_msg(4, " Running: %s", command); 451 asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));452 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 452 453 paranoid_free(command); 453 454 log_msg(4, " Return value: %s", tmp); … … 459 460 } 460 461 /* It's not swap. See if we can find the mount point from the mount command. */ 461 asprintf(&command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]);462 asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));462 mr_asprintf(&command, "mount 2>/dev/null | awk '{if((NF>0)&&($1==\"%s\")){print $3}}'", partitions[i]); 463 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 463 464 paranoid_free(command); 464 465 if (strlen(tmp)) { … … 477 478 log_msg(4, " It's not mounted. Checking to see if it's LVM..."); 478 479 /* Get the partition ID; 8e for LVM */ 479 asprintf(&command, "fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf, partitions[i]);480 mr_asprintf(&command, "fdisk -l %s |awk '{if($1 ~ \"^%s\"){print $5}}'", dsf, partitions[i]); 480 481 log_msg(4, " Running: %s", command); 481 asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));482 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 482 483 paranoid_free(command); 483 484 if (strlen(tmp)) { … … 486 487 /* It's LVM: Find the VG it's in */ 487 488 log_msg(4, " It's LVM: Find the VG it's in..."); 488 asprintf(&command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]);489 mr_asprintf(&command, "pvdisplay -v %s 2>/dev/null|grep \"VG Name\"|awk '{print $NF}'", partitions[i]); 489 490 log_msg(4, " Running: %s", command); 490 491 strcpy(VG, call_program_and_get_last_line_of_output(command)); … … 494 495 /* Found the Volume Group. Now find all of the VG's mount points */ 495 496 log_msg(4, " Found the Volume Group. Now find all of the VG's mount points"); 496 asprintf(&command,497 mr_asprintf(&command, 497 498 "mount 2>/dev/null|grep -E \"/dev/mapper/%s-|/dev/%s/\"|awk '{printf(\"%%s \",$3)}END{print \"\"}'", 498 499 VG, VG); 499 500 log_msg(4, " Running: %s", command); 500 asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));501 mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command)); 501 502 paranoid_free(command); 502 503 log_msg(4, " VG %s mount_list: %s", VG, mount_list); … … 516 517 *******/ 517 518 paranoid_free(mount_list); 518 asprintf(&command, "%s",519 mr_asprintf(&command, "%s", 519 520 "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); 520 521 log_msg (5, "Running: %s", command); 521 asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));522 mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command)); 522 523 paranoid_free(command); 523 524 log_msg(4, " Software raid device list: %s", mount_list); 524 525 lastpos = 0; 525 526 while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) { 526 asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG);527 mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, VG); 527 528 log_msg (5, "Running: %s", command); 528 529 paranoid_free(tmp); 529 asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));530 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 530 531 paranoid_free(command); 531 532 log_msg(4, "Number of Software raid device: %s", tmp); … … 557 558 ********/ 558 559 log_msg (5, "It's not swap, mounted, or LVM. See if it's used in a software raid device."); 559 asprintf(&command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]);560 mr_asprintf(&command, "mdadm --examine %s 2>/dev/null | awk '{if($1 == \"UUID\"){print $3}}'", partitions[i]); 560 561 log_msg(4, " Running: %s", command); 561 asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));562 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 562 563 paranoid_free(command); 563 564 if (!strlen(tmp)) { … … 568 569 log_msg (5, " UUID: %s", tmp); 569 570 /* Get the Software raid device list */ 570 asprintf(&command, "%s",571 mr_asprintf(&command, "%s", 571 572 "cat /proc/mdstat|grep -iv Personal|awk '{if($0~\"^.*[ ]+:\"){printf(\"/dev/%s \", $1)}}END{print \"\"}'"); 572 573 log_msg (5, " Running: %s", command); 573 asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command));574 mr_asprintf(&mount_list, "%s", call_program_and_get_last_line_of_output(command)); 574 575 paranoid_free(command); 575 576 log_msg(4, " Software raid device list: %s", mount_list); … … 577 578 lastpos = 0; 578 579 while ((token = mr_strtok(mount_list, token_chars, &lastpos)) != NULL) { 579 asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp);580 mr_asprintf(&command, "mdadm --detail %s 2>/dev/null | grep -c %s", token, tmp); 580 581 log_msg(4, " Running: %s", command); 581 582 paranoid_free(tmp); 582 asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));583 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 583 584 paranoid_free(command); 584 585 if (!atoi(tmp)) { … … 756 757 } 757 758 758 asprintf(&tmp1, "%s", flag_val['I']);759 mr_asprintf(&tmp1, "%s", flag_val['I']); 759 760 p = tmp1; 760 761 q = tmp1; … … 1035 1036 if (flag_set['z']) { 1036 1037 if (find_home_of_exe("getfattr")) { 1037 asprintf(&g_getfattr,"getfattr");1038 mr_asprintf(&g_getfattr,"getfattr"); 1038 1039 } 1039 1040 if (find_home_of_exe("getfacl")) { 1040 asprintf(&g_getfacl,"getfacl");1041 mr_asprintf(&g_getfacl,"getfacl"); 1041 1042 } 1042 1043 } … … 1055 1056 strcat(bkpinfo->exclude_paths, " "); 1056 1057 } 1057 asprintf(&tmp1, "%s", flag_val['E']);1058 mr_asprintf(&tmp1, "%s", flag_val['E']); 1058 1059 1059 1060 p = tmp1; … … 1211 1212 1212 1213 if ((flag_set['n']) && (! bkpinfo->restore_data)) { 1213 asprintf(&tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->nfs_remote_dir);1214 mr_asprintf(&tmp1,"%s/%s/.dummy.txt", bkpinfo->isodir,bkpinfo->nfs_remote_dir); 1214 1215 sprintf(tmp, "echo hi > %s", tmp1); 1215 1216 if (run_program_and_log_output(tmp, 2)) { … … 1467 1468 if (flag_set[optopt]) { 1468 1469 bad_switches = TRUE; 1469 (void)asprintf(&tmp, "Switch -%c previously defined as %s\n", opt,1470 mr_asprintf(&tmp, "Switch -%c previously defined as %s\n", opt, 1470 1471 flag_val[i]); 1471 1472 log_to_screen(tmp); … … 1484 1485 if (strchr(flag_val[opt], '/') 1485 1486 && flag_val[opt][0] != '/') { 1486 (void)asprintf(&tmp,1487 mr_asprintf(&tmp, 1487 1488 "-%c flag --- must be absolute path --- '%s' isn't absolute", 1488 1489 opt, flag_val[opt]); … … 1499 1500 for (i = optind; i < argc; i++) { 1500 1501 bad_switches = TRUE; 1501 (void)asprintf(&tmp, "Invalid arg -- %s\n", argv[i]);1502 mr_asprintf(&tmp, "Invalid arg -- %s\n", argv[i]); 1502 1503 log_to_screen(tmp); 1503 1504 paranoid_free(tmp); … … 1525 1526 void terminate_daemon(int sig) 1526 1527 { 1527 char tmp[64]; 1528 char tmp2[MAX_STR_LEN]; 1529 // char command[512]; 1530 // pid_t pid; 1528 char *tmp = NULL; 1529 char *tmp2 = NULL; 1531 1530 1532 1531 switch (sig) { 1533 1532 case SIGINT: 1534 sprintf(tmp, "SIGINT");1535 strcpy(tmp2, "You interrupted me :-)");1533 mr_asprintf(&tmp, "SIGINT"); 1534 mr_asprintf(&tmp2, "You interrupted me :-)"); 1536 1535 break; 1537 1536 case SIGKILL: 1538 sprintf(tmp, "SIGKILL");1539 strcpy(tmp2,1537 mr_asprintf(&tmp, "SIGKILL"); 1538 mr_asprintf(&tmp2, 1540 1539 "I seriously have no clue how this signal even got to me. Something's wrong with your system."); 1541 1540 break; 1542 1541 case SIGTERM: 1543 sprintf(tmp, "SIGTERM");1544 strcpy(tmp2, "Got terminate signal");1542 mr_asprintf(&tmp, "SIGTERM"); 1543 mr_asprintf(&tmp2, "Got terminate signal"); 1545 1544 break; 1546 1545 case SIGHUP: 1547 sprintf(tmp, "SIGHUP");1548 strcpy(tmp2, "Hangup on line");1546 mr_asprintf(&tmp, "SIGHUP"); 1547 mr_asprintf(&tmp2, "Hangup on line"); 1549 1548 break; 1550 1549 case SIGSEGV: 1551 sprintf(tmp, "SIGSEGV");1552 strcpy(tmp2,1550 mr_asprintf(&tmp, "SIGSEGV"); 1551 mr_asprintf(&tmp2, 1553 1552 "Internal programming error. Please send a backtrace as well as your log."); 1554 1553 break; 1555 1554 case SIGPIPE: 1556 sprintf(tmp, "SIGPIPE");1557 strcpy(tmp2, "Pipe was broken");1555 mr_asprintf(&tmp, "SIGPIPE"); 1556 mr_asprintf(&tmp2, "Pipe was broken"); 1558 1557 break; 1559 1558 case SIGABRT: 1560 sprintf(tmp, "SIGABRT");1561 sprintf(tmp2,1559 mr_asprintf(&tmp, "SIGABRT"); 1560 mr_asprintf(&tmp2, 1562 1561 "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message."); 1563 1562 break; 1564 1563 default: 1565 sprintf(tmp, "(Unknown)"); 1566 } 1567 1568 strcat(tmp, " signal received from OS"); 1564 mr_asprintf(&tmp, "(Unknown)"); 1565 mr_asprintf(&tmp2, "(Unknown)"); 1566 } 1567 1568 mr_strcat(tmp, " signal received from OS"); 1569 1569 log_to_screen(tmp); 1570 paranoid_free(tmp); 1571 1570 1572 log_to_screen(tmp2); 1573 paranoid_free(tmp2); 1571 1574 if (sig == SIGABRT) { 1572 1575 sleep(10);
Note:
See TracChangeset
for help on using the changeset viewer.