Changeset 2421


Ignore:
Timestamp:
Sep 24, 2009, 3:50:38 PM (10 years ago)
Author:
bruno
Message:
  • Remove some compiler warnings on main
  • Adds function mr_chomp and mr_strip_char and use them in mr_date and call_program_and_get_last_line_of_output
  • Fix call_program_and_get_last_line_of_output to return the right result using a temp file instead of popen
  • Fix an issue in mr_getline_int in case of eof (returns now an empty string)
  • Sequencing of Init of bkpinfo reviewed
Location:
branches/2.2.10
Files:
15 edited

Legend:

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

    r2420 r2421  
    993993        if (!does_file_exist(archiving_filelist_fname)) {
    994994            log_msg(3, "[%d:%d] - well, I would archive %d, except that it doesn't exist. I'll stop now.", getpid(), this_thread_no, archiving_set_no);
     995            mr_free(archiving_afioball_fname);
    995996            break;
    996997        }
     
    12911292    malloc_string(result_str);
    12921293    transfer_block = malloc(sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
    1293     memset((void *) transfer_block, 0,
    1294            sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
     1294    memset((void *) transfer_block, 0, sizeof(struct s_bkpinfo) + BKPINFO_LOC_OFFSET + 64);
    12951295    p_last_set_archived = (int *) transfer_block;
    12961296    p_archival_threads_running = (int *) (transfer_block + 4);
    12971297    p_next_set_to_archive = (int *) (transfer_block + 8);
    12981298    p_list_of_fileset_flags = (char *) (transfer_block + 12);
    1299     memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET),
    1300            (void *) bkpinfo, sizeof(struct s_bkpinfo));
     1299    memcpy((void *) (transfer_block + BKPINFO_LOC_OFFSET), (void *) bkpinfo, sizeof(struct s_bkpinfo));
    13011300    pvp = &vp;
    13021301    vp = (void *) result_str;
     
    13101309                       "Please wait. This may take a couple of hours.",
    13111310                       "Working...",
    1312                        get_last_filelist_number() + 1);
     1311                       (long)get_last_filelist_number() + 1L);
    13131312
    13141313    log_msg(5, "We're gonna party like it's your birthday.");
  • branches/2.2.10/mondo/src/common/libmondo-devices.c

    r2405 r2421  
    22572257char *where_is_root_mounted() {
    22582258    /*@ buffers **************** */
    2259     char *output;
     2259    char *output = NULL;
    22602260
    22612261
  • branches/2.2.10/mondo/src/common/libmondo-fork.c

    r2420 r2421  
    88#include "my-stuff.h"
    99#include "mr_mem.h"
     10#include "mr_str.h"
    1011#include "mondostructures.h"
    1112#include "libmondo-fork.h"
     
    3940    char *result = NULL;
    4041    char *tmpf = NULL;
     42    char *newcall = NULL;
     43    char *tmp = NULL;
    4144
    4245    /*@ pointers **************************************************** */
    43     FILE *fin;
     46    FILE *fin = NULL;
    4447
    4548    /*@******************************************************************** */
     
    4750    assert_string_is_neither_NULL_nor_zerolength(call);
    4851
    49     mr_asprintf(tmpf, "%s/cpgll.out", bkpinfo->scratchdir);
    50     mr_strcat(call, " > %s", tmpf);
    51     log_msg(4, "Calling command: %s", call);
     52    mr_asprintf(tmpf, "%s/cpgll.out", bkpinfo->tmpdir);
     53    mr_asprintf(newcall, "%s > %s", call, tmpf);
     54    log_msg(4, "Calling command: %s", newcall);
    5255    /* By default return an empty string in any case */
    5356    mr_asprintf(result, "");
    5457
    55     system(call);
    56     if ((fin = fopen(ftmp, "r"))) {
     58    system(newcall);
     59    mr_free(newcall);
     60
     61    if ((fin = fopen(tmpf, "r"))) {
    5762        while (!feof(fin)) {
    58             mr_getline(result, fin);
    59             log_msg(9, "Loop result: %s", result);
    60         }
    61         log_msg(4, "Final Result: %s", result);
     63            mr_getline(tmp, fin);
     64            mr_chomp(tmp);
     65            /* In case of extreme debug ;-)
     66            log_msg(9, "Loop result: ***%s***", tmp);
     67            */
     68            /*  There is empty contant at the end of the file that needs to be skiped */
     69            if (strlen(tmp) > 0) {
     70                mr_free(result);
     71                mr_asprintf(result, "%s", tmp);
     72            }
     73            mr_free(tmp);
     74        }
     75        log_msg(4, "Result: %s", result);
    6276        mr_strip_spaces(result);
    6377        paranoid_pclose(fin);
    6478    } else {
    65         log_OS_error("Unable to popen call");
    66     }
    67     mr_free(ftmp)
    68     log_msg(4, "Returns: %s", result);
     79        log_OS_error("Unable to open resulting file");
     80    }
     81    mr_free(tmpf);
    6982    return(result);
    7083}
  • branches/2.2.10/mondo/src/common/libmondo-tools-EXT.h

    r2325 r2421  
    33extern void clean_up_KDE_desktop_if_necessary(void);
    44extern long get_time();
    5 extern char *mr_date(void);
    65extern void (*log_debug_msg) (int debug_level, const char *szFile,
    76                              const char *szFunction, int nLine,
  • branches/2.2.10/mondo/src/common/libmondo-tools.c

    r2406 r2421  
    803803    bkpinfo = (struct s_bkpinfo *)mr_malloc(sizeof(struct s_bkpinfo));
    804804
     805    /*  We need tmpdir as early as possible for further function calls */
     806    bkpinfo->tmpdir = NULL;         // Really setup after
     807    setup_tmpdir(NULL);
     808
    805809    /* Initialized in same order as in the structure declaration to detect errors more easily */
    806810    bkpinfo->media_device = NULL;
     
    822826    bkpinfo->use_star = FALSE;
    823827    bkpinfo->internal_tape_block_size = DEFAULT_INTERNAL_TAPE_BLOCK_SIZE;
    824     bkpinfo->disaster_recovery = (am_I_in_disaster_recovery_mode()? TRUE : FALSE);
     828    bkpinfo->disaster_recovery = am_I_in_disaster_recovery_mode();
    825829    if (bkpinfo->disaster_recovery) {
    826830        mr_asprintf(bkpinfo->isodir, "%s", "/");
     
    829833    }
    830834    mr_asprintf(bkpinfo->prefix, "%s", STD_PREFIX);
     835    /*   bkpinfo->tmpdir is here in the struct */
    831836    bkpinfo->scratchdir = NULL;     // Really setup after
    832     bkpinfo->tmpdir = NULL;         // Really setup after
    833837    bkpinfo->optimal_set_size = 0;
    834838    bkpinfo->backup_media_type = none;
     
    857861    bkpinfo->restore_mode = interactive;
    858862
    859     setup_tmpdir(NULL);
    860863    sensibly_set_scratchdir();
    861864}
     
    13641367        va_end(args);
    13651368
    1366         // do not slow down the progran if standard debug level
    1367         // must be enabled: if no flush, the log won't be up-to-date if there
    1368         // is a segfault
    1369         //if (g_dwDebugLevel != 1)
    1370 
    13711369        fprintf(fout, "\n");
    13721370        paranoid_fclose(fout);
  • branches/2.2.10/mondo/src/common/libmondo-tools.h

    r2325 r2421  
    66
    77long get_time();
    8 char *mr_date(void);
    98extern void (*log_debug_msg) (int debug_level, const char *szFile,
    109                              const char *szFunction, int nLine,
  • branches/2.2.10/mondo/src/common/newt-specific.c

    r2414 r2421  
    9696    extern int g_current_media_number;
    9797    pid_t g_main_pid = 0;       ///< The PID of the main Mondo process.
    98     long g_maximum_progress = 999;  ///< The maximum amount of progress (100%) for the currently opened progress form.
     98    long g_maximum_progress = 999L; ///< The maximum amount of progress (100%) for the currently opened progress form.
    9999    long g_current_progress = -999; ///< The current amount of progress (filelist #, etc.) for the currently opened progress form.
    100100    long g_start_time = 0L;     ///< The time (in seconds since the epoch) that the progress form was opened.
     
    644644            g_blurb3 = newtLabel(2, 4, blurb2);
    645645            newtCenteredWindow(60, 11, title);
    646             g_scale = newtScale(3, 6, 54, g_maximum_progress);
     646            g_scale = newtScale(3, 6, 54, (long long)g_maximum_progress);
    647647            g_progressForm = newtForm(NULL, NULL, 0);
    648648            g_percentline = newtLabel(10, 9, "This is the percentline");
  • branches/2.2.10/mondo/src/include/mr_str.h

    r2208 r2421  
    1717extern char *mr_strtok(char *instr, const char *delims, int *lastpos);
    1818extern char *mr_stresc(char *instr, char *toesc, const char escchr);
    19 extern inline char *mr_date(void);
     19extern char *mr_date(void);
    2020extern void mr_strip_spaces(char *in_out);
     21extern void mr_strip_char(char *in_out, char *caracs);
     22extern void mr_chomp(char *in_out);
    2123
    2224#endif                          /* MR_STR_H */
  • branches/2.2.10/mondo/src/lib/mr_mem.c

    r2341 r2421  
    5353}
    5454
    55 /* encapsulation function for getline */
    56 void mr_getline_int(char **lineptr, FILE *fd, int line, const char *file) {
    57    
    58     ssize_t ret;
    59     size_t n = 0;
    60 
    61     ret = getline(lineptr,&n,fd);
    62     if ((ret == -1) && (! feof(fd))) {
    63         mr_msg_int(1,line,file,"Unable to alloc memory in mr_getline\nExiting...");
    64         mr_exit(-1,"Unable to alloc memory in mr_getline");
    65     }
    66 }
    67 
    6855/* encapsulation function for asprintf */
    6956void mr_asprintf_int(char **strp, int line, const char *file, const char *fmt, ...) {
     
    7966    }
    8067    va_end(args);
     68}
     69
     70/* encapsulation function for getline */
     71void mr_getline_int(char **lineptr, FILE *fd, int line, const char *file) {
     72   
     73    ssize_t ret;
     74    size_t n = 0;
     75
     76    ret = getline(lineptr,&n,fd);
     77    if ((ret == -1) && (! feof(fd))) {
     78        mr_msg_int(1,line,file,"Unable to alloc memory in mr_getline\nExiting...");
     79        mr_exit(-1,"Unable to alloc memory in mr_getline");
     80    }
     81    /*  We reached end of file, allocating empty string */
     82    if (ret == -1) {
     83        mr_asprintf_int(lineptr, line, file, "");
     84    }
    8185}
    8286
  • branches/2.2.10/mondo/src/lib/mr_str.c

    r1924 r2421  
    104104}
    105105
    106 /* Return a string containing the date */
    107 char *mr_date(void) {
    108    
    109     time_t tcurr;
    110 
    111     tcurr = time(NULL);
    112     return(ctime(&tcurr));
    113 }
    114 
    115 
    116106/**
    117  * Remove all characters whose ASCII value is less than or equal to 32
    118  * (spaces and control characters) from both sides of @p in_out.
    119  * @param in_out The string to strip spaces/control characters from (modified).
     107 * Remove all characters in caracs from begining and end of string @p in_out
     108 * @param in_out The string to strip char characters from (modified).
    120109 */
    121 void mr_strip_spaces(char *in_out) {
     110void mr_strip_char(char *in_out, char *caracs) {
    122111    int i = 0;
    123112    int j = 0;
    124     size_t length;
     113    int length = 0;
    125114
     115    if (caracs == NULL) {
     116        return;
     117    }
    126118    if (in_out == NULL) {
    127119        return;
    128120    }
    129     length = strlen(in_out);
     121    length = (int)strlen(in_out);
    130122
    131     /* Skip initial spaces and special chars */
    132     for (i = 0; in_out[i] <= ' ' && i < (int)length ; i++);
     123    /* Skip initial caracs */
     124    for (i = 0; index(caracs, in_out[i]) != NULL && i < length ; i++);
     125
    133126    /* Shift the string to the begining if needed */
    134127    if (i != 0) {
    135         for (j = 0; i < (int)length ; i++, j++) {
     128        for (j = 0; i < length ; i++, j++) {
    136129            in_out[j] = in_out[i];
    137130        }
     
    142135
    143136    /* Skip final spaces and special chars */
    144     for (i = (int)strlen(in_out) - 1; i >= 0  && in_out[i] <= ' '; i--);
     137    for (i = (int)strlen(in_out) - 1; i >= 0  && index(caracs, in_out[i]) != NULL; i--);
    145138
    146139    /* The string now ends after that char */
     
    148141    in_out[i] = '\0';
    149142}
     143
     144/**
     145 * Remove all characters whose ASCII value is less than or equal to 32
     146 * (spaces and control characters) from both sides of @p in_out.
     147 * @param in_out The string to strip spaces/control characters from (modified).
     148 */
     149void mr_strip_spaces(char *in_out) {
     150
     151    int i;
     152    char *tmp = NULL;
     153
     154    mr_asprintf(tmp, "");
     155
     156    /* Build the string of char to avoid: ctrl char up to space*/
     157    for (i = 0; i <= ' '; i++) {
     158        mr_strcat(tmp, "%c", i);
     159    }
     160   
     161    mr_strip_char(in_out, tmp);
     162    mr_free(tmp);
     163}
     164
     165/*
     166 * Remove '\n' char from both sides of @p in_out.
     167 * @param in_out The string to strip characters from (modified).
     168 */
     169void mr_chomp(char *in_out) {
     170
     171    mr_strip_char(in_out, "\n");
     172}
     173
     174/* Return an allocated string containing the date */
     175char *mr_date(void) {
     176   
     177    time_t tcurr;
     178    char *tmp = NULL;
     179
     180    tcurr = time(NULL);
     181    mr_asprintf(tmp, "%s", ctime(&tcurr));
     182    mr_chomp(tmp);
     183    return(tmp);
     184}
     185
     186
  • branches/2.2.10/mondo/src/mondoarchive/mondoarchive.c

    r2413 r2421  
    1010#include "my-stuff.h"
    1111#include "mr_mem.h"
     12#include "mr_str.h"
    1213#include "../common/mondostructures.h"
    1314#include "../common/libmondo.h"
     
    161162    printf("Initializing...\n");
    162163
    163     init_bkpinfo();
    164 
    165164    /* initialize log file with time stamp */
    166165    unlink(MONDO_LOGFILE);
    167     log_msg(0, "Time started: %s", mr_date());
     166    tmp = mr_date();
     167    log_msg(0, "Time started: %s", tmp);
     168    mr_free(tmp);
     169
     170    init_bkpinfo();
    168171
    169172    /* Memory allocation is done in those functions */
     
    416419
    417420    /* finalize log file with time stamp */
    418     log_msg(0, "Time finished: %s", mr_date());
     421    tmp = mr_date();
     422    log_msg(0, "Time finished: %s", tmp);
     423    mr_free(tmp);
    419424
    420425    chdir("/tmp");
  • branches/2.2.10/mondo/test/test-mountlist.c

    r2395 r2421  
    4646void (*mr_cleanup)(int) = NULL;
    4747
    48 void main() {
     48int main() {
    4949
    5050struct mountlist_itself *mountlist = NULL;
  • branches/2.2.10/mondo/test/test-msg.c

    r2310 r2421  
    2424    int l = 0;
    2525    char *str = NULL;
    26     size_t n = (size_t)0;
    2726    FILE *fd = NULL;
    2827
     
    5352
    5453    if ((fd = fopen(s,"r")) != NULL) {
    55         (void)getline(&str, &n, fd);
     54        mr_getline(str, fd);
    5655        fprintf(stdout, "%s", str);
    5756        mr_free(str);
  • branches/2.2.10/mondo/test/test-truncname.c

    r2323 r2421  
    4747}
    4848
    49 void main() {
     49int main() {
    5050
    5151char *part = NULL;
  • branches/2.2.10/tools/myval

    r2351 r2421  
    22
    33# Call valgrind to test mondo
     4PTH=$HOME/
    45
    5 sudo valgrind --log-file=/tmp/val.log --show-reachable=yes --track-origins=yes --leak-check=full /home/bruno/local/pb/projects/mondorescue/build/BUILD/mondo-2.2.10/src/mondoarchive/mondoarchive -K 99 -Oi -I "/etc /var/lib/rpm" -d /home
    6 sudo valgrind --log-file=/tmp/valg.log --show-reachable=yes --track-origins=yes --leak-check=full /home/bruno/local/pb/projects/mondorescue/build/BUILD/mondo-2.2.10/src/mondoarchive/mondoarchive -K 99 -Oi -g -G -I "/etc /var/lib/rpm"  -E /etc/init.d -d /home
    7 sudo valgrind --log-file=/tmp/valm.log --tool=massif --heap=yes --stacks=yes --alloc-fn=mr_malloc --massif-out-file=/tmp/valm.out /home/bruno/local/pb/projects/mondorescue/build/BUILD/mondo-2.2.10/src/mondoarchive/mondoarchive -K 99 -Oi -g -G -I "/etc /var/lib/rpm"  -E /etc/init.d -d /home
    8 sudo valgrind --log-file=/tmp/valc.log --tool=callgrind --callgrind-out-file=/tmp/valc.out /home/bruno/local/pb/projects/mondorescue/build/BUILD/mondo-2.2.10/src/mondoarchive/mondoarchive -K 99 -Oi -g -Y -I "/etc /var/lib/rpm"  -T /tmp -S /var/spool/mondo -E /etc/init.d -d /home
     6sudo valgrind $PTH/pb/projects/mondorescue/build/BUILD/mondo-2.2.10/src/mondoarchive/mondoarchive -v
     7sudo valgrind --log-file=/tmp/val.log --show-reachable=yes --track-origins=yes --leak-check=full $PTH/pb/projects/mondorescue/build/BUILD/mondo-2.2.10/src/mondoarchive/mondoarchive -K 99 -Oi -I "/etc /var/lib/rpm" -d /home
     8sudo valgrind --log-file=/tmp/valg.log --show-reachable=yes --track-origins=yes --leak-check=full $PTH/pb/projects/mondorescue/build/BUILD/mondo-2.2.10/src/mondoarchive/mondoarchive -K 99 -Oi -g -G -I "/etc /var/lib/rpm"  -E /etc/init.d -d /home
     9sudo valgrind --log-file=/tmp/valm.log --tool=massif --heap=yes --stacks=yes --alloc-fn=mr_malloc --massif-out-file=/tmp/valm.out $PTH/pb/projects/mondorescue/build/BUILD/mondo-2.2.10/src/mondoarchive/mondoarchive -K 99 -Oi -g -G -I "/etc /var/lib/rpm"  -E /etc/init.d -d /home
     10sudo valgrind --log-file=/tmp/valc.log --tool=callgrind --callgrind-out-file=/tmp/valc.out $PTH/pb/projects/mondorescue/build/BUILD/mondo-2.2.10/src/mondoarchive/mondoarchive -K 99 -Oi -g -Y -I "/etc /var/lib/rpm"  -T /tmp -S /var/spool/mondo -E /etc/init.d -d /home
Note: See TracChangeset for help on using the changeset viewer.