Changeset 42


Ignore:
Timestamp:
Oct 4, 2005, 1:32:14 AM (14 years ago)
Author:
bcornec
Message:

asprintf usage continues on libmondo-fifo.c + indent

Location:
trunk/mondo/mondo/common
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/common/X-specific.c

    r30 r42  
    2626
    2727
    28 char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN], g_blurb_str_1[MAX_STR_LEN] =
    29   "", g_blurb_str_2[MAX_STR_LEN] = "", g_blurb_str_3[MAX_STR_LEN] = "";
     28char err_log_lines[NOOF_ERR_LINES][MAX_STR_LEN],
     29    g_blurb_str_1[MAX_STR_LEN] = "", g_blurb_str_2[MAX_STR_LEN] =
     30    "", g_blurb_str_3[MAX_STR_LEN] = "";
    3031
    3132
     
    3536int g_mysterious_dot_counter;
    3637
    37 int g_currentY = 3;     /* purpose */
     38int g_currentY = 3;             /* purpose */
    3839int g_current_media_number;
    3940
    4041long g_maximum_progress = 999;  /* purpose */
    4142long g_current_progress = -999; /* purpose */
    42 long g_start_time = 0;      /* purpose */
     43long g_start_time = 0;          /* purpose */
    4344bool g_text_mode = TRUE;
    4445
    4546
    4647extern pid_t g_mastermind_pid;
    47 
    48 
    49 
    50 
  • trunk/mondo/mondo/common/libmondo-fifo.c

    r30 r42  
    1 /* libmondo-fifo.c
    2    $Id: libmondo-fifo.c,v 1.7 2004/06/10 15:29:12 hugo Exp $
    3 
    4 
    5 04/17
    6 - replaced INTERNAL_TAPE_BLK_SIZE with bkpinfo->internal_tape_block_size
    7 
    8 04/04/2004
    9 - ps wax is now ps wwax
    10 
    11 09/10/2003
    12 - p75 is now p80 in outopening tape call
    13 - negotiate largest buffer possible when opening tape drive
    14 - fall back to dd if buffer fails
    15 
    16 09/09
    17 - better logging for tape users
    18 - working on try_hard_to_fwrite(), try_hard_to_fread()
    19 - replaced internal w/ EXTERNAL 'buffer' exe.
    20 
    21 08/30
    22 - tweaked error msgs in try_hard_to_fwrite()
    23 
    24 08/02
    25 - updated is_incoming_block_valid() to make it
    26   return end-of-tape if >300 flotsam blocks
    27 
    28 05/02
    29 - when logging tape errors, don't repeat self
    30 
    31 04/24
    32 - added lots of log_OS_error()'s and assert()'s
    33 
    34 04/22
    35 - copy_file_from_here_to_there() --- added a bit of fault tolerance;
    36   if write fails, retry a few times before reporting error
    37 
    38 04/07/2003
    39 - line 866 --- set block_size used by internal buffer to 32768;
    40   was INTERNAL_TAPE_BLK_SIZE/2
    41 
    42 10/01 - 11/30/2002
    43 - is_incoming_block_valid() --- always make
    44   checksums %65536, just in case int size is
    45   odd (GRRR, ArkLinux)
    46 - disabled rotor-related superfluous warnings
    47 - added INTERNAL_TAPE_BLK_SIZE
    48 - do_sem() now returns int explicitly
    49 - changed internal_block_size
    50 - some irregularities (e.g. bad 'type'-ing) found by Kylix; fixed by Hugo
    51 
    52 09/01 - 09/30
    53 - change 64k to TAPE_BLOCK_SIZE
    54 - added internal_block_size; set it to TAPE_BLOCK_SIZE*2
    55 - if data is flowing FROM tape TO hard disk then set the threshold to 10 (not 75)
    56 - lots of multitape-related fixes
    57 - finally caught & fixed the 'won't finish unzipping last bigfile' bug
    58 - added WIFEXITED() after waitpid(), to improve multi-tape support
    59 
    60 08/01 - 08/31
    61 - trying to catch & stop 'won't finish unzipping last bigfile' bug by
    62   changing the copy_file_rom_here_to_there code
    63 - changed % threshold from 95 back to 75
    64 - don't insist on full 256K write of last block to tape
    65 - if >25 secs go by & all data (AFAIK) has been copied thru by FIFO wrapper
    66   and g_tape_stream is _still_ not closed then shrug shoulders & pthread_exit
    67   anyway...
    68 - change fprintf()'s to log_it()'s
    69 - added a header+footer to each block as it is read/written to/from tape
    70   by copy_file_from_here_to_there
    71 - wrote workaround to allow >2GB of archives w/buffering
    72 - changed % threshold from 75 to 95
    73 - added calls to set_signals(); 'buffer' was killing mondoarchive as
    74   it terminated
    75 - cleaned up struct-passing, to improve reliability and eliminate
    76   some race conditions
    77 - changed some forks to pthreads
    78 - added some comments
    79 - created libfifo{.c,.h,-EXT.h}
    80 - copied core of 'buffer' here
    81 - added some other, Mondo-specific functions
    82 - hacked 'buffer' into user-friendliness
    83 */
     1/* $Id$ */
    842
    853/**
     
    9210#include <stdio.h>
    9311#include <signal.h>
    94 #include <fcntl.h>     
     12#include <fcntl.h>
    9513#include <stdio.h>
    96  
     14
    9715#include <errno.h>
    9816#include <sys/types.h>
     
    11533 * The SIGPIPE handler sets this to TRUE.
    11634 */
    117 bool g_sigpipe=FALSE;
     35bool g_sigpipe = FALSE;
    11836
    11937/**
    12038 * PID of the "main" process.
    12139 */
    122 pid_t g_mastermind_pid=0;
     40pid_t g_mastermind_pid = 0;
    12341
    12442
     
    12745 * Command line with which @c buffer was invoked.
    12846 */
    129 char g_sz_call_to_buffer[MAX_STR_LEN];
     47char *g_sz_call_to_buffer;
    13048
    13149/**
    13250 * Size of the buffer used with @c buffer.
    13351 */
    134 int g_tape_buffer_size_MB=0;
     52int g_tape_buffer_size_MB = 0;
    13553
    13654/* @} - end of globalGroup */
     
    14866 * @return A file pointer to/from the @c buffer process.
    14967 */
    150 FILE*open_device_via_buffer(char*device, char direction, long internal_tape_block_size)
     68FILE *open_device_via_buffer(char *device, char direction,
     69                             long internal_tape_block_size)
    15170{
    152   char sz_dir[32];
    153   char keych;
    154   char *tmp;
    155   char *command;
    156   FILE*fres;
    157   int bufsize; // in megabytes
    158   int res;
    159   int wise_upper_limit;
    160   int wise_lower_limit;
     71    char *sz_dir;
     72    char keych;
     73    char *tmp;
     74    FILE *fres;
     75    int bufsize;                // in megabytes
     76    int res;
     77    int wise_upper_limit;
     78    int wise_lower_limit;
    16179
    162   malloc_string(tmp);
    163   malloc_string(command);
    164   assert_string_is_neither_NULL_nor_zerolength(device);
    165   assert(direction=='w'||direction=='r');
    166   sprintf(sz_dir, "%c", direction);
    167   wise_upper_limit = (am_I_in_disaster_recovery_mode() ? 8 : 32);
    168   wise_lower_limit = 1; // wise_upper_limit/2 + 1;
    169   paranoid_system("sync");
    170   for(bufsize=wise_upper_limit,res=-1; res!=0 && bufsize>=wise_lower_limit; bufsize--)
    171     {
    172       sprintf(tmp, "dd if=/dev/zero bs=1024 count=16k 2> /dev/null | buffer -o /dev/null -s %ld -m %d%c", internal_tape_block_size, bufsize, 'm');
    173       res = run_program_and_log_output(tmp, 2);
    174     }
    175   if (!res)
    176     {
    177       bufsize++;
    178       sprintf(tmp, "Negotiated max buffer of %d MB ", bufsize);
    179       log_to_screen(tmp);
    180     }
    181   else
    182     {
    183       bufsize=0;
    184       res=0;
    185       log_to_screen("Cannot negotiate a buffer of ANY size. Using dd instead.");
    186     }
    187   if (direction=='r')
    188     { keych = 'i'; }
    189   else
    190     { keych = 'o'; }
    191   if (bufsize)
    192     { sprintf(g_sz_call_to_buffer, "buffer -m %d%c -p%d -B -s%ld -%c %s 2>> %s", bufsize, 'm', (direction=='r')?20:75, internal_tape_block_size, keych, device, MONDO_LOGFILE); }
    193   else
    194     { sprintf(g_sz_call_to_buffer, "dd bs=%ld %cf=%s", internal_tape_block_size, keych, device); }
    195   log_msg (2, "Calling buffer --- command = '%s'", g_sz_call_to_buffer);
    196   fres = popen(g_sz_call_to_buffer, sz_dir);
    197   if (fres)
    198     { log_msg (2, "Successfully opened ('%c') tape device %s", direction, device); }
    199   else
    200     { log_msg (2, "Failed to open ('%c') tape device %s", direction, device); }
    201   sleep(2);
    202   sprintf(tmp, "ps wwax | grep \"%s\"", g_sz_call_to_buffer);
    203   if (run_program_and_log_output(tmp, 2))
    204     { log_msg(2, "Warning - I think I failed to open tape, actually."); }
    205   g_tape_buffer_size_MB = bufsize;
    206   strcmp(tmp, g_sz_call_to_buffer);
    207   tmp[30] = '\0';
    208   sprintf(command, "ps wwax | grep buffer | grep -v grep");
    209   if (run_program_and_log_output(command, 1))
    210     {
    211       fres = NULL;
    212       log_to_screen("Failed to open tape streamer. Buffer error.");
    213     }
    214   else
    215     {
    216       log_to_screen("Buffer successfully started.");
    217     }
    218 
    219   paranoid_free(command);
    220   paranoid_free(tmp);
    221   return(fres);
     80    assert_string_is_neither_NULL_nor_zerolength(device);
     81    assert(direction == 'w' || direction == 'r');
     82    asprintf(&sz_dir, "%c", direction);
     83    wise_upper_limit = (am_I_in_disaster_recovery_mode()? 8 : 32);
     84    wise_lower_limit = 1;       // wise_upper_limit/2 + 1;
     85    paranoid_system("sync");
     86    for (bufsize = wise_upper_limit, res = -1;
     87         res != 0 && bufsize >= wise_lower_limit; bufsize--) {
     88        asprintf(&tmp,
     89                 "dd if=/dev/zero bs=1024 count=16k 2> /dev/null | buffer -o /dev/null -s %ld -m %d%c",
     90                 internal_tape_block_size, bufsize, 'm');
     91        res = run_program_and_log_output(tmp, 2);
     92        paranoid_free(tmp);
     93    }
     94    if (!res) {
     95        bufsize++;
     96        asprintf(&tmp, "Negotiated max buffer of %d MB ", bufsize);
     97        log_to_screen(tmp);
     98        paranoid_free(tmp);
     99    } else {
     100        bufsize = 0;
     101        res = 0;
     102        log_to_screen
     103            ("Cannot negotiate a buffer of ANY size. Using dd instead.");
     104    }
     105    if (direction == 'r') {
     106        keych = 'i';
     107    } else {
     108        keych = 'o';
     109    }
     110    if (bufsize) {
     111        asprintf(&g_sz_call_to_buffer,
     112                 "buffer -m %d%c -p%d -B -s%ld -%c %s 2>> %s", bufsize,
     113                 'm', (direction == 'r') ? 20 : 75,
     114                 internal_tape_block_size, keych, device, MONDO_LOGFILE);
     115    } else {
     116        asprintf(&g_sz_call_to_buffer, "dd bs=%ld %cf=%s",
     117                 internal_tape_block_size, keych, device);
     118    }
     119    log_msg(2, "Calling buffer --- command = '%s'", g_sz_call_to_buffer);
     120    fres = popen(g_sz_call_to_buffer, sz_dir);
     121    paranoid_free(sz_dir);
     122    if (fres) {
     123        log_msg(2, "Successfully opened ('%c') tape device %s", direction,
     124                device);
     125    } else {
     126        log_msg(2, "Failed to open ('%c') tape device %s", direction,
     127                device);
     128    }
     129    sleep(2);
     130    asprintf(&tmp, "ps wwax | grep \"%s\"", g_sz_call_to_buffer);
     131    if (run_program_and_log_output(tmp, 2)) {
     132        log_msg(2, "Warning - I think I failed to open tape, actually.");
     133    }
     134    paranoid_free(tmp);
     135    g_tape_buffer_size_MB = bufsize;
     136    /* BERLIOS: usless ?
     137       strcmp(tmp, g_sz_call_to_buffer);
     138       tmp[30] = '\0';
     139     */
     140    asprintf(&tmp, "ps wwax | grep buffer | grep -v grep");
     141    if (run_program_and_log_output(tmp, 1)) {
     142        fres = NULL;
     143        log_to_screen("Failed to open tape streamer. Buffer error.");
     144    } else {
     145        log_to_screen("Buffer successfully started.");
     146    }
     147    paranoid_free(tmp);
     148    return (fres);
    222149}
    223150
     
    228155void kill_buffer()
    229156{
    230   char *tmp;
    231   char *command;
     157    char *tmp;
     158    char *command;
    232159
    233   malloc_string(tmp);
    234   malloc_string(command);
    235   paranoid_system("sync");
    236   sprintf(command, "ps wwax | fgrep \"%s\" | fgrep -v grep | awk '{print $1;}' | grep -v PID | tr -s '\n' ' ' | awk '{ print $1; }'", g_sz_call_to_buffer);
    237   log_msg (2, "kill_buffer() --- command = %s", command);
    238   strcpy(tmp, call_program_and_get_last_line_of_output(command));
    239   sprintf(command, "kill %s", tmp);
    240   log_msg (2, "kill_buffer() --- command = %s", command);
    241   if (strlen(tmp)>0) { run_program_and_log_output(command, TRUE); }
    242   paranoid_free(tmp);
    243   paranoid_free(command);
     160    paranoid_system("sync");
     161    asprintf(&command,
     162             "ps wwax | fgrep \"%s\" | fgrep -v grep | awk '{print $1;}' | grep -v PID | tr -s '\n' ' ' | awk '{ print $1; }'",
     163             g_sz_call_to_buffer);
     164    paranoid_free(g_sz_call_to_buffer);
     165    log_msg(2, "kill_buffer() --- command = %s", command);
     166
     167    asprintf(&tmp, "%s",
     168             call_program_and_get_last_line_of_output(command));
     169    paranoid_free(command);
     170
     171    asprintf(&command, "kill %s", tmp);
     172    log_msg(2, "kill_buffer() --- command = %s", command);
     173
     174    if (strlen(tmp) > 0) {
     175        run_program_and_log_output(command, TRUE);
     176    }
     177    paranoid_free(command);
     178    paranoid_free(tmp);
    244179}
    245 
    246 
    247 
    248180
    249181
     
    254186void sigpipe_occurred(int sig)
    255187{
    256   g_sigpipe = TRUE;
     188    g_sigpipe = TRUE;
    257189}
    258190
    259191/* @} - end of fifoGroup */
    260192
     193/* BERLIOS: useless ?
    261194int
    262195extract_config_file_from_ramdisk( struct s_bkpinfo *bkpinfo,
     
    264197                  char *output_cfg_file,
    265198                  char *output_mountlist_file);
     199*/
  • trunk/mondo/mondo/common/libmondo-gui.c

    r30 r42  
    11/* libmondo-gui.c
    2  * $Id: libmondo-gui.c,v 1.2 2004/06/10 15:29:12 hugo Exp $
     2 * $Id$
    33 */
    44
     
    1010
    1111#ifdef _XWIN
    12     #include "X-specific.c"
     12#include "X-specific.c"
    1313#else
    14     #include "newt-specific.c"
     14#include "newt-specific.c"
    1515#endif
    16 
    17 
    18 
    19 
    20 
    21 
Note: See TracChangeset for help on using the changeset viewer.