Changeset 2266 in MondoRescue for branches/2.2.10/mondo/src/common
- Timestamp:
- Jul 12, 2009, 2:04:45 AM (16 years ago)
- Location:
- branches/2.2.10/mondo/src/common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.10/mondo/src/common/libmondo-devices.c
r2257 r2266 108 108 { 109 109 char *tmp = NULL; 110 char *comment ;110 char *comment = NULL; 111 111 bool is_this_a_ramdisk = FALSE; 112 112 113 113 malloc_string(comment); 114 114 mr_asprintf(&tmp, "%s", where_is_root_mounted()); 115 sprintf(comment, "root is mounted at %s\n", tmp);115 mr_asprintf(&comment, "root is mounted at %s\n", tmp); 116 116 log_msg(0, comment); 117 mr_free(comment); 117 118 log_msg(0, 118 119 "No, Schlomo, that doesn't mean %s is the root partition. It's just a debugging message. Relax. It's part of am_I_in_disaster_recovery_mode().", … … 145 146 is_this_a_ramdisk = TRUE; 146 147 } 147 paranoid_free(comment);148 148 log_msg(1, "Is this a ramdisk? result = %d", is_this_a_ramdisk); 149 149 return (is_this_a_ramdisk); … … 210 210 int eject_device(char *dev) 211 211 { 212 char *command ;212 char *command = NULL; 213 213 int res1 = 0, res2 = 0; 214 215 malloc_string(command);216 214 217 215 if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type) 218 216 && g_backup_media_type != udev) { 219 sprintf(command, "mt -f %s offline", dev);217 mr_asprintf(&command, "mt -f %s offline", dev); 220 218 res1 = run_program_and_log_output(command, 1); 219 mr_free(command); 221 220 } else { 222 221 res1 = 0; … … 225 224 #ifdef __FreeBSD__ 226 225 if (strstr(dev, "acd")) { 227 sprintf(command, "cdcontrol -f %s eject", dev);226 mr_asprintf(&command, "cdcontrol -f %s eject", dev); 228 227 } else { 229 sprintf(command, "camcontrol eject `echo %s | sed 's|/dev/||'`",228 mr_asprintf(&command, "camcontrol eject `echo %s | sed 's|/dev/||'`", 230 229 dev); 231 230 } 232 231 #else 233 sprintf(command, "eject %s", dev);232 mr_asprintf(&command, "eject %s", dev); 234 233 #endif 235 234 236 235 log_msg(3, "Ejecting %s", dev); 237 236 res2 = run_program_and_log_output(command, 1); 238 paranoid_free(command);237 mr_free(command); 239 238 if (res1 && res2) { 240 239 return (1); … … 251 250 int inject_device(char *dev) 252 251 { 253 char *command ;252 char *command = NULL; 254 253 int i; 255 256 malloc_string(command);257 258 254 259 255 #ifdef __FreeBSD__ 260 256 if (strstr(dev, "acd")) { 261 sprintf(command, "cdcontrol -f %s close", dev);257 mr_asprintf(&command, "cdcontrol -f %s close", dev); 262 258 } else { 263 sprintf(command, "camcontrol load `echo %s | sed 's|/dev/||'`",259 mr_asprintf(&command, "camcontrol load `echo %s | sed 's|/dev/||'`", 264 260 dev); 265 261 } 266 262 #else 267 sprintf(command, "eject -t %s", dev);263 mr_asprintf(&command, "eject -t %s", dev); 268 264 #endif 269 265 i = run_program_and_log_output(command, FALSE); 270 paranoid_free(command);266 mr_free(command); 271 267 return (i); 272 268 } … … 282 278 283 279 /*@ buffers *********************************************************** */ 284 char *tmp ;280 char *tmp = NULL; 285 281 bool ret; 286 282 287 malloc_string(tmp);288 283 assert_string_is_neither_NULL_nor_zerolength(device); 289 284 290 sprintf(tmp, "ls %s > /dev/null 2> /dev/null", device);285 mr_asprintf(&tmp, "ls %s > /dev/null 2> /dev/null", device); 291 286 292 287 if (system(tmp)) { … … 295 290 ret = TRUE; 296 291 } 297 paranoid_free(tmp);292 mr_free(tmp); 298 293 return (ret); 299 294 } … … 326 321 { 327 322 /*@ buffers **************************************************** */ 328 char *program ;323 char *program = NULL; 329 324 char *incoming; 330 325 char *searchstr = NULL; … … 342 337 assert(partno >= 0 && partno < 999); 343 338 344 malloc_string(program);345 339 malloc_string(incoming); 346 340 malloc_string(searchstr); … … 349 343 #ifdef __FreeBSD__ 350 344 // We assume here that this is running from mondorestore. (It is.) 351 sprintf(program, "ls %s %s >/dev/null 2>&1", drive,345 mr_asprintf(&program, "ls %s %s >/dev/null 2>&1", drive, 352 346 build_partition_name(tmp, drive, partno)); 353 return system(program); 347 res = system(program); 348 mr_free(program); 349 return (res); 354 350 #else 355 351 tmp[0] = '\0'; 356 352 #endif 357 353 358 sprintf(program, "parted2fdisk -l %s 2> /dev/null", drive);354 mr_asprintf(&program, "parted2fdisk -l %s 2> /dev/null", drive); 359 355 fin = popen(program, "r"); 360 356 if (!fin) { 361 357 log_it("program=%s", program); 362 358 log_OS_error("Cannot popen-in program"); 359 mr_free(program); 363 360 return (0); 364 361 } 362 mr_free(program); 363 365 364 (void) build_partition_name(searchstr, drive, partno); 366 365 strcat(searchstr, " "); … … 373 372 log_OS_error("Cannot pclose fin"); 374 373 } 375 paranoid_free(program);376 374 paranoid_free(incoming); 377 375 paranoid_free(searchstr); … … 393 391 { 394 392 /*@ buffers **************************************************** */ 395 char *command ;393 char *command = NULL; 396 394 397 395 /*@ end vars *************************************************** */ … … 401 399 assert_string_is_neither_NULL_nor_zerolength(str); 402 400 403 malloc_string(command); 404 sprintf(command, 401 mr_asprintf(&command, 405 402 "dd if=%s bs=446 count=1 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", 406 403 dev, str); 407 404 i = system(command); 408 paranoid_free(command);405 mr_free(command); 409 406 if (i) { 410 407 return (FALSE); … … 424 421 { 425 422 /*@ buffers **************************************************** */ 426 char *command ;423 char *command = NULL; 427 424 /*@ end vars *************************************************** */ 428 425 int i; 429 426 430 malloc_string(command); 431 sprintf(command, 427 mr_asprintf(&command, 432 428 "dd if=%s bs=512 count=%i 2> /dev/null | strings | grep \"%s\" > /dev/null 2> /dev/null", 433 429 dev, n, str); 434 430 i = system(command); 435 paranoid_free(command);431 mr_free(command); 436 432 if (i) { 437 433 return (FALSE); … … 512 508 { 513 509 /*@ buffers ************************ */ 514 char *comment ;510 char *comment = NULL; 515 511 char *tmp = NULL; 516 512 char *cdr_exe = NULL; 517 char *command; 518 519 malloc_string(comment); 520 malloc_string(command); 513 char *command = NULL; 514 521 515 if (g_cdrw_drive_is_here[0]) { 522 516 strcpy(cdrw_device, g_cdrw_drive_is_here); 523 517 log_msg(3, "Been there, done that. Returning %s", cdrw_device); 524 paranoid_free(comment);525 paranoid_free(command);526 518 return (0); 527 519 } … … 529 521 log_msg(1, 530 522 "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?"); 531 paranoid_free(comment);532 paranoid_free(command);533 523 return (1); 534 524 } … … 540 530 } 541 531 if (find_home_of_exe(cdr_exe)) { 542 sprintf(command,532 mr_asprintf(&command, 543 533 "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep CD | cut -d' ' -f2 | head -n1", 544 534 cdr_exe); 545 535 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command)); 536 mr_free(command); 546 537 } 547 538 if ((tmp == NULL) || (strlen(tmp) < 2)) { 548 paranoid_free(comment);549 539 mr_free(tmp); 550 540 mr_free(cdr_exe); 551 paranoid_free(command);552 541 return 1; 553 542 } else { 554 543 strcpy(cdrw_device, tmp); 555 sprintf(comment, "Found CDRW device - %s", cdrw_device);544 mr_asprintf(&comment, "Found CDRW device - %s", cdrw_device); 556 545 log_it(comment); 557 546 strcpy(g_cdrw_drive_is_here, cdrw_device); 558 paranoid_free(comment);547 mr_free(comment); 559 548 mr_free(tmp); 560 549 mr_free(cdr_exe); 561 paranoid_free(command);562 550 return (0); 563 551 } 564 552 } 565 566 567 553 568 554 … … 594 580 char *phrase_one; 595 581 char *phrase_two; 596 char *command; 597 char *dvd_last_resort; 598 char *mountpoint; 582 char *command = NULL; 583 #ifndef __FreeBSD__ 584 char *dvd_last_resort = NULL; 585 #endif 586 char *mountpoint = NULL; 599 587 static char the_last_place_i_found_it[MAX_STR_LEN] = ""; 600 588 … … 603 591 malloc_string(phrase_one); 604 592 malloc_string(phrase_two); 605 malloc_string(command);606 malloc_string(dvd_last_resort);607 malloc_string(mountpoint);608 593 609 594 output[0] = '\0'; 610 595 phrase_one[0] = '\0'; 611 596 phrase_two[0] = '\0'; 612 dvd_last_resort[0] = '\0'; 597 #ifndef __FreeBSD__ 598 mr_asprintf(&dvd_last_resort, "%s", "");; 599 #endif 613 600 614 601 /*@ end vars **************************************************** */ … … 629 616 } 630 617 631 sprintf(mountpoint, "%s/cd.mnt", bkpinfo->tmpdir);618 mr_asprintf(&mountpoint, "%s/cd.mnt", bkpinfo->tmpdir); 632 619 make_hole_for_dir(mountpoint); 633 620 … … 651 638 } 652 639 653 sprintf(command, "%s -scanbus 2> /dev/null", cdr_exe);640 mr_asprintf(&command, "%s -scanbus 2> /dev/null", cdr_exe); 654 641 fin = popen(command, "r"); 642 log_msg(4, "command=%s", command); 643 mr_free(command); 644 655 645 if (!fin) { 656 log_msg(4, "command=%s", command);657 646 log_OS_error("Cannot popen command"); 658 647 mr_free(cdr_exe); 659 648 return (1); 660 649 } 650 661 651 for ((void)fgets(tmp, MAX_STR_LEN, fin); !feof(fin); 662 652 (void)fgets(tmp, MAX_STR_LEN, fin)) { … … 688 678 log_msg(4, "Not running phase two. String is empty."); 689 679 } else { 690 sprintf(command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two);680 mr_asprintf(&command, "dmesg | grep \"%s\" 2> /dev/null", phrase_two); 691 681 fin = popen(command, "r"); 682 mr_free(command); 683 692 684 if (!fin) { 693 685 log_msg(4, "Cannot run 2nd command - non-fatal, fortunately"); … … 701 693 *p = '\0'; 702 694 if (strstr(tmp, "DVD")) { 703 sprintf(dvd_last_resort, "/dev/%s", tmp); 695 mr_free(dvd_last_resort); 696 mr_asprintf(&dvd_last_resort, "/dev/%s", tmp); 704 697 log_msg(4, 705 698 "Ignoring '%s' because it's a DVD drive", … … 755 748 #else 756 749 if (!found_it && strlen(dvd_last_resort) > 0) { 757 log_msg(4, "Well, I'll use the DVD - %s - as a last resort", 758 dvd_last_resort); 750 log_msg(4, "Well, I'll use the DVD - %s - as a last resort", dvd_last_resort); 759 751 strcpy(output, dvd_last_resort); 760 752 found_it = TRUE; 761 753 } 754 mr_free(dvd_last_resort); 762 755 if (found_it) { 763 756 sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", … … 832 825 found_it = FALSE; 833 826 } else { 834 sprintf(command, "umount %s", output);827 mr_asprintf(&command, "umount %s", output); 835 828 paranoid_system(command); 829 mr_free(command); 830 836 831 log_msg(4, "I'm confident the Mondo CD is in %s", output); 837 832 } … … 839 834 } 840 835 unlink(mountpoint); 836 mr_free(mountpoint); 841 837 842 838 if (found_it) { … … 852 848 } 853 849 854 sprintf(command,850 mr_asprintf(&command, 855 851 "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2", 856 852 cdr_exe, g_cdrw_drive_is_here); 857 853 log_msg(1, "command=%s", command); 858 854 mr_asprintf(&tmp1, "%s", call_program_and_get_last_line_of_output(command)); 855 mr_free(command); 856 859 857 if (strlen(tmp1) > 0) { 860 858 strcpy(output, tmp1); … … 872 870 paranoid_free(phrase_one); 873 871 paranoid_free(phrase_two); 874 paranoid_free(command);875 paranoid_free(dvd_last_resort);876 paranoid_free(mountpoint);877 872 return (retval); 878 873 } … … 884 879 int find_dvd_device(char *output, bool try_to_mount) 885 880 { 886 char *command; 887 char *tmp; 881 char *tmp = NULL; 888 882 int retval = 0, devno = -1; 889 890 malloc_string(command);891 malloc_string(tmp);892 883 893 884 if (g_dvd_drive_is_here[0]) { … … 897 888 } 898 889 899 sprintf(tmp, "%s", call_program_and_get_last_line_of_output890 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output 900 891 ("dvdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1") 901 892 ); 902 893 log_msg(5, "tmp = '%s'", tmp); 903 894 if (!tmp[0]) 904 sprintf(tmp, "%s", call_program_and_get_last_line_of_output 895 mr_free(tmp); 896 mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output 905 897 ("cdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1") 906 898 ); … … 908 900 devno = atoi(tmp) - 1; 909 901 } 902 mr_free(tmp); 903 910 904 if (devno >= 0) { 911 905 retval = 0; … … 1036 1030 { 1037 1031 char *good_formats = NULL; 1038 char *command ;1039 char *format_sz ;1032 char *command = NULL; 1033 char *format_sz = NULL; 1040 1034 1041 1035 FILE *pin; 1042 1036 int retval; 1043 1037 malloc_string(good_formats); 1044 malloc_string(command);1045 malloc_string(format_sz);1046 1038 1047 1039 assert_string_is_neither_NULL_nor_zerolength(format); 1048 1040 1049 sprintf(format_sz, "%s ", format);1041 mr_asprintf(&format_sz, "%s ", format); 1050 1042 1051 1043 #ifdef __FreeBSD__ 1052 sprintf(command,1044 mr_asprintf(&command, 1053 1045 "lsvfs | tr -s '\t' ' ' | grep -v Filesys | grep -v -- -- | cut -d' ' -f1 | tr -s '\n' ' '"); 1054 1046 #else 1055 sprintf(command,1047 mr_asprintf(&command, 1056 1048 "grep -v nodev /proc/filesystems | tr -s '\t' ' ' | cut -d' ' -f2 | tr -s '\n' ' '"); 1057 1049 #endif 1058 1050 1059 1051 pin = popen(command, "r"); 1052 mr_free(command); 1053 1060 1054 if (!pin) { 1061 1055 log_OS_error("Unable to read good formats"); … … 1075 1069 } 1076 1070 } 1071 mr_free(format_sz); 1072 1077 1073 paranoid_free(good_formats); 1078 paranoid_free(command);1079 paranoid_free(format_sz);1080 1074 return (retval); 1081 1075 } … … 1206 1200 int kick_vn(char *dname) 1207 1201 { 1208 char command[MAX_STR_LEN]; 1202 char *command = NULL; 1203 int res = 0; 1209 1204 1210 1205 if (strncmp(dname, "/dev/", 5) == 0) { … … 1215 1210 (call_program_and_get_last_line_of_output 1216 1211 ("/sbin/sysctl -n kern.osreldate")) < 500000) { 1217 sprintf(command, "vnconfig -d %s", dname); 1218 return system(command); 1212 mr_asprintf(&command, "vnconfig -d %s", dname); 1219 1213 } else { 1220 sprintf(command, "mdconfig -d -u %s", dname); 1221 return system(command); 1222 } 1223 /*NOTREACHED*/ return 255; 1214 mr_asprintf(&command, "mdconfig -d -u %s", dname); 1215 } 1216 res = system(command); 1217 mr_free(command); 1218 return(res); 1224 1219 } 1225 1220 #endif … … 1235 1230 { 1236 1231 /*@ buffer ****************************************************** */ 1237 char *command ;1232 char *command = NULL; 1238 1233 int retval; 1239 1234 1240 malloc_string(command);1241 1235 assert_string_is_neither_NULL_nor_zerolength(device); 1242 1236 assert_string_is_neither_NULL_nor_zerolength(mountpoint); … … 1250 1244 1251 1245 #ifdef __FreeBSD__ 1252 sprintf(command, "mount_vfat %s %s 2>> %s",1246 mr_asprintf(&command, "mount_vfat %s %s 2>> %s", 1253 1247 device, mountpoint, MONDO_LOGFILE); 1254 1248 1255 1249 #else 1256 sprintf(command, "mount %s -t vfat %s 2>> %s",1250 mr_asprintf(&command, "mount %s -t vfat %s 2>> %s", 1257 1251 device, mountpoint, MONDO_LOGFILE); 1258 1252 #endif … … 1261 1255 retval = system(command); 1262 1256 log_msg(1, "system(%s) returned %d", command, retval); 1263 1264 paranoid_free(command); 1257 mr_free(command); 1258 1265 1259 return (retval); 1266 1260 } … … 1360 1354 1361 1355 /*@ buffers ********************************************************* */ 1362 char *tmp ;1356 char *tmp = NULL; 1363 1357 char *mds = NULL; 1364 char *request ;1358 char *request = NULL; 1365 1359 1366 1360 assert(bkpinfo != NULL); … … 1374 1368 return; 1375 1369 } 1376 malloc_string(tmp); 1377 malloc_string(request); 1378 sprintf(tmp, "mkdir -p " MNT_CDROM); 1370 mr_asprintf(&tmp, "mkdir -p " MNT_CDROM); 1379 1371 run_program_and_log_output(tmp, 5); 1372 mr_free(tmp); 1373 1380 1374 if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso 1381 1375 || bkpinfo->backup_media_type == nfs) { 1382 1376 log_msg(3, "Remounting CD"); 1383 1377 g_ISO_restore_mode = TRUE; 1384 // FIXME --- I'm tempted to do something about this...1385 // Why unmount and remount again and again?1378 // FIXME --- I'm tempted to do something about this... 1379 // Why unmount and remount again and again? 1386 1380 if (is_this_device_mounted(MNT_CDROM)) { 1387 1381 run_program_and_log_output("umount " MNT_CDROM, 5); 1388 1382 } 1389 sprintf(tmp, "mkdir -p %s/isodir &> /dev/null", bkpinfo->tmpdir);1383 mr_asprintf(&tmp, "mkdir -p %s/isodir &> /dev/null", bkpinfo->tmpdir); 1390 1384 (void)system(tmp); 1391 sprintf(tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir, 1385 mr_free(tmp); 1386 1387 mr_asprintf(&tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir, 1392 1388 bkpinfo->nfs_remote_dir, bkpinfo->prefix, 1393 1389 cd_number_i_want); 1394 1390 if (!does_file_exist(tmp)) { 1395 sprintf(tmp, "%s/isodir/%s/%s-%d.iso", bkpinfo->tmpdir, 1391 mr_free(tmp); 1392 mr_asprintf(&tmp, "%s/isodir/%s/%s-%d.iso", bkpinfo->tmpdir, 1396 1393 bkpinfo->nfs_remote_dir, bkpinfo->prefix, 1397 1394 cd_number_i_want); … … 1405 1402 log_msg(3, "Mounting %s at %s", tmp, MNT_CDROM); 1406 1403 if (mount_CDROM_here(tmp, MNT_CDROM)) { 1404 mr_free(tmp); 1407 1405 fatal_error("Mommy!"); 1408 1406 } 1409 // g_current_media_number = cd_number_i_want; 1410 // return; 1407 mr_free(tmp); 1411 1408 } 1412 1409 if ((res = what_number_cd_is_this()) != cd_number_i_want) { … … 1414 1411 cd_number_i_want); 1415 1412 mds = media_descriptor_string(bkpinfo->backup_media_type); 1416 sprintf(tmp, "Insisting on %s #%d", mds, cd_number_i_want);1417 sprintf(request, "Please insert %s #%d and press Enter.", mds, cd_number_i_want);1413 mr_asprintf(&tmp, "Insisting on %s #%d", mds, cd_number_i_want); 1414 mr_asprintf(&request, "Please insert %s #%d and press Enter.", mds, cd_number_i_want); 1418 1415 mr_free(mds); 1419 1416 log_msg(3, tmp); 1417 mr_free(tmp); 1418 1420 1419 while (what_number_cd_is_this() != cd_number_i_want) { 1421 1420 paranoid_system("sync"); … … 1443 1442 paranoid_system("sync"); 1444 1443 } 1444 mr_free(request); 1445 1445 1446 log_msg(1, "Thankyou. Proceeding..."); 1446 1447 g_current_media_number = cd_number_i_want; 1447 1448 } 1448 paranoid_free(tmp);1449 paranoid_free(request);1450 1449 } 1451 1450 1452 1451 /* @} - end of deviceGroup */ 1453 1454 1455 1456 1457 1452 1458 1453 … … 1472 1467 char *tmp = NULL; 1473 1468 char *mds = NULL; 1474 char *sz_size ;1475 char *command ;1476 char *comment ;1469 char *sz_size = NULL; 1470 char *command = NULL; 1471 char *comment = NULL; 1477 1472 char *prompt; 1478 1473 int i; 1479 1474 FILE *fin; 1480 1475 1476 malloc_string(prompt); 1481 1477 malloc_string(sz_size); 1482 malloc_string(command);1483 malloc_string(comment);1484 malloc_string(prompt);1485 1478 assert(bkpinfo != NULL); 1486 sz_size[0] = '\0';1487 1479 bkpinfo->nonbootable_backup = FALSE; 1488 1480 … … 1537 1529 } 1538 1530 mds = media_descriptor_string(bkpinfo->backup_media_type); 1539 sprintf(comment, "What speed is your %s (re)writer?", mds);1531 mr_asprintf(&comment, "What speed is your %s (re)writer?", mds); 1540 1532 if (bkpinfo->backup_media_type == dvd) { 1541 1533 find_dvd_device(bkpinfo->media_device, FALSE); … … 1546 1538 strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM); 1547 1539 mr_asprintf(&tmp, "4"); 1548 s trcpy(sz_size, "650");1540 sprintf(sz_size, "%d", 650); 1549 1541 log_msg(1, "Setting to CD defaults"); 1550 1542 } … … 1552 1544 if (!popup_and_get_string("Speed", comment, tmp, 4)) { 1553 1545 log_to_screen("User has chosen not to backup the PC"); 1546 mr_free(comment); 1554 1547 finish(1); 1555 1548 } 1556 1549 } 1550 mr_free(comment); 1551 1557 1552 bkpinfo->cdrw_speed = atoi(tmp); // if DVD then this shouldn't ever be used anyway :) 1558 1553 mr_free(tmp); 1559 1554 1560 sprintf(comment,1555 mr_asprintf(&comment, 1561 1556 "How much data (in Megabytes) will each %s store?", mds); 1562 1557 mr_free(mds); 1563 1558 if (!popup_and_get_string("Size", comment, sz_size, 5)) { 1559 mr_free(comment); 1564 1560 log_to_screen("User has chosen not to backup the PC"); 1565 1561 finish(1); 1566 1562 } 1563 mr_free(comment); 1564 1567 1565 for (i = 0; i <= MAX_NOOF_MEDIA; i++) { 1568 1566 bkpinfo->media_size[i] = atoi(sz_size); 1569 1567 } 1568 1570 1569 if (bkpinfo->media_size[0] <= 0) { 1571 1570 log_to_screen("User has chosen not to backup the PC"); … … 1592 1591 log_msg(1, "bkpinfo->media_device = %s", 1593 1592 bkpinfo->media_device); 1594 sprintf(comment,1593 mr_asprintf(&comment, 1595 1594 "Please specify your %s drive's /dev entry", mds); 1596 1595 if (!popup_and_get_string 1597 1596 ("Device?", comment, bkpinfo->media_device, 1598 1597 MAX_STR_LEN / 4)) { 1598 mr_free(comment); 1599 1599 log_to_screen("User has chosen not to backup the PC"); 1600 1600 finish(1); 1601 1601 } 1602 mr_free(comment); 1602 1603 } 1603 1604 log_msg(2, "%s device found at %s", mds, bkpinfo->media_device); … … 1705 1706 } 1706 1707 mr_free(tmp); 1707 log_msg(4, "sz_size = %s", sz_size);1708 sz_size[0] = '\0';1709 1708 1710 1709 bkpinfo->use_obdr = ask_me_yes_or_no 1711 1710 ("Do you want to activate OBDR support for your tapes ?"); 1712 if (sz_size[0] == '\0') { 1713 bkpinfo->media_size[0] = 0; 1714 } else { 1715 bkpinfo->media_size[0] = 1716 friendly_sizestr_to_sizelong(sz_size) / 2 - 50; 1717 } 1711 bkpinfo->media_size[0] = 0; 1718 1712 log_msg(4, "media_size[0] = %ld", bkpinfo->media_size[0]); 1719 1713 if (bkpinfo->media_size[0] <= 0) { … … 1769 1763 if (bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] == '/') 1770 1764 bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] = '\0'; 1771 sprintf(command, "mount | grep \"%s \" | cut -d' ' -f3",1765 mr_asprintf(&command, "mount | grep \"%s \" | cut -d' ' -f3", 1772 1766 bkpinfo->nfs_mount); 1773 1767 strcpy(bkpinfo->isodir, 1774 1768 call_program_and_get_last_line_of_output(command)); 1769 mr_free(command); 1775 1770 1776 1771 if (!bkpinfo->restore_data) { 1777 sprintf(comment,1772 mr_asprintf(&comment, 1778 1773 "How much data (in Megabytes) will each media store?"); 1779 1774 if (!popup_and_get_string("Size", comment, sz_size, 5)) { 1775 mr_free(comment); 1780 1776 log_to_screen("User has chosen not to backup the PC"); 1781 1777 finish(1); 1782 1778 } 1779 mr_free(comment); 1783 1780 } else { 1784 1781 strcpy(sz_size, "0"); … … 1793 1790 } 1794 1791 if (bkpinfo->disaster_recovery) { 1795 sprintf(command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir);1792 mr_asprintf(&command ,"umount %s/isodir 2> /dev/null", bkpinfo->tmpdir); 1796 1793 (void)system(command); 1794 mr_free(command); 1795 1797 1796 if (!popup_and_get_string 1798 1797 ("NFS share", "Which remote NFS share should I mount?", … … 1809 1808 } else { 1810 1809 sprintf(bkpinfo->isodir, "%s/nfsdir", bkpinfo->tmpdir); 1811 sprintf(command, "mkdir -p %s", bkpinfo->isodir);1810 mr_asprintf(&command, "mkdir -p %s", bkpinfo->isodir); 1812 1811 run_program_and_log_output(command, 5); 1812 mr_free(command); 1813 1813 1814 mr_asprintf(&tmp, "mount -t nfs -o nolock %s %s", bkpinfo->nfs_mount, 1814 1815 bkpinfo->isodir); … … 2081 2082 } 2082 2083 paranoid_free(sz_size); 2083 paranoid_free(command);2084 paranoid_free(comment);2085 2084 paranoid_free(prompt); 2086 2085 return (0); … … 2152 2151 void make_fifo(char *store_name_here, char *stub) 2153 2152 { 2154 char *tmp; 2155 2156 malloc_string(tmp); 2153 char *tmp = NULL; 2154 2157 2155 assert_string_is_neither_NULL_nor_zerolength(stub); 2158 2156 … … 2161 2159 make_hole_for_file(store_name_here); 2162 2160 mkfifo(store_name_here, S_IRWXU | S_IRWXG); 2163 sprintf(tmp, "chmod 770 %s", store_name_here);2161 mr_asprintf(&tmp, "chmod 770 %s", store_name_here); 2164 2162 paranoid_system(tmp); 2165 paranoid_free(tmp);2163 mr_free(tmp); 2166 2164 } 2167 2165 … … 2236 2234 bool set_dev_to_this_if_rx_OK(char *output, char *dev) 2237 2235 { 2238 char *command ;2239 2240 malloc_string(command); 2236 char *command = NULL; 2237 bool res; 2238 2241 2239 if (!dev || dev[0] == '\0') { 2242 2240 output[0] = '\0'; 2243 2241 return (FALSE); 2244 2242 } 2245 // assert_string_is_neither_NULL_nor_zerolength(dev);2246 2243 log_msg(10, "Injecting %s", dev); 2247 2244 inject_device(dev); … … 2250 2247 return (FALSE); 2251 2248 } 2252 sprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null", 2253 512L, dev); 2249 mr_asprintf(&command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null", 512L, dev); 2254 2250 if (!run_program_and_log_output(command, FALSE) 2255 2251 && !run_program_and_log_output(command, FALSE)) { 2256 2252 strcpy(output, dev); 2257 2253 log_msg(4, "Found it - %s", dev); 2258 re turn (TRUE);2254 res = TRUE; 2259 2255 } else { 2260 2256 output[0] = '\0'; 2261 2257 log_msg(4, "It's not %s", dev); 2262 return (FALSE); 2263 } 2258 res = FALSE; 2259 } 2260 mr_free(command); 2261 return(res); 2264 2262 } 2265 2263 … … 2556 2554 { 2557 2555 static char output[MAX_STR_LEN]; 2558 char *command ;2556 char *command = NULL; 2559 2557 char *curr_fname; 2560 2558 char *scratch = NULL; … … 2563 2561 2564 2562 struct stat statbuf; 2565 command = malloc(1000);2566 2563 malloc_string(curr_fname); 2567 2564 if (!does_file_exist(incoming)) { … … 2574 2571 while (S_ISLNK(statbuf.st_mode)) { 2575 2572 log_msg(1, "curr_fname = %s", curr_fname); 2576 sprintf(command, "file %s", curr_fname);2573 mr_asprintf(&command, "file %s", curr_fname); 2577 2574 mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command)); 2575 mr_free(command); 2578 2576 for (p = tmp + strlen(tmp); p != tmp && *p != '`' && *p != ' '; 2579 2577 p--); … … 2603 2601 log_it("resolved %s to %s", incoming, output); 2604 2602 } 2605 paranoid_free(command);2606 2603 paranoid_free(curr_fname); 2607 2604 return (output); … … 2618 2615 static char output[4]; 2619 2616 char *tmp = NULL; 2620 char *command ;2621 char *fdisk ;2617 char *command = NULL; 2618 char *fdisk = NULL; 2622 2619 #ifdef __IA64__ 2623 2620 struct stat buf; 2624 2621 #endif 2625 malloc_string(command);2626 malloc_string(fdisk);2627 2622 log_msg(0, "Looking for partition table format type"); 2628 sprintf(fdisk, "/sbin/parted2fdisk");2623 mr_asprintf(&fdisk, "/sbin/parted2fdisk"); 2629 2624 log_msg(1, "Using %s", fdisk); 2630 sprintf(command, "%s -l %s | grep 'EFI GPT'", fdisk, drive); 2625 mr_asprintf(&command, "%s -l %s | grep 'EFI GPT'", fdisk, drive); 2626 mr_free(fdisk); 2627 2631 2628 mr_asprintf(&tmp, call_program_and_get_last_line_of_output(command)); 2629 mr_free(command); 2630 2632 2631 if (strstr(tmp, "GPT") == NULL) { 2633 2632 strcpy(output, "MBR"); … … 2638 2637 2639 2638 log_msg(0, "Found %s partition table format type", output); 2640 paranoid_free(command);2641 paranoid_free(fdisk);2642 2639 return (output); 2643 2640 } -
branches/2.2.10/mondo/src/common/libmondo-stream.c
r2264 r2266 264 264 265 265 log_to_screen("I am looking for your tape streamer. Please wait."); 266 dev[0] = siz[0] = '\0'; 266 dev[0] = '\0'; 267 if (siz != NULL) { 268 siz[0] = '\0'; 269 } 267 270 if (find_home_of_exe("cdrecord")) { 268 271 strcpy(cdr_exe, "cdrecord"); … … 339 342 } 340 343 341 siz[0] = '\0';342 344 log_it("res=%d; dev=%s", res, dev); 343 345 … … 347 349 348 350 if (strlen(tmp) < 2) { 349 siz[0] = '\0';350 351 log_it("Warning - size of tape unknown"); 351 352 return (0); 352 353 } else { 353 strcpy(siz, tmp); 354 if (siz != NULL) { 355 strcpy(siz, tmp); 356 } 354 357 return (0); 355 358 }
Note:
See TracChangeset
for help on using the changeset viewer.