Ignore:
Timestamp:
Aug 18, 2009, 3:19:15 PM (15 years ago)
Author:
Bruno Cornec
Message:

r3336@localhost: bruno | 2009-08-11 16:32:36 +0200

  • bkpinfo->media_device, bkpinfo->nfs_remote_dir, and bkpinfo->nfs_mount are now dynamically allocated
  • new interfaces for find_cdrom_device(), find_tape_device_and_size(), find_dvd_device(), find_cdrw_device(), set_dev_to_this_if_rx_OK() and read_cfg_var() which allocate the string now returned
  • Better differentiation between ISO and NFS iso file names construction
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.10/mondo/src/common/libmondo-devices.c

    r2324 r2325  
    6464
    6565
    66 void set_g_cdrom_and_g_dvd_to_bkpinfo_value()
    67 {
    68     strcpy(g_cdrom_drive_is_here, bkpinfo->media_device);   // just in case
    69     strcpy(g_dvd_drive_is_here, bkpinfo->media_device); // just in case
     66void set_g_cdrom_and_g_dvd_to_bkpinfo_value() {
     67
     68    if (bkpinfo->media_device) {
     69        strcpy(g_cdrom_drive_is_here, bkpinfo->media_device);   // just in case
     70        strcpy(g_dvd_drive_is_here, bkpinfo->media_device); // just in case
     71    }
    7072}
    7173
     
    205207    int res1 = 0, res2 = 0;
    206208
     209    if (dev == NULL) {
     210        return (1);
     211    }
     212
    207213    if (IS_THIS_A_STREAMING_BACKUP(g_backup_media_type)
    208214        && g_backup_media_type != udev) {
     
    243249    char *command = NULL;
    244250    int i;
     251
     252    if (dev == NULL) {
     253        return (1);
     254    }
    245255
    246256#ifdef __FreeBSD__
     
    429439 * Try to mount CD-ROM at @p mountpoint. If the CD-ROM is not found or has
    430440 * not been specified, call find_cdrom_device() to find it.
    431  * @param bkpinfo The backup information structure. The only field used is @c bkpinfo->media_device.
    432441 * @param mountpoint Where to mount the CD-ROM.
    433442 * @return 0 for success, nonzero for failure.
    434443 * @see mount_CDROM_here
    435444 */
    436 int find_and_mount_actual_cd(char *mountpoint)
    437 {
     445int find_and_mount_actual_cd(char *mountpoint) {
     446
    438447    /*@ buffers ***************************************************** */
    439448
    440449    /*@ int's  ****************************************************** */
    441450    int res;
    442     char *dev;
     451    char *dev = NULL;
    443452    char *p = NULL;
    444453
    445454    /*@ end vars **************************************************** */
    446455
    447     malloc_string(dev);
    448456    assert(bkpinfo != NULL);
    449457    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    450458
    451459    if (g_backup_media_type == dvd) {
    452         strcpy(dev, g_dvd_drive_is_here);
    453         if (!dev[0]) {
    454             find_dvd_device(dev, FALSE);
     460        if (g_dvd_drive_is_here[0]) {
     461            mr_asprintf(dev, "%s", g_dvd_drive_is_here);
     462        }
     463        if (dev == NULL) {
     464            dev = find_dvd_device();
    455465        }
    456466    } else {
    457         strcpy(dev, g_cdrom_drive_is_here);
    458         if (!dev[0]) {
    459             find_cdrom_device(dev, FALSE);
     467        if (g_cdrom_drive_is_here[0]) {
     468            mr_asprintf(dev, "%s", g_cdrom_drive_is_here);
     469        }
     470        if (dev == NULL) {
     471            dev = find_cdrom_device(FALSE);
    460472        }
    461473    }
     
    465477    }
    466478
    467     if (!dev[0] || (res = mount_CDROM_here(dev, mountpoint))) {
     479    if ((dev == NULL) || (res = mount_CDROM_here(dev, mountpoint))) {
    468480        p = popup_and_get_string ("CD-ROM device", "Please enter your CD-ROM's /dev device",dev);
    469481        if (p == NULL) {
     
    479491        log_msg(1, "mount succeeded with %s", dev);
    480492    }
    481     paranoid_free(dev);
     493    mr_free(dev);
    482494    return (res);
    483495}
     
    493505 * @return 0 for success, nonzero for failure.
    494506 */
    495 int find_cdrw_device(char *cdrw_device)
     507char *find_cdrw_device()
    496508{
    497509    /*@ buffers ************************ */
     
    499511    char *cdr_exe = NULL;
    500512    char *command = NULL;
     513    char *cdrw_device = NULL;
    501514
    502515    if (g_cdrw_drive_is_here[0]) {
    503         strcpy(cdrw_device, g_cdrw_drive_is_here);
     516        mr_asprintf(cdrw_device, g_cdrw_drive_is_here);
    504517        log_msg(3, "Been there, done that. Returning %s", cdrw_device);
    505         return (0);
     518        return(cdrw_device);
    506519    }
    507520    if (g_backup_media_type == dvd) {
    508         log_msg(1,
    509                 "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?");
    510         return (1);
     521        log_msg(1, "This is dumb. You're calling find_cdrw_device() but you're backing up to DVD. WTF?");
     522        return(NULL);
    511523    }
    512524    run_program_and_log_output("insmod ide-scsi", -1);
     
    524536        mr_free(tmp);
    525537        mr_free(cdr_exe);
    526         return 1;
     538        return(NULL);
    527539    } else {
    528         strcpy(cdrw_device, tmp);
     540        cdrw_device = tmp;
    529541        log_it("Found CDRW device - %s", cdrw_device);
    530542        strcpy(g_cdrw_drive_is_here, cdrw_device);
    531         mr_free(tmp);
    532543        mr_free(cdr_exe);
    533         return (0);
     544        return (cdrw_device);
    534545    }
    535546}
     
    545556 * @return 0 for success, nonzero for failure.
    546557 */
    547 int find_cdrom_device(char *output, bool try_to_mount)
     558char *find_cdrom_device(bool try_to_mount)
    548559{
    549560    /*@ pointers **************************************************** */
     
    552563    char *q;
    553564    char *r;
    554     int retval = 0;
    555565
    556566    /*@ bool's ****************************************************** */
     
    558568
    559569    /*@ buffers ***************************************************** */
    560     char *tmp;
     570    char *tmp = NULL;
    561571    char *tmp1 = NULL;
     572    char *output = NULL;
    562573    char *cdr_exe = NULL;
    563     char *phrase_one;
    564     char *phrase_two;
     574    char *phrase_one = NULL;
     575    char *phrase_two = NULL;
    565576    char *command = NULL;
    566577#ifndef __FreeBSD__
     
    571582
    572583    /*@ intialize *************************************************** */
    573     malloc_string(tmp);
    574     malloc_string(phrase_one);
    575     malloc_string(phrase_two);
    576 
    577     output[0] = '\0';
    578     phrase_one[0] = '\0';
    579     phrase_two[0] = '\0';
     584
     585    output = NULL;
    580586#ifndef __FreeBSD__
    581587    mr_asprintf(dvd_last_resort, "%s", "");;
     
    585591
    586592    if (g_cdrom_drive_is_here[0] && !isdigit(g_cdrom_drive_is_here[0])) {
    587         strcpy(output, g_cdrom_drive_is_here);
     593        mr_asprintf(output, "%s", g_cdrom_drive_is_here);
    588594        log_msg(3, "Been there, done that. Returning %s", output);
    589         retval = 0;
    590         goto end_of_find_cdrom_device;
     595        return(output);
    591596    }
    592597    if (the_last_place_i_found_it[0] != '\0' && !try_to_mount) {
    593         strcpy(output, the_last_place_i_found_it);
    594         log_msg(3,
    595                 "find_cdrom_device() --- returning last found location - '%s'",
    596                 output);
    597         retval = 0;
    598         goto end_of_find_cdrom_device;
     598        mr_asprintf(output, "%s", the_last_place_i_found_it);
     599        log_msg(3, "find_cdrom_device() --- returning last found location - '%s'", output);
     600        return(output);
    599601    }
    600602
     
    607609        mr_asprintf(cdr_exe, "dvdrecord");
    608610    }
    609     tmp[0] = '\0';
     611
    610612    if (!find_home_of_exe(cdr_exe)) {
    611         strcpy(output, "/dev/cdrom");
     613        mr_asprintf(output, "/dev/cdrom");
    612614        log_msg(4, "Can't find cdrecord; assuming %s", output);
     615        mr_free(cdr_exe);
    613616        if (!does_device_exist(output)) {
    614617            log_msg(4, "That didn't work. Sorry.");
    615             retval = 1;
    616             goto end_of_find_cdrom_device;
     618            mr_free(output);
     619            return(output);
    617620        } else {
    618             retval = 0;
    619             goto end_of_find_cdrom_device;
     621            return(output);
    620622        }
    621623    }
     
    629631        log_OS_error("Cannot popen command");
    630632        mr_free(cdr_exe);
    631         return (1);
    632     }
    633 
     633        return(NULL);
     634    }
     635
     636    malloc_string(phrase_one);
     637    phrase_one[0] = '\0';
     638    malloc_string(phrase_two);
     639    phrase_two[0] = '\0';
     640
     641    malloc_string(tmp);
     642    tmp[0] = '\0';
    634643    for ((void)fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
    635644         (void)fgets(tmp, MAX_STR_LEN, fin)) {
     
    656665    }
    657666    paranoid_pclose(fin);
     667    paranoid_free(phrase_one);
    658668
    659669#ifndef __FreeBSD__
     
    678688                            mr_free(dvd_last_resort);
    679689                            mr_asprintf(dvd_last_resort, "/dev/%s", tmp);
    680                             log_msg(4,
    681                                     "Ignoring '%s' because it's a DVD drive",
    682                                     tmp);
     690                            log_msg(4, "Ignoring '%s' because it's a DVD drive", tmp);
    683691                        } else {
    684                             sprintf(output, "/dev/%s", tmp);
     692                            mr_asprintf(output, "/dev/%s", tmp);
    685693                            found_it = TRUE;
    686694                        }
     
    691699        }
    692700    }
     701    paranoid_free(phrase_two);
     702    paranoid_free(tmp);
    693703
    694704#endif
     
    696706    if (!found_it) {
    697707        log_msg(4, "OK, approach 2");
    698         if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/cdrom"))) {
    699             if (!
    700                 (found_it =
    701                  set_dev_to_this_if_rx_OK(output, "/dev/cdrom1"))) {
    702                 if (!
    703                     (found_it =
    704                      set_dev_to_this_if_rx_OK(output, "/dev/dvd"))) {
    705                     if (!
    706                         (found_it =
    707                          set_dev_to_this_if_rx_OK(output, "/dev/acd0"))) {
    708                         if (!
    709                             (found_it =
    710                              set_dev_to_this_if_rx_OK(output,
    711                                                       "/dev/cd01"))) {
    712                             if (!
    713                                 (found_it =
    714                                  set_dev_to_this_if_rx_OK(output,
    715                                                           "/dev/acd1"))) {
    716                                 if (!
    717                                     (found_it =
    718                                      set_dev_to_this_if_rx_OK(output,
    719                                                               "/dev/cd1")))
    720                                 {
    721                                     retval = 1;
    722                                     goto end_of_find_cdrom_device;
     708        if (!(output = set_dev_to_this_if_rx_OK("/dev/cdrom"))) {
     709            if (!(output = set_dev_to_this_if_rx_OK("/dev/cdrom1"))) {
     710                if (!(output = set_dev_to_this_if_rx_OK("/dev/dvd"))) {
     711                    if (!(output = set_dev_to_this_if_rx_OK("/dev/acd0"))) {
     712                        if (!(output = set_dev_to_this_if_rx_OK("/dev/cd01"))) {
     713                            if (!(output = set_dev_to_this_if_rx_OK("/dev/acd1"))) {
     714                                if (!(output = set_dev_to_this_if_rx_OK("/dev/cd1"))) {
     715                                    mr_free(cdr_exe);
     716                                    return(NULL);
    723717                                }
    724718                            }
     
    732726    if (!found_it && strlen(dvd_last_resort) > 0) {
    733727        log_msg(4, "Well, I'll use the DVD - %s - as a last resort", dvd_last_resort);
    734         strcpy(output, dvd_last_resort);
     728        mr_asprintf(output, "%s", dvd_last_resort);
    735729        found_it = TRUE;
    736730    }
    737731    mr_free(dvd_last_resort);
     732
    738733    if (found_it) {
    739         sprintf(tmp, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null",
    740                 strrchr(output, '/') + 1);
    741         if (system(tmp) == 0) {
    742             log_msg(4,
    743                     "%s is not right. It's being SCSI-emulated. Continuing.",
    744                     output);
     734        mr_asprintf(tmp1, "grep \"%s=ide-scsi\" /proc/cmdline &> /dev/null", strrchr(output, '/') + 1);
     735        if (system(tmp1) == 0) {
     736            log_msg(4, "%s is not right. It's being SCSI-emulated. Continuing.", output);
    745737            found_it = FALSE;
    746             output[0] = '\0';
    747         }
     738            mr_free(output);
     739        }
     740        mr_free(tmp1);
    748741    }
    749742
     
    753746            found_it = FALSE;
    754747            log_msg(4, "OK, I was wrong, I haven't found it... yet.");
     748            mr_free(output);
    755749        }
    756750    }
     
    758752    if (!found_it) {
    759753        log_msg(4, "OK, approach 2");
    760         if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/scd0"))) {
    761             if (!(found_it = set_dev_to_this_if_rx_OK(output, "/dev/sr0"))) {
    762                 if (!
    763                     (found_it =
    764                      set_dev_to_this_if_rx_OK(output, "/dev/cdrom"))) {
    765                     if (!
    766                         (found_it =
    767                          set_dev_to_this_if_rx_OK(output,
    768                                                   "/dev/cdrom0"))) {
    769                         if (!
    770                             (found_it =
    771                              set_dev_to_this_if_rx_OK(output,
    772                                                       "/dev/cdrom1"))) {
    773                             if (!
    774                                 (found_it =
    775                                  set_dev_to_this_if_rx_OK(output,
    776                                                           "/dev/sr1"))) {
    777                                 if (!
    778                                     (found_it =
    779                                      set_dev_to_this_if_rx_OK(output,
    780                                                               "/dev/dvd")))
    781                                 {
    782                                     if (!
    783                                         (found_it =
    784                                          set_dev_to_this_if_rx_OK(output,
    785                                                                   g_cdrw_drive_is_here)))
    786                                     {
    787                                         retval = 1;
    788                                         goto end_of_find_cdrom_device;
     754        if (!(output = set_dev_to_this_if_rx_OK("/dev/scd0"))) {
     755            if (!(output = set_dev_to_this_if_rx_OK("/dev/sr0"))) {
     756                if (!(output = set_dev_to_this_if_rx_OK("/dev/cdrom"))) {
     757                    if (!(output = set_dev_to_this_if_rx_OK("/dev/cdrom0"))) {
     758                        if (!(output = set_dev_to_this_if_rx_OK("/dev/cdrom1"))) {
     759                            if (!(output = set_dev_to_this_if_rx_OK("/dev/sr1"))) {
     760                                if (!(output = set_dev_to_this_if_rx_OK("/dev/dvd"))) {
     761                                    if (!(output = set_dev_to_this_if_rx_OK(g_cdrw_drive_is_here))) {
     762                                        mr_free(cdr_exe);
     763                                        return(NULL);
    789764                                    }
    790765                                }
     
    802777            log_msg(4, "[Cardigans] I've changed my mind");
    803778            found_it = FALSE;
     779            mr_free(output);
    804780        } else {
    805             sprintf(tmp, "%s/archives", mountpoint);
     781            mr_asprintf(tmp1, "%s/archives", mountpoint);
    806782            if (!does_file_exist(tmp)) {
    807783                log_msg(4, "[Cardigans] I'll take it back");
    808784                found_it = FALSE;
     785                mr_free(output);
    809786            } else {
    810787                mr_asprintf(command, "umount %s", output);
     
    814791                log_msg(4, "I'm confident the Mondo CD is in %s", output);
    815792            }
     793            mr_free(tmp1);
    816794        }
    817795    }
     
    822800        if (!does_file_exist(output)) {
    823801            log_msg(3, "I still haven't found it.");
    824             return (1);
     802            mr_free(cdr_exe);
     803            mr_free(output);
     804            return (NULL);
    825805        }
    826806        log_msg(3, "(find_cdrom_device) --> '%s'", output);
    827807        strcpy(the_last_place_i_found_it, output);
    828808        strcpy(g_cdrom_drive_is_here, output);
    829         retval = 0;
    830         goto end_of_find_cdrom_device;
     809        mr_free(cdr_exe);
     810        return (output);
    831811    }
    832812
    833813    mr_asprintf(command, "%s -scanbus | grep \"[0-9],[0-9],[0-9]\" | grep \"[D|C][V|D]\" | grep -n \"\" | grep \"%s\" | cut -d':' -f2", cdr_exe, g_cdrw_drive_is_here);
     814    mr_free(cdr_exe);
     815
    834816    log_msg(1, "command=%s", command);
    835817    mr_asprintf(tmp1, "%s", call_program_and_get_last_line_of_output(command));
    836818    mr_free(command);
    837819
     820    mr_free(output);
    838821    if (strlen(tmp1) > 0) {
    839         strcpy(output, tmp1);
     822        mr_asprintf(output, "%s", tmp1);
    840823        log_msg(4, "Finally found it at %s", output);
    841         retval = 0;
    842824    } else {
    843825        log_msg(4, "Still couldn't find it.");
    844         retval = 1;
    845826    }
    846827    mr_free(tmp1);
    847828
    848   end_of_find_cdrom_device:
    849     paranoid_free(tmp);
    850     mr_free(cdr_exe);
    851     paranoid_free(phrase_one);
    852     paranoid_free(phrase_two);
    853     return (retval);
    854 }
    855 
    856 
    857 
    858 
    859 
    860 int find_dvd_device(char *output, bool try_to_mount)
     829    return (output);
     830}
     831
     832
     833char *find_dvd_device()
    861834{
    862835    char *tmp = NULL;
    863     int retval = 0, devno = -1;
     836    int devno = -1;
     837    char *output = NULL;
    864838
    865839    if (g_dvd_drive_is_here[0]) {
    866         strcpy(output, g_dvd_drive_is_here);
     840        mr_asprintf(output, g_dvd_drive_is_here);
    867841        log_msg(3, "Been there, done that. Returning %s", output);
    868         return (0);
    869     }
    870 
    871     mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("dvdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1")
    872         );
     842        return (output);
     843    }
     844
     845    mr_asprintf(tmp, "%s", call_program_and_get_last_line_of_output("dvdrecord -scanbus 2> /dev/null | grep \") '\" | grep -n \"\" | grep DVD | cut -d':' -f1"));
    873846    log_msg(5, "tmp = '%s'", tmp);
    874847    if (!tmp[0])
     
    882855
    883856    if (devno >= 0) {
    884         retval = 0;
    885         sprintf(output, "/dev/scd%d", devno);
     857        mr_asprintf(output, "/dev/scd%d", devno);
    886858        strcpy(g_dvd_drive_is_here, output);
    887859        log_msg(2, "I think DVD is at %s", output);
    888860    } else {
    889861        log_msg(2, "I cannot find DVD");
    890         retval = 1;
    891     }
    892 
    893     if (try_to_mount) {
    894         log_msg(1, "Ignoring the fact that try_to_mount==TRUE");
    895     }
    896     return (retval);
     862    }
     863
     864    return (output);
    897865}
    898866
     
    10791047    /*@ end vars **************************************************** */
    10801048
     1049    if (device_raw == NULL) {
     1050        return(FALSE);
     1051    }
     1052
    10811053    malloc_string(incoming);
    1082     assert(device_raw != NULL);
    10831054    if (device_raw[0] != '/' && !strstr(device_raw, ":/")) {
    10841055        log_msg(1, "%s needs to have a '/' prefixed - I'll do it",
     
    12131184        return(1);
    12141185    }
    1215     log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device,
    1216             mountpoint);
     1186    log_msg(4, "(mount_USB_here --- device=%s, mountpoint=%s", device, mountpoint);
    12171187
    12181188#ifdef __FreeBSD__
     
    12371207 * @return 0 for success, nonzero for failure.
    12381208 */
    1239 int mount_CDROM_here(char *device, char *mountpoint)
     1209int mount_CDROM_here(char *device, const char *mountpoint)
    12401210{
    12411211    /*@ buffer ****************************************************** */
     
    12481218#endif
    12491219
    1250     assert_string_is_neither_NULL_nor_zerolength(device);
    12511220    assert_string_is_neither_NULL_nor_zerolength(mountpoint);
    12521221
    12531222    make_hole_for_dir(mountpoint);
    12541223
    1255     if (isdigit(device[0])) {
    1256         find_cdrom_device(device, FALSE);
     1224    if ((device == NULL) || (isdigit(device[0]))) {
     1225        mr_free(device);
     1226        device = find_cdrom_device(FALSE);
    12571227    }
    12581228#ifndef __FreeBSD__
     
    12681238            fatal_error(command);
    12691239        }
    1270         strcpy(device, dev);
    1271         paranoid_free(dev);
     1240        mr_free(device);
     1241        device = dev;
    12721242#else
    12731243        mr_strcat(options, ",loop");
     
    12751245
    12761246    }
    1277     log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device,
    1278             mountpoint);
     1247    log_msg(4, "(mount_CDROM_here --- device=%s, mountpoint=%s", device, mountpoint);
    12791248    /*@ end vars *************************************************** */
    12801249
     
    12931262    retval = system(command);
    12941263    log_msg(1, "system(%s) returned %d", command, retval);
    1295     paranoid_free(command);
     1264    mr_free(command);
    12961265
    12971266    return (retval);
     
    13241293    /*@ buffers ********************************************************* */
    13251294    char *tmp = NULL;
    1326     char *p = NULL;
    13271295    char *mds = NULL;
    13281296    char *request = NULL;
     
    13421310    mr_free(tmp);
    13431311
    1344     if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso
    1345         || bkpinfo->backup_media_type == nfs) {
     1312    if (g_ISO_restore_mode || bkpinfo->backup_media_type == iso || bkpinfo->backup_media_type == nfs) {
     1313        // BERLIOS --- I'm tempted to do something about this...
     1314        // Why unmount and remount again and again?
    13461315        log_msg(3, "Remounting CD");
    13471316        g_ISO_restore_mode = TRUE;
    1348         // FIXME --- I'm tempted to do something about this...
    1349         // Why unmount and remount again and again?
    13501317        if (is_this_device_mounted(MNT_CDROM)) {
    13511318            run_program_and_log_output("umount " MNT_CDROM, 5);
     
    13551322        mr_free(tmp);
    13561323
    1357         mr_asprintf(tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir, bkpinfo->prefix, cd_number_i_want);
     1324        if (((bkpinfo->isodir == NULL) && (bkpinfo->nfs_remote_dir == NULL)) || (bkpinfo->prefix == NULL)) {
     1325            fatal_error("Unable to prepare ISO file name. Please report to dev team");
     1326        }
     1327        if (bkpinfo->nfs_remote_dir) {
     1328            // NFS
     1329            mr_asprintf(tmp, "%s/%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->nfs_remote_dir, bkpinfo->prefix, cd_number_i_want);
     1330        } else {
     1331            // ISO
     1332            mr_asprintf(tmp, "%s/%s-%d.iso", bkpinfo->isodir, bkpinfo->prefix, cd_number_i_want);
     1333        }
    13581334        if (!does_file_exist(tmp)) {
    13591335            mr_free(tmp);
    1360             mr_asprintf(tmp, "%s/isodir/%s/%s-%d.iso", bkpinfo->tmpdir, bkpinfo->nfs_remote_dir, bkpinfo->prefix, cd_number_i_want);
     1336            if (bkpinfo->nfs_remote_dir) {
     1337                // NFS
     1338                mr_asprintf(tmp, "%s/isodir/%s/%s-%d.iso", bkpinfo->tmpdir, bkpinfo->nfs_remote_dir, bkpinfo->prefix, cd_number_i_want);
     1339            } else {
     1340                // ISO
     1341                mr_asprintf(tmp, "%s/isodir/%s-%d.iso", bkpinfo->tmpdir, bkpinfo->prefix, cd_number_i_want);
     1342            }
    13611343            if (does_file_exist(tmp)) {
    13621344                log_msg(1, "FIXME - hacking bkpinfo->isodir from '%s' to %s/isodir", bkpinfo->isodir, bkpinfo->tmpdir);
     
    13731355    }
    13741356    if ((res = what_number_cd_is_this()) != cd_number_i_want) {
    1375         log_msg(3, "Currently, we hold %d but we want %d", res,
    1376                 cd_number_i_want);
     1357        log_msg(3, "Currently, we hold %d but we want %d", res, cd_number_i_want);
    13771358        mds = media_descriptor_string(bkpinfo->backup_media_type);
    13781359        log_msg(3, "Insisting on %s #%d", mds, cd_number_i_want);
     
    14901471            mds = media_descriptor_string(bkpinfo->backup_media_type);
    14911472            mr_asprintf(comment, "What speed is your %s (re)writer?", mds);
     1473            mr_free(bkpinfo->media_device);
    14921474            if (bkpinfo->backup_media_type == dvd) {
    1493                 find_dvd_device(bkpinfo->media_device, FALSE);
     1475                bkpinfo->media_device = find_dvd_device();
    14941476                mr_asprintf(tmp, "1");
    14951477                mr_asprintf(sz_size, "%d", DEFAULT_DVD_DISK_SIZE);  // 4.7 salesman's GB = 4.482 real GB = 4482 MB
    14961478                log_msg(1, "Setting to DVD defaults");
    14971479            } else {
    1498                 strcpy(bkpinfo->media_device, VANILLA_SCSI_CDROM);
     1480                mr_asprintf(bkpinfo->media_device, "%s", VANILLA_SCSI_CDROM);
    14991481                mr_asprintf(tmp, "4");
    15001482                mr_asprintf(sz_size, "%d", 650);
     
    15421524        mds = media_descriptor_string(bkpinfo->backup_media_type);
    15431525
     1526        mr_free(bkpinfo->media_device);
    15441527        if ((bkpinfo->disaster_recovery) && (bkpinfo->backup_media_type != usb)) {
    1545             strcpy(bkpinfo->media_device, "/dev/cdrom");
    1546             log_msg(2, "CD-ROM device assumed to be at %s",
    1547                     bkpinfo->media_device);
    1548         } else if ((bkpinfo->restore_data && (bkpinfo->backup_media_type != usb))
    1549                    || bkpinfo->backup_media_type == dvd) {
    1550             if (!bkpinfo->media_device[0]) {
    1551                 strcpy(bkpinfo->media_device, "/dev/cdrom");
    1552             }                   // just for the heck of it :)
    1553             log_msg(1, "bkpinfo->media_device = %s",
    1554                     bkpinfo->media_device);
    1555             if (bkpinfo->backup_media_type == dvd
    1556                 || find_cdrom_device(bkpinfo->media_device, FALSE)) {
    1557                 log_msg(1, "bkpinfo->media_device = %s",
    1558                         bkpinfo->media_device);
     1528            mr_asprintf(bkpinfo->media_device, "/dev/cdrom");
     1529            log_msg(2, "CD-ROM device assumed to be at %s", bkpinfo->media_device);
     1530        } else if ((bkpinfo->restore_data && (bkpinfo->backup_media_type != usb)) || bkpinfo->backup_media_type == dvd) {
     1531            if ((bkpinfo->backup_media_type == dvd) || ((bkpinfo->media_device = find_cdrom_device(FALSE)) != NULL)) {
    15591532                mr_asprintf(comment, "Please specify your %s drive's /dev entry", mds);
    15601533                p = popup_and_get_string("Device?", comment, bkpinfo->media_device);
     
    15651538                    finish(1);
    15661539                }
    1567                 strcpy(bkpinfo->media_device, p);
    1568                 mr_free(p);
    1569             }
    1570             log_msg(2, "%s device found at %s", mds, bkpinfo->media_device);
     1540                mr_free(bkpinfo->media_device);
     1541                bkpinfo->media_device = p;
     1542            }
     1543            if (bkpinfo->media_device != NULL) {
     1544                log_msg(2, "%s device found at %s", mds, bkpinfo->media_device);
     1545            } else {
     1546                log_msg(2, "%s device not found (bkpinfo->media_device is NULL)", mds);
     1547            }
    15711548        } else {
    1572             if ((find_cdrw_device(bkpinfo->media_device)) && (bkpinfo->backup_media_type != usb)) {
    1573                 bkpinfo->media_device[0] = '\0';
    1574             }
    1575             if (bkpinfo->media_device[0]) {
     1549            if (((bkpinfo->media_device = find_cdrw_device()) != NULL) && (bkpinfo->backup_media_type != usb)) {
     1550                mr_free(bkpinfo->media_device);
     1551            }
     1552            if (bkpinfo->media_device != NULL) {
    15761553                if (bkpinfo->backup_media_type == usb) {
    15771554                    mr_asprintf(tmp, "I think your %s media corresponds to %s. Is this correct?", mds, bkpinfo->media_device);
     
    15801557                }
    15811558                if (!ask_me_yes_or_no(tmp)) {
    1582                     bkpinfo->media_device[0] = '\0';
     1559                    mr_free(bkpinfo->media_device);
    15831560                }
    15841561                mr_free(tmp);
    15851562            }
    1586             if (!bkpinfo->media_device[0]) {
     1563            if (!bkpinfo->media_device) {
    15871564                if (bkpinfo->backup_media_type == usb) {
    1588                     p = popup_and_get_string("/dev entry?", "What is the /dev entry of your USB Disk/Key, please?", bkpinfo->media_device);
     1565                    p = popup_and_get_string("/dev entry?", "What is the /dev entry of your USB Disk/Key, please?", NULL);
    15891566                } else {
    15901567                    if (g_kernel_version < 2.6) {
    1591                         p = popup_and_get_string("Device node?", "What is the SCSI node of your CD (re)writer, please?", bkpinfo->media_device);
     1568                        p = popup_and_get_string("Device node?", "What is the SCSI node of your CD (re)writer, please?", NULL);
    15921569                    } else {
    1593                         p = popup_and_get_string("/dev entry?", "What is the /dev entry of your CD (re)writer, please?", bkpinfo->media_device);
     1570                        p = popup_and_get_string("/dev entry?", "What is the /dev entry of your CD (re)writer, please?", NULL);
    15941571                    }
    15951572                }
     
    15981575                    finish(1);
    15991576                }
    1600                 strcpy(bkpinfo->media_device, p);
    1601                 mr_free(p);
     1577                bkpinfo->media_device = p;
    16021578            }
    16031579        }
     
    16181594    case tape:
    16191595
    1620         if ((!bkpinfo->restore_mode) && (!mr_find_tape_device())) {
     1596        mr_free(bkpinfo->media_device);
     1597        if ((!bkpinfo->restore_mode) && ((bkpinfo->media_device = find_tape_device_and_size(NULL)) == NULL)) {
    16211598            log_msg(3, "Ok, using vanilla scsi tape.");
    1622             strcpy(bkpinfo->media_device, VANILLA_SCSI_TAPE);
     1599            mr_asprintf(bkpinfo->media_device, "%s", VANILLA_SCSI_TAPE);
    16231600            if ((fin = fopen(bkpinfo->media_device, "r"))) {
    16241601                paranoid_fclose(fin);
    16251602            } else {
    1626                 strcpy(bkpinfo->media_device, "/dev/osst0");
    1627             }
    1628         }
    1629         if (bkpinfo->media_device[0]) {
     1603                mr_free(bkpinfo->media_device);
     1604                mr_asprintf(bkpinfo->media_device, "/dev/osst0");
     1605            }
     1606        }
     1607        if (bkpinfo->media_device != NULL) {
    16301608            if ((fin = fopen(bkpinfo->media_device, "r"))) {
    16311609                paranoid_fclose(fin);
    16321610            } else {
    16331611                if (does_file_exist("/tmp/mondo-restore.cfg")) {
    1634                     read_cfg_var("/tmp/mondo-restore.cfg", "media-dev",
    1635                                  bkpinfo->media_device);
     1612                    mr_free(bkpinfo->media_device);
     1613                    bkpinfo->media_device = read_cfg_var("/tmp/mondo-restore.cfg", "media-dev");
    16361614                }
    16371615            }
    16381616        }
    1639         if (bkpinfo->media_device[0]) {
     1617        if (bkpinfo->media_device != NULL) {
    16401618            mr_asprintf(tmp, "I think I've found your tape streamer at %s; am I right on the money?", bkpinfo->media_device);
    16411619            if (!ask_me_yes_or_no(tmp)) {
    1642                 bkpinfo->media_device[0] = '\0';
     1620                mr_free(bkpinfo->media_device);
    16431621            }
    16441622            mr_free(tmp);
    16451623        }
    1646         if (!bkpinfo->media_device[0]) {
     1624        if (bkpinfo->media_device == NULL) {
    16471625            p = popup_and_get_string("Device name?", "What is the /dev entry of your tape streamer?", bkpinfo->media_device);
    16481626            if (p == NULL) {
     
    16501628                finish(1);
    16511629            }
    1652             strcpy(bkpinfo->media_device, p);
    1653             mr_free(p);
     1630            bkpinfo->media_device = p;
    16541631        }
    16551632        mr_asprintf(tmp, "ls -l %s", bkpinfo->media_device);
     
    16861663
    16871664        /* Initiate bkpinfo nfs_mount path from running environment if not already done */
    1688         if (!bkpinfo->nfs_mount[0]) {
    1689             strcpy(bkpinfo->nfs_mount,
    1690                    call_program_and_get_last_line_of_output
    1691                    ("mount | grep \":\" | cut -d' ' -f1 | head -n1"));
     1665        if (bkpinfo->nfs_mount == NULL) {
     1666            mr_asprintf(bkpinfo->nfs_mount, "%s", call_program_and_get_last_line_of_output("mount | grep \":\" | cut -d' ' -f1 | head -n1"));
    16921667        }
    16931668#ifdef __FreeBSD__
     
    17021677                finish(1);
    17031678            }
    1704             strcpy(bkpinfo->nfs_mount, p);
    1705             mr_free(p);
     1679            mr_free(bkpinfo->nfs_mount);
     1680            bkpinfo->nfs_mount = p;
    17061681            if (!bkpinfo->restore_data) {
    17071682                if ((bkpinfo->compression_level =
     
    17131688            // check whether already mounted - we better remove
    17141689            // surrounding spaces and trailing '/' for this
    1715             strip_spaces(bkpinfo->nfs_mount);
     1690            mr_strip_spaces(bkpinfo->nfs_mount);
    17161691            if (bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] == '/')
    17171692                bkpinfo->nfs_mount[strlen(bkpinfo->nfs_mount) - 1] = '\0';
     
    17521727                finish(1);
    17531728            }
    1754             strcpy(bkpinfo->nfs_mount, p);
    1755             mr_free(p);
     1729            mr_free(bkpinfo->nfs_mount);
     1730            bkpinfo->nfs_mount = p;
    17561731        }
    17571732        /* Initiate bkpinfo isodir path from running environment if mount already done */
     
    17821757            finish(1);
    17831758        }
    1784         strcpy(bkpinfo->nfs_remote_dir, p);
    1785         mr_free(p);
     1759        mr_free(bkpinfo->nfs_remote_dir);
     1760        bkpinfo->nfs_remote_dir = p;
    17861761
    17871762        // check whether writable - we better remove surrounding spaces for this
    1788         strip_spaces(bkpinfo->nfs_remote_dir);
     1763        mr_strip_spaces(bkpinfo->nfs_remote_dir);
    17891764
    17901765        p = popup_and_get_string("Prefix.", "Please enter the prefix that will be prepended to your ISO filename.  Example: machine1 to obtain machine1-[1-9]*.iso files", bkpinfo->prefix);
     
    19981973    }
    19991974    log_it("isodir = %s", bkpinfo->isodir);
    2000     log_it("nfs_mount = '%s'", bkpinfo->nfs_mount);
     1975    if (bkpinfo->nfs_mount) {
     1976        log_it("nfs_mount = '%s'", bkpinfo->nfs_mount);
     1977    }
    20011978    if (bkpinfo->nfs_user) {
    20021979        log_it("nfs_user = '%s'", bkpinfo->nfs_user);
     
    21352112        fatal_error("I couldn't figure out the scratchdir!");
    21362113    }
     2114
     2115    /* Cleaning a potential previous scratchdir */
     2116    if (bkpinfo->scratchdir) {
     2117        mr_asprintf(command, "rm -Rf %s", bkpinfo->scratchdir);
     2118        paranoid_system(command);
     2119        mr_free(command);
     2120    }
    21372121    mr_free(bkpinfo->scratchdir);
     2122
    21382123    mr_asprintf(bkpinfo->scratchdir , "%s/mondo.scratch.%d", tmp, (int) (random() % 32768));
    21392124    log_it("bkpinfo->scratchdir is being set to %s", bkpinfo->scratchdir);
    21402125
     2126    /* Cleaning potential previous scratchdir */
    21412127    mr_asprintf(command, "rm -Rf %s/mondo.scratch.*", tmp);
    21422128    mr_free(tmp);
     
    21562142 */
    21572143/**
    2158  * If we can read @p dev, set @p output to it.
    2159  * If @p dev cannot be read, set @p output to "".
     2144 * If we can read @p dev, set @return output to it.
     2145 * If @p dev cannot be read, set @p output to NULL.
    21602146 * @param dev The device to check for.
    2161  * @param output Set to @p dev if @p dev exists, "" otherwise.
    2162  * @return TRUE if @p dev exists, FALSE if it doesn't.
    2163  */
    2164 bool set_dev_to_this_if_rx_OK(char *output, char *dev)
     2147 * @return output Set to @p dev if @p dev exists, NULL otherwise.
     2148 */
     2149char *set_dev_to_this_if_rx_OK(char *dev)
    21652150{
    21662151    char *command = NULL;
    2167     bool res;
     2152    char *output = NULL;
    21682153
    21692154    if (!dev || dev[0] == '\0') {
    2170         output[0] = '\0';
    2171         return (FALSE);
     2155        return(NULL);
    21722156    }
    21732157    log_msg(10, "Injecting %s", dev);
     
    21752159    if (!does_file_exist(dev)) {
    21762160        log_msg(10, "%s doesn't exist. Returning FALSE.", dev);
    2177         return (FALSE);
     2161        return(NULL);
    21782162    }
    21792163    mr_asprintf(command, "dd bs=%ld count=1 if=%s of=/dev/null &> /dev/null", 512L, dev);
    21802164    if (!run_program_and_log_output(command, FALSE)
    21812165        && !run_program_and_log_output(command, FALSE)) {
    2182         strcpy(output, dev);
     2166        mr_asprintf(output, "%s", dev);
    21832167        log_msg(4, "Found it - %s", dev);
    2184         res = TRUE;
    21852168    } else {
    2186         output[0] = '\0';
    21872169        log_msg(4, "It's not %s", dev);
    2188         res = FALSE;
    21892170    }
    21902171    mr_free(command);
    2191     return(res);
     2172    return(output);
    21922173}
    21932174
     
    22212202    }
    22222203
    2223     mr_asprintf(mountdev, "%s", bkpinfo->media_device);
    2224     if (!mountdev[0]) {
     2204    if (bkpinfo->media_device) {
     2205        mr_asprintf(mountdev, "%s", bkpinfo->media_device);
     2206    }
     2207    if (!mountdev) {
    22252208        log_it("(what_number_cd_is_this) Warning - media_device unknown. Finding out...");
    2226         find_cdrom_device(bkpinfo->media_device, FALSE);
     2209        mr_free(bkpinfo->media_device);
     2210        bkpinfo->media_device = find_cdrom_device(FALSE);
     2211        mr_asprintf(mountdev, "%s", bkpinfo->media_device);
    22272212    }
    22282213    if (!is_this_device_mounted(MNT_CDROM)) {
Note: See TracChangeset for help on using the changeset viewer.