Changeset 171 in MondoRescue for trunk/mondo/mondo/mondoarchive


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)

Location:
trunk/mondo/mondo/mondoarchive
Files:
4 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);
  • trunk/mondo/mondo/mondoarchive/mondo-cli-EXT.h

    r59 r171  
    55extern int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value);
    66extern int process_switches(struct s_bkpinfo *bkpinfo,
    7                             char flag_val[128][MAX_STR_LEN],
     7                            char *flag_val[128],
    88                            bool flag_set[128]);
    99extern int retrieve_switches_from_command_line(int argc, char *argv[],
    1010                                               char
    11                                                flag_val[128][MAX_STR_LEN],
     11                                               *flag_val[128],
    1212                                               bool flag_set[128]);
    1313extern void help_screen();
  • trunk/mondo/mondo/mondoarchive/mondo-cli.c

    r146 r171  
    11/***************************************************************************
    2 mondo-cli.c
    3 -------------------
    4 begin                : Fri Apr 19 16:40:35 EDT 2002
    5 copyright        : (C) 2002 Mondo  Hugo Rabson
    6 email                : Hugo Rabson <hugorabson@msn.com>
    7 edited by            : by Stan Benoit 4/2002
    8 email                : troff@nakedsoul.org
    9 cvsid                : $Id$
    10  ***************************************************************************/
    11 
    12 /***************************************************************************
    13  *                                                                         *
    14  *   This program is free software; you can redistribute it and/or modify  *
    15  *   it under the terms of the GNU General Public License as published by  *
    16  *   the Free Software Foundation; either version 2 of the License, or     *
    17  *   (at your option) any later version.                                   *
    18  *                                                                         *
    19  ***************************************************************************/
    20 
    21 /***************************************************************************
    22 UPDATE LOG
    23 
    24 
    25 08/04
    26 - if user specifies a dumb -T value, abort
    27 
    28 07/22
    29 - handle -Q sensibly (don't abort if only -Q supplied)
    30 
    31 07/17
    32 - better checking of NFS dir's validity
    33 
    34 06/19
    35 - added AUX_VER
    36 
    37 04/17
    38 - added '-b' support
    39 04/03
    40 - added star support
    41 
    42 02/06
    43 - fixed "Please give /dev entry" error msg
    44 
    45 01/20/2004
    46 - added 2.6.x-kernel "device = /dev/...." support to param reader
    47 - better handling of SCSI and /dev entries
    48 - touch /boot/boot.b if necessary
    49 
    50 09/26/2003
    51 - typo in command-line handling of 'r'
    52 
    53 09/25
    54 - added DVD write support
    55 
    56 09/24
    57 - if tape backup (-t) but user doesn't specify tape drive then
    58   make an educated guess using find_tape_device_and_size()
    59 
    60 09/18
    61 - insist on partimagehack being present if -x found
    62 
    63 09/16
    64 - added support for multiple -I's and -E's in call to mondoarchive
    65 - the '-D' flag doesn't take a value now
    66 
    67 07/14
    68 - fatal error if -E too short
    69 
    70 05/14
    71 - if 'n' and user doesn't have rights to write to output dir
    72   then error out
    73 
    74 05/05
    75 - added Joshua Oreman's FreeBSD patches
    76 
    77 05/04
    78 - added Herman Kuster's multi-level bkp patch
    79 
    80 05/02
    81 - write errors to screen, not just to log
    82 
    83 04/25
    84 - added lots of assert()'s and log_OS_error()'s
    85 
    86 04/21
    87 - line 570 --- resolve boot device if softlink
    88 
    89 04/08
    90 - changed a bunch of fprintf(stderr,...)'s to log_it()'s
    91 - fixed final / removal in retrieve_switches_from_command_line()
    92 
    93 04/04
    94 - added -e
    95 
    96 03/15
    97 - reject relative paths if -d flag (Alessandro Polverini)
    98 
    99 01/02/2003
    100 - added -J flag (to let user specify incoming filelist)
    101 
    102 12/13/2002
    103 - various strcpy() calls replaced with strncpy() calls
    104 
    105 12/10
    106 - added g_loglevel
    107 
    108 11/25
    109 - line 614 --- if commmand-line param ends in '/' then drop that '/'
    110 
    111 11/19
    112 - rewrote finish() to kill processes more softly
    113 - if user calls with '-l RAW' then
    114 
    115 09/01 - 09/30
    116 - added -N to let user exclude all NFS-related mounts and devices
    117 - run_program_and_log_output() now takes boolean operator to specify
    118   whether it will log its activities in the event of _success_
    119 
    120 08/01 - 08/31
    121 - if no device specified when backing up to tape streamer then assume /dev/st0
    122 - abort if tape user specifies tape size (just for testing porpoises)
    123 - tape users no longer need to specify tape size
    124 - added some comments
    125 - added bkpinfo->backup_media_type
    126 - renamed from mondo-archive.c to mondo-cli.c
    127 
    128 07/01 - 07/31
    129 - better check for mkfs.vfat
    130 - more sanity-checking for -d flag
    131 - if isodir does not exist then abort
    132 - removed "the rest are..." comment from log
    133 - do not permit '-H' and '-t' in the same command line
    134 - if not '-o' then insist on vfat-friendly kernel
    135 
    136 06/01 - 06/30
    137 - added signal-trapping
    138 - added '-W' (won't make bootable CD or floppies) flag
    139 - added missing 'j++' to -s switch's code
    140 - expanded -s switch
    141 - added -u switch
    142 - if dvdrecord exists and cdrecord doesn't then use
    143   dvdrecord instead of cdrecord
    144 
    145 04/01 - 04/30
    146 - if CD-ROM is supermounted then unmount, run, and remount
    147 - replace MONDO_VERSION #define with VERSION from ../config.h
    148 - if CD-ROM is mounted at start then abort
    149 - improved homedir-locating code
    150 - improved "backup will occupy N CD's" calculation a bit
    151 - added -m (manual CD tray) flag
    152 
    153 
    154 *******************************************************************/
    155 
    156 /**
    157  * @file
     2 * $Id$
     3 *
    1584 * Functions for handling command-line arguments passed to mondoarchive.
    1595 */
     
    18026extern bool g_skip_floppies;    ///< Whether to skip the creation of boot disks
    18127extern char g_startdir[MAX_STR_LEN];    ///< ????? @bug ?????
    182 extern char g_erase_tmpdir_and_scratchdir[MAX_STR_LEN];
    18328extern char g_tmpfs_mountpt[MAX_STR_LEN];
    18429extern bool g_sigpipe;
     
    24590    /*@ buffers *************** */
    24691    char *tmp;
    247     char flag_val[128][MAX_STR_LEN];
     92    char *flag_val[128];
    24893    bool flag_set[128];
    24994
    250     malloc_string(tmp);
    25195    sensibly_set_tmpdir_and_scratchdir(bkpinfo);
     96
    25297    for (i = 0; i < 128; i++) {
    253         flag_val[i][0] = '\0';
     98        flag_val[i] = NULL;
    25499        flag_set[i] = FALSE;
    255100    }
    256     //  strcpy (bkpinfo->tmpdir, "/root/images/mondo");
    257     //  strcpy (bkpinfo->scratchdir, "/home");
    258101    for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
    259102        bkpinfo->media_size[j] = 650;
     
    275118    for (i = 0; i < 128; i++) {
    276119        if (flag_set[i]) {
    277             sprintf(tmp, "-%c %s", i, flag_val[i]);
     120            asprintf(&tmp, "-%c %s", i, flag_val[i]);
    278121            log_msg(3, tmp);
     122            paranoid_free(tmp);
    279123        }
    280124    }
    281125//    }
    282     sprintf(tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir);
     126    asprintf(&tmp, "rm -Rf %s/tmp.mondo.*", bkpinfo->tmpdir);
    283127    paranoid_system(tmp);
    284     sprintf(tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir);
     128    paranoid_free(tmp);
     129
     130    asprintf(&tmp, "rm -Rf %s/mondo.scratch.*", bkpinfo->scratchdir);
    285131    paranoid_system(tmp);
     132    paranoid_free(tmp);
     133
    286134    sprintf(bkpinfo->tmpdir + strlen(bkpinfo->tmpdir), "/tmp.mondo.%ld",
    287135            random() % 32767);
    288136    sprintf(bkpinfo->scratchdir + strlen(bkpinfo->scratchdir),
    289137            "/mondo.scratch.%ld", random() % 32767);
    290     sprintf(tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
     138
     139    asprintf(&tmp, "mkdir -p %s/tmpfs", bkpinfo->tmpdir);
    291140    paranoid_system(tmp);
    292     sprintf(tmp, "mkdir -p %s", bkpinfo->scratchdir);
     141    paranoid_free(tmp);
     142
     143    asprintf(&tmp, "mkdir -p %s", bkpinfo->scratchdir);
    293144    paranoid_system(tmp);
     145    paranoid_free(tmp);
     146
    294147    if (bkpinfo->nfs_mount[0] != '\0') {
    295148        store_nfs_config(bkpinfo);
    296149    }
    297     paranoid_free(tmp);
    298150    return (retval);
    299151}
    300 
    301 
    302152
    303153
     
    312162{
    313163    int j;
    314     char tmp[MAX_STR_LEN], *p, comment[MAX_STR_LEN];
     164    char *tmp;
     165    char *p;
     166    char *q;
     167    char *comment;
    315168
    316169    assert(bkpinfo != NULL);
     
    320173    for (j = 1, p = value; j < MAX_NOOF_MEDIA && strchr(p, ',');
    321174         j++, p = strchr(p, ',') + 1) {
    322         strncpy(tmp, p, MAX_STR_LEN);
    323         *(strchr(tmp, ',')) = '\0';
     175        asprintf(&tmp, p);
     176        q = strchr(tmp, ',');
     177        if (q != NULL) {
     178            *q = '\0';
     179        }
    324180        bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(tmp);
    325         sprintf(comment, "media_size[%d] = %ld", j,
     181        paranoid_free(tmp);
     182
     183        asprintf(&comment, "media_size[%d] = %ld", j,
    326184                bkpinfo->media_size[j]);
    327185        log_msg(3, comment);
     186        paranoid_free(comment);
    328187    }
    329188    for (; j <= MAX_NOOF_MEDIA; j++) {
    330189        bkpinfo->media_size[j] = friendly_sizestr_to_sizelong(p);
    331190    }
    332 //      bkpinfo->media_size[0] = bkpinfo->media_size[MAX_NOOF_MEDIA];
    333191    for (j = 1; j <= MAX_NOOF_MEDIA; j++) {
    334192        if (bkpinfo->media_size[j] <= 0) {
     
    339197    return (0);
    340198}
    341 
    342199
    343200
     
    354211int
    355212process_switches(struct s_bkpinfo *bkpinfo,
    356                  char flag_val[128][MAX_STR_LEN], bool flag_set[128])
     213                 char *flag_val[128], bool flag_set[128])
    357214{
    358215
     
    364221    /*@ buffers ** */
    365222    char *tmp;
     223    char *tmp2;
    366224    char *psz;
    367225
     
    374232    bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
    375233
    376 /* compulsory */
     234    /* compulsory */
    377235    i = flag_set['c'] + flag_set['i'] + flag_set['n'] +
    378236        flag_set['t'] + flag_set['u'] + flag_set['r'] +
     
    502360                    ("You must use -L with -C. Therefore I am setting it for you.");
    503361                flag_set['L'] = 1;
    504                 flag_val['L'][0] = '\0';
     362                flag_val['L'] = NULL;
    505363            }
    506364        } else {
    507365            log_msg(3, "flag_val['c'] = %s", flag_val['c']);
    508366            log_msg(3, "flag_val['w'] = %s", flag_val['w']);
    509 //    log_msg(3, "flag_set['r'] = %i", flag_set['r'] );
    510367            if (flag_set['c']) {
    511368                bkpinfo->cdrw_speed = atoi(flag_val['c']);
     
    546403        }
    547404        if (!flag_set['d']) {
    548             if (!find_dvd_device(flag_val['d'], FALSE)) {
     405            if ((flag_val['d'] = find_dvd_device()) != NULL) {
    549406                flag_set['d'] = TRUE;
    550407                log_to_screen("I guess DVD drive is at %s", flag_val['d']);
     
    564421        }
    565422        if (!flag_set['s']) {
    566             sprintf(flag_val['s'], "%d", DEFAULT_DVD_DISK_SIZE);    // 4.7 salesman's GB = 4.482 real GB = 4582 MB
    567             strcat(flag_val['s'], "m");
     423            asprintf(&flag_val['s'], "%dm", DEFAULT_DVD_DISK_SIZE); // 4.7 salesman's GB = 4.482 real GB = 4582 MB
    568424            log_to_screen
    569425                ("You did not specify a size (-s) for DVD. I'm guessing %s.",
     
    571427            flag_set['s'] = 1;
    572428        }
    573 /*
    574       if (flag_set['Z']) {
    575       bkpinfo->blank_dvd_first = TRUE;
    576       }
    577 */
    578429    }
    579430
     
    612463    }
    613464    if (flag_set['n']) {
    614         strncpy(bkpinfo->nfs_mount, flag_val['n'], MAX_STR_LEN);
     465        asprintf(&tmp, flag_val['n']);
     466        bkpinfo->nfs_mount = tmp;
    615467        if (!flag_set['d']) {
    616             strncpy(bkpinfo->nfs_remote_dir, "/", MAX_STR_LEN);
     468            asprintf(&tmp, "/");
     469            bkpinfo->nfs_remote_dir = tmp;
    617470        }
    618471        asprintf(&tmp, "mount | grep -x \"%s .*\" | cut -d' ' -f3",
    619472                bkpinfo->nfs_mount);
    620         strncpy(bkpinfo->isodir,
    621                 call_program_and_get_last_line_of_output(tmp),
    622                 MAX_STR_LEN / 4);
     473        asprintf(&tmp2, call_program_and_get_last_line_of_output(tmp));
     474        bkpinfo->isodir = tmp2;
    623475        paranoid_free(tmp);
    624476
     
    714566    }
    715567    if (flag_set['x']) {
    716         strncpy(bkpinfo->image_devs, flag_val['x'], MAX_STR_LEN / 4);
     568        asprintf(&tmp, flag_val['x']);
     569        bkpinfo->image_devs = tmp;
    717570        if (run_program_and_log_output("which partimagehack", 2)) {
    718571            fatal_error("Please install partimagehack RPM/tarball.");
     
    723576    }
    724577    if (flag_set['k']) {
    725         strncpy(bkpinfo->kernel_path, flag_val['k'], MAX_STR_LEN);
    726         if (!strcmp(bkpinfo->kernel_path, "failsafe")) {
    727             strcpy(bkpinfo->kernel_path, "FAILSAFE");
    728         }
    729         if (strcmp(bkpinfo->kernel_path, "FAILSAFE")
    730             && !does_file_exist(bkpinfo->kernel_path)) {
    731             retval++;
    732             asprintf(&tmp,
     578        if (strcasecmp(flag_val['k'], "FAILSAFE")) {
     579            asprintf(&tmp, "FAILSAFE");
     580            bkpinfo->kernel_path = tmp;
     581
     582            if (!does_file_exist(bkpinfo->kernel_path)) {
     583                retval++;
     584                asprintf(&tmp,
    733585                    "You specified kernel '%s', which does not exist\n",
    734586                    bkpinfo->kernel_path);
    735             log_to_screen(tmp);
    736             paranoid_free(tmp);
     587                log_to_screen(tmp);
     588                paranoid_free(tmp);
     589            }
     590        } else {
     591            asprintf(&tmp, flag_val['k']);
     592            bkpinfo->kernel_path = tmp;
    737593        }
    738594    }
    739595    if (flag_set['p']) {
    740         strncpy(bkpinfo->prefix, flag_val['p'], MAX_STR_LEN / 4);
     596        asprintf(&tmp, bkpinfo->prefix);
     597        bkpinfo->prefix = tmp;
    741598    }
    742599
     
    744601    if (flag_set['d']) {        /* backup directory (if ISO/NFS) */
    745602        if (flag_set['i']) {
    746             strncpy(bkpinfo->isodir, flag_val['d'], MAX_STR_LEN / 4);
     603            asprintf(&tmp, flag_val['d']);
     604            bkpinfo->isodir = tmp;
    747605            asprintf(&tmp, "ls -l %s", bkpinfo->isodir);
    748606            if (run_program_and_log_output(tmp, FALSE)) {
     
    752610            paranoid_free(tmp);
    753611        } else if (flag_set['n']) {
    754             strncpy(bkpinfo->nfs_remote_dir, flag_val['d'], MAX_STR_LEN);
     612            asprintf(&tmp, flag_val['d']);
     613            bkpinfo->nfs_remote_dir = tmp;
    755614        } else {                /* backup device (if tape/CD-R/CD-RW) */
    756615
    757             strncpy(bkpinfo->media_device, flag_val['d'], MAX_STR_LEN / 4);
     616            paranoid_alloc(bkpinfo->media_device, flag_val['d']);
    758617        }
    759618    }
     
    782641                log_to_screen("User opted to cancel.");
    783642            }
    784         } else if (find_cdrw_device(bkpinfo->media_device)) {
     643        } else if ((tmp = find_cdrw_device()) ==  NULL) {
     644            paranoid_free(bkpinfo->media_device);
     645            bkpinfo->media_device = tmp;
    785646            retval++;
    786647            log_to_screen
     
    788649        } else {
    789650            flag_set['d'] = TRUE;
    790             strncpy(flag_val['d'], bkpinfo->media_device, MAX_STR_LEN / 4);
     651            asprintf(&flag_val['d'], bkpinfo->media_device);
    791652        }
    792653    }
     
    805666    }
    806667    if (flag_set['S']) {
    807         sprintf(bkpinfo->scratchdir, "%s/mondo.scratch.%ld", flag_val['S'],
     668        asprintf(&tmp, "%s/mondo.scratch.%ld", flag_val['S'],
    808669                random() % 32768);
     670        bkpinfo->scratchdir = tmp;
    809671    }
    810672    if (flag_set['T']) {
    811         sprintf(bkpinfo->tmpdir, "%s/tmp.mondo.%ld", flag_val['T'],
     673        asprintf(&tmp, "%s/tmp.mondo.%ld", flag_val['T'],
    812674                random() % 32768);
     675        bkpinfo->tmpdir = tmp;
    813676        asprintf(&tmp, "touch %s/.foo.dat", flag_val['T']);
    814677        if (run_program_and_log_output(tmp, 1)) {
     
    831694    }
    832695    if (flag_set['A']) {
    833         strncpy(bkpinfo->call_after_iso, flag_val['A'], MAX_STR_LEN);
     696        asprintf(&tmp, flag_val['A']);
     697        bkpinfo->call_after_iso = tmp;
    834698    }
    835699    if (flag_set['B']) {
    836         strncpy(bkpinfo->call_before_iso, flag_val['B'], MAX_STR_LEN);
     700        asprintf(&tmp, flag_val['B']);
     701        bkpinfo->call_before_iso = tmp;
    837702    }
    838703    if (flag_set['F']) {
     
    864729    if (flag_set['f']) {
    865730        tmp = resolve_softlinks_to_get_to_actual_device_file(flag_val['f']);
    866         strncpy(bkpinfo->boot_device, tmp,
    867                 MAX_STR_LEN / 4);
     731        bkpinfo->boot_device = tmp;
    868732    }
    869733    if (flag_set['Q']) {
     
    880744
    881745    if (flag_set['P']) {
    882         strncpy(bkpinfo->postnuke_tarball, flag_val['P'], MAX_STR_LEN);
     746        asprintf(&tmp, flag_val['P']);
     747        bkpinfo->postnuke_tarball = tmp;
    883748    }
    884749    if (flag_set['L']) {
     
    894759        &&
    895760        !run_program_and_log_output
    896         ("cat /etc/issue.net | grep -i suse | grep 64", TRUE)) {
     761        ("grep -i suse /etc/issue.net | grep 64", TRUE)) {
    897762        bkpinfo->make_cd_use_lilo = TRUE;
    898763        log_to_screen
     
    963828int
    964829retrieve_switches_from_command_line(int argc, char *argv[],
    965                                     char flag_val[128][MAX_STR_LEN],
     830                                    char *flag_val[128],
    966831                                    bool flag_set[128])
    967832{
    968833    /*@ ints ** */
    969834    int opt = 0;
    970     char tmp[MAX_STR_LEN];
     835    char *tmp;
    971836    int i = 0;
    972837    int len;
     
    979844
    980845    for (i = 0; i < 128; i++) {
    981         flag_val[i][0] = '\0';
     846        flag_val[i] = NULL;
    982847        flag_set[i] = FALSE;
    983848    }
     
    992857            if (flag_set[optopt]) {
    993858                bad_switches = TRUE;
    994                 sprintf(tmp, "Switch -%c previously defined as %s\n", opt,
     859                asprintf(&tmp, "Switch -%c previously defined as %s\n", opt,
    995860                        flag_val[i]);
    996861                log_to_screen(tmp);
     862                paranoid_free(tmp);
    997863            } else {
    998864                flag_set[opt] = TRUE;
     
    1008874                        if (strchr(flag_val[opt], '/')
    1009875                            && flag_val[opt][0] != '/') {
    1010                             sprintf(tmp,
     876                            asprintf(&tmp,
    1011877                                    "-%c flag --- must be absolute path --- '%s' isn't absolute",
    1012878                                    opt, flag_val[opt]);
    1013879                            log_to_screen(tmp);
     880                            paranoid_free(tmp);
    1014881                            bad_switches = TRUE;
    1015882                        }
    1016883                    }
    1017                     strcpy(flag_val[opt], optarg);
     884                    asprintf(&flag_val[opt], optarg);
    1018885                }
    1019886            }
     
    1022889    for (i = optind; i < argc; i++) {
    1023890        bad_switches = TRUE;
    1024         sprintf(tmp, "Invalid arg -- %s\n", argv[i]);
     891        asprintf(&tmp, "Invalid arg -- %s\n", argv[i]);
    1025892        log_to_screen(tmp);
     893        paranoid_free(tmp);
    1026894    }
    1027895    return (bad_switches);
     
    1047915void terminate_daemon(int sig)
    1048916{
    1049     char tmp[64];
    1050     char tmp2[MAX_STR_LEN];
    1051     //  char command[512];
    1052     //  pid_t pid;
     917    char *tmp;
     918    char *tmp2;
    1053919
    1054920    switch (sig) {
    1055921    case SIGINT:
    1056         sprintf(tmp, "SIGINT");
    1057         strcpy(tmp2, "You interrupted me :-)");
     922        asprintf(&tmp, "SIGINT signal received from OS");
     923        asprintf(&tmp2, "You interrupted me :-)");
    1058924        break;
    1059925    case SIGKILL:
    1060         sprintf(tmp, "SIGKILL");
    1061         strcpy(tmp2,
     926        asprintf(&tmp, "SIGKILL signal received from OS");
     927        asprintf(&tmp2,
    1062928               "I seriously have no clue how this signal even got to me. Something's wrong with your system.");
    1063929        break;
    1064930    case SIGTERM:
    1065         sprintf(tmp, "SIGTERM");
    1066         strcpy(tmp2, "Got terminate signal");
     931        asprintf(&tmp, "SIGTERM signal received from OS");
     932        asprintf(&tmp2, "Got terminate signal");
    1067933        break;
    1068934    case SIGHUP:
    1069         sprintf(tmp, "SIGHUP");
    1070         strcpy(tmp2, "Hangup on line");
     935        asprintf(&tmp, "SIGHUP signal received from OS");
     936        asprintf(&tmp2, "Hangup on line");
    1071937        break;
    1072938    case SIGSEGV:
    1073         sprintf(tmp, "SIGSEGV");
    1074         strcpy(tmp2,
     939        asprintf(&tmp, "SIGSEGV signal received from OS");
     940        asprintf(&tmp2,
    1075941               "Internal programming error. Please send a backtrace as well as your log.");
    1076942        break;
    1077943    case SIGPIPE:
    1078         sprintf(tmp, "SIGPIPE");
    1079         strcpy(tmp2, "Pipe was broken");
     944        asprintf(&tmp, "SIGPIPE signal received from OS");
     945        asprintf(&tmp2, "Pipe was broken");
    1080946        break;
    1081947    case SIGABRT:
    1082         sprintf(tmp, "SIGABRT");
    1083         sprintf(tmp2,
     948        asprintf(&tmp, "SIGABRT signal received from OS");
     949        asprintf(&tmp2,
    1084950                "Abort - probably failed assertion. I'm sleeping for a few seconds so you can read the message.");
    1085951        break;
    1086952    default:
    1087         sprintf(tmp, "(Unknown)");
    1088     }
    1089 
    1090     strcat(tmp, " signal received from OS");
     953        asprintf(&tmp, "(Unknown)");
     954        asprintf(&tmp2, "(Unknown)");
     955    }
     956
    1091957    log_to_screen(tmp);
    1092958    log_to_screen(tmp2);
     959    paranoid_free(tmp);
     960    paranoid_free(tmp2);
    1093961    if (sig == SIGABRT) {
    1094962        sleep(10);
     
    1099967    finish(254);                // just in case
    1100968}
    1101 
    1102 
    1103969
    1104970
     
    1122988    }
    1123989}
    1124 
    1125 
    1126990
    1127991
  • trunk/mondo/mondo/mondoarchive/mondo-cli.h

    r59 r171  
    77int process_the_s_switch(struct s_bkpinfo *bkpinfo, char *value);
    88int process_switches(struct s_bkpinfo *bkpinfo,
    9                      char flag_val[128][MAX_STR_LEN], bool flag_set[128]);
     9                     char *flag_val[128], bool flag_set[128]);
    1010int retrieve_switches_from_command_line(int argc, char *argv[],
    11                                         char flag_val[128][MAX_STR_LEN],
     11                                        char *flag_val[128],
    1212                                        bool flag_set[128]);
    1313void help_screen();
Note: See TracChangeset for help on using the changeset viewer.