Changeset 1109


Ignore:
Timestamp:
Feb 8, 2007, 12:37:50 AM (12 years ago)
Author:
bruno
Message:

Improve memory management for libmondo-fifo.c (trunk merge begining)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/common/libmondo-fifo.c

    r1107 r1109  
    1111#include <unistd.h>
    1212#include <stdio.h>
     13#ifndef S_SPLINT_S
    1314#include <signal.h>
     15#endif
    1416#include <fcntl.h>
    15 #include <stdio.h>
    1617
    1718#include <errno.h>
     
    2223#include <sys/sem.h>
    2324#include <sys/wait.h>
     25#ifndef S_SPLINT_S
    2426#include <pthread.h>
     27#endif
    2528
    2629#include "my-stuff.h"
    2730#include "mondostructures.h"
    2831#include "libmondo.h"
     32#include "mr_mem.h"
    2933
    3034/**
     
    4145 */
    4246pid_t g_mastermind_pid = 0;
    43 
    44 
    4547
    4648/**
     
    7375                             long internal_tape_block_size)
    7476{
    75     char sz_dir[32];
     77    char *sz_dir;
    7678    char keych;
    7779    char *tmp;
    78     char *command;
    7980    FILE *fres;
    8081    int bufsize;                // in megabytes
     
    8384    int wise_lower_limit;
    8485
    85     malloc_string(tmp);
    86     malloc_string(command);
    8786    assert_string_is_neither_NULL_nor_zerolength(device);
    8887    assert(direction == 'w' || direction == 'r');
    89     sprintf(sz_dir, "%c", direction);
     88    mr_asprintf(&sz_dir, "%c", direction);
    9089    wise_upper_limit = (am_I_in_disaster_recovery_mode()? 8 : 32);
    9190    wise_lower_limit = 1;       // wise_upper_limit/2 + 1;
    92     paranoid_system("sync");
     91    sync();
    9392    for (bufsize = wise_upper_limit, res = -1;
    9493         res != 0 && bufsize >= wise_lower_limit; bufsize--) {
    95         sprintf(tmp,
    96                 "dd if=/dev/zero bs=1024 count=16k 2> /dev/null | buffer -o /dev/null -s %ld -m %d%c",
    97                 internal_tape_block_size, bufsize, 'm');
     94        mr_asprintf(&tmp,
     95                 "dd if=/dev/zero bs=1024 count=16k 2> /dev/null | buffer -o /dev/null -s %ld -m %d%c",
     96                 internal_tape_block_size, bufsize, 'm');
    9897        res = run_program_and_log_output(tmp, 2);
     98        mr_free(tmp);
    9999    }
    100100    if (!res) {
    101101        bufsize++;
    102         sprintf(tmp, "Negotiated max buffer of %d MB ", bufsize);
     102        mr_asprintf(&tmp, _("Negotiated max buffer of %d MB "), bufsize);
    103103        log_to_screen(tmp);
     104        mr_free(tmp);
    104105    } else {
    105106        bufsize = 0;
    106107        res = 0;
    107108        log_to_screen
    108             ("Cannot negotiate a buffer of ANY size. Using dd instead.");
     109            (_("Cannot negotiate a buffer of ANY size. Using dd instead."));
    109110    }
    110111    if (direction == 'r') {
     
    124125    mr_msg(2, "Calling buffer --- command = '%s'", g_sz_call_to_buffer);
    125126    fres = popen(g_sz_call_to_buffer, sz_dir);
     127    mr_free(sz_dir);
    126128    if (fres) {
    127129        mr_msg(2, "Successfully opened ('%c') tape device %s", direction,
     
    132134    }
    133135    sleep(2);
    134     sprintf(tmp, "ps %s | grep \"%s\"", ps_options, g_sz_call_to_buffer);
     136    mr_asprintf(&tmp, "ps %s | grep \"%s\"", ps_options, g_sz_call_to_buffer);
    135137    if (run_program_and_log_output(tmp, 2)) {
    136138        mr_msg(2, "Warning - I think I failed to open tape, actually.");
    137139    }
     140    mr_free(tmp);
    138141    g_tape_buffer_size_MB = bufsize;
    139     tmp[30] = '\0';
    140     sprintf(command, "ps %s | grep buffer | grep -v grep", ps_options);
    141     if (run_program_and_log_output(command, 1)) {
     142    mr_asprintf(&tmp, "ps %s | grep buffer | grep -v grep", ps_options);
     143    if (run_program_and_log_output(tmp, 1)) {
    142144        fres = NULL;
    143         log_to_screen("Failed to open tape streamer. Buffer error.");
    144     } else {
    145         log_to_screen("Buffer successfully started.");
    146     }
    147 
    148     mr_free(command);
     145        log_to_screen(_("Failed to open tape streamer. Buffer error."));
     146    } else {
     147        log_to_screen(_("Buffer successfully started."));
     148    }
    149149    mr_free(tmp);
    150150    return (fres);
     
    161161    char *command;
    162162
     163    malloc_string(tmp);
     164    sync();
    163165    if (g_sz_call_to_buffer == NULL) {
    164166        return;
     
    167169        return;
    168170    }
    169     malloc_string(tmp);
    170     malloc_string(command);
    171     paranoid_system("sync");
    172     sprintf(command,
     171    mr_asprintf(&command,
    173172            "ps %s | grep -F \"%s\" | grep -Fv grep | awk '{print $2;}' | grep -v PID | head -1", ps_options, g_sz_call_to_buffer);
    174173    mr_msg(2, "kill_buffer() --- command = %s", command);
    175174    strcpy(tmp, call_program_and_get_last_line_of_output(command));
    176     sprintf(command, "kill %s", tmp);
     175    mr_free(command);
     176
     177    mr_asprintf(&command, "kill %s", tmp);
    177178    mr_msg(2, "kill_buffer() --- command = %s", command);
    178179    if (strlen(tmp) > 0) {
     
    182183    mr_free(command);
    183184}
    184 
    185 
    186 
    187185
    188186
     
    198196/* @} - end of fifoGroup */
    199197
    200 int
    201 extract_config_file_from_ramdisk(struct s_bkpinfo *bkpinfo,
    202                                  char *ramdisk_fname,
    203                                  char *output_cfg_file,
    204                                  char *output_mountlist_file);
     198/* BERLIOS: useless ?
     199int
     200extract_config_file_from_ramdisk( struct s_bkpinfo *bkpinfo,
     201                  char *ramdisk_fname,
     202                  char *output_cfg_file,
     203                  char *output_mountlist_file);
     204*/
Note: See TracChangeset for help on using the changeset viewer.