Ignore:
Timestamp:
Jul 17, 2006, 3:44:46 PM (13 years ago)
Author:
bcornec
Message:

Huge memory management patch.
Still not finished but a lot as been done.
What remains is around some functions returning strings, and some structure members.
(Could not finish due to laptop failure !)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/mondo/common/libmondo-fork.c

    r687 r688  
    1 /* libmondo-fork.c
    2    $Id$
    3 
    4 - subroutines for handling forking/pthreads/etc.
    5 
    6 
    7 01/20/2006
    8 - replaced partimagehack with ntfsclone
    9 
    10 06/20/2004
    11 - create fifo /var/log/partimagehack-debug.log and empty it
    12   to keep ramdisk from filling up
    13 
    14 04/13/2004
    15 - >= should be <= g_loglevel
    16 
    17 11/15/2003
    18 - changed a few []s to char*s
    19  
    20 10/12
    21 - rewrote partimagehack handling (multiple fifos, chunks, etc.)
    22 
    23 10/11
    24 - partimagehack now has debug level of N (set in my-stuff.h)
    25 
    26 10/08
    27 - call to partimagehack when restoring will now log errors to /var/log/....log
    28 
    29 10/06
    30 - cleaned up logging a bit
    31 
    32 09/30
    33 - line 735 - missing char* cmd in sprintf()
    34 
    35 09/28
    36 - added run_external_binary_with_percentage_indicator()
    37 - rewritten eval_call_to_make_ISO()
    38 
    39 09/18
    40 - call mkstemp instead of mktemp
    41 
    42 09/13
    43 - major NTFS hackage
    44 
    45 09/12
    46 - paranoid_system("rm -f /tmp/ *PARTIMAGE*") before calling partimagehack
    47 
    48 09/11
    49 - forward-ported unbroken feed_*_partimage() subroutines
    50   from early August 2003
    51 
    52 09/08
    53 - detect & use partimagehack if it exists
    54 
    55 09/05
    56 - finally finished partimagehack hack :)
    57 
    58 07/04
    59 - added subroutines to wrap around partimagehack
    60 
    61 04/27
    62 - don't echo (...res=%d...) at end of log_it()
    63   unnecessarily
    64 - replace newtFinished() and newtInit() with
    65   newtSuspend() and newtResume()
    66 
    67 04/24
    68 - added some assert()'s and log_OS_error()'s
    69 
    70 04/09
    71 - cleaned up run_program_and_log_output()
    72 
    73 04/07
    74 - cleaned up code a bit
    75 - let run_program_and_log_output() accept -1 (only log if _no error_)
    76 
    77 01/02/2003
    78 - in eval_call_to_make_ISO(), append output to MONDO_LOGFILE
    79   instead of a temporary stderr text file
    80 
    81 12/10
    82 - patch by Heiko Schlittermann to handle % chars in issue.net
    83 
    84 11/18
    85 - if mkisofs in eval_call_to_make_ISO() returns an error then return it,
    86   whether ISO was created or not
    87 
    88 10/30
    89 - if mkisofs in eval_call_to_make_ISO() returns an error then find out if
    90   the output (ISO) file has been created; if it has then return 0 anyway
    91 
    92 08/01 - 09/30
    93 - run_program_and_log_output() now takes boolean operator to specify
    94   whether it will log its activities in the event of _success_
    95 - system() now includes 2>/dev/null
    96 - enlarged some tmp[]'s
    97 - added run_program_and_log_to_screen() and run_program_and_log_output()
    98 
    99 07/24
    100 - created
    101 */
    102 
     1/* libmondo-fork.c - subroutines for handling forking/pthreads/etc.
     2 * $Id$
     3 */
    1034
    1045#include "my-stuff.h"
     
    11011#include "libmondo-tools-EXT.h"
    11112
    112 /*@unused@*/
    113 //static char cvsid[] = "$Id$";
    114 
    11513extern char *g_tmpfs_mountpt;
    11614extern t_bkptype g_backup_media_type;
     
    12321 * @param call The program to run.
    12422 * @return The last line of its output.
    125  * @note The returned value points to static storage that will be overwritten with each call.
     23 * @note The returned value should be freed by caller
    12624 */
    12725char *call_program_and_get_last_line_of_output(char *call)
    12826{
    129     /*@ buffers ***************************************************** */
    130     static char *result = NULL;
    131     char *tmp = NULL;
    132 
    133     /*@ pointers **************************************************** */
    134     FILE *fin;
    135 
     27    char *result = NULL;
     28    FILE *fin = NULL;
    13629    size_t n = 0;
    13730
    138     /*@******************************************************************** */
    139 
    14031    assert_string_is_neither_NULL_nor_zerolength(call);
     32
    14133    if ((fin = popen(call, "r"))) {
    142         for (getline(&tmp, &n, fin); !feof(fin);
    143              getline(&tmp, &n, fin)) {
    144             if (strlen(tmp) > 1) {
    145                 if (result != NULL) {
    146                     paranoid_free(result);
    147                 }
    148                 asprintf(&result, tmp);
    149             }
    150         }
     34        for (getline(&result, &n, fin); !feof(fin); getline(&result, &n, fin));
    15135        paranoid_pclose(fin);
    15236    } else {
    15337        log_OS_error("Unable to popen call");
    15438    }
    155     strip_spaces(result);
    156     paranoid_free(tmp);
    157     return (result);
     39    return(result);
    15840}
    15941
     
    425307    if (!(fin = popen(command, "r"))) {
    426308        log_OS_error("Unable to popen-in command");
    427         asprintf(&tmp, _("Failed utterly to call '%s'", command));
     309        asprintf(&tmp, _("Failed utterly to call '%s'"), command);
    428310        log_to_screen(tmp);
    429311        paranoid_free(tmp);
     
    648530{
    649531
    650     /*@ int *************************************************************** */
    651532    int res = 0;
    652533    int percentage = 0;
     
    655536    int last_pcno = 0;
    656537
    657     /*@ buffers *********************************************************** */
    658     char *command;
    659     char *tempfile;
    660     /*@ pointers ********************************************************** */
    661     FILE *pin;
     538    char *command = NULL;
     539    char *tempfile = NULL;
     540    FILE *pin = NULL;
    662541
    663542    assert_string_is_neither_NULL_nor_zerolength(cmd);
    664543
    665     asprintf(&tempfile,
    666            call_program_and_get_last_line_of_output
    667            ("mktemp -q /tmp/mondo.XXXXXXXX"));
     544    tempfile = call_program_and_get_last_line_of_output("mktemp -q /tmp/mondo.XXXXXXXX");
    668545    asprintf(&command, "%s >> %s 2>> %s; rm -f %s", cmd, tempfile, tempfile,
    669546            tempfile);
Note: See TracChangeset for help on using the changeset viewer.