Changeset 171 in MondoRescue for trunk/mondo/mondo/mondoarchive/main.c


Ignore:
Timestamp:
Dec 8, 2005, 5:20:29 PM (18 years ago)
Author:
bcornec
Message:

memory management continues:

  • mondoarchive handled completely
  • bkpinfo, begining of dyn. alloc.
  • lot of changes around memory everywhere

=> even if it compiles, i'm pretty sure it doesn't work yet (even not tried)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/mondoarchive/main.c

    r170 r171  
    1 /***************************************************************************
    2                           main.c  -  description
    3                              -------------------
    4     begin                : Fri Apr 19 16:40:35 EDT 2002
    5     copyright            : (C) 2002 by Stan Benoit
    6     email                : troff@nakedsoul.org
    7     cvsid                : $Id$
    8  ***************************************************************************/
    9 
    10 /***************************************************************************
     1/*
     2 * $Id$
    113 *                                                                         *
    124 *   This program is free software; you can redistribute it and/or modify  *
     
    157 *   (at your option) any later version.                                   *
    168 *                                                                         *
    17  ***************************************************************************/
    18 
    19 /** change log ****** MONDO-DEVEL
    20 
    21 
    22 12/10
    23 - disable stopping/starting of autofs
    24 
    25 10/01
    26 - update g_erase_tmpdir_and_scratchdir to delete user-specified tmpdir, scratchdir
    27 
    28 06/19
    29 - added AUX_VER
    30 
    31 06/14/2004
    32 - use mondorescue.iso, not mindi.iso
    33 
    34 02/10/2004
    35 - tell users where BusyBox's sources are
    36 
    37 11/14/2003
    38 - cleaned up logging at end#
    39 
    40 10/23
    41 - don't try to test-read tape ... That's already
    42   handled by post_param_configuration()
    43  
    44 10/19
    45 - if your PATH var is too long, abort
    46 
    47 09/23
    48 - added some comments
    49 - malloc/free global strings in new subroutines - malloc_libmondo_global_strings()
    50   and free_libmondo_global_strings() - which are in libmondo-tools.c
    51 - better magicdev support
    52 
    53 
    54 09/16
    55 - delete /var/log/partimagehack-debug.log at start of main()
    56 
    57 09/15
    58 - added askbootloader
    59 
    60 09/09
    61 - if your tape is weird, I'll pause between backup and verify
    62 - fixed silly bug in main() - re: say_at_end
    63 
    64 01/01 - 08/31
    65 - call 'dmesg -n1' at start, to shut the kernel logger up
    66 - moved g_erase_tmpdir_and_scratchdir to common/newt-specific.c
    67 - added 'don't panic' msg to start of logfile
    68 - added 'nice(20)' to main()
    69 - added lots of assert()'s and log_OS_error()'s
    70 - clean-up (Hugo)
    71 - make post_param_configuration() setup g_erase_tmpdir_and_scratchdir
    72 - if --version then print & exit quickly
    73 - re-run g_erase_tmpdir_and_scratchdir via system() at very end
    74 
    75 Year: 2002
    76 - if user goes root with 'su' instead of 'su -' then
    77   workaround it by setting PATH correctly
    78 - wipe mondoarchive.log at very beginning
    79 - cleaned up code
    80 - if changed.files.N exists then copy to changes.files for display
    81 - run_program_and_log_output() now takes boolean operator to specify
    82   whether it will log its activities in the event of _success_
    83 - added popup list of changed files
    84 - removed 'beta-quality' warnings
    85 - if kernel not found and mondo in graphics mode then popup and ask
    86   for kernel path+filename
    87 - fixed tmp[] 'too small' bug
    88 - unmount and eject CD at end of verify cycle
    89 - moved interactively_obtain...() to libmondo-stream.c
    90 - wrote stuff to autodetect tape+cdrw+etc.
    91 - renamed from main.c to mondo-archive.c
    92 - fore+after warnings that this code is beta-quality
    93 - abort if running from ramdisk
    94 - remount floppy at end & unmount at start if Mandrake
    95 - took out #debug stuff
    96 - add 2> /dev/null to 'find' command
    97 - add support for bkpinfo->nonbootable_backup
    98 - add main function begin comment and debug conditional
    99   compilation - Stan Benoit
    100 - add debug statements to build a run tree. Stan Benoit
    101 **** end change log **********/
    102 
    103 
    104 /**
    105  * @file
     9 ***************************************************************************
    10610 * The main file for mondoarchive.
    10711 */
     
    11115#include <pthread.h>
    11216#endif
    113 //#include <config.h>
    114 //#include "../../config.h"
    11517#include <stdio.h>
    11618#include <stdlib.h>
     
    14143extern char *g_tmpfs_mountpt;
    14244extern char *g_erase_tmpdir_and_scratchdir;
    143 extern char *g_cdrw_drive_is_here;
    144 static char *g_cdrom_drive_is_here = NULL;
    145 static char *g_dvd_drive_is_here = NULL;
    14645extern double g_kernel_version;
    14746
     
    211110        ("umount `mount | grep shm | grep mondo | cut -d' ' -f3`", 2);
    212111    unmount_supermounts_if_necessary(); // for Mandrake users whose CD-ROMs are supermounted
    213     //  stop_autofs_if_necessary(); // for Xandros users
    214112    mount_boot_if_necessary();  // for Gentoo users with non-mounted /boot partitions
    215113    clean_up_KDE_desktop_if_necessary();    // delete various misc ~/.* files that get in the way
    216114}
    217 
    218115
    219116
     
    223120void distro_specific_kludges_at_end_of_mondoarchive()
    224121{
    225 //  char tmp[500];
    226122    log_msg(2, "Restarting magicdev if necessary");
    227123    sync();
    228124    restart_magicdev_if_necessary();    // for RH+Gnome users
    229125
    230     log_msg(2, "Restarting autofs if necessary");
    231     sync();
    232     //  restart_autofs_if_necessary(); // for Xandros users
    233 
    234126    log_msg(2, "Restarting supermounts if necessary");
    235127    sync();
     
    239131    sync();
    240132    unmount_boot_if_necessary();    // for Gentoo users
    241 
    242 //  log_msg( 2, "Cleaning up KDE desktop");
    243 //  clean_up_KDE_desktop_if_necessary();
    244133}
    245 
    246 
    247 /*-----------------------------------------------------------*/
    248 
    249134
    250135
     
    257142    struct s_bkpinfo *bkpinfo;
    258143    char *tmp;
    259     int res, retval;
    260     char *say_at_end;
     144    int res = 0;
     145    int retval = 0;
     146    char *say_at_end = NULL;
    261147
    262148/* Make sure I'm root; abort if not */
     
    277163
    278164    malloc_libmondo_global_strings();
    279     malloc_string(tmp);
    280     malloc_string(say_at_end);
    281 
    282     res = 0;
    283     retval = 0;
     165
    284166    diffs = 0;
    285     say_at_end[0] = '\0';
    286167    unlink("/var/log/partimagehack-debug.log");
    287168    printf("Initializing...\n");
     
    292173
    293174/* make sure PATH environmental variable allows access to mkfs, fdisk, etc. */
    294     strncpy(tmp, getenv("PATH"), MAX_STR_LEN - 1);
    295     tmp[MAX_STR_LEN - 1] = '\0';
    296     if (strlen(tmp) >= MAX_STR_LEN - 33) {
    297         fatal_error
    298             ("Your PATH environmental variable is too long. Please shorten it.");
    299     }
    300     strcat(tmp, ":/sbin:/usr/sbin:/usr/local/sbin");
     175    asprintf(&tmp, "/sbin:/usr/sbin:%s:/usr/local/sbin", getenv("PATH"));
    301176    setenv("PATH", tmp, 1);
     177    paranoid_free(tmp);
    302178
    303179/* Add the ARCH environment variable for ia64 purposes */
    304     strncpy(tmp, get_architecture(), MAX_STR_LEN - 1);
    305     tmp[MAX_STR_LEN - 1] = '\0';
    306     setenv("ARCH", tmp, 1);
     180    setenv("ARCH", get_architecture(), 1);
    307181
    308182    unlink(MONDO_LOGFILE);
     
    339213    if (argc == 4 && !strcmp(argv[1], "setfattr")) {
    340214        g_loglevel = 10;
    341 //      chdir("/tmp");
    342215        g_text_mode = TRUE;
    343216        setup_newt_stuff();
     
    351224        turn_wildcard_chars_into_literal_chars(tmp, argv[2]);
    352225        printf("in=%s; out=%s\n", argv[2], tmp);
     226        paranoid_free(tmp);
    353227        finish(1);
    354228    }
     
    368242    if (argc == 4 && !strcmp(argv[1], "setfacl")) {
    369243        g_loglevel = 10;
    370 //      chdir("/tmp");
    371244        g_text_mode = TRUE;
    372245        setup_newt_stuff();
     
    378251        g_text_mode = TRUE;
    379252        setup_newt_stuff();
    380         if (find_cdrw_device(tmp)) {
     253        if ((tmp = find_cdrw_device()) == NULL) {
    381254            printf("Failed to find CDR-RW drive\n");
    382255        } else {
    383256            printf("CD-RW is at %s\n", tmp);
    384257        }
    385         tmp[0] = '\0';
    386         if (find_cdrom_device(tmp, atoi(argv[2]))) {
     258        paranoid_free(tmp);
     259
     260        if ((tmp = find_cdrom_device(FALSE)) == NULL) {
    387261            printf("Failed to find CD-ROM drive\n");
    388262        } else {
    389263            printf("CD-ROM is at %s\n", tmp);
    390264        }
     265        paranoid_free(tmp);
    391266        finish(0);
    392267    }
     
    396271        g_text_mode = TRUE;
    397272        setup_newt_stuff();
    398         if (find_dvd_device(tmp, atoi(argv[2]))) {
     273        if ((tmp = find_dvd_device()) == NULL) {
    399274            printf("Failed to find DVD drive\n");
    400275        } else {
    401276            printf("DVD is at %s\n", tmp);
    402277        }
     278        paranoid_free(tmp);
    403279        finish(0);
    404280    }
     
    451327    log_to_screen
    452328        ("BusyBox's sources are available from http://www.busybox.net");
    453     sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
    454             bkpinfo->scratchdir);
    455329
    456330    /* If we're meant to backup then backup */
    457331    if (bkpinfo->backup_data) {
    458 /*
    459       log_to_screen("INFERNAL PORPOISES");
    460       res = archive_this_fileset_with_star(bkpinfo, "/tmp/filelist.0", "/tmp/0.star.bz2", 0);
    461       log_to_screen("atfws returned %d", res);
    462       finish(0);
    463 */
    464332        res = backup_data(bkpinfo);
    465333        retval += res;
    466334        if (res) {
    467             strcat(say_at_end,
     335            asprintf(&say_at_end,
    468336                   "Data archived. Please check the logs, just as a precaution. ");
    469337        } else {
    470             strcat(say_at_end, "Data archived OK. ");
     338            asprintf(&say_at_end, "Data archived OK. ");
    471339        }
    472340    }
     
    476344        res = verify_data(bkpinfo);
    477345        if (res < 0) {
    478             sprintf(tmp, "%d difference%c found.", -res,
     346            asprintf(&say_at_end, "%d difference%c found.", -res,
    479347                    (-res != 1) ? 's' : ' ');
    480             strcat(say_at_end, tmp);
    481             log_to_screen(tmp);
    482348            res = 0;
    483349        }
     
    485351    }
    486352
    487 /* Offer to write floppy disk images to physical disks */
     353    /* Offer to write floppy disk images to physical disks */
    488354    if (bkpinfo->backup_data && !g_skip_floppies) {
    489355        res = offer_to_write_boot_floppies_to_physical_disks(bkpinfo);
    490356        retval += res;
    491 //      res = offer_to_write_boot_ISO_to_physical_CD(bkpinfo);
    492 //      retval += res;
    493     }
    494 
    495 /* Report result of entire operation (success? errors?) */
    496     if (!retval) {
     357    }
     358
     359    /* Report result of entire operation (success? errors?) */
     360    if (retval == 0) {
    497361        mvaddstr_and_log_it(g_currentY++, 0,
    498362                            "Backup and/or verify ran to completion. Everything appears to be fine.");
     
    523387    }
    524388    log_to_screen(say_at_end);
    525     sprintf(tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
     389    paranoid_free(say_at_end);
     390
     391    asprintf(&tmp, "umount %s/tmpfs", bkpinfo->tmpdir);
    526392    run_program_and_log_output(tmp, TRUE);
     393    paranoid_free(tmp);
     394
     395    sprintf(g_erase_tmpdir_and_scratchdir, "rm -Rf %s %s", bkpinfo->tmpdir,
     396            bkpinfo->scratchdir);
    527397    run_program_and_log_output(g_erase_tmpdir_and_scratchdir, TRUE);
    528398
     
    531401    system("rm -f /var/cache/mondo-archive/last-backup.aborted");
    532402    system("rm -Rf /tmp.mondo.* /mondo.scratch.*");
    533     if (!retval) {
     403    if (retval == 0) {
    534404        printf("Mondoarchive ran OK.\n");
    535405    } else {
     
    542412    system(g_erase_tmpdir_and_scratchdir);
    543413    free_libmondo_global_strings();
    544     paranoid_free(say_at_end);
    545     paranoid_free(tmp);
    546414    paranoid_free(bkpinfo);
    547415
    548416    unlink("/tmp/filelist.full");
    549417    unlink("/tmp/filelist.full.gz");
    550 
    551     if (!g_cdrom_drive_is_here) {
    552         log_msg(10, "FYI, g_cdrom_drive_is_here was never used");
    553     }
    554     if (!g_dvd_drive_is_here) {
    555         log_msg(10, "FYI, g_dvd_drive_is_here was never used");
    556     }
    557418
    558419    run_program_and_log_output("date", 1);
Note: See TracChangeset for help on using the changeset viewer.