Changeset 2211 in MondoRescue for branches/2.2.9/mondo/src/mondorestore/mondo-rstr-tools.c
- Timestamp:
- Jun 3, 2009, 7:10:19 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2.9/mondo/src/mondorestore/mondo-rstr-tools.c
r2206 r2211 1 1 /*************************************************************************** 2 2 $Id$ 3 4 ***************************************************************************5 * *6 * This program is free software; you can redistribute it and/or modify *7 * it under the terms of the GNU General Public License as published by *8 * the Free Software Foundation; either version 2 of the License, or *9 * (at your option) any later version. *10 * *11 3 ***************************************************************************/ 12 4 … … 14 6 #include <linux/fd.h> 15 7 #include "my-stuff.h" 8 #include "mr_mem.h" 16 9 #include "../common/mondostructures.h" 17 10 #include "../common/libmondo.h" … … 284 277 int iso_fiddly_bits(bool nuke_me_please) 285 278 { 286 char *mount_isodir_command, *tmp, *command; 279 char *mount_isodir_command = NULL; 280 char *tmp, *command; 287 281 int retval = 0, i; 288 282 bool already_mounted = FALSE; 289 283 290 284 assert(bkpinfo != NULL); 291 malloc_string(mount_isodir_command);292 285 malloc_string(tmp); 293 286 malloc_string(command); … … 295 288 read_cfg_var(g_mondo_cfg_file, "iso-dev", g_isodir_device); 296 289 if (bkpinfo->disaster_recovery) { 297 /* Patch Conor Daly 26-june-2004 298 * Don't let this clobber an existing bkpinfo->isodir */ 299 if (!bkpinfo->isodir[0]) { 300 strcpy(bkpinfo->isodir, "/tmp/isodir"); 301 } 302 /* End patch */ 303 sprintf(command, "mkdir -p %s", bkpinfo->isodir); 304 run_program_and_log_output(command, 5); 305 log_msg(2, "Setting isodir to %s", bkpinfo->isodir); 306 } 307 308 if (!get_isodir_info 309 (g_isodir_device, g_isodir_format, bkpinfo->isodir, 310 nuke_me_please)) { 311 return (1); 290 /* Patch Conor Daly 26-june-2004 291 * Don't let this clobber an existing bkpinfo->isodir */ 292 if (!bkpinfo->isodir[0]) { 293 strcpy(bkpinfo->isodir, "/tmp/isodir"); 294 } 295 /* End patch */ 296 sprintf(command, "mkdir -p %s", bkpinfo->isodir); 297 run_program_and_log_output(command, 5); 298 log_msg(2, "Setting isodir to %s", bkpinfo->isodir); 299 } 300 301 if (!get_isodir_info(g_isodir_device, g_isodir_format, bkpinfo->isodir, nuke_me_please)) { 302 return (1); 312 303 } 313 304 paranoid_system("umount " MNT_CDROM " 2> /dev/null"); /* just in case */ 314 305 315 306 if (is_this_device_mounted(g_isodir_device)) { 316 log_to_screen("WARNING - isodir is already mounted");317 already_mounted = TRUE;307 log_to_screen("WARNING - isodir is already mounted"); 308 already_mounted = TRUE; 318 309 } else { 319 sprintf(mount_isodir_command, "mount %s", g_isodir_device); 320 if (strlen(g_isodir_format) > 1) { 321 sprintf(mount_isodir_command + strlen(mount_isodir_command), 322 " -t %s", g_isodir_format); 323 } 324 strcat(mount_isodir_command, " -o ro "); 325 strcat(mount_isodir_command, bkpinfo->isodir); 326 run_program_and_log_output("df -m", FALSE); 327 sprintf(tmp, 310 mr_asprintf(&mount_isodir_command, "mount %s", g_isodir_device); 311 if (strlen(g_isodir_format) > 1) { 312 mr_strcat(mount_isodir_command, " -t %s", g_isodir_format); 313 } 314 mr_strcat(mount_isodir_command, " -o ro %s", bkpinfo->isodir); 315 run_program_and_log_output("df -m", FALSE); 316 sprintf(tmp, 328 317 "The 'mount' command is '%s'. PLEASE report this command to be if you have problems, ok?", 329 318 mount_isodir_command); 330 log_msg(1, tmp); 331 if (run_program_and_log_output(mount_isodir_command, FALSE)) { 332 popup_and_OK 333 ("Cannot mount the device where the ISO files are stored."); 334 return (1); 335 } 336 log_to_screen 319 log_msg(1, tmp); 320 if (run_program_and_log_output(mount_isodir_command, FALSE)) { 321 popup_and_OK 322 ("Cannot mount the device where the ISO files are stored."); 323 return (1); 324 } 325 paranoid_free(mount_isodir_command); 326 log_to_screen 337 327 ("I have mounted the device where the ISO files are stored."); 338 328 } … … 351 341 log_msg(2, "%ld: bkpinfo->isodir is now %s", __LINE__, 352 342 bkpinfo->isodir); 353 paranoid_free(mount_isodir_command);354 343 paranoid_free(tmp); 355 344 paranoid_free(command); … … 385 374 386 375 /** malloc **/ 387 char *tmp, *command, *mountdir, *mountpoint, *additional_parameters; 376 char *tmp, *command, *mountdir, *mountpoint; 377 char *additional_parameters = NULL; 388 378 389 379 assert_string_is_neither_NULL_nor_zerolength(device); … … 394 384 malloc_string(mountdir); 395 385 malloc_string(mountpoint); 396 malloc_string(additional_parameters);397 386 398 387 if (!strcmp(mpt, "/1")) { … … 412 401 log_msg(1, tmp); 413 402 /* Deal with additional params only if not /proc or /sys */ 403 mr_asprintf(&additional_parameters, ""); 414 404 if (strcmp(format, "proc") && strcmp(format, "sys")) { 415 405 if (writeable) { 416 strcpy(additional_parameters, "-o rw");406 mr_strcat(additional_parameters, "-o rw"); 417 407 } else { 418 strcpy(additional_parameters, "-o ro");408 mr_strcat(additional_parameters, "-o ro"); 419 409 } 420 410 if (find_home_of_exe("setfattr")) { 421 strcat(additional_parameters, ",user_xattr");411 mr_strcat(additional_parameters, ",user_xattr"); 422 412 } 423 413 if (find_home_of_exe("setfacl")) { 424 strcat(additional_parameters, ",acl");414 mr_strcat(additional_parameters, ",acl"); 425 415 } 426 416 } … … 440 430 log_msg(2, "command='%s'", command); 441 431 } 432 paranoid_free(additional_parameters); 442 433 443 434 res = run_program_and_log_output(command, TRUE); … … 479 470 paranoid_free(mountdir); 480 471 paranoid_free(mountpoint); 481 paranoid_free(additional_parameters);482 472 483 473 return (res); … … 498 488 { 499 489 int retval = 0, lino, res; 500 char *tmp, *these_failed, *format; 501 struct mountlist_itself *mountlist = NULL; 490 char *tmp; 491 char *these_failed = NULL; 492 char *format; 493 struct mountlist_itself *mountlist = NULL; 502 494 503 495 malloc_string(tmp); 504 496 malloc_string(format); 505 malloc_string(these_failed);506 /** menset **/507 these_failed[0] = '\0';508 497 509 498 assert(p_external_copy_of_mountlist != NULL); … … 520 509 "", mountlist->entries); 521 510 511 mr_asprintf(&these_failed, ""); 522 512 for (lino = 0; lino < mountlist->entries; lino++) { 523 513 if (!strcmp(mountlist->el[lino].device, "/proc")) { … … 540 530 retval += res; 541 531 if (res) { 542 strcat(these_failed, mountlist->el[lino].device); 543 strcat(these_failed, " "); 532 mr_strcat(these_failed, "%s ",mountlist->el[lino].device); 544 533 } 545 534 } … … 556 545 ("format and restore *without* partitioning first. Sorry for the inconvenience."); 557 546 } 558 sprintf(tmp, "Could not mount device(s) %s- shall I abort?", 559 these_failed); 547 sprintf(tmp, "Could not mount device(s) %s- shall I abort?", these_failed); 560 548 561 549 if (!ask_me_yes_or_no(tmp)) { … … 573 561 mvaddstr_and_log_it(g_currentY++, 74, "Done."); 574 562 } 563 paranoid_free(these_failed); 564 575 565 /* Also mounting under MNT_RESTORING special FS */ 576 566 (void)mount_device("/proc","/proc","proc",TRUE); … … 580 570 paranoid_free(tmp); 581 571 paranoid_free(format); 582 paranoid_free(these_failed);583 572 return (retval); 584 573 } … … 896 885 read_cfg_var(cfg_file, "acl", value); 897 886 if (strstr(value, "TRUE")) { 898 asprintf(&g_getfacl,"setfacl");887 mr_asprintf(&g_getfacl,"setfacl"); 899 888 log_msg(1, "We will restore ACLs"); 900 889 if (! find_home_of_exe("setfacl")) { … … 904 893 read_cfg_var(cfg_file, "xattr", value); 905 894 if (strstr(value, "TRUE")) { 906 asprintf(&g_getfattr,"setfattr");895 mr_asprintf(&g_getfattr,"setfattr"); 907 896 log_msg(1, "We will restore XATTRs"); 908 897 if (! find_home_of_exe("setfattr")) { … … 1398 1387 * the current /dev location 1399 1388 */ 1400 asprintf(&cmd,"tar cf - /dev | ( cd %s ; tar xf - )",MNT_RESTORING);1389 mr_asprintf(&cmd,"tar cf - /dev | ( cd %s ; tar xf - )",MNT_RESTORING); 1401 1390 run_program_and_log_output(cmd, 3); 1402 1391 paranoid_free(cmd); … … 1410 1399 read_cfg_var(g_mondo_cfg_file, "bootloader.device", device); 1411 1400 read_cfg_var(g_mondo_cfg_file, "bootloader.name", name); 1412 asprintf(&tmp, "run_boot_loader: device='%s', name='%s'", device, name);1401 mr_asprintf(&tmp, "run_boot_loader: device='%s', name='%s'", device, name); 1413 1402 log_msg(2, tmp); 1414 1403 paranoid_free(tmp); … … 1427 1416 #ifdef __FreeBSD__ 1428 1417 else if (!strcmp(name, "BOOT0")) { 1429 asprintf(&tmp, "boot0cfg -B %s", device);1418 mr_asprintf(&tmp, "boot0cfg -B %s", device); 1430 1419 res = run_program_and_log_output(tmp, FALSE); 1431 1420 paranoid_free(tmp); 1432 1421 } else { 1433 asprintf(&tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device);1422 mr_asprintf(&tmp, "ls /dev | grep -Eq '^%ss[1-4].*'", device); 1434 1423 if (!system(tmp)) { 1435 1424 paranoid_free(tmp); 1436 asprintf(&tmp, MNT_RESTORING "/sbin/fdisk -B %s", device);1425 mr_asprintf(&tmp, MNT_RESTORING "/sbin/fdisk -B %s", device); 1437 1426 res = run_program_and_log_output(tmp, 3); 1438 1427 } else { … … 2019 2008 int retval = 0, lino, res = 0, i; 2020 2009 char *command; 2021 char *tmp ;2010 char *tmp = NULL; 2022 2011 2023 2012 malloc_string(command); 2024 malloc_string(tmp);2025 2013 assert(p_external_copy_of_mountlist != NULL); 2026 2014 … … 2049 2037 paranoid_system("sync"); 2050 2038 2051 sprintf(tmp, "cp -f %s " MNT_RESTORING "/var/log", MONDO_LOGFILE);2039 mr_asprintf(&tmp, "cp -f %s " MNT_RESTORING "/var/log", MONDO_LOGFILE); 2052 2040 if (run_program_and_log_output(tmp, FALSE)) { 2053 2041 log_msg(1, 2054 2042 "Error. Failed to copy log to PC's /var/log dir. (Mounted read-only?)"); 2055 2043 } 2044 paranoid_free(tmp); 2056 2045 if (does_file_exist("/tmp/DUMBASS-GENTOO")) { 2057 2046 run_program_and_log_output("mkdir -p " MNT_RESTORING … … 2067 2056 continue; 2068 2057 } 2069 sprintf(tmp, "Unmounting device %s ", mountlist->el[lino].device);2058 mr_asprintf(&tmp, "Unmounting device %s ", mountlist->el[lino].device); 2070 2059 2071 2060 update_progress_form(tmp); 2061 2072 2062 if (is_this_device_mounted(mountlist->el[lino].device)) { 2073 2063 if (!strcmp(mountlist->el[lino].mountpoint, "swap")) { … … 2094 2084 res = run_program_and_log_output(command, 3); 2095 2085 } else { 2096 strcat(tmp, "...not mounted anyway :-) OK");2086 mr_strcat(tmp, "...not mounted anyway :-) OK"); 2097 2087 res = 0; 2098 2088 } 2099 2089 g_current_progress++; 2100 2090 if (res) { 2101 strcat(tmp, "...Failed");2091 mr_strcat(tmp, "...Failed"); 2102 2092 retval++; 2103 2093 log_to_screen(tmp); … … 2105 2095 log_msg(2, tmp); 2106 2096 } 2097 paranoid_free(tmp); 2107 2098 } 2108 2099 close_progress_form(); … … 2119 2110 free(mountlist); 2120 2111 paranoid_free(command); 2121 paranoid_free(tmp);2122 2112 return (retval); 2123 2113 }
Note:
See TracChangeset
for help on using the changeset viewer.