Ignore:
Timestamp:
Jul 17, 2006, 3:44:46 PM (13 years ago)
Author:
bcornec
Message:

Huge memory management patch.
Still not finished but a lot as been done.
What remains is around some functions returning strings, and some structure members.
(Could not finish due to laptop failure !)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/common/libmondo-stream.c

    r687 r688  
    99 * Functions for writing data to/reading data from streams (tape, CD stream, etc.)
    1010 */
     11
     12#include <unistd.h>
    1113
    1214#include "my-stuff.h"
     
    2325#define EXTRA_TAPE_CHECKSUMS
    2426
    25 /*@unused@*/
    26 //static char cvsid[] = "$Id$";
    2727extern bool g_sigpipe;
    2828extern int g_tape_buffer_size_MB;
     
    119119    }
    120120    sleep(1);
    121     paranoid_system("sync");
     121    sync();
    122122    sleep(1);
    123123    paranoid_pclose(g_tape_stream);
     
    152152
    153153    sleep(1);
    154     paranoid_system("sync");
     154    sync();
    155155    sleep(1);
    156156    log_it("closeout_tape() -- entering");
     
    213213int find_tape_device_and_size(char *dev, char *siz)
    214214{
    215     char *tmp;
    216     char *command;
    217     char *cdr_exe;
    218     int res;
     215    char *tmp = NULL;
     216    char *tmp1 = NULL;
     217    char *command = NULL;
     218    char *cdr_exe = NULL;
     219    int res = 0;
    219220
    220221    log_to_screen("I am looking for your tape streamer. Please wait.");
    221     dev[0] = '\0';
     222    dev = NULL;
    222223    siz = NULL;
    223224    if (find_home_of_exe("cdrecord")) {
     
    228229    asprintf(&command, "%s -scanbus 2> /dev/null | grep -i tape | wc -l",
    229230             cdr_exe);
    230     asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     231    tmp = call_program_and_get_last_line_of_output(command);
    231232    paranoid_free(command);
    232233
     
    234235        log_it
    235236            ("Either too few or too many tape streamers for me to detect...");
    236         strcpy(dev, VANILLA_SCSI_TAPE);
     237        asprintf(&dev, VANILLA_SCSI_TAPE"0");
    237238        paranoid_free(tmp);
    238239        paranoid_free(cdr_exe);
     
    244245             "%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",
    245246             cdr_exe);
    246     asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     247    tmp = call_program_and_get_last_line_of_output(command);
    247248    paranoid_free(command);
    248249    if (strlen(tmp) < 2) {
     
    259260    paranoid_free(cdr_exe);
    260261
    261     asprintf(&tmp, call_program_and_get_last_line_of_output(command));
     262    tmp = call_program_and_get_last_line_of_output(command);
    262263    paranoid_free(command);
    263     strcpy(dev, VANILLA_SCSI_TAPE);
    264     dev[strlen(dev) - 1] = '\0';
    265     strcat(dev, tmp);           // e.g. '/dev/st0' becomes '/dev/stN'
     264
     265    asprintf(&dev, VANILLA_SCSI_TAPE"%s", tmp);
    266266    paranoid_free(tmp);
    267267
    268     res = 0;
    269268    if (!mt_says_tape_exists(dev)) {
    270         strcpy(dev, ALT_TAPE);
     269        paranoid_free(dev);
     270
     271        asprintf(&dev, ALT_TAPE"%s", tmp);
    271272        if (!mt_says_tape_exists(dev)) {
    272273            log_it("Cannot openin %s", dev);
    273             strcpy(dev, "/dev/st0");
     274            paranoid_free(dev);
     275
     276            asprintf(&dev, VANILLA_SCSI_TAPE"0");
    274277            if (!mt_says_tape_exists(dev)) {
    275278                log_it("Cannot openin %s", dev);
    276                 strcpy(dev, "/dev/osst0");
     279                paranoid_free(dev);
     280
     281                asprintf(&dev, "/dev/osst0");
    277282                if (!mt_says_tape_exists(dev)) {
    278283                    res++;
     
    286291    log_it("At this point, dev = %s and res = %d", dev, res);
    287292
    288     asprintf(&tmp, call_program_and_get_last_line_of_output("\
     293    tmp = call_program_and_get_last_line_of_output("\
    289294cdrecord -scanbus 2> /dev/null | tr -s '\t' ' ' | \
    290295grep \"[0-9]*,[0-9]*,[0-9]*\" | grep -v \"[0-9]*) \\*\" | grep -i TAPE | \
    291 awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'"));
     296awk '{for(i=1; i<NF; i++) { if (index($i, \"GB\")>0) { print $i;};};};'");
    292297
    293298    if (mt_says_tape_exists(dev)) {
     
    296301        log_it("Turning %s", dev);
    297302        paranoid_free(tmp);
    298         asprintf(&tmp,
     303        asprintf(&tmp1,
    299304                 (strrchr(dev, '/') != NULL) ? strrchr(dev, '/') : dev);
    300         sprintf(dev, "/dev/os%s", tmp);
     305        paranoid_free(dev);
     306        asprintf(&dev, "/dev/os%s", tmp1);
     307        paranoid_free(tmp1);
     308
    301309        log_it("...into %s", dev);
    302310        if (mt_says_tape_exists(dev)) {
     
    12281236
    12291237    paranoid_pclose(g_tape_stream);
    1230     system("sync");
    1231     system("sync");
    1232     system("sync");
     1238    sync();
     1239    sync();
     1240    sync();
    12331241    log_it("Next tape requested.");
    12341242    insist_on_this_tape_number(g_current_media_number + 1); // will increment it, too
     
    12691277
    12701278    paranoid_pclose(g_tape_stream);
    1271     system("sync");
    1272     system("sync");
    1273     system("sync");
     1279    sync();
     1280    sync();
     1281    sync();
    12741282    log_it("New tape requested.");
    12751283    insist_on_this_tape_number(g_current_media_number + 1); // will increment g_current_media, too
Note: See TracChangeset for help on using the changeset viewer.