Changeset 2303


Ignore:
Timestamp:
Jul 24, 2009, 9:19:38 PM (10 years ago)
Author:
bruno
Message:

find_tape_device_and_size => mr_find_tape_device which allocates 1 string to be freed by caller

Location:
branches/2.2.10/mondo/src/common
Files:
6 edited

Legend:

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

    r2301 r2303  
    12131213    mr_asprintf(&data_disks_file, "%s/all.tar.gz", bkpinfo->tmpdir);
    12141214
    1215     mr_sprintf(&g_serial_string, "%s", call_program_and_get_last_line_of_output("dd if=/dev/urandom bs=16 count=1 2> /dev/null | hexdump | tr -s ' ' '0' | head -n1"));
     1215    mr_asprintf(&g_serial_string, "%s", call_program_and_get_last_line_of_output("dd if=/dev/urandom bs=16 count=1 2> /dev/null | hexdump | tr -s ' ' '0' | head -n1"));
    12161216    strip_spaces(g_serial_string);
    12171217    mr_strcat(g_serial_string, "...word.");
  • branches/2.2.10/mondo/src/common/libmondo-cli.c

    r2296 r2303  
    896896    if ((flag_set['t'] && !flag_set['d']) && (! bkpinfo->restore_data)) {
    897897        log_it("Hmm! No tape drive specified. Let's see what we can do.");
    898         if (find_tape_device_and_size(flag_val['d'], tmp)) {
    899             fatal_error
    900                 ("Tape device not specified. I couldn't find it either.");
     898        p = mr_find_tape_device();
     899        if (!p) {
     900            fatal_error("Tape device not specified. I couldn't find it either.");
    901901        }
    902902        flag_set['d'] = TRUE;
     903        strcpy(flag_val['d'], p);
     904        mr_free(p);
    903905        mr_asprintf(&tmp1, "You didn't specify a tape streamer device. I'm assuming %s", flag_val['d']);
    904906        log_to_screen(tmp1);
  • branches/2.2.10/mondo/src/common/libmondo-devices.c

    r2296 r2303  
    16361636    case tape:
    16371637
    1638         if ((!bkpinfo->restore_mode) && (find_tape_device_and_size(bkpinfo->media_device, sz_size))) {
     1638        if ((!bkpinfo->restore_mode) && (!mr_find_tape_device())) {
    16391639            log_msg(3, "Ok, using vanilla scsi tape.");
    16401640            strcpy(bkpinfo->media_device, VANILLA_SCSI_TAPE);
  • branches/2.2.10/mondo/src/common/libmondo-stream-EXT.h

    r1954 r2303  
    55extern int closein_tape();
    66extern int closeout_tape();
    7 extern int find_tape_device_and_size(char *dev, char *siz);
     7extern char *mr_find_tape_device(void);
    88extern void insist_on_this_tape_number(int tapeno);
    99extern void log_tape_pos(void);
  • branches/2.2.10/mondo/src/common/libmondo-stream.c

    r2296 r2303  
    250250
    251251/**
    252  * Determine the name and size of the tape device. Tries the SCSI tape for
     252 * Determine the name of the tape device. Tries the SCSI tape for
    253253 * this platform, then the IDE tape, then "/dev/st0", then "/dev/osst0".
    254  * @param dev Where to put the found tape device.
    255  * @param siz Where to put the tape size (a string like "4GB")
    256  * @return 0 if success, nonzero if failure (in which @p dev and @p siz are undefined).
    257  */
    258 int find_tape_device_and_size(char *dev, char *siz)
    259 {
    260     char tmp[MAX_STR_LEN];
     254 * @return the allocated tape string if success, NULL if failure
     255 */
     256char *mr_find_tape_device(void)
     257{
     258    char *tmp = NULL;
    261259    char *command = NULL;
    262     char cdr_exe[MAX_STR_LEN];
     260    char *cdr_exe = NULL;
     261    char *dev = NULL;
    263262    int res;
    264263
    265264    log_to_screen("I am looking for your tape streamer. Please wait.");
    266     dev[0] = '\0';
    267     if (siz != NULL) {
    268         siz[0] = '\0';
    269     }
    270265    if (find_home_of_exe("cdrecord")) {
    271         strcpy(cdr_exe, "cdrecord");
    272     } else {
    273         strcpy(cdr_exe, "dvdrecord");
     266        mr_asprintf(&cdr_exe, "cdrecord");
     267    } else {
     268        mr_asprintf(&cdr_exe, "dvdrecord");
    274269    }
    275270    mr_asprintf(&command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l", cdr_exe);
    276     strcpy(tmp, call_program_and_get_last_line_of_output(command));
     271    mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    277272    mr_free(command);
    278273
    279274    if (atoi(tmp) != 1) {
    280         log_it
    281             ("Either too few or too many tape streamers for me to detect...");
    282         strcpy(dev, VANILLA_SCSI_TAPE);
    283         return 1;
    284     }
     275        log_it("Either too few or too many tape streamers for me to detect...");
     276        mr_asprintf(&dev, "%s", VANILLA_SCSI_TAPE);
     277        mr_free(tmp);
     278        return(dev);
     279    }
     280    mr_free(tmp);
     281
    285282    mr_asprintf(&command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f2 | head -n1", cdr_exe);
    286     strcpy(tmp, call_program_and_get_last_line_of_output(command));
     283    mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    287284    mr_free(command);
    288285
    289286    if (strlen(tmp) < 2) {
    290287        log_it("Could not find tape device");
    291         return 1;
    292     }
     288        mr_free(tmp);
     289        return(dev);
     290    }
     291    mr_free(tmp);
    293292    mr_asprintf(&command, "%s -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | cut -d' ' -f3 | cut -d')' -f1 | head -n1", cdr_exe);
    294     strcpy(tmp, call_program_and_get_last_line_of_output(command));
     293    mr_free(cdr_exe);
     294
     295    mr_asprintf(&tmp, "%s", call_program_and_get_last_line_of_output(command));
    295296    mr_free(command);
    296297
    297     strcpy(dev, VANILLA_SCSI_TAPE);
     298    mr_asprintf(&dev, "%s", VANILLA_SCSI_TAPE);
    298299    dev[strlen(dev) - 1] = '\0';
    299     strcat(dev, tmp);           // e.g. '/dev/st0' becomes '/dev/stN'
     300    mr_strcat(dev, tmp);            // e.g. '/dev/st0' becomes '/dev/stN'
     301    mr_free(tmp);
     302
    300303    res = 0;
    301304    if (!mt_says_tape_exists(dev)) {
    302         strcpy(dev, ALT_TAPE);
     305        mr_free(dev);
     306        mr_asprintf(&dev, "%s", ALT_TAPE);
    303307        if (!mt_says_tape_exists(dev)) {
    304308            log_it("Cannot openin %s", dev);
    305             strcpy(dev, "/dev/st0");
     309            mr_free(dev);
     310            mr_asprintf(&dev, "/dev/st0");
    306311            if (!mt_says_tape_exists(dev)) {
    307312                log_it("Cannot openin %s", dev);
    308                 strcpy(dev, "/dev/osst0");
     313                mr_free(dev);
     314                mr_asprintf(&dev, "/dev/osst0");
    309315                if (!mt_says_tape_exists(dev)) {
    310316                    res++;
     
    318324    log_it("At this point, dev = %s and res = %d", dev, res);
    319325
    320     strcpy(tmp, call_program_and_get_last_line_of_output("\
    321 cdrecord -scanbus 2> /dev/null | tr -s '\t' ' ' | \
    322 grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | \
    323 awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'"));
     326    mr_asprintf(&tmp, call_program_and_get_last_line_of_output("cdrecord -scanbus 2> /dev/null | tr -s '\t' ' ' | grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'"));
    324327
    325328    if (mt_says_tape_exists(dev)) {
     
    327330    } else {
    328331        log_it("Turning %s", dev);
    329         strcpy(tmp, (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev);
    330         sprintf(dev, "/dev/os%s", tmp);
     332        mr_free(tmp);
     333        mr_asprintf(&tmp, (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev);
     334        mr_free(dev);
     335        mr_asprintf(&dev, "/dev/os%s", tmp);
    331336        log_it("...into %s", dev);
    332337        if (mt_says_tape_exists(dev)) {
     
    340345
    341346    if (res) {
    342         return (res);
     347        mr_free(tmp);
     348        return (dev);
    343349    }
    344350
    345351    if (strlen(tmp) < 2) {
    346352        log_it("Warning - size of tape unknown");
    347         return (0);
    348     } else {
    349         if (siz != NULL) {
    350             strcpy(siz, tmp);
    351         }
    352         return (0);
    353     }
    354 }
    355 
    356 
    357 
    358 
     353    }
     354    mr_free(tmp);
     355    return (NULL);
     356}
    359357
    360358
  • branches/2.2.10/mondo/src/common/libmondo-stream.h

    r1954 r2303  
    77int closein_tape();
    88int closeout_tape();
    9 int find_tape_device_and_size(char *dev, char *siz);
     9char *mr_find_tape_device(void);
    1010void insist_on_this_tape_number(int tapeno);
    1111void log_tape_pos(void);
Note: See TracChangeset for help on using the changeset viewer.