Changeset 688 in MondoRescue for trunk/mondo/mondo/mondorestore/mondo-rstr-tools.c
- Timestamp:
- Jul 17, 2006, 3:44:46 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mondo/mondo/mondorestore/mondo-rstr-tools.c
r687 r688 1 1 /* 2 2 * $Id$ 3 */ 4 3 **/ 4 5 #include <unistd.h> 5 6 6 7 #include "../common/my-stuff.h" … … 8 9 #include "../common/libmondo.h" 9 10 #include "mr-externs.h" 10 //#include "mondo-restore.h"11 //#include "mondo-rstr-compare-EXT.h"12 11 #include "mondo-rstr-tools.h" 13 12 #ifndef S_SPLINT_S … … 55 54 paranoid_free(g_filelist_full); 56 55 paranoid_free(g_filelist_imagedevs); 57 // paranoid_free (g_imagedevs_pot );58 56 paranoid_free(g_imagedevs_restthese); 59 57 paranoid_free(g_mondo_cfg_file); … … 67 65 68 66 69 70 67 /** 71 68 * Ask the user which imagedevs from the list contained in @p infname should … … 77 74 void ask_about_these_imagedevs(char *infname, char *outfname) 78 75 { 79 FILE *fin ;80 FILE *fout ;76 FILE *fin = NULL; 77 FILE *fout = NULL; 81 78 /************************************************************************ 82 79 * allocate memory regions. test and set -sab 16 feb 2003 * 83 80 ************************************************************************/ 84 char *incoming ;85 char *question ;81 char *incoming = NULL; 82 char *question = NULL; 86 83 87 84 size_t n = 0; … … 105 102 106 103 asprintf(&question, 107 _("Should I restore the image of %s ?", incoming));104 _("Should I restore the image of %s ?"), incoming); 108 105 109 106 if (ask_me_yes_or_no(question)) { 110 107 fprintf(fout, "%s\n", incoming); 111 108 } 109 paranoid_free(question); 112 110 } 113 111 114 112 /*** free memory ***********/ 115 113 paranoid_free(incoming); 116 paranoid_free(question);117 118 114 119 115 paranoid_fclose(fout); … … 124 120 *ASK_ABOUT_THESE_IMAGEDEVS * 125 121 **************************************************************************/ 126 127 128 129 130 131 132 122 133 123 … … 147 137 char *output_mountlist_file) 148 138 { 149 char *mountpt ;150 char *command ;151 char *orig_fname ;139 char *mountpt = NULL; 140 char *command = NULL; 141 char *orig_fname = NULL; 152 142 int retval = 0; 153 143 154 144 assert(bkpinfo != NULL); 155 malloc_string(mountpt);156 malloc_string(command);157 malloc_string(orig_fname);158 145 assert_string_is_neither_NULL_nor_zerolength(ramdisk_fname); 159 146 assert_string_is_neither_NULL_nor_zerolength(output_cfg_file); 160 147 assert_string_is_neither_NULL_nor_zerolength(output_mountlist_file); 161 sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir);162 sprintf(command, "mkdir -p %s", mountpt);148 asprintf(&mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir); 149 asprintf(&command, "mkdir -p %s", mountpt); 163 150 run_program_and_log_output(command, FALSE); 164 sprintf(command, "gzip -dc %s > %s/mindi.rd 2> /dev/null", 151 paranoid_free(command); 152 153 asprintf(&command, "gzip -dc %s > %s/mindi.rd 2> /dev/null", 165 154 ramdisk_fname, bkpinfo->tmpdir); 166 167 155 run_program_and_log_output(command, FALSE); 168 sprintf(command, "umount %s", mountpt); 169 156 paranoid_free(command); 157 158 asprintf(&command, "umount %s", mountpt); 170 159 run_program_and_log_output(command, FALSE); 171 172 sprintf(command, "mount -o loop %s/mindi.rd -t ext2 %s", 160 paranoid_free(command); 161 162 asprintf(&command, "mount -o loop %s/mindi.rd -t ext2 %s", 173 163 bkpinfo->tmpdir, mountpt); 174 175 164 run_program_and_log_output(command, FALSE); 176 177 sprintf(command, "mkdir -p %s/tmp", bkpinfo->tmpdir); 178 165 paranoid_free(command); 166 167 asprintf(&command, "mkdir -p %s/tmp", bkpinfo->tmpdir); 179 168 run_program_and_log_output(command, FALSE); 180 181 sprintf(command, "cp -f %s/%s %s", // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg 169 paranoid_free(command); 170 171 asprintf(&command, "cp -f %s/%s %s", // %s/%s becomes {mountpt}/tmp/m*ndo-restore.cfg 182 172 mountpt, g_mondo_cfg_file, output_cfg_file); 183 173 run_program_and_log_output(command, FALSE); 184 185 sprintf(orig_fname, "%s/%s", mountpt, g_mountlist_fname); 174 paranoid_free(command); 175 176 asprintf(&orig_fname, "%s/%s", mountpt, g_mountlist_fname); 186 177 if (does_file_exist(orig_fname)) { 187 sprintf(command, "cp -f %s %s", orig_fname, output_mountlist_file);178 asprintf(&command, "cp -f %s %s", orig_fname, output_mountlist_file); 188 179 run_program_and_log_output(command, FALSE); 189 } 190 sprintf(command, "umount %s", mountpt); 180 paranoid_free(command); 181 } 182 asprintf(&command, "umount %s", mountpt); 183 paranoid_free(mountpt); 184 191 185 run_program_and_log_output(command, FALSE); 186 paranoid_free(command); 187 192 188 if (!does_file_exist(output_cfg_file) 193 189 || (!does_file_exist(output_mountlist_file) … … 199 195 retval = 0; 200 196 } 201 paranoid_free(mountpt);202 paranoid_free(command);203 197 paranoid_free(orig_fname); 204 198 return (retval); 205 206 } 207 208 199 } 209 200 210 201 … … 217 208 while (get_cfg_file_from_archive(bkpinfo)) { 218 209 if (!ask_me_yes_or_no 219 (_("Failed to find config file/archives. Choose another source?"))) 210 (_ 211 ("Failed to find config file/archives. Choose another source?"))) 220 212 { 221 213 fatal_error("Could not find config file/archives. Aborting."); … … 237 229 238 230 /** needs malloc **/ 239 char *command; 240 char *file; 241 char *tmp; 242 int res; 243 244 malloc_string(command); 245 malloc_string(file); 246 malloc_string(tmp); 231 char *command = NULL; 232 char *file = NULL; 233 char *tmp = NULL; 234 int res = 0; 235 247 236 assert_string_is_neither_NULL_nor_zerolength(f); 248 237 assert_string_is_neither_NULL_nor_zerolength(list_fname); … … 250 239 251 240 if (strncmp(preamble, f, strlen(preamble)) == 0) { 252 strcpy(file, f + strlen(preamble));253 } else { 254 strcpy(file, f);241 asprintf(&file, f + strlen(preamble)); 242 } else { 243 asprintf(&file, f); 255 244 } 256 245 if (file[0] == '/' && file[1] == '/') { 257 strcpy(tmp, file); 258 strcpy(file, tmp + 1); 259 } 260 sprintf(tmp, 246 asprintf(&tmp, file); 247 paranoid_free(file); 248 asprintf(&file, tmp + 1); 249 paranoid_free(tmp); 250 } 251 asprintf(&tmp, 261 252 "Checking to see if f=%s, file=%s, is in the list of biggiefiles", 262 253 f, file); 263 254 log_msg(2, tmp); 264 sprintf(command, "grep -x \"%s\" %s", file, list_fname); 255 paranoid_free(tmp); 256 257 asprintf(&command, "grep -x \"%s\" %s", file, list_fname); 258 paranoid_free(file); 259 265 260 res = run_program_and_log_output(command, FALSE); 266 261 paranoid_free(command); 267 paranoid_free(file);268 paranoid_free(tmp);269 262 if (res) { 270 263 return (FALSE); … … 273 266 } 274 267 } 275 276 268 /************************************************************************** 277 269 *END_IS_FILE_IN_LIST * 278 270 **************************************************************************/ 279 280 271 281 272 … … 291 282 int iso_fiddly_bits(struct s_bkpinfo *bkpinfo, bool nuke_me_please) 292 283 { 293 char *mount_isodir_command, *tmp, *command; 294 int retval = 0, i; 284 char *mount_isodir_command = NULL; 285 char *tmp = NULL; 286 char *command = NULL; 287 int retval = 0, i = 0; 295 288 bool already_mounted = FALSE; 296 289 297 290 assert(bkpinfo != NULL); 298 malloc_string(mount_isodir_command);299 malloc_string(tmp);300 malloc_string(command);301 291 g_ISO_restore_mode = TRUE; 302 292 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device); … … 308 298 } 309 299 /* End patch */ 310 sprintf(command, "mkdir -p %s", bkpinfo->isodir);300 asprintf(&command, "mkdir -p %s", bkpinfo->isodir); 311 301 run_program_and_log_output(command, 5); 302 paranoid_free(command); 312 303 log_msg(2, "Setting isodir to %s", bkpinfo->isodir); 313 304 } … … 324 315 already_mounted = TRUE; 325 316 } else { 326 sprintf(mount_isodir_command, "mount %s", g_isodir_device); 327 if (strlen(g_isodir_format) > 1) { 328 sprintf(mount_isodir_command + strlen(mount_isodir_command), 329 " -t %s", g_isodir_format); 330 } 331 strcat(mount_isodir_command, " -o ro "); 332 strcat(mount_isodir_command, bkpinfo->isodir); 317 if (g_isodir_format != NULL) { 318 asprintf(&mount_isodir_command, "mount %s -t %s -o ro %s", g_isodir_device, g_isodir_format, bkpinfo->isodir); 319 } else { 320 asprintf(&mount_isodir_command, "mount %s -o ro %s", g_isodir_device, bkpinfo->isodir); 321 } 333 322 run_program_and_log_output("df -P -m", FALSE); 334 sprintf(tmp,323 asprintf(&tmp, 335 324 "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", 336 325 mount_isodir_command); 337 326 log_msg(1, tmp); 327 paranoid_free(tmp); 328 338 329 if (run_program_and_log_output(mount_isodir_command, FALSE)) { 339 330 popup_and_OK 340 (_("Cannot mount the device where the ISO files are stored.")); 331 (_ 332 ("Cannot mount the device where the ISO files are stored.")); 333 paranoid_free(mount_isodir_command); 341 334 return (1); 342 335 } 336 paranoid_free(mount_isodir_command); 343 337 log_to_screen 344 (_("I have mounted the device where the ISO files are stored.")); 338 (_ 339 ("I have mounted the device where the ISO files are stored.")); 345 340 } 346 341 if (!IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { … … 348 343 } 349 344 i = what_number_cd_is_this(bkpinfo); /* has the side-effect of calling mount_cdrom() */ 350 sprintf(tmp, "%s #%d has been mounted via loopback mount",345 asprintf(&tmp, "%s #%d has been mounted via loopback mount", 351 346 media_descriptor_string(bkpinfo->backup_media_type), i); 352 347 log_msg(1, tmp); 348 paranoid_free(tmp); 349 353 350 if (i < 0) { 354 351 popup_and_OK … … 358 355 log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__, 359 356 bkpinfo->isodir); 360 paranoid_free(mount_isodir_command);361 paranoid_free(tmp);362 paranoid_free(command);363 357 return (retval); 364 358 } 365 359 366 360 367 368 369 361 /** 370 362 * Kill all Petris processes. … … 373 365 { 374 366 char *command; 375 malloc_string(command); 376 sprintf(command, 367 asprintf(&command, 377 368 "kill `ps wax 2> /dev/null | grep petris 2> /dev/null | grep -v grep | cut -d' ' -f2` 2> /dev/null"); 378 369 paranoid_system(command); … … 383 374 *END_KILL_PETRIS * 384 375 **************************************************************************/ 385 386 387 /**388 * (Disabled) Modify rc.local to fix some things on first boot.389 * This function currently doesn't do anything except make sure /tmp has the390 * right permissions.391 * @param path The path to /etc on the user's filesystem.392 * @return 0 for success, nonzero for failure.393 */394 int modify_rclocal_one_time(char *path)395 {396 /** malloc **/397 char *rclocal_fname;398 char *newfile_fname;399 char *tmp;400 401 malloc_string(rclocal_fname);402 malloc_string(newfile_fname);403 malloc_string(tmp);404 assert_string_is_neither_NULL_nor_zerolength(path);405 406 sprintf(rclocal_fname, "%s/rc.local", path);407 408 // sprintf(tmp, "chmod 1777 %s/tmp", MNT_RESTORING);409 // run_program_and_log_output( tmp, FALSE );410 return (0); /* remove this line to open the floodgates... */411 412 if (!does_file_exist(rclocal_fname)) {413 sprintf(rclocal_fname, "%s/rc.d/rc.local", path);414 }415 if (!does_file_exist(rclocal_fname)) {416 paranoid_free(rclocal_fname);417 paranoid_free(newfile_fname);418 paranoid_free(tmp);419 return (1);420 }421 sprintf(newfile_fname, "%s/rc.local.mondorescue", path);422 sprintf(tmp, "grep mondorescue %s > /dev/null 2> /dev/null",423 rclocal_fname);424 if (system(tmp)) {425 sprintf(tmp, "echo \"[ -e %s ] && %s\n\" >> %s",426 newfile_fname, newfile_fname, rclocal_fname);427 428 paranoid_system(tmp);429 }430 sprintf(tmp, "echo -en \"#!/bin/sh\431 \\n\432 \\n\433 grep -v mondorescue %s > %s\\n\434 rm -f /var/lock/subsys/*xfs*\\n\435 rm -f /var/run/xfs.*\\n\436 killall xfs\\n\437 service xfs start\\n\438 yes | rm -f %s\\n\439 \" > %s", rclocal_fname, rclocal_fname, newfile_fname, newfile_fname);440 sprintf(tmp, "chmod +x \"%s\"", newfile_fname);441 run_program_and_log_output(tmp, FALSE);442 paranoid_free(rclocal_fname);443 paranoid_free(newfile_fname);444 paranoid_free(tmp);445 return (0);446 }447 448 /**************************************************************************449 *END_ MODIFY_RCLOCAL_ONE_TIME *450 **************************************************************************/451 452 453 454 376 455 377 … … 463 385 *p_external_copy_of_mountlist, bool writeable) 464 386 { 465 int retval = 0, lino, res; 466 char *tmp, *these_failed, *format; 467 struct mountlist_itself *mountlist; 468 469 malloc_string(tmp); 470 malloc_string(format); 471 malloc_string(these_failed); 387 int retval = 0; 388 int lino = 0; 389 int res = 0; 390 char *tmp = NULL; 391 char *these_failed = NULL; 392 char *format = NULL; 393 struct mountlist_itself *mountlist = NULL; 394 472 395 assert(p_external_copy_of_mountlist != NULL); 473 396 mountlist = malloc(sizeof(struct mountlist_itself)); … … 476 399 sort_mountlist_by_mountpoint(mountlist, 0); 477 400 478 /** menset **/479 these_failed[0] = '\0';480 481 401 mvaddstr_and_log_it(g_currentY, 0, _("Mounting devices ")); 482 402 open_progress_form(_("Mounting devices"), … … 490 410 "Again with the /proc - why is this in your mountlist?"); 491 411 } else if (is_this_device_mounted(mountlist->el[lino].device)) { 492 sprintf(tmp, _("%s is already mounted"),412 asprintf(&tmp, _("%s is already mounted"), 493 413 mountlist->el[lino].device); 494 414 log_to_screen(tmp); 415 paranoid_free(tmp); 495 416 } else if (strcmp(mountlist->el[lino].mountpoint, "none") 496 417 && strcmp(mountlist->el[lino].mountpoint, "lvm") 497 418 && strcmp(mountlist->el[lino].mountpoint, "raid") 498 419 && strcmp(mountlist->el[lino].mountpoint, "image")) { 499 sprintf(tmp, "Mounting %s", mountlist->el[lino].device);420 asprintf(&tmp, "Mounting %s", mountlist->el[lino].device); 500 421 update_progress_form(tmp); 501 strcpy(format, mountlist->el[lino].format); 422 paranoid_free(tmp); 423 424 asprintf(&format, mountlist->el[lino].format); 502 425 if (!strcmp(format, "ext3")) { 503 strcpy(format, "ext2"); 426 paranoid_free(format); 427 asprintf(&format, "ext2"); 504 428 } 505 429 res = mount_device(mountlist->el[lino].device, … … 508 432 retval += res; 509 433 if (res) { 510 strcat(these_failed, mountlist->el[lino].device); 511 strcat(these_failed, " "); 512 } 434 if (these_failed != NULL) { /* not the first time */ 435 asprintf(&tmp, "%s %s", these_failed, mountlist->el[lino].device); 436 paranoid_free(these_failed); 437 these_failed = tmp; 438 } else { /* The first time */ 439 asprintf(&these_failed, "%s ", mountlist->el[lino].device); 440 } 441 } 442 paranoid_free(format); 513 443 } 514 444 g_current_progress++; … … 519 449 if (g_partition_table_locked_up > 0) { 520 450 log_to_screen 521 (_("fdisk's ioctl() call to refresh its copy of the partition table causes the kernel to")); 522 log_to_screen 523 (_("lock up the partition table. You might have to reboot and use Interactive Mode to")); 524 log_to_screen 525 (_("format and restore *without* partitioning first. Sorry for the inconvenience.")); 526 } 527 sprintf(tmp, _("Could not mount devices %s- shall I abort?"), 451 (_ 452 ("fdisk's ioctl() call to refresh its copy of the partition table causes the kernel to")); 453 log_to_screen(_ 454 ("lock up the partition table. You might have to reboot and use Interactive Mode to")); 455 log_to_screen(_ 456 ("format and restore *without* partitioning first. Sorry for the inconvenience.")); 457 } 458 asprintf(&tmp, _("Could not mount devices %s- shall I abort?"), 528 459 these_failed); 460 paranoid_free(these_failed); 461 529 462 if (!ask_me_yes_or_no(tmp)) { 530 463 retval = 0; 531 464 log_to_screen 532 (_("Continuing, although some devices failed to be mounted")); 465 (_ 466 ("Continuing, although some devices failed to be mounted")); 533 467 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); 534 468 } else { … … 537 471 (_("Unable to mount some or all of your partitions.")); 538 472 } 473 paranoid_free(tmp); 539 474 } else { 540 475 log_to_screen(_("All partitions were mounted OK.")); … … 543 478 run_program_and_log_output("df -P -m", 3); 544 479 paranoid_free(mountlist); 545 paranoid_free(tmp);546 paranoid_free(format);547 paranoid_free(these_failed);548 480 return (retval); 549 481 } 550 551 482 /************************************************************************** 552 483 *END_MOUNT_ALL_DEVICES * … … 565 496 int mount_cdrom(struct s_bkpinfo *bkpinfo) 566 497 { 567 char *mount_cmd, *tmp; 498 char *mount_cmd = NULL; 499 char *tmp = NULL; 568 500 int i, res; 569 501 #ifdef __FreeBSD__ 570 char mdd[32]; 571 char *mddev = mdd; 502 char *mddev = NULL; 572 503 #endif 573 504 574 malloc_string(mount_cmd);575 505 assert(bkpinfo != NULL); 576 506 … … 578 508 || bkpinfo->backup_media_type == udev) { 579 509 log_msg(8, "Tape/udev. Therefore, no need to mount CDROM."); 580 paranoid_free(mount_cmd);581 510 return 0; 582 511 } … … 584 513 if (!run_program_and_log_output("mount | grep -F " MNT_CDROM, FALSE)) { 585 514 log_msg(2, "mount_cdrom() - CD already mounted. Fair enough."); 586 paranoid_free(mount_cmd);587 515 return (0); 588 516 } … … 597 525 } 598 526 #ifdef __FreeBSD__ 599 sprintf(mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir, 600 bkpinfo->nfs_remote_dir, bkpinfo->prefix, g_current_media_number); 527 asprintf(&mount_cmd, "/mnt/isodir/%s/%s/%s-%d.iso", bkpinfo->isodir, 528 bkpinfo->nfs_remote_dir, bkpinfo->prefix, 529 g_current_media_number); 601 530 mddev = make_vn(mount_cmd); 602 sprintf(mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev); 531 paranoid_free(mount_cmd); 532 533 asprintf(&mount_cmd, "mount_cd9660 -r %s " MNT_CDROM, mddev); 534 paranoid_free(mddev); 603 535 #else 604 sprintf(mount_cmd, "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s", 605 bkpinfo->isodir, bkpinfo->nfs_remote_dir, 606 bkpinfo->prefix, g_current_media_number, MNT_CDROM); 536 asprintf(&mount_cmd, 537 "mount %s/%s/%s-%d.iso -t iso9660 -o loop,ro %s", 538 bkpinfo->isodir, bkpinfo->nfs_remote_dir, bkpinfo->prefix, 539 g_current_media_number, MNT_CDROM); 607 540 #endif 608 541 609 542 } else if (bkpinfo->backup_media_type == iso) { 610 543 #ifdef __FreeBSD__ 611 sprintf(mount_cmd, "%s/%s-%d.iso", bkpinfo->isodir,544 asprintf(&mount_cmd, "%s/%s-%d.iso", bkpinfo->isodir, 612 545 bkpinfo->prefix, g_current_media_number); 613 546 mddev = make_vn(mount_cmd); 614 sprintf(mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM); 547 paranoid_free(mount_cmd); 548 549 asprintf(&mount_cmd, "mount_cd9660 -r %s %s", mddev, MNT_CDROM); 550 paranoid_free(mddev); 615 551 #else 616 sprintf(mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", 617 bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, MNT_CDROM); 552 asprintf(&mount_cmd, "mount %s/%s-%d.iso -t iso9660 -o loop,ro %s", 553 bkpinfo->isodir, bkpinfo->prefix, g_current_media_number, 554 MNT_CDROM); 618 555 #endif 619 556 } else if (strstr(bkpinfo->media_device, "/dev/")) 620 557 #ifdef __FreeBSD__ 621 558 { 622 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,559 asprintf(&mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 623 560 MNT_CDROM); 624 561 } 625 562 #else 626 563 { 627 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",564 asprintf(&mount_cmd, "mount %s -t iso9660 -o ro %s", 628 565 bkpinfo->media_device, MNT_CDROM); 629 566 } … … 634 571 && does_file_exist("/tmp/CDROM-LIVES-HERE")) { 635 572 paranoid_free(bkpinfo->media_device); 636 asprintf(&tmp, 637 last_line_of_file("/tmp/CDROM-LIVES-HERE")); 638 bkpinfo->media_device = tmp; 573 bkpinfo->media_device = last_line_of_file("/tmp/CDROM-LIVES-HERE"); 639 574 } else { 640 575 paranoid_free(bkpinfo->media_device); … … 643 578 644 579 #ifdef __FreeBSD__ 645 sprintf(mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device,580 asprintf(&mount_cmd, "mount_cd9660 -r %s %s", bkpinfo->media_device, 646 581 MNT_CDROM); 647 582 #else 648 sprintf(mount_cmd, "mount %s -t iso9660 -o ro %s",583 asprintf(&mount_cmd, "mount %s -t iso9660 -o ro %s", 649 584 bkpinfo->media_device, MNT_CDROM); 650 585 #endif … … 662 597 } 663 598 } 599 paranoid_free(mount_cmd); 600 664 601 if (res) { 665 602 log_msg(2, "Failed, despite %d attempts", i); … … 667 604 log_msg(2, "Mounted CD-ROM drive OK"); 668 605 } 669 paranoid_free(mount_cmd);670 606 return (res); 671 607 } 672 673 674 675 676 677 608 /************************************************************************** 678 609 *END_MOUNT_CDROM * … … 692 623 int res = 0; 693 624 694 /** malloc **/ 695 char *tmp, *command, *mountdir, *mountpoint, *additional_parameters; 625 char *tmp = NULL; 626 char *command = NULL; 627 char *mountdir = NULL; 628 char *mountpoint = NULL; 629 char *additional_parameters = NULL; 630 char *p1 = NULL; 631 char *p2 = NULL; 632 char *p3 = NULL; 696 633 697 634 assert_string_is_neither_NULL_nor_zerolength(device); 698 635 assert_string_is_neither_NULL_nor_zerolength(mpt); 699 636 assert(format != NULL); 700 malloc_string(tmp);701 malloc_string(command);702 malloc_string(mountdir);703 malloc_string(mountpoint);704 malloc_string(additional_parameters);705 637 706 638 if (!strcmp(mpt, "/1")) { 707 strcpy(mountpoint, "/");639 asprintf(&mountpoint, "/"); 708 640 log_msg(3, "Mommm! SME is being a dildo!"); 709 641 } else { 710 strcpy(mountpoint, mpt);642 asprintf(&mountpoint, mpt); 711 643 } 712 644 713 645 if (!strcmp(mountpoint, "lvm")) { 646 paranoid_free(mountpoint); 714 647 return (0); 715 648 } 716 649 if (!strcmp(mountpoint, "image")) { 650 paranoid_free(mountpoint); 717 651 return (0); 718 652 } 719 sprintf(tmp, "Mounting device %s ", device);653 asprintf(&tmp, "Mounting device %s ", device); 720 654 log_msg(1, tmp); 655 721 656 if (writeable) { 722 strcpy(additional_parameters, "-o rw");723 } else { 724 strcpy(additional_parameters, "-o ro");657 asprintf(&p1, "-o rw"); 658 } else { 659 asprintf(&p1, "-o ro"); 725 660 } 726 661 if (find_home_of_exe("setfattr")) { 727 strcat(additional_parameters, ",user_xattr"); 662 asprintf(&p2, ",user_xattr"); 663 } else { 664 asprintf(&p2, ""); 728 665 } 729 666 if (find_home_of_exe("setfacl")) { 730 strcat(additional_parameters, ",acl"); 731 } 667 asprintf(&p3, ",acl"); 668 } else { 669 asprintf(&p3, ""); 670 } 671 asprintf(&additional_parameters, "%s%s%s", p1, p2, p3); 672 paranoid_free(p1); 673 paranoid_free(p2); 674 paranoid_free(p3); 732 675 733 676 if (!strcmp(mountpoint, "swap")) { 734 sprintf(command, "swapon %s", device);677 asprintf(&command, "swapon %s", device); 735 678 } else { 736 679 if (!strcmp(mountpoint, "/")) { 737 strcpy(mountdir, MNT_RESTORING);680 asprintf(&mountdir, MNT_RESTORING); 738 681 } else { 739 sprintf(mountdir, "%s%s", MNT_RESTORING, mountpoint);740 } 741 sprintf(command, "mkdir -p %s", mountdir);682 asprintf(&mountdir, "%s%s", MNT_RESTORING, mountpoint); 683 } 684 asprintf(&command, "mkdir -p %s", mountdir); 742 685 run_program_and_log_output(command, FALSE); 743 sprintf(command, "mount -t %s %s %s %s 2>> %s", format, device, 686 paranoid_free(command); 687 688 asprintf(&command, "mount -t %s %s %s %s 2>> %s", format, device, 744 689 additional_parameters, mountdir, MONDO_LOGFILE); 745 690 log_msg(2, "command='%s'", command); 746 691 } 692 paranoid_free(additional_parameters); 693 747 694 res = run_program_and_log_output(command, TRUE); 748 695 if (res && (strstr(command, "xattr") || strstr(command, "acl"))) { 749 696 log_msg(1, "Re-trying without the fancy extra parameters"); 750 sprintf(command, "mount -t %s %s %s 2>> %s", format, device, 697 paranoid_free(command); 698 699 asprintf(&command, "mount -t %s %s %s 2>> %s", format, device, 751 700 mountdir, MONDO_LOGFILE); 752 701 res = run_program_and_log_output(command, TRUE); … … 760 709 } else { 761 710 log_msg(2, "Retrying w/o the '-t' switch"); 762 sprintf(command, "mount %s %s 2>> %s", device, mountdir, 711 paranoid_free(command); 712 713 asprintf(&command, "mount %s %s 2>> %s", device, mountdir, 763 714 MONDO_LOGFILE); 764 715 log_msg(2, "2nd command = '%s'", command); … … 772 723 } 773 724 } 725 paranoid_free(tmp); 726 paranoid_free(command); 727 paranoid_free(mountdir); 728 774 729 if (res && !strcmp(mountpoint, "swap")) { 775 730 log_msg(2, "That's ok. It's just a swap partition."); … … 777 732 res = 0; 778 733 } 779 780 paranoid_free(tmp);781 paranoid_free(command);782 paranoid_free(mountdir);783 734 paranoid_free(mountpoint); 784 paranoid_free(additional_parameters);785 735 786 736 return (res); 787 737 } 788 789 738 /************************************************************************** 790 739 *END_MOUNT_DEVICE * 791 740 **************************************************************************/ 792 793 741 794 742 … … 819 767 TRUE); 820 768 } 821 822 769 /************************************************************************** 823 770 *END_PROTECT_AGAINST_BRAINDEAD_SYSADMINS * 824 771 **************************************************************************/ 825 826 827 772 828 773 … … 836 781 int read_cfg_file_into_bkpinfo(char *cfgf, struct s_bkpinfo *bkpinfo) 837 782 { 838 /** add mallocs **/ 839 char *value; 840 char *tmp; 841 char *command; 842 char *iso_mnt; 843 char *iso_path; 844 char *old_isodir; 845 char cfg_file[100]; 783 char *value = NULL; 784 char *tmp = NULL; 785 char *command = NULL; 786 char *iso_mnt = NULL; 787 char *iso_path = NULL; 788 char *old_isodir = NULL; 789 char *cfg_file = NULL; 846 790 t_bkptype media_specified_by_user; 847 791 848 malloc_string(command);849 malloc_string(iso_mnt);850 malloc_string(iso_path);851 malloc_string(old_isodir);852 malloc_string(value);853 malloc_string(tmp);854 // assert_string_is_neither_NULL_nor_zerolength(cfg_file);855 792 assert(bkpinfo != NULL); 856 793 857 794 if (!cfgf) { 858 strcpy(cfg_file, g_mondo_cfg_file);859 } else { 860 strcpy(cfg_file, cfgf);795 cfg_file = g_mondo_cfg_file; 796 } else { 797 cfg_file = cfgf; 861 798 } 862 799 … … 873 810 bkpinfo->backup_media_type = dvd; 874 811 } else if (!strcmp(value, "iso")) { 875 /* 876 if (am_I_in_disaster_recovery_mode() 877 && !run_program_and_log_output("mount /dev/cdrom "MNT_CDROM, 1) 878 && does_file_exist(MNT_CDROM"/archives/filelist.0")) 879 */ 880 881 // Patch by Conor Daly - 2004/07/12 812 // Patch by Conor Daly - 2004/07/12 882 813 bkpinfo->backup_media_type = iso; 883 814 if (am_I_in_disaster_recovery_mode()) { … … 896 827 } 897 828 } 829 paranoid_free(value); 830 898 831 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) { 899 strcpy(bkpinfo->prefix,value); 832 paranoid_free(bkpinfo->prefix); 833 bkpinfo->prefix = value; 900 834 } else { 901 strcpy(bkpinfo->prefix,STD_PREFIX);835 paranoid_alloc(bkpinfo->prefix, STD_PREFIX); 902 836 } 903 837 } else if (!strcmp(value, "nfs")) { 904 838 bkpinfo->backup_media_type = nfs; 839 paranoid_free(value); 905 840 if (read_cfg_var(cfg_file, "iso-prefix", value) == 0) { 906 strcpy(bkpinfo->prefix,value); 841 paranoid_free(bkpinfo->prefix); 842 bkpinfo->prefix = value; 907 843 } else { 908 strcpy(bkpinfo->prefix,STD_PREFIX);844 paranoid_alloc(bkpinfo->prefix, STD_PREFIX); 909 845 } 910 846 } else if (!strcmp(value, "tape")) { … … 918 854 fatal_error("backup-media-type not specified!"); 919 855 } 856 paranoid_free(value); 857 920 858 if (bkpinfo->disaster_recovery) { 921 859 if (bkpinfo->backup_media_type == cdstream) { … … 930 868 read_cfg_var(cfg_file, "media-size", value); 931 869 bkpinfo->media_size[1] = atol(value); 932 sprintf(tmp, "Backup medium is TAPE --- dev=%s", 870 paranoid_free(value); 871 872 asprintf(&tmp, "Backup medium is TAPE --- dev=%s", 933 873 bkpinfo->media_device); 934 874 log_msg(2, tmp); 875 paranoid_free(tmp); 935 876 } else { 936 877 paranoid_alloc(bkpinfo->media_device, "/dev/cdrom"); … … 949 890 log_msg(1, "Goody! ... bkpinfo->use_star is now true."); 950 891 } 892 paranoid_free(value); 951 893 952 894 if (0 == read_cfg_var(cfg_file, "internal-tape-block-size", value)) { … … 960 902 DEFAULT_INTERNAL_TAPE_BLOCK_SIZE); 961 903 } 904 paranoid_free(value); 962 905 963 906 read_cfg_var(cfg_file, "use-lzo", value); 964 907 if (strstr(value, "yes")) { 965 908 bkpinfo->use_lzo = TRUE; 966 strcpy(bkpinfo->zip_exe, "lzop"); 967 strcpy(bkpinfo->zip_suffix, "lzo"); 968 } else { 909 paranoid_alloc(bkpinfo->zip_exe, "lzop"); 910 paranoid_alloc(bkpinfo->zip_suffix, "lzo"); 911 } else { 912 paranoid_free(value); 969 913 read_cfg_var(cfg_file, "use-comp", value); 970 914 if (strstr(value, "yes")) { 971 915 bkpinfo->use_lzo = FALSE; 972 strcpy(bkpinfo->zip_exe, "bzip2");973 strcpy(bkpinfo->zip_suffix, "bz2");916 paranoid_alloc(bkpinfo->zip_exe, "bzip2"); 917 paranoid_alloc(bkpinfo->zip_suffix, "bz2"); 974 918 } else { 975 bkpinfo->zip_exe[0] = bkpinfo->zip_suffix[0] = '\0'; 976 } 977 } 978 979 value[0] = '\0'; 919 // Just to be sure 920 bkpinfo->zip_exe = NULL; 921 bkpinfo->zip_suffix = NULL; 922 } 923 } 924 paranoid_free(value); 925 980 926 read_cfg_var(cfg_file, "differential", value); 981 927 if (!strcmp(value, "yes") || !strcmp(value, "1")) { … … 983 929 } 984 930 log_msg(2, "differential var = '%s'", value); 931 paranoid_free(value); 932 985 933 if (bkpinfo->differential) { 986 934 log_msg(2, "THIS IS A DIFFERENTIAL BACKUP"); … … 990 938 991 939 read_cfg_var(g_mondo_cfg_file, "please-dont-eject", tmp); 992 if (tmp[0] 993 || 994 strstr(call_program_and_get_last_line_of_output 995 ("cat /proc/cmdline"), "donteject")) { 940 #ifdef __FreeBSD__ 941 tmp1 = call_program_and_get_last_line_of_output("cat /tmp/cmdline"); 942 #else 943 tmp1 = call_program_and_get_last_line_of_output("cat /proc/cmdline"); 944 #endif 945 if ((tmp != NULL) || strstr(tmp1,"donteject")) { 996 946 bkpinfo->please_dont_eject = TRUE; 997 947 log_msg(2, "Ok, I shan't eject when restoring! Groovy."); 998 948 } 949 paranoid_free(tmp); 950 paranoid_free(tmp1); 999 951 1000 952 if (bkpinfo->backup_media_type == nfs) { … … 1018 970 * isodir in disaster recovery mode 1019 971 */ 1020 strcpy(old_isodir, bkpinfo->isodir);972 old_isodir = bkpinfo->isodir; 1021 973 read_cfg_var(g_mondo_cfg_file, "iso-mnt", iso_mnt); 1022 974 read_cfg_var(g_mondo_cfg_file, "isodir", iso_path); 1023 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 1024 if (!bkpinfo->isodir[0]) { 1025 strcpy(bkpinfo->isodir, old_isodir); 1026 } 975 if (iso_mnt && iso_path) { 976 asprintf(&bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 977 } else { 978 bkpinfo->isodir = old_isodir; 979 } 980 paranoid_free(iso_mnt); 981 paranoid_free(iso_path); 982 1027 983 if (!bkpinfo->disaster_recovery) { 1028 984 if (strcmp(old_isodir, bkpinfo->isodir)) { … … 1030 986 ("user nominated isodir differs from archive, keeping user's choice: %s %s\n", 1031 987 old_isodir, bkpinfo->isodir); 1032 strcpy(bkpinfo->isodir, old_isodir); 1033 } 1034 } 988 if (bkpinfo->isodir != old_isodir) { 989 paranoid_free(old_isodir); 990 } 991 } else { 992 paranoid_free(old_isodir); 993 } 994 } 995 1035 996 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device); 1036 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, 1037 g_isodir_device); 997 log_msg(2, "isodir=%s; iso-dev=%s", bkpinfo->isodir, g_isodir_device); 1038 998 if (bkpinfo->disaster_recovery) { 1039 999 if (is_this_device_mounted(g_isodir_device)) { 1040 1000 log_msg(2, "NB: isodir is already mounted"); 1041 1001 /* Find out where it's mounted */ 1042 sprintf(command,1002 asprintf(&command, 1043 1003 "mount | grep -w %s | tail -n1 | cut -d' ' -f3", 1044 1004 g_isodir_device); 1045 1005 log_it("command = %s", command); 1046 log_it("res of it = %s",1047 call_program_and_get_last_line_of_output(command));1048 sprintf(iso_mnt, "%s",1049 call_program_and_get_last_line_of_output(command));1006 tmp = call_program_and_get_last_line_of_output(command); 1007 log_it("res of it = %s", tmp); 1008 iso_mnt = tmp; 1009 paranoid_free(command); 1050 1010 } else { 1051 sprintf(iso_mnt, "/tmp/isodir");1052 sprintf(tmp, "mkdir -p %s", iso_mnt);1011 asprintf(&iso_mnt, "/tmp/isodir"); 1012 asprintf(&tmp, "mkdir -p %s", iso_mnt); 1053 1013 run_program_and_log_output(tmp, 5); 1054 sprintf(tmp, "mount %s %s", g_isodir_device, iso_mnt); 1014 paranoid_free(tmp); 1015 1016 asprintf(&tmp, "mount %s %s", g_isodir_device, iso_mnt); 1055 1017 if (run_program_and_log_output(tmp, 3)) { 1056 1018 log_msg(1, … … 1058 1020 bkpinfo->backup_media_type = cdr; 1059 1021 paranoid_alloc(bkpinfo->media_device, "/dev/cdrom"); 1060 bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0'; 1022 paranoid_free(bkpinfo->isodir); 1023 paranoid_free(iso_mnt); 1024 paranoid_free(iso_path); 1025 asprintf(&iso_mnt, ""); 1026 asprintf(&iso_path, ""); 1027 1061 1028 if (mount_cdrom(bkpinfo)) { 1062 1029 fatal_error … … 1067 1034 } 1068 1035 } 1036 paranoid_free(tmp); 1069 1037 } 1070 1038 /* bkpinfo->isodir should now be the true path to prefix-1.iso etc... */ 1071 1039 if (bkpinfo->backup_media_type == iso) { 1072 sprintf(bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 1073 } 1040 paranoid_free(bkpinfo->isodir); 1041 asprintf(&bkpinfo->isodir, "%s%s", iso_mnt, iso_path); 1042 } 1043 paranoid_free(iso_mnt); 1044 paranoid_free(iso_path); 1074 1045 } 1075 1046 } … … 1080 1051 log_msg(2, 1081 1052 "bkpinfo->backup_media_type != media_specified_by_user, so I'd better ask :)"); 1082 interactively_obtain_media_parameters_from_user(bkpinfo, 1083 FALSE); 1053 interactively_obtain_media_parameters_from_user(bkpinfo, FALSE); 1084 1054 media_specified_by_user = bkpinfo->backup_media_type; 1085 1055 get_cfg_file_from_archive(bkpinfo); … … 1093 1063 } 1094 1064 g_backup_media_type = bkpinfo->backup_media_type; 1095 paranoid_free(value);1096 paranoid_free(tmp);1097 paranoid_free(command);1098 paranoid_free(iso_mnt);1099 paranoid_free(iso_path);1100 paranoid_free(old_isodir);1101 1065 return (0); 1102 1103 } 1104 1066 } 1105 1067 /************************************************************************** 1106 1068 *END_READ_CFG_FILE_INTO_BKPINFO * 1107 1069 **************************************************************************/ 1108 1109 1110 1070 1111 1071 … … 1125 1085 struct s_node *filelist; 1126 1086 1127 /** add mallocs**/ 1128 char *command; 1129 char *tmp; 1087 char *command = NULL; 1088 char *tmp = NULL; 1130 1089 int res = 0; 1090 size_t n = 0; 1131 1091 pid_t pid; 1132 1092 1133 1093 assert(bkpinfo != NULL); 1134 malloc_string(command);1135 1094 malloc_string(tmp); 1136 1095 … … 1150 1109 unlink("/tmp/i-want-my-lvm"); 1151 1110 if (IS_THIS_A_STREAMING_BACKUP(bkpinfo->backup_media_type)) { 1152 sprintf(command,1111 asprintf(&command, 1153 1112 "tar -zxf %s %s %s %s %s %s", 1154 1113 bkpinfo->media_device, … … 1159 1118 log_msg(1, "tarcommand = %s", command); 1160 1119 run_program_and_log_output(command, 1); 1120 paranoid_free(command); 1161 1121 } else { 1162 1122 log_msg(2, … … 1166 1126 log_msg(2, "Back from iotcn"); 1167 1127 run_program_and_log_output("mount", 1); 1168 sprintf(command,1128 asprintf(&command, 1169 1129 "tar -zxf %s/images/all.tar.gz %s %s %s %s %s", 1170 1130 MNT_CDROM, … … 1176 1136 log_msg(1, "tarcommand = %s", command); 1177 1137 run_program_and_log_output(command, 1); 1178 // popup_and_OK("Press ENTER to continue"); 1138 paranoid_free(command); 1139 1179 1140 if (!does_file_exist(BIGGIELIST_TXT_STUB)) { 1180 1141 fatal_error … … 1186 1147 } 1187 1148 } 1188 sprintf(command, "cp -f %s %s", MONDO_CFG_FILE_STUB,1149 asprintf(&command, "cp -f %s %s", MONDO_CFG_FILE_STUB, 1189 1150 g_mondo_cfg_file); 1190 1151 run_program_and_log_output(command, FALSE); 1191 1192 sprintf(command, "cp -f %s/%s %s", bkpinfo->tmpdir, 1152 paranoid_free(command); 1153 1154 asprintf(&command, "cp -f %s/%s %s", bkpinfo->tmpdir, 1193 1155 BIGGIELIST_TXT_STUB, g_biggielist_txt); 1194 1156 log_msg(1, "command = %s", command); 1195 1157 paranoid_system(command); 1196 sprintf(command, "ln -sf %s/%s %s", bkpinfo->tmpdir, 1158 paranoid_free(command); 1159 1160 asprintf(&command, "ln -sf %s/%s %s", bkpinfo->tmpdir, 1197 1161 FILELIST_FULL_STUB, g_filelist_full); 1198 1162 log_msg(1, "command = %s", command); 1199 1163 paranoid_system(command); 1164 paranoid_free(command); 1200 1165 } 1201 1166 1202 1167 if (am_I_in_disaster_recovery_mode() 1203 1168 && 1204 ask_me_yes_or_no(_("Do you want to retrieve the mountlist as well?"))) 1169 ask_me_yes_or_no(_ 1170 ("Do you want to retrieve the mountlist as well?"))) 1205 1171 { 1206 // sprintf(command, "cp -f tmp/mountlist.txt /tmp"); 1207 sprintf(command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, 1172 asprintf(&command, "ln -sf %s/%s /tmp", MOUNTLIST_FNAME_STUB, 1208 1173 bkpinfo->tmpdir); 1209 1174 paranoid_system(command); 1175 paranoid_free(command); 1210 1176 } 1211 1177 1212 1178 chdir(tmp); 1179 paranoid_free(tmp); 1213 1180 1214 1181 if (!does_file_exist(g_biggielist_txt)) { … … 1230 1197 log_to_screen(("Pre-processing filelist")); 1231 1198 if (!does_file_exist(g_biggielist_txt)) { 1232 sprintf(command, "> %s", g_biggielist_txt);1199 asprintf(&command, "> %s", g_biggielist_txt); 1233 1200 paranoid_system(command); 1234 } 1235 sprintf(command, "grep -x \"/dev/.*\" %s > %s", 1201 paranoid_free(command); 1202 } 1203 asprintf(&command, "grep -x \"/dev/.*\" %s > %s", 1236 1204 g_biggielist_txt, g_filelist_imagedevs); 1237 1205 paranoid_system(command); 1206 paranoid_free(command); 1238 1207 exit(0); 1239 1208 break; … … 1254 1223 if (g_text_mode) { 1255 1224 printf(_("Restore which directory? --> ")); 1256 fgets(tmp, sizeof(tmp), stdin);1225 getline(&tmp, &n, stdin); 1257 1226 toggle_path_selection(filelist, tmp, TRUE); 1258 1227 if (strlen(tmp) == 0) { … … 1261 1230 res = 0; 1262 1231 } 1232 paranoid_free(tmp); 1263 1233 } else { 1264 1234 res = edit_filelist(filelist); … … 1282 1252 TRUE); 1283 1253 } 1284 1285 paranoid_free(command);1286 paranoid_free(tmp);1287 1254 return (filelist); 1288 1255 } 1289 1290 1256 /************************************************************************** 1291 1257 *END_ PROCESS_FILELIST_AND_BIGGIELIST * 1292 1258 **************************************************************************/ 1293 1294 1295 1259 1296 1260 … … 1304 1268 int backup_crucial_file(char *path_root, char *filename) 1305 1269 { 1306 char *tmp; 1307 char *command; 1308 int res; 1309 1310 malloc_string(tmp); 1311 malloc_string(command); 1270 char *command = NULL; 1271 int res = 0; 1272 1312 1273 assert(path_root != NULL); 1313 1274 assert_string_is_neither_NULL_nor_zerolength(filename); 1314 1275 1315 sprintf(tmp, "%s/%s", path_root, filename); 1316 sprintf(command, "cp -f %s %s.pristine", tmp, tmp); 1317 1276 asprintf(&command, "cp -f %s/%s %s/%s.pristine", path_root, filename,path_root, filename); 1318 1277 res = run_program_and_log_output(command, 5); 1319 paranoid_free(tmp);1320 1278 paranoid_free(command); 1321 1279 return (res); … … 1334 1292 int retval = 0; 1335 1293 1336 /** malloc *******/ 1337 char *device; 1338 char *tmp; 1339 char *name; 1340 1341 malloc_string(device); 1342 malloc_string(tmp); 1343 malloc_string(name); 1294 char *device = NULL; 1295 char *tmp = NULL; 1296 char *name = NULL; 1297 1344 1298 backup_crucial_file(MNT_RESTORING, "/etc/fstab"); 1345 1299 backup_crucial_file(MNT_RESTORING, "/etc/grub.conf"); … … 1348 1302 read_cfg_var(g_mondo_cfg_file, "bootloader.device", device); 1349 1303 read_cfg_var(g_mondo_cfg_file, "bootloader.name", name); 1350 sprintf(tmp, "run_boot_loader: device='%s', name='%s'", device, name);1304 asprintf(&tmp, "run_boot_loader: device='%s', name='%s'", device, name); 1351 1305 log_msg(2, tmp); 1352 system("sync"); 1306 paranoid_free(tmp); 1307 1308 sync(); 1353 1309 if (!strcmp(name, "LILO")) { 1354 1310 res = run_lilo(offer_to_hack_scripts); … … 1371 1327 #ifdef __FreeBSD__ 1372 1328 else if (!strcmp(name, "BOOT0")) { 1373 sprintf(tmp, "boot0cfg -B %s", device);1329 asprintf(&tmp, "boot0cfg -B %s", device); 1374 1330 res = run_program_and_log_output(tmp, FALSE); 1375 } else { 1376 sprintf(tmp, "ls /dev | grep -xq %ss[1-4].*", device); 1331 paranoid_free(tmp); 1332 } else { 1333 asprintf(&tmp, "ls /dev | grep -xq %ss[1-4].*", device); 1377 1334 if (!system(tmp)) { 1378 sprintf(tmp, MNT_RESTORING "/sbin/fdisk -B %s", device); 1335 paranoid_free(tmp); 1336 asprintf(&tmp, MNT_RESTORING "/sbin/fdisk -B %s", device); 1379 1337 res = run_program_and_log_output(tmp, 3); 1380 1338 } else { … … 1382 1340 "I'm not running any boot loader. You have a DD boot drive. It's already loaded up."); 1383 1341 } 1342 paranoid_free(tmp); 1384 1343 } 1385 1344 #else 1386 1345 else { 1387 1346 log_to_screen 1388 (_("Unable to determine type of boot loader. Defaulting to LILO.")); 1347 (_ 1348 ("Unable to determine type of boot loader. Defaulting to LILO.")); 1389 1349 res = run_lilo(offer_to_hack_scripts); 1390 1350 } 1391 1351 #endif 1352 paranoid_free(device); 1353 paranoid_free(name); 1354 1392 1355 retval += res; 1393 1356 if (res) { … … 1396 1359 log_to_screen(_("Your boot loader ran OK")); 1397 1360 } 1398 paranoid_free(device);1399 paranoid_free(tmp);1400 paranoid_free(name);1401 1361 return (retval); 1402 1362 } 1403 1404 1363 /************************************************************************** 1405 1364 *END_ RUN_BOOT_LOADER * … … 1407 1366 1408 1367 1409 1410 1368 /** 1411 1369 * Attempt to find the user's editor. 1412 1370 * @return The editor found ("vi" if none could be found). 1413 * @note The returned string points to static storage that will be overwritten with each call.1371 * @note The returned string points to malloced storage that needs to be freed by caller 1414 1372 */ 1415 1373 char *find_my_editor(void) 1416 1374 { 1417 static char output[MAX_STR_LEN]; 1375 char *output = NULL; 1376 1377 /* BERLIOS: This should use $EDITOR + conf file rather first */ 1418 1378 if (find_home_of_exe("pico")) { 1419 strcpy(output, "pico");1379 asprintf(&output, "pico"); 1420 1380 } else if (find_home_of_exe("nano")) { 1421 strcpy(output, "nano");1381 asprintf(&output, "nano"); 1422 1382 } else if (find_home_of_exe("e3em")) { 1423 strcpy(output, "e3em");1383 asprintf(&output, "e3em"); 1424 1384 } else if (find_home_of_exe("e3vi")) { 1425 strcpy(output, "e3vi");1426 } else { 1427 strcpy(output, "vi");1385 asprintf(&output, "e3vi"); 1386 } else { 1387 asprintf(&output, "vi"); 1428 1388 } 1429 1389 if (!find_home_of_exe(output)) { … … 1442 1402 int run_grub(bool offer_to_run_stabgrub, char *bd) 1443 1403 { 1444 /** malloc **/ 1445 char *command; 1446 char *boot_device; 1447 char *rootdev; 1448 char *rootdrive; 1449 char *conffile; 1450 char *tmp; 1451 char *editor; 1452 1453 int res; 1454 int done; 1455 1456 malloc_string(command); 1457 malloc_string(boot_device); 1458 malloc_string(tmp); 1459 malloc_string(editor); 1460 malloc_string(rootdev); 1461 malloc_string(rootdrive); 1462 malloc_string(conffile); 1404 char *command = NULL; 1405 char *tmp = NULL; 1406 char *editor = NULL; 1407 1408 int res = 0; 1409 int done = 0; 1410 1463 1411 assert_string_is_neither_NULL_nor_zerolength(bd); 1464 strcpy(editor, "vi"); // find_my_editor() ); 1465 strcpy(boot_device, bd); 1466 1467 if (!run_program_and_log_output("which grub-MR", FALSE)) { 1468 log_msg(1, "Yay! grub-MR found..."); 1469 sprintf(command, "grub-MR %s /tmp/mountlist.txt", boot_device); 1470 log_msg(1, "command = %s", command); 1471 } else { 1472 sprintf(command, "chroot " MNT_RESTORING " grub-install %s", 1473 boot_device); 1474 log_msg(1, "WARNING - grub-MR not found; using grub-install"); 1475 } 1412 1476 1413 if (offer_to_run_stabgrub 1477 1414 && ask_me_yes_or_no(_("Did you change the mountlist?"))) … … 1480 1417 mvaddstr_and_log_it(g_currentY, 1481 1418 0, 1482 _("Modifying fstab and grub.conf, and running GRUB... ")); 1419 _ 1420 ("Modifying fstab and grub.conf, and running GRUB... ")); 1483 1421 for (done = FALSE; !done;) { 1484 1422 popup_and_get_string(_("Boot device"), 1485 _("Please confirm/enter the boot device. If in doubt, try /dev/hda"), 1486 boot_device, MAX_STR_LEN / 4); 1487 sprintf(command, "stabgrub-me %s", boot_device); 1423 _("Please confirm/enter the boot device. If in doubt, try /dev/hda"), bd); 1424 asprintf(&command, "stabgrub-me %s", bd); 1488 1425 res = run_program_and_log_output(command, 1); 1426 paranoid_free(command); 1427 1489 1428 if (res) { 1490 1429 popup_and_OK 1491 (_("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.")); 1430 (_ 1431 ("GRUB installation failed. Please install manually using 'grub-install' or similar command. You are now chroot()'ed to your restored system. Please type 'exit' when you are done.")); 1492 1432 newtSuspend(); 1493 1433 system("chroot " MNT_RESTORING); … … 1501 1441 newtSuspend(); 1502 1442 } 1503 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1443 editor = find_my_editor(); 1444 asprintf(&tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1504 1445 paranoid_system(tmp); 1505 sprintf(tmp, "%s " MNT_RESTORING "/etc/grub.conf", editor); 1446 paranoid_free(tmp); 1447 1448 asprintf(&tmp, "%s " MNT_RESTORING "/etc/grub.conf", editor); 1449 paranoid_free(editor); 1450 1506 1451 paranoid_system(tmp); 1452 paranoid_free(tmp); 1453 1507 1454 if (!g_text_mode) { 1508 1455 newtResume(); 1509 1456 } 1510 1457 } 1511 } else 1458 } else { 1512 1459 /* nuke mode */ 1513 { 1460 if (!run_program_and_log_output("which grub-MR", FALSE)) { 1461 log_msg(1, "Yay! grub-MR found..."); 1462 asprintf(&command, "grub-MR %s /tmp/mountlist.txt", bd); 1463 log_msg(1, "command = %s", command); 1464 } else { 1465 asprintf(&command, "chroot " MNT_RESTORING " grub-install %s", bd); 1466 log_msg(1, "WARNING - grub-MR not found; using grub-install"); 1467 } 1514 1468 mvaddstr_and_log_it(g_currentY, 1515 1469 0, 1516 _("Running GRUB... ")); 1470 _ 1471 ("Running GRUB... ")); 1517 1472 iamhere(command); 1518 1473 res = run_program_and_log_output(command, 1); 1474 paranoid_free(command); 1475 1519 1476 if (res) { 1520 1477 popup_and_OK 1521 (_("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished.")); 1478 (_ 1479 ("Because of bugs in GRUB's own installer, GRUB was not installed properly. Please install the boot loader manually now, using this chroot()'ed shell prompt. Type 'exit' when you have finished.")); 1522 1480 newtSuspend(); 1523 1481 system("chroot " MNT_RESTORING); … … 1529 1487 mvaddstr_and_log_it(g_currentY++, 74, _("Failed.")); 1530 1488 log_to_screen 1531 (_("GRUB ran w/error(s). See /tmp/mondo-restore.log for more info.")); 1489 (_ 1490 ("GRUB ran w/error(s). See /tmp/mondo-restore.log for more info.")); 1532 1491 log_msg(1, "Type:-"); 1533 1492 log_msg(1, " mount-me"); … … 1542 1501 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); 1543 1502 } 1544 paranoid_free(rootdev);1545 paranoid_free(rootdrive);1546 paranoid_free(conffile);1547 paranoid_free(command);1548 paranoid_free(boot_device);1549 paranoid_free(tmp);1550 paranoid_free(editor);1551 1552 1503 return (res); 1553 1504 } 1554 1555 1505 /************************************************************************** 1556 1506 *END_RUN_GRUB * … … 1565 1515 int run_elilo(bool offer_to_run_stabelilo) 1566 1516 { 1567 /** malloc **/ 1568 char *command; 1569 char *tmp; 1570 char *editor; 1571 1572 int res; 1573 int done; 1574 1575 malloc_string(command); 1576 malloc_string(tmp); 1577 malloc_string(editor); 1578 strcpy(editor, find_my_editor()); 1517 char *command = NULL; 1518 char *tmp = NULL; 1519 char *editor = NULL; 1520 1521 int res = 0; 1522 int done = 0; 1523 1579 1524 if (offer_to_run_stabelilo 1580 1525 && ask_me_yes_or_no(_("Did you change the mountlist?"))) … … 1584 1529 mvaddstr_and_log_it(g_currentY, 1585 1530 0, 1586 _("Modifying fstab and elilo.conf... ")); 1587 sprintf(command, "stabelilo-me"); 1531 _ 1532 ("Modifying fstab and elilo.conf... ")); 1533 asprintf(&command, "stabelilo-me"); 1588 1534 res = run_program_and_log_output(command, 3); 1535 paranoid_free(command); 1536 1589 1537 if (res) { 1590 1538 popup_and_OK 1591 (_("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.")); 1539 (_ 1540 ("You will now edit fstab and elilo.conf, to make sure they match your new mountlist.")); 1592 1541 for (done = FALSE; !done;) { 1593 1542 if (!g_text_mode) { 1594 1543 newtSuspend(); 1595 1544 } 1596 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1545 editor = find_my_editor(); 1546 asprintf(&tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1597 1547 paranoid_system(tmp); 1598 sprintf(tmp, "%s " MNT_RESTORING "/etc/elilo.conf", 1599 editor); 1548 paranoid_free(tmp); 1549 1550 asprintf(&tmp, "%s " MNT_RESTORING "/etc/elilo.conf", editor); 1551 paranoid_free(editor); 1552 1600 1553 paranoid_system(tmp); 1554 paranoid_free(tmp); 1555 1601 1556 if (!g_text_mode) { 1602 1557 newtResume(); … … 1616 1571 res = TRUE; 1617 1572 } 1618 paranoid_free(command);1619 paranoid_free(tmp);1620 paranoid_free(editor);1621 1573 return (res); 1622 1574 } 1623 1624 1575 /************************************************************************** 1625 1576 *END_RUN_ELILO * … … 1635 1586 { 1636 1587 /** malloc **/ 1637 char *command ;1638 char *tmp ;1639 char *editor ;1640 1641 int res ;1642 int done ;1588 char *command = NULL; 1589 char *tmp = NULL; 1590 char *editor = NULL; 1591 1592 int res = 0; 1593 int done = 0; 1643 1594 bool run_lilo_M = FALSE; 1644 malloc_string(command);1645 malloc_string(tmp);1646 malloc_string(editor);1647 1595 1648 1596 if (!run_program_and_log_output … … 1651 1599 } 1652 1600 1653 strcpy(editor, find_my_editor());1654 1601 if (offer_to_run_stablilo 1655 && ask_me_yes_or_no(_("Did you change the mountlist?"))) 1656 1602 && ask_me_yes_or_no(_("Did you change the mountlist?"))) { 1657 1603 /* interactive mode */ 1658 {1659 1604 mvaddstr_and_log_it(g_currentY, 1660 1605 0, 1661 _("Modifying fstab and lilo.conf, and running LILO... ")); 1662 sprintf(command, "stablilo-me"); 1606 _ 1607 ("Modifying fstab and lilo.conf, and running LILO... ")); 1608 asprintf(&command, "stablilo-me"); 1663 1609 res = run_program_and_log_output(command, 3); 1610 paranoid_free(command); 1611 1664 1612 if (res) { 1665 1613 popup_and_OK 1666 (_("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.")); 1614 (_ 1615 ("You will now edit fstab and lilo.conf, to make sure they match your new mountlist.")); 1667 1616 for (done = FALSE; !done;) { 1668 1617 if (!g_text_mode) { 1669 1618 newtSuspend(); 1670 1619 } 1671 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1620 editor = find_my_editor(); 1621 asprintf(&tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1672 1622 paranoid_system(tmp); 1673 sprintf(tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor); 1623 paranoid_free(tmp); 1624 1625 asprintf(&tmp, "%s " MNT_RESTORING "/etc/lilo.conf", editor); 1626 paranoid_free(editor); 1627 1674 1628 paranoid_system(tmp); 1629 paranoid_free(tmp); 1630 1675 1631 if (!g_text_mode) { 1676 1632 newtResume(); … … 1699 1655 log_to_screen(_("lilo.conf and fstab were modified OK")); 1700 1656 } 1701 } else 1657 } else { 1702 1658 /* nuke mode */ 1703 {1704 1659 mvaddstr_and_log_it(g_currentY, 1705 1660 0, 1706 _("Running LILO... ")); 1661 _ 1662 ("Running LILO... ")); 1707 1663 res = 1708 1664 run_program_and_log_output("chroot " MNT_RESTORING " lilo -L", … … 1716 1672 mvaddstr_and_log_it(g_currentY++, 74, _("Failed.")); 1717 1673 log_to_screen 1718 (_("Failed to re-jig fstab and/or lilo. Edit/run manually, please.")); 1674 (_ 1675 ("Failed to re-jig fstab and/or lilo. Edit/run manually, please.")); 1719 1676 } else { 1720 1677 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); … … 1727 1684 " lilo -M /dev/sda", 3); 1728 1685 } 1729 paranoid_free(command);1730 paranoid_free(tmp);1731 paranoid_free(editor);1732 1686 return (res); 1733 1687 } … … 1746 1700 int run_raw_mbr(bool offer_to_hack_scripts, char *bd) 1747 1701 { 1748 /** malloc **/ 1749 char *command; 1750 char *boot_device; 1751 char *tmp; 1752 char *editor; 1753 int res; 1754 int done; 1755 1756 malloc_string(command); 1757 malloc_string(boot_device); 1758 malloc_string(tmp); 1759 malloc_string(editor); 1702 char *command = NULL; 1703 char *tmp = NULL; 1704 char *editor = NULL; 1705 int res = 0; 1706 int done = 0; 1707 1760 1708 assert_string_is_neither_NULL_nor_zerolength(bd); 1761 1709 1762 strcpy(editor, find_my_editor());1763 strcpy(boot_device, bd);1764 sprintf(command, "raw-MR %s /tmp/mountlist.txt", boot_device);1765 log_msg(2, "run_raw_mbr() --- command='%s'", command);1766 1767 1710 if (offer_to_hack_scripts 1768 && ask_me_yes_or_no(_("Did you change the mountlist?"))) 1711 && ask_me_yes_or_no(_("Did you change the mountlist?"))) { 1769 1712 /* interactive mode */ 1770 {1771 1713 mvaddstr_and_log_it(g_currentY, 0, 1772 _("Modifying fstab and restoring MBR... ")); 1714 _ 1715 ("Modifying fstab and restoring MBR... ")); 1773 1716 for (done = FALSE; !done;) { 1774 1717 if (!run_program_and_log_output("which vi", FALSE)) { … … 1777 1720 newtSuspend(); 1778 1721 } 1779 sprintf(tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1722 editor = find_my_editor(); 1723 asprintf(&tmp, "%s " MNT_RESTORING "/etc/fstab", editor); 1724 paranoid_free(editor); 1725 1780 1726 paranoid_system(tmp); 1727 paranoid_free(tmp); 1728 1781 1729 if (!g_text_mode) { 1782 1730 newtResume(); … … 1785 1733 } 1786 1734 popup_and_get_string(_("Boot device"), 1787 _ ("Please confirm/enter the boot device. If in doubt, try /dev/hda"),1788 boot_device, MAX_STR_LEN / 4);1789 sprintf(command, "stabraw-me %s", boot_device);1735 _ 1736 ("Please confirm/enter the boot device. If in doubt, try /dev/hda"), bd); 1737 asprintf(&command, "stabraw-me %s", bd); 1790 1738 res = run_program_and_log_output(command, 3); 1739 paranoid_free(command); 1740 1791 1741 if (res) { 1792 done = ask_me_yes_or_no(_("Modifications failed. Re-try?")); 1742 done = 1743 ask_me_yes_or_no(_("Modifications failed. Re-try?")); 1793 1744 } else { 1794 1745 done = TRUE; 1795 1746 } 1796 1747 } 1797 } else 1748 } else { 1798 1749 /* nuke mode */ 1799 {1800 1750 mvaddstr_and_log_it(g_currentY, 0, 1801 _("Restoring MBR... ")); 1751 _ 1752 ("Restoring MBR... ")); 1753 asprintf(&command, "raw-MR %s /tmp/mountlist.txt", bd); 1754 log_msg(2, "run_raw_mbr() --- command='%s'", command); 1802 1755 res = run_program_and_log_output(command, 3); 1756 paranoid_free(command); 1803 1757 } 1804 1758 if (res) { 1805 1759 mvaddstr_and_log_it(g_currentY++, 74, _("Failed.")); 1806 1760 log_to_screen 1807 (_("MBR+fstab processed w/error(s). See /tmp/mondo-restore.log for more info.")); 1761 (_ 1762 ("MBR+fstab processed w/error(s). See /tmp/mondo-restore.log for more info.")); 1808 1763 } else { 1809 1764 mvaddstr_and_log_it(g_currentY++, 74, _("Done.")); 1810 1765 } 1811 paranoid_free(command);1812 paranoid_free(boot_device);1813 paranoid_free(tmp);1814 paranoid_free(editor);1815 1766 return (res); 1816 1767 } 1817 1818 1768 /************************************************************************** 1819 1769 *END_RUN_RAW_MBR * 1820 1770 **************************************************************************/ 1821 1822 1823 1824 1771 1825 1772 … … 1858 1805 void setup_MR_global_filenames(struct s_bkpinfo *bkpinfo) 1859 1806 { 1860 char *temppath;1861 1862 1807 assert(bkpinfo != NULL); 1863 1808 1864 malloc_string(g_biggielist_txt);1865 malloc_string(g_filelist_full);1866 malloc_string(g_filelist_imagedevs);1867 malloc_string(g_imagedevs_restthese);1868 malloc_string(g_mondo_cfg_file);1869 malloc_string(g_mountlist_fname);1870 1809 malloc_string(g_tmpfs_mountpt); 1871 malloc_string(g_isodir_device); 1872 malloc_string(g_isodir_format); 1873 1874 temppath = bkpinfo->tmpdir; 1875 1876 sprintf(g_biggielist_txt, "%s/%s", temppath, BIGGIELIST_TXT_STUB); 1877 sprintf(g_filelist_full, "%s/%s", temppath, FILELIST_FULL_STUB); 1878 sprintf(g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", temppath); 1879 // sprintf(g_imagedevs_pot, "%s/tmp/imagedevs.pot", temppath); 1880 sprintf(g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these", 1881 temppath); 1810 1811 asprintf(&g_biggielist_txt, "%s/%s",bkpinfo->tmpdir , BIGGIELIST_TXT_STUB); 1812 asprintf(&g_filelist_full, "%s/%s", bkpinfo->tmpdir, FILELIST_FULL_STUB); 1813 asprintf(&g_filelist_imagedevs, "%s/tmp/filelist.imagedevs", bkpinfo->tmpdir); 1814 asprintf(&g_imagedevs_restthese, "%s/tmp/imagedevs.restore-these", 1815 bkpinfo->tmpdir); 1882 1816 if (bkpinfo->disaster_recovery) { 1883 sprintf(g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB); 1884 sprintf(g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB); 1885 } else { 1886 sprintf(g_mondo_cfg_file, "%s/%s", temppath, MONDO_CFG_FILE_STUB); 1887 sprintf(g_mountlist_fname, "%s/%s", temppath, 1888 MOUNTLIST_FNAME_STUB); 1889 } 1890 } 1891 1817 asprintf(&g_mondo_cfg_file, "/%s", MONDO_CFG_FILE_STUB); 1818 asprintf(&g_mountlist_fname, "/%s", MOUNTLIST_FNAME_STUB); 1819 } else { 1820 asprintf(&g_mondo_cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB); 1821 asprintf(&g_mountlist_fname, "%s/%s", bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB); 1822 } 1823 } 1892 1824 /************************************************************************** 1893 1825 *END_SET_GLOBAL_FILENAME * … … 1905 1837 FILE *fin; 1906 1838 FILE *fout; 1907 /** malloc **/ 1908 char *incoming;1839 char *incoming = NULL; 1840 size_t n = 0; 1909 1841 1910 1842 assert_string_is_neither_NULL_nor_zerolength(output_file); 1911 1843 assert_string_is_neither_NULL_nor_zerolength(input_file); 1912 malloc_string(incoming);1913 1844 1914 1845 if (!(fin = fopen(input_file, "r"))) { … … 1919 1850 fatal_error("cannot open output_file"); 1920 1851 } 1921 for ( fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);1922 fgets(incoming, MAX_STR_LEN - 1, fin)) {1852 for (getline(&incoming, &n, fin); !feof(fin); 1853 getline(&incoming, &n, fin)) { 1923 1854 if (strncmp(incoming, "etc/adjtime", 11) 1924 1855 && strncmp(incoming, "etc/mtab", 8) … … 1930 1861 fprintf(fout, "%s", incoming); /* don't need \n here, for some reason.. */ 1931 1862 } 1863 paranoid_free(incoming); 1932 1864 paranoid_fclose(fout); 1933 1865 paranoid_fclose(fin); 1934 paranoid_free(incoming); 1935 } 1936 1866 } 1937 1867 /************************************************************************** 1938 1868 *END_STREAMLINE_CHANGES_FILE * … … 1947 1877 { 1948 1878 log_to_screen 1949 (_("Mondorestore is terminating in response to a signal from the OS")); 1879 (_ 1880 ("Mondorestore is terminating in response to a signal from the OS")); 1950 1881 paranoid_MR_finish(254); 1951 1882 } 1952 1953 1883 /************************************************************************** 1954 1884 *END_TERMINATE_DAEMON * … … 1962 1892 { 1963 1893 int i; 1964 /* MALLOC * */ 1965 char *tmp; 1966 1967 malloc_string(tmp); 1894 char *tmp = NULL; 1895 1968 1896 if (does_file_exist("/tmp/NOPAUSE")) { 1969 1897 return; 1970 1898 } 1971 1899 open_progress_form(_("CAUTION"), 1972 _("Be advised: I am about to ERASE your hard disk(s)!"), 1900 _ 1901 ("Be advised: I am about to ERASE your hard disk(s)!"), 1973 1902 _("You may press Ctrl+Alt+Del to abort safely."), 1974 1903 "", 20); 1975 1904 for (i = 0; i < 20; i++) { 1976 1905 g_current_progress = i; 1977 sprintf(tmp, _("You have %d seconds left to abort."), 20 - i);1906 asprintf(&tmp, _("You have %d seconds left to abort."), 20 - i); 1978 1907 update_progress_form(tmp); 1908 paranoid_free(tmp); 1979 1909 sleep(1); 1980 1910 } 1981 1911 close_progress_form(); 1982 paranoid_free(tmp); 1983 } 1984 1912 } 1985 1913 /************************************************************************** 1986 1914 *END_TWENTY_SECONDS_TIL_YIKES * … … 1988 1916 1989 1917 1990 1991 1992 1993 1918 /** 1994 1919 * Exit due to a signal (no cleanup). … … 2001 1926 pthread_exit(0); 2002 1927 } 2003 2004 1928 /************************************************************************** 2005 1929 *END_TERMINATION_IN_PROGRESS * … … 2007 1931 2008 1932 2009 2010 1933 /** 2011 1934 * Unmount all devices in @p p_external_copy_of_mountlist. … … 2017 1940 { 2018 1941 struct mountlist_itself *mountlist; 2019 int retval = 0, lino, res = 0, i; 2020 char *command; 2021 char *tmp; 2022 2023 malloc_string(command); 2024 malloc_string(tmp); 1942 int retval = 0; 1943 int lino = 0; 1944 int res = 0; 1945 int i = 0; 1946 char *command = NULL; 1947 char *tmp = NULL; 1948 char *tmp1 = NULL; 1949 2025 1950 assert(p_external_copy_of_mountlist != NULL); 2026 1951 … … 2034 1959 open_progress_form(_("Unmounting devices"), 2035 1960 _("Unmounting all devices that were mounted,"), 2036 _("in preparation for the post-restoration reboot."), 1961 _ 1962 ("in preparation for the post-restoration reboot."), 2037 1963 "", mountlist->entries); 2038 1964 chdir("/"); … … 2047 1973 } 2048 1974 2049 paranoid_system("sync");1975 sync(); 2050 1976 2051 1977 if (run_program_and_log_output … … 2067 1993 continue; 2068 1994 } 2069 sprintf(tmp, _("Unmounting device %s "), mountlist->el[lino].device); 1995 asprintf(&tmp, _("Unmounting device %s "), 1996 mountlist->el[lino].device); 2070 1997 2071 1998 update_progress_form(tmp); 1999 2072 2000 if (is_this_device_mounted(mountlist->el[lino].device)) { 2073 2001 if (!strcmp(mountlist->el[lino].mountpoint, "swap")) { 2074 sprintf(command, "swapoff %s", mountlist->el[lino].device);2002 asprintf(&command, "swapoff %s", mountlist->el[lino].device); 2075 2003 } else { 2076 2004 if (!strcmp(mountlist->el[lino].mountpoint, "/1")) { 2077 sprintf(command, "umount %s/", MNT_RESTORING);2005 asprintf(&command, "umount %s/", MNT_RESTORING); 2078 2006 log_msg(3, 2079 2007 "Well, I know a certain kitty-kitty who'll be sleeping with Mommy tonight..."); 2080 2008 } else { 2081 sprintf(command, "umount " MNT_RESTORING "%s",2009 asprintf(&command, "umount " MNT_RESTORING "%s", 2082 2010 mountlist->el[lino].mountpoint); 2083 2011 } … … 2085 2013 log_msg(10, "The 'umount' command is '%s'", command); 2086 2014 res = run_program_and_log_output(command, 3); 2015 paranoid_free(command); 2087 2016 } else { 2088 strcat(tmp, _("...not mounted anyway :-) OK")); 2017 asprintf(&tmp1, "%s%s", tmp, _("...not mounted anyway :-) OK")); 2018 paranoid_free(tmp); 2019 tmp = tmp1; 2089 2020 res = 0; 2090 2021 } 2091 2022 g_current_progress++; 2092 2023 if (res) { 2093 strcat(tmp, _("...Failed")); 2024 asprintf(&tmp1, "%s%s", tmp, _("...Failed")); 2025 paranoid_free(tmp); 2026 tmp = tmp1; 2094 2027 retval++; 2095 2028 log_to_screen(tmp); … … 2097 2030 log_msg(2, tmp); 2098 2031 } 2032 paranoid_free(tmp); 2099 2033 } 2100 2034 close_progress_form(); … … 2110 2044 } 2111 2045 free(mountlist); 2112 paranoid_free(command);2113 paranoid_free(tmp);2114 2046 return (retval); 2115 2047 } 2116 2117 2048 /************************************************************************** 2118 2049 *END_UNMOUNT_ALL_DEVICES * 2119 2050 **************************************************************************/ 2120 2121 2051 2122 2052 … … 2129 2059 int extract_cfg_file_and_mountlist_from_tape_dev(char *dev) 2130 2060 { 2131 char *command ;2061 char *command = NULL; 2132 2062 int res = 0; 2133 // B CO: below 32KB seems to block at least on RHAS 2.1 and MDK 10.02063 // BERLIOS: below 32KB seems to block at least on RHAS 2.1 and MDK 10.0 2134 2064 long tape_block_size = 32768; 2135 2065 2136 malloc_string(command);2137 2138 2066 // tar -zxvf- 2139 sprintf(command,2067 asprintf(&command, 2140 2068 "dd if=%s bs=%ld count=%ld 2> /dev/null | tar -zx %s %s %s %s %s", 2141 2069 dev, … … 2146 2074 log_msg(2, "command = '%s'", command); 2147 2075 res = run_program_and_log_output(command, -1); 2076 paranoid_free(command); 2077 2148 2078 if (res != 0 && does_file_exist(MONDO_CFG_FILE_STUB)) { 2149 2079 res = 0; 2150 2080 } 2151 paranoid_free(command);2152 2081 return (res); 2153 2082 } 2154 2155 2083 2156 2084 … … 2166 2094 { 2167 2095 int retval = 0; 2168 2169 /** malloc *****/ 2170 char *device; 2171 char *command; 2172 char *cfg_file; 2173 char *mounted_cfgf_path; 2174 char *tmp; 2175 char *sav; 2176 char *mountpt; 2177 char *ramdisk_fname; 2178 char *mountlist_file; 2179 int res; 2096 char *device = NULL; 2097 char *command = NULL; 2098 char *cfg_file = NULL; 2099 char *mounted_cfgf_path = NULL; 2100 char *tmp = NULL; 2101 char *tmp1 = NULL; 2102 char *sav = NULL; 2103 char *mountpt = NULL; 2104 char *ramdisk_fname = NULL; 2105 char *mountlist_file = NULL; 2106 int res = 0; 2180 2107 2181 2108 bool try_plan_B; 2182 2109 2183 2110 assert(bkpinfo != NULL); 2184 malloc_string(cfg_file);2185 malloc_string(mounted_cfgf_path);2186 malloc_string(mountpt);2187 malloc_string(ramdisk_fname);2188 malloc_string(mountlist_file);2189 malloc_string(device);2190 malloc_string(command);2191 malloc_string(tmp);2192 2111 log_msg(2, "gcffa --- starting"); 2193 2112 log_to_screen(_("I'm thinking...")); 2194 sprintf(mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir); 2195 device[0] = '\0'; 2113 asprintf(&mountpt, "%s/mount.bootdisk", bkpinfo->tmpdir); 2196 2114 chdir(bkpinfo->tmpdir); 2197 strcpy(cfg_file, MONDO_CFG_FILE_STUB); 2198 unlink(cfg_file); // cfg_file[] is missing the '/' at the start, FYI, by intent 2115 // MONDO_CFG_FILE_STUB is missing the '/' at the start, FYI, by intent 2116 unlink(MONDO_CFG_FILE_STUB); 2117 2199 2118 unlink(FILELIST_FULL_STUB); 2200 2119 unlink(BIGGIELIST_TXT_STUB); 2201 2120 unlink("tmp/i-want-my-lvm"); 2202 sprintf(command, "mkdir -p %s", mountpt);2121 asprintf(&command, "mkdir -p %s", mountpt); 2203 2122 run_program_and_log_output(command, FALSE); 2204 2205 // unlink( "tmp/mondo-restore.cfg" ); // superfluous, surely? 2206 2207 sprintf(cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB); 2208 sprintf(mountlist_file, "%s/%s", bkpinfo->tmpdir, 2123 paranoid_free(command); 2124 2125 asprintf(&cfg_file, "%s/%s", bkpinfo->tmpdir, MONDO_CFG_FILE_STUB); 2126 asprintf(&mountlist_file, "%s/%s", bkpinfo->tmpdir, 2209 2127 MOUNTLIST_FNAME_STUB); 2210 // make_hole_for_file( cfg_file );2211 // make_hole_for_file( mountlist_file);2212 2128 log_msg(2, "mountpt = %s; cfg_file=%s", mountpt, cfg_file); 2213 2129 2214 2130 /* Floppy? */ 2215 sprintf(tmp, "mkdir -p %s", mountpt);2131 asprintf(&tmp, "mkdir -p %s", mountpt); 2216 2132 run_program_and_log_output(tmp, FALSE); 2217 sprintf(tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir); 2133 paranoid_free(tmp); 2134 2135 asprintf(&tmp, "mkdir -p %s/tmp", bkpinfo->tmpdir); 2218 2136 run_program_and_log_output(tmp, FALSE); 2219 2220 sprintf(command, "mount /dev/fd0u1722 %s", mountpt); 2221 sprintf(tmp, 2137 paranoid_free(tmp); 2138 2139 asprintf(&command, "mount /dev/fd0u1722 %s", mountpt); 2140 asprintf(&tmp, 2222 2141 "(sleep 15; kill `ps ax | grep \"%s\" | cut -d' ' -f1` 2> /dev/null) &", 2223 2142 command); 2224 2143 log_msg(1, "tmp = '%s'", tmp); 2225 2144 system(tmp); 2145 paranoid_free(tmp); 2146 2226 2147 res = run_program_and_log_output(command, FALSE); 2148 paranoid_free(command); 2149 2227 2150 if (res) { 2228 sprintf(command, "mount /dev/fd0H1440 %s", mountpt);2151 asprintf(&command, "mount /dev/fd0H1440 %s", mountpt); 2229 2152 res = run_program_and_log_output(command, FALSE); 2153 paranoid_free(command); 2230 2154 } 2231 2155 if (res) { … … 2237 2161 // NB: If busybox does not support 'mount -o loop' then Plan A WILL NOT WORK. 2238 2162 log_msg(2, "Processing floppy (plan A?)"); 2239 sprintf(ramdisk_fname, "%s/mindi.rdz", mountpt);2163 asprintf(&ramdisk_fname, "%s/mindi.rdz", mountpt); 2240 2164 if (!does_file_exist(ramdisk_fname)) { 2241 sprintf(ramdisk_fname, "%s/initrd.img", mountpt); 2165 paranoid_free(ramdisk_fname); 2166 asprintf(&ramdisk_fname, "%s/initrd.img", mountpt); 2242 2167 } 2243 2168 if (!does_file_exist(ramdisk_fname)) { … … 2250 2175 "Warning - failed to extract config file from ramdisk. I think this boot disk is mangled."); 2251 2176 } 2252 sprintf(command, "umount %s", mountpt);2177 asprintf(&command, "umount %s", mountpt); 2253 2178 run_program_and_log_output(command, 5); 2179 paranoid_free(command); 2180 2254 2181 unlink(ramdisk_fname); 2182 paranoid_free(ramdisk_fname); 2255 2183 } 2256 2184 if (!does_file_exist(cfg_file)) { … … 2277 2205 run_program_and_log_output("mkdir -p tmp", FALSE); 2278 2206 2279 if (strlen(bkpinfo->media_device) == 0) { 2280 paranoid_alloc(bkpinfo->media_device, "/dev/st0"); 2281 log_msg(2, "media_device is blank; assuming %s", bkpinfo->media_device); 2282 } 2283 asprintf(&sav,bkpinfo->media_device); 2207 if (bkpinfo->media_device == NULL) { 2208 asprintf(&bkpinfo->media_device, "/dev/st0"); 2209 log_msg(2, "media_device is blank; assuming %s", 2210 bkpinfo->media_device); 2211 } 2212 asprintf(&sav, bkpinfo->media_device); 2284 2213 if (extract_cfg_file_and_mountlist_from_tape_dev 2285 2214 (bkpinfo->media_device)) { … … 2303 2232 2304 2233 if (!does_file_exist("tmp/mondo-restore.cfg")) { 2305 log_to_screen(_("Cannot find config info on tape/CD/floppy")); 2234 log_to_screen(_ 2235 ("Cannot find config info on tape/CD/floppy")); 2306 2236 return (1); 2307 2237 } … … 2309 2239 log_msg(2, 2310 2240 "gcffa --- looking at mounted CD for mindi-boot.2880.img"); 2311 sprintf(command, 2241 /* BERLIOS : Useless ? 2242 asprintf(&command, 2312 2243 "mount " MNT_CDROM 2313 2244 "/images/mindi-boot.2880.img -o loop %s", mountpt); 2314 sprintf(mounted_cfgf_path, "%s/%s", mountpt, cfg_file); 2245 */ 2246 asprintf(&mounted_cfgf_path, "%s/%s", mountpt, cfg_file); 2315 2247 if (!does_file_exist(mounted_cfgf_path)) { 2316 2248 log_msg(2, 2317 2249 "gcffa --- Plan C, a.k.a. untarring some file from all.tar.gz"); 2318 sprintf(command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm"); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary2250 asprintf(&command, "tar -zxvf " MNT_CDROM "/images/all.tar.gz %s %s %s %s %s", MOUNTLIST_FNAME_STUB, MONDO_CFG_FILE_STUB, BIGGIELIST_TXT_STUB, FILELIST_FULL_STUB, "tmp/i-want-my-lvm"); // add -b TAPE_BLOCK_SIZE if you _really_ think it's necessary 2319 2251 run_program_and_log_output(command, TRUE); 2252 paranoid_free(command); 2253 2320 2254 if (!does_file_exist(MONDO_CFG_FILE_STUB)) { 2321 2255 fatal_error … … 2323 2257 } 2324 2258 } 2325 } 2326 } 2259 paranoid_free(mounted_cfgf_path); 2260 } 2261 } 2262 paranoid_free(mountpt); 2263 2327 2264 if (does_file_exist(MONDO_CFG_FILE_STUB)) { 2328 2265 log_msg(1, "gcffa --- great! We've got the config file"); 2329 sprintf(tmp, "%s/%s", 2330 call_program_and_get_last_line_of_output("pwd"), 2331 MONDO_CFG_FILE_STUB); 2332 sprintf(command, "cp -f %s %s", tmp, cfg_file); 2266 tmp1 = call_program_and_get_last_line_of_output("pwd"); 2267 asprintf(&tmp, "%s/%s", tmp1,MONDO_CFG_FILE_STUB); 2268 asprintf(&command, "cp -f %s %s", tmp, cfg_file); 2333 2269 iamhere(command); 2270 2334 2271 if (strcmp(tmp, cfg_file) 2335 2272 && run_program_and_log_output(command, 1)) { … … 2340 2277 log_msg(1, "... and I moved it successfully to %s", cfg_file); 2341 2278 } 2342 sprintf(command, "cp -f %s/%s %s", 2343 call_program_and_get_last_line_of_output("pwd"), 2279 paranoid_free(command); 2280 2281 asprintf(&command, "cp -f %s/%s %s",tmp1, 2344 2282 MOUNTLIST_FNAME_STUB, mountlist_file); 2283 paranoid_free(tmp1); 2284 2345 2285 iamhere(command); 2346 2286 if (strcmp(tmp, cfg_file) … … 2349 2289 } else { 2350 2290 log_msg(1, "Got mountlist too"); 2351 sprintf(command, "cp -f %s %s", mountlist_file, 2291 paranoid_free(command); 2292 asprintf(&command, "cp -f %s %s", mountlist_file, 2352 2293 g_mountlist_fname); 2353 2294 if (run_program_and_log_output(command, 1)) { … … 2355 2296 } else { 2356 2297 log_msg(1, "Copied mountlist to /tmp as well OK"); 2357 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/"); 2298 paranoid_free(command); 2299 asprintf(&command, "cp -f tmp/i-want-my-lvm /tmp/"); 2358 2300 run_program_and_log_output(command, 1); 2359 /* sprintf(command, "grep \" lvm \" %s", g_mountlist_fname); 2360 if (!run_program_and_log_output(command, 5) && !does_file_exist("/tmp/i-want-my-lvm")) 2361 { 2362 log_msg(1, "Warning. You want LVM but I don't have i-want-my-lvm. FIXME."); 2363 } 2364 else if (run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm")) 2365 { 2366 log_msg(1, "Warning. You don't want LVM but i-want-my-lvm exists. I'll delete it. Cool."); 2367 do_my_funky_lvm_stuff(TRUE, FALSE); // ...after I stop any LVMs :) 2368 stop_raid_device("/dev/md0"); 2369 stop_raid_device("/dev/md1"); 2370 stop_raid_device("/dev/md2"); 2371 unlink("/tmp/i-want-my-lvm"); 2372 } 2373 else if (!run_program_and_log_output(command,5) && does_file_exist("/tmp/i-want-my-lvm")) 2374 { 2375 log_msg(1, "You had better pray that i-want-my-lvm patches your mountlist. FIXME."); 2376 } 2377 */ 2378 } 2379 } 2301 } 2302 } 2303 paranoid_free(command); 2304 paranoid_free(tmp); 2380 2305 } 2381 2306 run_program_and_log_output("umount " MNT_CDROM, FALSE); … … 2384 2309 log_msg(1, "%s not found", cfg_file); 2385 2310 log_to_screen 2386 (_("Oh dear. Unable to recover configuration file from boot disk")); 2311 (_ 2312 ("Oh dear. Unable to recover configuration file from boot disk")); 2387 2313 return (1); 2388 2314 } … … 2394 2320 /* start SAH */ 2395 2321 else { 2396 sprintf(command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB,2322 asprintf(&command, "cp -f %s %s/%s", MOUNTLIST_FNAME_STUB, 2397 2323 bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB); 2398 2324 run_program_and_log_output(command, FALSE); 2399 } 2400 /*--commented out by SAH 2401 sprintf( command, "cp -f %s %s/%s", cfg_file, bkpinfo->tmpdir, MONDO_CFG_FILE_STUB ); 2402 run_program_and_log_output( command, FALSE ); 2403 sprintf( command, "cp -f %s %s/%s", mountlist_file, bkpinfo->tmpdir, MOUNTLIST_FNAME_STUB ); 2404 run_program_and_log_output( command, FALSE ); 2405 */ 2325 paranoid_free(command); 2326 } 2406 2327 /* end SAH */ 2407 2328 2408 sprintf(command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB); 2329 asprintf(&command, "cp -f %s /%s", cfg_file, MONDO_CFG_FILE_STUB); 2330 paranoid_free(cfg_file); 2331 2409 2332 run_program_and_log_output(command, FALSE); 2410 sprintf(command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB); 2333 paranoid_free(command); 2334 2335 asprintf(&command, "cp -f %s /%s", mountlist_file, MOUNTLIST_FNAME_STUB); 2336 paranoid_free(mountlist_file); 2337 2411 2338 run_program_and_log_output(command, FALSE); 2412 sprintf(command, "cp -f etc/raidtab /etc/"); 2339 paranoid_free(command); 2340 2341 asprintf(&command, "cp -f etc/raidtab /etc/"); 2413 2342 run_program_and_log_output(command, FALSE); 2414 sprintf(command, "cp -f tmp/i-want-my-lvm /tmp/"); 2343 paranoid_free(command); 2344 2345 asprintf(&command, "cp -f tmp/i-want-my-lvm /tmp/"); 2415 2346 run_program_and_log_output(command, FALSE); 2347 paranoid_free(command); 2348 2416 2349 g_backup_media_type = bkpinfo->backup_media_type; 2417 paranoid_free(device);2418 paranoid_free(command);2419 paranoid_free(tmp);2420 paranoid_free(cfg_file);2421 paranoid_free(mounted_cfgf_path);2422 paranoid_free(mountpt);2423 paranoid_free(ramdisk_fname);2424 paranoid_free(mountlist_file);2425 2350 return (retval); 2426 2351 } 2427 2428 2352 /************************************************************************** 2429 2353 *END_GET_CFG_FILE_FROM_ARCHIVE * 2430 2354 **************************************************************************/ 2431 2432 2355 /* @} - end restoreUtilityGroup */ 2433 2434 2435 /***************************************************************************2436 * F@ *2437 * () -- Hugo Rabson *2438 * *2439 * Purpose: *2440 * *2441 * Called by: *2442 * Params: - - *2443 * Returns: 0=success; nonzero=failure *2444 ***************************************************************************/2445 2446 2356 2447 2357 … … 2449 2359 int wait_for_percentage) 2450 2360 { 2451 struct raidlist_itself *raidlist; 2452 int unfinished_mdstat_devices = 9999, i; 2453 char *screen_message; 2454 2455 malloc_string(screen_message); 2361 struct raidlist_itself *raidlist = NULL; 2362 int unfinished_mdstat_devices = 9999, i = 0; 2363 char *screen_message = NULL; 2364 2456 2365 raidlist = malloc(sizeof(struct raidlist_itself)); 2457 2366 … … 2461 2370 if (parse_mdstat(raidlist, "/dev/")) { 2462 2371 log_to_screen("Sorry, cannot read %s", MDSTAT_FILE); 2463 log_msg(1, "Sorry, cannot read %s", MDSTAT_FILE);2372 log_msg(1, "Sorry, cannot read %s", MDSTAT_FILE); 2464 2373 return; 2465 2374 } 2466 for (unfinished_mdstat_devices = i = 0; i <= raidlist->entries; i++) { 2375 for (unfinished_mdstat_devices = i = 0; i <= raidlist->entries; 2376 i++) { 2467 2377 if (raidlist->el[i].progress < wait_for_percentage) { 2468 2378 unfinished_mdstat_devices++; 2469 log_msg(1,"Sync'ing %s (i=%d)", raidlist->el[i].raid_device, i); 2470 sprintf(screen_message, "Sync'ing %s", 2379 log_msg(1, "Sync'ing %s (i=%d)", 2380 raidlist->el[i].raid_device, i); 2381 asprintf(&screen_message, "Sync'ing %s", 2471 2382 raidlist->el[i].raid_device); 2472 2383 open_evalcall_form(screen_message); 2384 paranoid_free(screen_message); 2385 2473 2386 if (raidlist->el[i].progress == -1) // delayed while another partition inits 2474 2387 { … … 2476 2389 } 2477 2390 while (raidlist->el[i].progress < wait_for_percentage) { 2478 log_msg(1,"Percentage sync'ed: %d", raidlist->el[i].progress); 2391 log_msg(1, "Percentage sync'ed: %d", 2392 raidlist->el[i].progress); 2479 2393 update_evalcall_form(raidlist->el[i].progress); 2480 2394 sleep(2); … … 2488 2402 } 2489 2403 } 2490 paranoid_free(screen_message);2491 2404 paranoid_free(raidlist); 2492 2405 }
Note:
See TracChangeset
for help on using the changeset viewer.