Changeset 3822 in MondoRescue


Ignore:
Timestamp:
Mar 3, 2024, 2:44:57 AM (4 months ago)
Author:
Bruno Cornec
Message:

manages media_device dynamically

Location:
branches/3.3/mondo/src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3/mondo/src/common/libmondo-archive.c

    r3798 r3822  
    487487        ntapedev = get_non_rewind_dev(bkpinfo->media_device);
    488488        if ((bkpinfo->use_obdr) && (ntapedev != NULL)) {
    489             strncpy(bkpinfo->media_device,ntapedev,(size_t)((MAX_STR_LEN / 4)-1));
     489            mr_asprintf(bkpinfo->media_device, "%s", ntapedev);
    490490        } else {
    491491            if (ntapedev == NULL) {
  • branches/3.3/mondo/src/common/libmondo-cli.c

    r3821 r3822  
    695695            mr_asprintf(bkpinfo->netfs_remote_dir, "%s", flag_val['d']);
    696696        } else {                /* backup device (if tape/CD-R/CD-RW) */
    697             strncpy(bkpinfo->media_device, flag_val['d'],(MAX_STR_LEN / 4)-1);
     697            mr_asprintf(bkpinfo->media_device, "%s", flag_val['d']);
    698698        }
    699699    }
     
    719719    if (!flag_set['d'] && (flag_set['c'] || flag_set['w'] || flag_set['C'])) {
    720720        if (g_kernel_version >= 2.6) {
    721             if (popup_and_get_string
    722                 ("Device", "Please specify the device",
    723                  bkpinfo->media_device, MAX_STR_LEN / 4)) {
     721            tmp1 = popup_and_get_string("Device", "Please specify the device",bkpinfo->media_device, MAX_STR_LEN / 4);
     722            if (tmp1 == NULL) {
    724723                retval++;
    725724                log_to_screen("User opted to cancel.");
     725            } else {
     726                mr_free(bkpinfo->media_device);
     727                bkpinfo->media_device = tmp1;
    726728            }
    727729        } else if (find_cdrw_device(bkpinfo->media_device)) {
    728730            retval++;
    729             log_to_screen
    730                 ("Tried and failed to find CD-R[W] drive automatically.\n");
     731            log_to_screen("Tried and failed to find CD-R[W] drive automatically.\n");
    731732        } else {
    732733            flag_set['d'] = TRUE;
  • branches/3.3/mondo/src/common/libmondo-devices.c

    r3821 r3822  
    14071407        if (bkpinfo->disaster_recovery
    14081408            && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
    1409             strcpy(bkpinfo->media_device,
    1410                 last_line_of_file("/tmp/CDROM-LIVES-HERE"));
     1409            mr_asprintf(bkpinfo->media_device, "%s", last_line_of_file("/tmp/CDROM-LIVES-HERE"));
    14111410        } else {
    14121411            find_cdrom_device(bkpinfo->media_device, TRUE);
     
    21742173    char *tmpro = NULL;
    21752174    char *tmp1 = NULL;
     2175    char *tmp2 = NULL;
    21762176    char *mds = NULL;
    21772177    char *oldtmp = NULL;
     
    22632263                log_msg(1, "Setting to DVD defaults");
    22642264            } else {
    2265                 strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM);
     2265                mr_asprintf(bkpinfo->media_device, "%s", VANILLA_SCSI_CDROM);
    22662266                strcpy(tmp1, "4");
    22672267                mr_asprintf(sz_size, "%d", 650);
     
    22982298
    22992299        if ((bkpinfo->disaster_recovery) && (bkpinfo->backup_media_type != usb)) {
    2300             strcpy(bkpinfo->media_device, "/dev/cdrom");
     2300            mr_asprintf(bkpinfo->media_device, "%s", "/dev/cdrom");
    23012301            log_msg(2, "CD-ROM device assumed to be at %s", bkpinfo->media_device);
    23022302        } else if ((bkpinfo->restore_data && (bkpinfo->backup_media_type != usb))  || bkpinfo->backup_media_type == dvd) {
    2303             if (!bkpinfo->media_device[0]) {
    2304                 strcpy(bkpinfo->media_device, "/dev/cdrom");
     2303            if (bkpinfo->media_device == NULL) {
     2304                mr_asprintf(bkpinfo->media_device, "%s", "/dev/cdrom");
    23052305            }                   // just for the heck of it :)
    23062306            log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device);
     
    23082308                log_msg(1, "bkpinfo->media_device = %s", bkpinfo->media_device);
    23092309                mr_asprintf(comment, "Please specify your %s drive's /dev entry", mds);
    2310                 if (!popup_and_get_string("Device?", comment, bkpinfo->media_device,(MAX_STR_LEN / 4)-1)) {
     2310                tmp2 = popup_and_get_string("Device?", comment, bkpinfo->media_device,(MAX_STR_LEN / 4)-1);
     2311                if (!tmp2) {
    23112312                    log_to_screen("User has chosen not to backup the machine");
    23122313                    finish(1);
     2314                } else {
     2315                    mr_free(bkpinfo->media_device);
     2316                    bkpinfo->media_device = tmp2;
    23132317                }
    23142318            }
     
    23162320        } else {
    23172321            if ((find_cdrw_device(bkpinfo->media_device)) && (bkpinfo->backup_media_type != usb)) {
    2318                 bkpinfo->media_device[0] = '\0';
    2319             }
    2320             if (bkpinfo->media_device[0]) {
     2322                mr_free(bkpinfo->media_device);
     2323            }
     2324            if (bkpinfo->media_device != NULL) {
    23212325                if (bkpinfo->backup_media_type == usb) {
    23222326                    mr_asprintf(tmp, "I think your %s media corresponds to %s. Is this correct?", mds, bkpinfo->media_device);
     
    23252329                }
    23262330                if (!ask_me_yes_or_no(tmp)) {
    2327                     bkpinfo->media_device[0] = '\0';
     2331                    mr_free(bkpinfo->media_device);
    23282332                }
    23292333                mr_free(tmp);
    23302334            }
    2331             if (!bkpinfo->media_device[0]) {
     2335            if (bkpinfo->media_device != NULL) {
    23322336                if (bkpinfo->backup_media_type == usb) {
    2333                     i = popup_and_get_string("/dev entry?", "What is the /dev entry of your USB Disk/Key, please?", bkpinfo->media_device, (MAX_STR_LEN / 4)-1);
     2337                    tmp2 = popup_and_get_string("/dev entry?", "What is the /dev entry of your USB Disk/Key, please?", bkpinfo->media_device, (MAX_STR_LEN / 4)-1);
    23342338                } else {
    23352339                    if (g_kernel_version < 2.6) {
    2336                         i = popup_and_get_string("Device node?", "What is the SCSI node of your CD (re)writer, please?", bkpinfo->media_device,(MAX_STR_LEN / 4)-1);
     2340                        tmp2 = popup_and_get_string("Device node?", "What is the SCSI node of your CD (re)writer, please?", bkpinfo->media_device,(MAX_STR_LEN / 4)-1);
    23372341                    } else {
    2338                         i = popup_and_get_string("/dev entry?", "What is the /dev entry of your CD (re)writer, please?", bkpinfo->media_device,(MAX_STR_LEN / 4)-1);
     2342                        tmp2 = popup_and_get_string("/dev entry?", "What is the /dev entry of your CD (re)writer, please?", bkpinfo->media_device,(MAX_STR_LEN / 4)-1);
    23392343                    }
    23402344                }
    2341                 if (!i) {
     2345                if (tmp2 == NULL) {
    23422346                    log_to_screen("User has chosen not to backup the machine");
    23432347                    finish(1);
     2348                } else {
     2349                    mr_free(bkpinfo->media_device);
     2350                    bkpinfo->media_device = tmp2;
    23442351                }
    23452352            }
     
    23612368        if ((!bkpinfo->restore_mode) && (find_tape_device_and_size(bkpinfo->media_device, sz_size))) {
    23622369            log_msg(3, "Ok, using vanilla scsi tape.");
    2363             strcpy(bkpinfo->media_device, VANILLA_SCSI_TAPE);
     2370            mr_asprintf(bkpinfo->media_device, "%s", VANILLA_SCSI_TAPE);
    23642371            if ((fin = fopen(bkpinfo->media_device, "r"))) {
    23652372                paranoid_fclose(fin);
    23662373            } else {
    2367                 strcpy(bkpinfo->media_device, "/dev/osst0");
    2368             }
    2369         }
    2370         if (bkpinfo->media_device[0]) {
     2374                mr_asprintf(bkpinfo->media_device, "%s", "/dev/osst0");
     2375            }
     2376        }
     2377        if (bkpinfo->media_device != NULL) {
    23712378            if ((fin = fopen(bkpinfo->media_device, "r"))) {
    23722379                paranoid_fclose(fin);
     
    23772384            }
    23782385        }
    2379         if (bkpinfo->media_device[0]) {
     2386        if (bkpinfo->media_device != NULL) {
    23802387            mr_asprintf(tmp, "I think I've found your tape streamer at %s; am I right on the money?", bkpinfo->media_device);
    23812388            if (!ask_me_yes_or_no(tmp)) {
    2382                 bkpinfo->media_device[0] = '\0';
     2389                mr_free(bkpinfo->media_device);
    23832390            }
    23842391            mr_free(tmp);
    23852392        }
    2386         if (!bkpinfo->media_device[0]) {
    2387             if (!popup_and_get_string("Device name?", "What is the /dev entry of your tape streamer?", bkpinfo->media_device,(MAX_STR_LEN / 4)-1)) {
     2393        if (bkpinfo->media_device == NULL) {
     2394            tmp2 = popup_and_get_string("Device name?", "What is the /dev entry of your tape streamer?", bkpinfo->media_device,(MAX_STR_LEN / 4)-1);
     2395            if (tmp2 == NULL) {
    23882396                log_to_screen("User has chosen not to backup the machine");
    23892397                finish(1);
     2398            } else {
     2399                mr_free(bkpinfo->media_device);
     2400                bkpinfo->media_device = tmp2;
    23902401            }
    23912402        }
     
    27362747                finish(1);
    27372748            }
    2738             mr_asprint(bkpinfo->image_devs, "%s", tmp1);
     2749            mr_asprintf(bkpinfo->image_devs, "%s", tmp1);
    27392750        }
    27402751
     
    30223033    }
    30233034
    3024     if (!bkpinfo->media_device[0]) {
     3035    if (bkpinfo->media_device == NULL) {
    30253036        log_it("ERROR: bkpinfo->media_device shoulnd't be empty here\n");
    30263037        return(0);
  • branches/3.3/mondo/src/common/libmondo-tools.c

    r3821 r3822  
    814814    memset((void *) bkpinfo, 0, sizeof(struct s_bkpinfo));
    815815
    816     bkpinfo->media_device[0] = '\0';
     816    bkpinfo->media_device = NULL;
    817817    bkpinfo->media_size = -1;
    818818    bkpinfo->boot_loader = '\0';
  • branches/3.3/mondo/src/common/mondostructures.h

    r3821 r3822  
    343343   * If backup_media_type is anything else, this should be blank.
    344344   */
    345     char media_device[MAX_STR_LEN / 4];
     345    char *media_device;
    346346
    347347  /**
  • branches/3.3/mondo/src/common/newt-specific.c

    r3821 r3822  
    429429        mr_free(bkpinfo->subdir);
    430430        mr_free(bkpinfo->image_devs);
     431        mr_free(bkpinfo->media_device);
    431432        /* Then free the structure */
    432433        paranoid_free(bkpinfo);
  • branches/3.3/mondo/src/mondorestore/mondo-rstr-compare.c

    r3613 r3822  
    656656    if (bkpinfo->disaster_recovery
    657657        && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
    658         strcpy(bkpinfo->media_device,
    659                last_line_of_file("/tmp/CDROM-LIVES-HERE"));
     658        mr_asprintf(bkpinfo->media_device, "%s", last_line_of_file("/tmp/CDROM-LIVES-HERE"));
    660659    } else {
    661660        find_cdrom_device(bkpinfo->media_device, FALSE);
  • branches/3.3/mondo/src/mondorestore/mondo-rstr-tools.c

    r3790 r3822  
    734734if (bkpinfo->disaster_recovery) {
    735735    if (bkpinfo->backup_media_type == cdstream) {
    736         sprintf(bkpinfo->media_device, "/dev/cdrom");
     736        mr_asprintf(bkpinfo->media_device, "%s", "/dev/cdrom");
    737737        bkpinfo->media_size = 650;  /* good guess */
    738738    } else if (bkpinfo->backup_media_type == usb) {
     
    745745            strcpy(value,envtmp1);
    746746        }
    747         sprintf(bkpinfo->media_device, "%s1", value);
     747        mr_asprintf(bkpinfo->media_device, "%s1", value);
    748748        log_msg(2, "Backup medium is USB --- dev=%s", bkpinfo->media_device);
    749749    } else if (bkpinfo->backup_media_type == tape || bkpinfo->backup_media_type == udev) {
     
    751751            fatal_error("Cannot get tape device name from cfg file");
    752752        }
    753         strcpy(bkpinfo->media_device, value);
     753        mr_asprintf(bkpinfo->media_device, "%s", value);
    754754        read_cfg_var(cfg_file, "media-size", value);
    755755        bkpinfo->media_size = atol(value);
    756756        log_msg(2, "Backup medium is TAPE --- dev=%s", bkpinfo->media_device);
    757757    } else {
    758         strcpy(bkpinfo->media_device, "/dev/cdrom");    /* we don't really need this var */
     758        mr_asprintf(bkpinfo->media_device, "%s", "/dev/cdrom"); /* we don't really need this var */
    759759        bkpinfo->media_size = 1999 * 1024;  /* 650, probably, but we don't need this var anyway */
    760760        log_msg(2, "Backup medium is similar to CD-R[W]");
     
    968968                log_msg(1, "Unable to mount isodir. Perhaps this is really a CD backup?");
    969969                bkpinfo->backup_media_type = cdr;
    970                 strcpy(bkpinfo->media_device, "/dev/cdrom");    /* superfluous */
     970                mr_asprintf(bkpinfo->media_device, "%s", "/dev/cdrom"); /* superfluous */
    971971                bkpinfo->isodir[0] = iso_mnt[0] = iso_path[0] = '\0';
    972972                if (mount_media()) {
     
    21602160            run_program_and_log_output("mkdir -p tmp", FALSE);
    21612161
    2162             if (strlen(bkpinfo->media_device) == 0) {
    2163                 strcpy(bkpinfo->media_device, "/dev/st0");
    2164                 log_msg(2, "media_device is blank; assuming %s");
     2162            if (bkpinfo->media_device == NULL) {
     2163                mr_asprintf(bkpinfo->media_device, "%s", "/dev/st0");
     2164                log_msg(2, "media_device is blank; assuming %s", bkpinfo->media_device);
    21652165            }
    21662166            mr_asprintf(tmp, "%s", bkpinfo->media_device);
    2167             if (extract_cfg_file_and_mountlist_from_tape_dev
    2168                 (bkpinfo->media_device)) {
    2169                 strcpy(bkpinfo->media_device, "/dev/st0");
    2170                 if (extract_cfg_file_and_mountlist_from_tape_dev
    2171                     (bkpinfo->media_device)) {
    2172                     strcpy(bkpinfo->media_device, "/dev/osst0");
    2173                     if (extract_cfg_file_and_mountlist_from_tape_dev
    2174                         (bkpinfo->media_device)) {
    2175                         strcpy(bkpinfo->media_device, "/dev/ht0");
    2176                         if (extract_cfg_file_and_mountlist_from_tape_dev
    2177                             (bkpinfo->media_device)) {
    2178                             log_msg(3,
    2179                                     "I tried lots of devices but none worked.");
    2180                             strcpy(bkpinfo->media_device, tmp);
     2167            if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) {
     2168                mr_free(bkpinfo->media_device);
     2169                mr_asprintf(bkpinfo->media_device, "%s", "/dev/st0");
     2170                if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) {
     2171                    mr_free(bkpinfo->media_device);
     2172                    mr_asprintf(bkpinfo->media_device, "%s", "/dev/osst0");
     2173                    if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) {
     2174                        mr_free(bkpinfo->media_device);
     2175                        mr_asprintf(bkpinfo->media_device, "%s", "/dev/ht0");
     2176                        if (extract_cfg_file_and_mountlist_from_tape_dev(bkpinfo->media_device)) {
     2177                            log_msg(3, "I tried lots of devices but none worked.");
     2178                            mr_free(bkpinfo->media_device);
    21812179                        }
    21822180                    }
    21832181                }
    21842182            }
    2185             mr_free(tmp);
     2183            if (bkpinfo->media_device == NULL) {
     2184                bkpinfo->media_device = tmp;
     2185            } else {
     2186                mr_free(tmp);
     2187            }
    21862188
    21872189            if (!does_file_exist("tmp/mondorestore.cfg")) {
  • branches/3.3/mondo/src/mondorestore/mondorestore.c

    r3819 r3822  
    24742474        interactively_obtain_media_parameters_from_user(FALSE);
    24752475    }
    2476     log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
    2477     if (!bkpinfo->media_device[0]) {
    2478         log_msg(2, "Warning - failed to find media dev");
     2476    if (bkpinfo->media_device == NULL) {
     2477        log_msg(2, "Warning - failed to find media_device");
     2478    } else {
     2479        log_msg(2, "bkpinfo->media_device = %s", bkpinfo->media_device);
    24792480    }
    24802481
Note: See TracChangeset for help on using the changeset viewer.