Ignore:
Timestamp:
Sep 24, 2009, 3:50:38 PM (11 years ago)
Author:
Bruno Cornec
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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.