Changeset 3034


Ignore:
Timestamp:
Sep 26, 2012, 11:39:22 PM (7 years ago)
Author:
bruno
Message:
  • Backport a 3.1 patch to use dynamic memory allocation for the function run_program_and_log_output and try to solve #644
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.0/mondo/src/common/libmondo-fork.c

    r2931 r3034  
    255255{
    256256    /*@ buffer ****************************************************** */
    257     char callstr[MAX_STR_LEN * 2];
     257    char *callstr = NULL;
    258258    char incoming[MAX_STR_LEN * 2];
    259     char tmp[MAX_STR_LEN * 2];
    260     char initial_label[MAX_STR_LEN * 2];
     259    char *tmp1 = NULL;
    261260
    262261    /*@ int ********************************************************* */
     
    286285        log_if_failure = TRUE;
    287286    }
    288     sprintf(callstr, "%s > %s/mondo-run-prog-thing.tmp 2> %s/mondo-run-prog-thing.err",
    289              program, bkpinfo->tmpdir, bkpinfo->tmpdir);
     287    mr_asprintf(callstr, "%s > %s/mondo-run-prog-thing.tmp 2> %s/mondo-run-prog-thing.err", program, bkpinfo->tmpdir, bkpinfo->tmpdir);
    290288    while ((p = strchr(callstr, '\r'))) {
    291289        *p = ' ';
     
    311309    if (((res == 0) && log_if_success) || ((res != 0) && log_if_failure)) {
    312310        log_msg(0, "running: %s", callstr);
    313         log_msg(0,
    314                 "--------------------------------start of output-----------------------------");
    315     }
    316     sprintf(callstr, "cat %s/mondo-run-prog-thing.err >> %s/mondo-run-prog-thing.tmp 2> /dev/null", bkpinfo->tmpdir, bkpinfo->tmpdir);
     311        log_msg(0, "--------------------------------start of output-----------------------------");
     312    }
     313    mr_free(callstr);
     314
     315    mr_asprintf(callstr, "cat %s/mondo-run-prog-thing.err >> %s/mondo-run-prog-thing.tmp 2> /dev/null", bkpinfo->tmpdir, bkpinfo->tmpdir);
    317316    if (log_if_failure && system(callstr)) {
    318317        log_OS_error("Command failed");
    319318    }
    320     sprintf(tmp, "%s/mondo-run-prog-thing.err", bkpinfo->tmpdir);
    321     unlink(tmp);
    322     sprintf(tmp, "%s/mondo-run-prog-thing.tmp", bkpinfo->tmpdir);
    323     fin = fopen(tmp, "r");
     319    mr_free(callstr);
     320
     321    mr_asprintf(tmp1, "%s/mondo-run-prog-thing.err", bkpinfo->tmpdir);
     322    unlink(tmp1);
     323    mr_free(tmp1);
     324
     325    mr_asprintf(tmp1, "%s/mondo-run-prog-thing.tmp", bkpinfo->tmpdir);
     326    fin = fopen(tmp1, "r");
    324327    if (fin) {
    325         for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin);
    326              fgets(incoming, MAX_STR_LEN, fin)) {
    327             /* patch by Heiko Schlittermann */
     328        for (fgets(incoming, MAX_STR_LEN, fin); !feof(fin); fgets(incoming, MAX_STR_LEN, fin)) {
    328329            p = incoming;
    329330            while (p && *p) {
     
    335336            /* end of patch */
    336337            strip_spaces(incoming);
    337             if ((res == 0 && log_if_success)
    338                 || (res != 0 && log_if_failure)) {
     338            if ((res == 0 && log_if_success) || (res != 0 && log_if_failure)) {
    339339                log_msg(0, incoming);
    340340            }
     
    342342        paranoid_fclose(fin);
    343343    }
    344     unlink(tmp);
     344    unlink(tmp1);
     345    mr_free(tmp1);
     346
    345347    if ((res == 0 && log_if_success) || (res != 0 && log_if_failure)) {
    346348        log_msg(0,
Note: See TracChangeset for help on using the changeset viewer.