Ignore:
Timestamp:
Nov 19, 2005, 2:27:41 AM (18 years ago)
Author:
bcornec
Message:

indent on all the C code

File:
1 edited

Legend:

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

    r30 r128  
    11/* libmondo-fifo.c
    2    $Id: libmondo-fifo.c,v 1.7 2004/06/10 15:29:12 hugo Exp $
     2   $Id$
    33
    44
     
    9292#include <stdio.h>
    9393#include <signal.h>
    94 #include <fcntl.h>     
     94#include <fcntl.h>
    9595#include <stdio.h>
    96  
     96
    9797#include <errno.h>
    9898#include <sys/types.h>
     
    115115 * The SIGPIPE handler sets this to TRUE.
    116116 */
    117 bool g_sigpipe=FALSE;
     117bool g_sigpipe = FALSE;
    118118
    119119/**
    120120 * PID of the "main" process.
    121121 */
    122 pid_t g_mastermind_pid=0;
     122pid_t g_mastermind_pid = 0;
    123123
    124124
     
    132132 * Size of the buffer used with @c buffer.
    133133 */
    134 int g_tape_buffer_size_MB=0;
     134int g_tape_buffer_size_MB = 0;
    135135
    136136/* @} - end of globalGroup */
     
    148148 * @return A file pointer to/from the @c buffer process.
    149149 */
    150 FILE*open_device_via_buffer(char*device, char direction, long internal_tape_block_size)
     150FILE *open_device_via_buffer(char *device, char direction,
     151                             long internal_tape_block_size)
    151152{
    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;
    161 
    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);
     153    char sz_dir[32];
     154    char keych;
     155    char *tmp;
     156    char *command;
     157    FILE *fres;
     158    int bufsize;                // in megabytes
     159    int res;
     160    int wise_upper_limit;
     161    int wise_lower_limit;
     162
     163    malloc_string(tmp);
     164    malloc_string(command);
     165    assert_string_is_neither_NULL_nor_zerolength(device);
     166    assert(direction == 'w' || direction == 'r');
     167    sprintf(sz_dir, "%c", direction);
     168    wise_upper_limit = (am_I_in_disaster_recovery_mode()? 8 : 32);
     169    wise_lower_limit = 1;       // wise_upper_limit/2 + 1;
     170    paranoid_system("sync");
     171    for (bufsize = wise_upper_limit, res = -1;
     172         res != 0 && bufsize >= wise_lower_limit; bufsize--) {
     173        sprintf(tmp,
     174                "dd if=/dev/zero bs=1024 count=16k 2> /dev/null | buffer -o /dev/null -s %ld -m %d%c",
     175                internal_tape_block_size, bufsize, 'm');
     176        res = run_program_and_log_output(tmp, 2);
     177    }
     178    if (!res) {
     179        bufsize++;
     180        sprintf(tmp, "Negotiated max buffer of %d MB ", bufsize);
     181        log_to_screen(tmp);
     182    } else {
     183        bufsize = 0;
     184        res = 0;
     185        log_to_screen
     186            ("Cannot negotiate a buffer of ANY size. Using dd instead.");
     187    }
     188    if (direction == 'r') {
     189        keych = 'i';
     190    } else {
     191        keych = 'o';
     192    }
     193    if (bufsize) {
     194        sprintf(g_sz_call_to_buffer,
     195                "buffer -m %d%c -p%d -B -s%ld -%c %s 2>> %s", bufsize, 'm',
     196                (direction == 'r') ? 20 : 75, internal_tape_block_size,
     197                keych, device, MONDO_LOGFILE);
     198    } else {
     199        sprintf(g_sz_call_to_buffer, "dd bs=%ld %cf=%s",
     200                internal_tape_block_size, keych, device);
     201    }
     202    log_msg(2, "Calling buffer --- command = '%s'", g_sz_call_to_buffer);
     203    fres = popen(g_sz_call_to_buffer, sz_dir);
     204    if (fres) {
     205        log_msg(2, "Successfully opened ('%c') tape device %s", direction,
     206                device);
     207    } else {
     208        log_msg(2, "Failed to open ('%c') tape device %s", direction,
     209                device);
     210    }
     211    sleep(2);
     212    sprintf(tmp, "ps wwax | grep \"%s\"", g_sz_call_to_buffer);
     213    if (run_program_and_log_output(tmp, 2)) {
     214        log_msg(2, "Warning - I think I failed to open tape, actually.");
     215    }
     216    g_tape_buffer_size_MB = bufsize;
     217    strcmp(tmp, g_sz_call_to_buffer);
     218    tmp[30] = '\0';
     219    sprintf(command, "ps wwax | grep buffer | grep -v grep");
     220    if (run_program_and_log_output(command, 1)) {
     221        fres = NULL;
     222        log_to_screen("Failed to open tape streamer. Buffer error.");
     223    } else {
     224        log_to_screen("Buffer successfully started.");
     225    }
     226
     227    paranoid_free(command);
     228    paranoid_free(tmp);
     229    return (fres);
    222230}
    223231
     
    228236void kill_buffer()
    229237{
    230   char *tmp;
    231   char *command;
    232 
    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);
     238    char *tmp;
     239    char *command;
     240
     241    malloc_string(tmp);
     242    malloc_string(command);
     243    paranoid_system("sync");
     244    sprintf(command,
     245            "ps wwax | fgrep \"%s\" | fgrep -v grep | awk '{print $1;}' | grep -v PID | tr -s '\n' ' ' | awk '{ print $1; }'",
     246            g_sz_call_to_buffer);
     247    log_msg(2, "kill_buffer() --- command = %s", command);
     248    strcpy(tmp, call_program_and_get_last_line_of_output(command));
     249    sprintf(command, "kill %s", tmp);
     250    log_msg(2, "kill_buffer() --- command = %s", command);
     251    if (strlen(tmp) > 0) {
     252        run_program_and_log_output(command, TRUE);
     253    }
     254    paranoid_free(tmp);
     255    paranoid_free(command);
    244256}
    245257
     
    254266void sigpipe_occurred(int sig)
    255267{
    256   g_sigpipe = TRUE;
     268    g_sigpipe = TRUE;
    257269}
    258270
    259271/* @} - end of fifoGroup */
    260272
    261 int 
    262 extract_config_file_from_ramdisk( struct s_bkpinfo *bkpinfo,
    263                   char *ramdisk_fname,
    264                   char *output_cfg_file,
    265                   char *output_mountlist_file);
     273int
     274extract_config_file_from_ramdisk(struct s_bkpinfo *bkpinfo,
     275                                 char *ramdisk_fname,
     276                                 char *output_cfg_file,
     277                                char *output_mountlist_file);
Note: See TracChangeset for help on using the changeset viewer.