Changeset 1187 in MondoRescue


Ignore:
Timestamp:
Feb 20, 2007, 3:03:33 AM (17 years ago)
Author:
Bruno Cornec
Message:

Merge trunk memory management for mondoarchive
Rename main.c to mondoarchive.c

Location:
branches/stable/mondo/src/mondoarchive
Files:
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/mondoarchive/Makefile.am

    r1170 r1187  
    1111## The program
    1212sbin_PROGRAMS        = mondoarchive
    13 mondoarchive_SOURCES = main.c mondo-cli.c
     13mondoarchive_SOURCES = mondoarchive.c mondo-cli.c
    1414mondoarchive_LDADD   = ${top_builddir}/src/common/libmondo.a ${top_builddir}/src/lib/libmr.a
  • branches/stable/mondo/src/mondoarchive/mondo-cli.c

    r1164 r1187  
    1010/** @def BOOT_LOADER_CHARS The characters allowed for boot loader on this platform. */
    1111
     12#include "my-stuff.h"
     13#include "mondostructures.h"
     14#include "mondo-cli-EXT.h"
     15#include "libmondo.h"
    1216#include <pthread.h>
    13 #include "my-stuff.h"
    14 #include "../common/mondostructures.h"
    15 #include "mondo-cli-EXT.h"
    16 #include "../common/libmondo.h"
    1717#include "mr_mem.h"
    1818#include "mr_msg.h"
     
    5050 */
    5151bool g_ISO_restore_mode = FALSE;
    52 
    5352
    5453extern double g_kernel_version;
     
    8079    int res = 0;
    8180    int retval = 0;
    82     int i = 0, j;
     81    int i = 0, j = 0;
    8382
    8483    /*@ buffers *************** */
    85     char *tmp;
     84    char *tmp = NULL;
    8685    char flag_val[128][MAX_STR_LEN];
    8786    bool flag_set[128];
    8887
    89     malloc_string(tmp);
    9088    sensibly_set_tmpdir_and_scratchdir(bkpinfo);
     89
    9190    for (i = 0; i < 128; i++) {
    9291        flag_val[i][0] = '\0';
    9392        flag_set[i] = FALSE;
    9493    }
    95     //  strcpy (bkpinfo->tmpdir, "/root/images/mondo");
    96     //  strcpy (bkpinfo->scratchdir, "/home");
    9794    for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
    9895        bkpinfo->media_size[j] = 650;
     
    113110    for (i = 0; i < 128; i++) {
    114111        if (flag_set[i]) {
    115             sprintf(tmp, "-%c %s", i, flag_val[i]);
    116             mr_msg(3, tmp);
     112            mr_msg(3, "-%c %s", i, flag_val[i]);
    117113        }
    118114    }
    119115//    }
    120     sprintf(tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir);
     116    mr_asprintf(&tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir);
    121117    paranoid_system(tmp);
    122     sprintf(tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir);
     118    mr_free(tmp);
     119
     120    mr_asprintf(&tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir);
    123121    paranoid_system(tmp);
     122    mr_free(tmp);
     123
    124124    sprintf(bkpinfo->tmpdir + strlen(bkpinfo->tmpdir), "/tmp.mondo.%ld",
    125125            random() % 32767);
    126126    sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir),
    127127            "/mondo.scratch.%ld", random() % 32767);
    128     sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
     128
     129    mr_asprintf(&tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
    129130    paranoid_system(tmp);
    130     sprintf(tmp, "mkdir -p %s", bkpinfo->scratchdir);
     131    mr_free(tmp);
     132
     133    mr_asprintf(&tmp, "mkdir -p %s", bkpinfo->scratchdir);
    131134    paranoid_system(tmp);
    132135    mr_free(tmp);
    133136    return (retval);
    134137}
    135 
    136 
    137138
    138139
     
    165166        bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p);
    166167    }
    167 //      bkpinfo->media_size[0] = bkpinfo->media_size[MAX_NOOF_MEDIA];
    168168    for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
    169169        if (bkpinfo->media_size[j] <= 0) {
     
    174174    return (0);
    175175}
    176 
    177176
    178177
  • branches/stable/mondo/src/mondoarchive/mondoarchive.c

    r1183 r1187  
    2222#include "mondo-cli-EXT.h"
    2323
     24#include "mr_mem.h"
    2425#include "mr_str.h"
    2526#include "mr_msg.h"
     
    112113        ("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2);
    113114    unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted
    114     //  stop_autofs_if_necessary(); // for Xandros users
    115115    mount_boot_if_necessary();  // for Gentoo users with non-mounted /boot partitions
    116116    clean_up_KDE_desktop_if_necessary();    // delete various misc ~/.* files that get in the way
    117117}
    118 
    119118
    120119
     
    124123void distro_specific_kludges_at_end_of_mondoarchive(void)
    125124{
    126 //  char tmp[500];
    127125    mr_msg(2, "Restarting magicdev if necessary");
    128126    sync();
    129127    restart_magicdev_if_necessary();    // for RH+Gnome users
    130128
    131     mr_msg(2, "Restarting autofs if necessary");
    132     sync();
    133     //  restart_autofs_if_necessary(); // for Xandros users
    134 
    135129    mr_msg(2, "Restarting supermounts if necessary");
    136130    sync();
     
    140134    sync();
    141135    unmount_boot_if_necessary();    // for Gentoo users
    142 
    143 //  mr_msg( 2, "Cleaning up KDE desktop");
    144 //  clean_up_KDE_desktop_if_necessary();
    145136}
    146137
     
    158149    struct stat stbuf;
    159150    char *tmp = NULL;
    160     int res, retval;
    161     char *say_at_end;
    162 
     151    int res = 0;
     152    int retval = 0;
     153    char *say_at_end = NULL;
     154
     155#ifdef ENABLE_NLS
     156    setlocale(LC_ALL, "");
     157    (void) textdomain("mondo");
     158#endif
    163159/* Make sure I'm root; abort if not */
    164160    if (getuid() != 0) {
    165         fprintf(stderr, "Please run as root.\r\n");
     161        fprintf(stderr, _("Please run as root.\n"));
    166162        exit(127);
    167163    }
    168164
    169 /* If -V, -v or --version then echo version no. and quit */
     165    /* If -V, -v or --version then echo version no. and quit */
    170166    if (argc == 2
    171167        && (!strcmp(argv[argc - 1], "-v") || !strcmp(argv[argc - 1], "-V")
    172168            || !strcmp(argv[argc - 1], "--version"))) {
    173         printf("mondoarchive v%s\nSee man page for help\n", PACKAGE_VERSION);
     169        printf(_("mondoarchive v%s\nSee man page for help\n"), PACKAGE_VERSION);
    174170        exit(0);
    175171    }
    176172
    177 /* Initialize variables */
    178 
     173    /* Initialize variables */
    179174    malloc_libmondo_global_strings();
    180     malloc_string(say_at_end);
    181175
    182176    res = 0;
    183177    retval = 0;
    184178    diffs = 0;
    185     say_at_end[0] = '\0';
    186     printf("Initializing...\n");
     179    printf(_("Initializing...\n"));
    187180
    188181    /* initialize log file with time stamp */
     
    225218        setup_newt_stuff();
    226219        if (!strstr(argv[2], "filelist")) {
    227             printf("Sorry - filelist goes first\n");
     220            mr_msg(1,_("Sorry - filelist goes first\n"));
    228221            finish(1);
    229222        } else {
     
    255248        setup_newt_stuff();
    256249        if (!strstr(argv[2], "filelist")) {
    257             printf("Sorry - filelist goes first\n");
     250            mr_msg(1,_("Sorry - filelist goes first\n"));
    258251            finish(1);
    259252        } else {
     
    275268        malloc_string(tmp);
    276269        if (find_cdrw_device(tmp)) {
    277             printf("Failed to find CDR-RW drive\n");
    278         } else {
    279             printf("CD-RW is at %s\n", tmp);
     270            mr_msg(1,_("Failed to find CDR-RW drive\n"));
     271        } else {
     272            mr_msg(1,_("CD-RW is at %s\n"), tmp);
    280273        }
    281274        tmp[0] = '\0';
    282275        if (find_cdrom_device(tmp, atoi(argv[2]))) {
    283             printf("Failed to find CD-ROM drive\n");
    284         } else {
    285             printf("CD-ROM is at %s\n", tmp);
     276            mr_msg(1,_("Failed to find CD-ROM drive\n"));
     277        } else {
     278            mr_msg(1,_("CD-ROM is at %s\n"), tmp);
    286279        }
    287280        mr_free(tmp);
     
    295288        malloc_string(tmp);
    296289        if (find_dvd_device(tmp, atoi(argv[2]))) {
    297             printf("Failed to find DVD drive\n");
    298         } else {
    299             printf("DVD is at %s\n", tmp);
     290            mr_msg(1,_("Failed to find DVD drive\n"));
     291        } else {
     292            mr_msg(1,_("DVD is at %s\n"), tmp);
    300293        }
    301294        mr_free(tmp);
     
    309302    if (argc > 2 && !strcmp(argv[1], "test-dev")) {
    310303        if (is_dev_an_NTFS_dev(argv[2])) {
    311             printf("%s is indeed an NTFS dev\n", argv[2]);
    312         } else {
    313             printf("%s is _not_ an NTFS dev\n", argv[2]);
     304            mr_msg(1,_("%s is indeed an NTFS dev\n"), argv[2]);
     305        } else {
     306            mr_msg(1,_("%s is _not_ an NTFS dev\n"), argv[2]);
    314307        }
    315308        finish(0);
     
    335328        res = handle_incoming_parameters(argc, argv, bkpinfo);
    336329        if (res) {
    337             printf
    338                 ("Errors were detected in the command line you supplied.\n");
    339             printf("Please review the log file - " MONDO_LOGFILE "\n");
     330            mr_msg(1,
     331                _("Errors were detected in the command line you supplied.\n"));
     332            mr_msg(1,_("Please review the log file - %s \n"),MONDO_LOGFILE);
    340333            mr_msg(1, "Mondoarchive will now exit.");
    341334            finish(1);
     
    351344
    352345    log_to_screen
    353         ("BusyBox's sources are available from http://www.busybox.net");
     346        (_("BusyBox's sources are available from http://www.busybox.net"));
     347
    354348    sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
    355349            bkpinfo->scratchdir);
     
    360354        retval += res;
    361355        if (res) {
    362             strcat(say_at_end,
    363                    "Data archived. Please check the logs, just as a precaution. ");
    364         } else {
    365             strcat(say_at_end, "Data archived OK. ");
    366         }
    367     }
    368 
    369 /* If we're meant to verify then verify */
     356            mr_strcat(say_at_end,
     357                   _("Data archived. Please check the logs, just as a precaution. "));
     358        } else {
     359            mr_strcat(say_at_end, _("Data archived OK. "));
     360        }
     361    }
     362
     363    /* If we're meant to verify then verify */
    370364    if (bkpinfo->verify_data) {
    371365        res = verify_data(bkpinfo);
    372366        if (res < 0) {
    373             mr_asprintf(&tmp, "%d difference%c found.", -res,
     367            mr_strcat(say_at_end, _("%d difference%c found."), -res,
    374368                    (-res != 1) ? 's' : ' ');
    375             strcat(say_at_end, tmp);
    376             log_to_screen(tmp);
    377             mr_free(tmp);
    378369            res = 0;
    379370        }
     
    381372    }
    382373
    383 /* Offer to write floppy disk images to physical disks */
     374    /* Offer to write floppy disk images to physical disks */
    384375    if (bkpinfo->backup_data && !g_skip_floppies) {
    385376        res = offer_to_write_boot_floppies_to_physical_disks(bkpinfo);
    386377        retval += res;
    387 //      res = offer_to_write_boot_ISO_to_physical_CD(bkpinfo);
    388 //      retval += res;
    389     }
    390 
    391 /* Report result of entire operation (success? errors?) */
     378    }
     379
     380    /* Report result of entire operation (success? errors?) */
    392381    if (!retval) {
    393382        mvaddstr_and_log_it(g_currentY++, 0,
    394                             "Backup and/or verify ran to completion. Everything appears to be fine.");
     383                            _("Backup and/or verify ran to completion. Everything appears to be fine."));
    395384    } else {
    396385        mvaddstr_and_log_it(g_currentY++, 0,
    397                             "Backup and/or verify ran to completion. However, errors did occur.");
     386                            _("Backup and/or verify ran to completion. However, errors did occur."));
    398387    }
    399388
    400389    if (does_file_exist("/var/cache/mindi/mondorescue.iso")) {
    401390        log_to_screen
    402             ("/var/cache/mindi/mondorescue.iso, a boot/utility CD, is available if you want it.");
     391            (_("/var/cache/mindi/mondorescue.iso, a boot/utility CD, is available if you want it."));
    403392    }
    404393
     
    407396        if (g_text_mode) {
    408397            log_to_screen
    409                 ("Type 'less /tmp/changed.files' to see which files don't match the archives");
     398                (_("Type 'less /tmp/changed.files' to see which files don't match the archives"));
    410399        } else {
    411400            mr_msg(1,
    412                     "Type 'less /tmp/changed.files' to see which files don't match the archives");
     401                    _("Type 'less /tmp/changed.files' to see which files don't match the archives"));
    413402            mr_msg(2, "Calling popup_changelist_from_file()");
    414403            popup_changelist_from_file("/tmp/changed.files");
     
    419408    }
    420409    log_to_screen(say_at_end);
     410    mr_free(say_at_end);
     411
    421412    mr_asprintf(&tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
    422413    run_program_and_log_output(tmp, TRUE);
     
    429420    system("rm -Rf /tmp.mondo.* /mondo.scratch.*");
    430421    if (!retval) {
    431         printf("Mondoarchive ran OK.\n");
     422        printf(_("Mondoarchive ran OK.\n"));
    432423    } else {
    433         printf("Errors occurred during backup. Please check logfile.\n");
     424        printf(_("Errors occurred during backup. Please check logfile.\n"));
    434425    }
    435426    distro_specific_kludges_at_end_of_mondoarchive();
     
    439430    system(g_erase_tmpdir_and_scratchdir);
    440431    free_libmondo_global_strings();
    441     mr_free(say_at_end);
    442432    mr_free(bkpinfo);
    443433
     
    453443
    454444    /* finalize log file with time stamp */
    455     mr_msg(0, "Time finished: %s", mr_date());
     445    mr_msg(1, "Time finished: %s", mr_date());
    456446    mr_msg_close();
    457447
    458448    if (!g_text_mode) {
    459449        popup_and_OK
    460             ("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt.");
    461         log_to_screen("See %s for details of backup run.", MONDO_LOGFILE);
     450            (_("Mondo Archive has finished its run. Please press ENTER to return to the shell prompt."));
     451        log_to_screen(_("See %s for details of backup run."), MONDO_LOGFILE);
    462452        finish(retval);
    463453    } else {
    464         printf("See %s for details of backup run.\n", MONDO_LOGFILE);
     454        printf(_("See %s for details of backup run.\n"), MONDO_LOGFILE);
    465455        exit(retval);
    466456    }
Note: See TracChangeset for help on using the changeset viewer.