Changeset 1074 in MondoRescue for trunk


Ignore:
Timestamp:
Jan 25, 2007, 4:18:12 PM (17 years ago)
Author:
Bruno Cornec
Message:

This version of trunk desn't seg fault on mr_msg anymore.
Still not ready for 3.0.0 but improvements ongoing

Location:
trunk/mondo/src
Files:
14 edited

Legend:

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

    r1046 r1074  
    38543854
    38553855    /* mindi conf parameters also needed in mondo */
    3856     mr_asprintf(&command, "mindi -printvar IA64_BOOT_SIZE");
     3856    mr_asprintf(&command, "mindi --printvar IA64_BOOT_SIZE");
    38573857    fin = popen(command, "r");
    38583858    mr_getline(&param, &n, fin);
  • trunk/mondo/src/common/libmondo-verify.c

    r1043 r1074  
    238238        if (bkpinfo->use_lzo) {
    239239            mr_asprintf(&sz_exe, "lzop");
    240         else if (bkpinfo->use_gzip) {
     240        } else if (bkpinfo->use_gzip) {
    241241            strcpy(sz_exe, "gzip");
    242242        } else if (bkpinfo->use_gzip) {
  • trunk/mondo/src/common/newt-specific.c

    r932 r1074  
    463463
    464464        va_start(args, fmt);
    465         mr_vasprintf(&output, fmt, args);
     465        mr_asprintf(&output, fmt, args);
    466466        log_msg(0, output);
    467467        if (strlen(output) > 80) {
  • trunk/mondo/src/include/mr_conf.h

    r852 r1074  
    1919/*initialization and closing*/
    2020extern int mr_conf_open(const char *filename);
    21 extern void mr_conf_close();
     21extern void mr_conf_close(void);
    2222
    2323/*read integer number after string str in the current file*/
  • trunk/mondo/src/include/mr_err.h

    r900 r1074  
    1111/* functions (public methods) */
    1212
    13 extern void mr_exit(int errorcode, const char *message);
    14 extern void mr_log_exit(int errorcode, const char *message);
     13extern inline void mr_exit(int errorcode, const char *message);
     14extern inline void mr_log_exit(int errorcode, const char *message);
    1515
    1616#endif                          /* MR_ERR_H */
  • trunk/mondo/src/include/mr_mem.h

    r900 r1074  
    99#define MR_MEM_H
    1010
     11#ifndef _GNU_SOURCE
     12#define _GNU_SOURCE
     13#endif
     14#include <stdarg.h>
     15
    1116/* functions (public methods) */
    1217
    13 extern void mr_free(char *allocated);
    14 extern void mr_allocstr(char *alloc, const char *orig);
    15 extern void mr_asprintf(char **alloc, const char *fmt, ...);
    16 extern void mr_vasprintf(char **alloc, const char *fmt, va_list ap);
    17 extern void mr_getline(char **lineptr, size_t *n, FILE *stream);
    18 extern void *mr_malloc(size_t size);
     18extern inline void mr_free(char *allocated);
     19extern inline void mr_allocstr(char *alloc, const char *orig);
     20extern inline void mr_asprintf(char **alloc, const char *fmt, ...);
     21extern inline void mr_getline(char **lineptr, size_t *n, FILE *stream);
     22extern inline void *mr_malloc(size_t size);
    1923
    2024#endif                          /* MR_MEM_H */
  • trunk/mondo/src/include/mr_msg.h

    r900 r1074  
    99#define MR_MSG_H
    1010
     11#ifndef _GNU_SOURCE
     12#define _GNU_SOURCE
     13#endif
     14#include <stdarg.h>
     15
    1116/* functions (public methods) */
    1217
    13 extern void _mr_msg(int debug, const char *file, const char *function, int line, const char *fmt, ...);
    14 
    15 #define mr_msg(level, format, args...) _mr_msg(level, __FILE__, __FUNCTION__, __LINE__, format, ## args)
     18extern inline void mr_msg(int debug, const char *fmt, ...);
     19extern void mr_msg_init(const char *configfile, int loglevel);
     20extern void mr_msg_close(void);
    1621
    1722#endif                          /* MR_MSG_H */
  • trunk/mondo/src/include/mr_str.h

    r900 r1074  
    1111/* functions (public methods) */
    1212
    13 extern char *mr_strtok(char *instr, const char *delims, int *lastpos);
    14 extern char *mr_stresc(char *instr, char *toesc, const char escchr);
     13extern inline char *mr_strtok(char *instr, const char *delims, int *lastpos);
     14extern inline char *mr_stresc(char *instr, char *toesc, const char escchr);
    1515
    1616#endif                          /* MR_STR_H */
  • trunk/mondo/src/include/my-stuff.h

    r973 r1074  
    88#define _MY_STUFF_H_
    99
    10 /* BERLIOS
    11 #define HAVE_MALLOC 1
    12 */
    13 
    1410// Extra info for ACLs and SELINUX users
    1511#define STAR_ACL_SZ "-xfflags -acl"
    16 //#define STAR_ACL_SZ "-xfflags"
    17 //#define STAR_ACL_SZ ""
    18 // Enable the first line and disable the second if you are a Fedora Core 2 user
     12
     13/*The number of lines of log output to keep at the bottom of the screen.*/
     14#define NOOF_ERR_LINES  6   
     15
     16#define paranoid_free(exp) mr_free(exp)
    1917
    2018/**
     
    5351
    5452#include <stdlib.h>
    55 /* BERLIOS
    56 #ifndef  __USE_FILE_OFFSET64
    57 #define  __USE_FILE_OFFSET64
    58 #endif
    59 #ifndef  __USE_LARGEFILE64
    60 #define  __USE_LARGEFILE64
    61 #endif
    62 */
    6353#include <sys/stat.h>
    6454#include <fcntl.h>
     
    7969#endif
    8070#include <assert.h>
    81 
    82 /*
    83 #if defined(DEBUG) && !__cplusplus
    84 int count;
    85 char trace_log[255];
    86 char *trace_log_ptr;
    87 #endif
    88 */
    8971
    9072#define STD_PREFIX "mondorescue"
     
    210192
    211193/**
    212  * @c mkisofs command to generate a bootable CD using LILO, except for -o option and the directory to image.
    213  */
    214 // -b images/mindi-boot.2880.img
    215 
    216 /**
    217  * @c mkisofs command to generate a bootable CD using ELILO, except for -o option and the directory to image.
    218  */
    219 // -b images/mindi-boot.2880.img
    220 // Should replace 8192 by IA64_BOOT_SIZE
    221 
    222 /**
    223194 * The stub name of the temporary ISO image to create, burn, and remove.
    224195 */
     
    332303#define VANILLA_SCSI_CDROM  "/dev/cd0"
    333304#define VANILLA_SCSI_TAPE   "/dev/sa"
     305#define VANILLA_USB_DEVICE  "/dev/tobegivenbyfreebsdguru"
    334306#define DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE  "/dev/vinum/"
    335307#define RAID_DEVICE_STUB    DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE
     
    341313#define VANILLA_SCSI_CDROM  "/dev/scd0"
    342314#define VANILLA_SCSI_TAPE   "/dev/st"
     315#define VANILLA_USB_DEVICE  "/dev/hda"
    343316#define DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE  "/dev/md"
    344317#define RAID_DEVICE_STUB    DONT_KNOW_HOW_TO_EVALUATE_THIS_DEVICE_TYPE
  • trunk/mondo/src/lib/mr_conf.c

    r900 r1074  
    3434#define MRCONF_OPEN_OPENED          0xA
    3535#define MRCONF_CALL_BUT_NOT_OPEN    0xB
     36#define MRCONF_STRING_QUOTE         0xC
    3637
    3738/*setting flags*/
     
    5657#define MRCONF_STR_CLOSE_BUT_NOT_OPEN _("attempt to close mr_conf but it has not been opened yet")
    5758#define MRCONF_STR_CALL_BUT_NOT_OPEN _("attempt to use mr_conf when it has not been opened yet")
     59#define MRCONF_STR_STRING_QUOTE     _("string should be surrounded by quotes")
    5860
    5961/*Flags of internal state*/
     
    6668static size_t mr_conf_filesize(const char *name);
    6769static void mr_conf_error_msg(int error_code, const char *add_line);
    68 static void mr_conf_remove_comments();
     70static void mr_conf_remove_comments(void);
    6971static int mr_conf_check_int_flag(const int flag);
    7072static void mr_conf_set_int_flag(const int flag);
     
    112114
    113115    /*allocate memory for the buffers */
    114     buffer = (char *) malloc(sizeof(char) * (length + 1));
     116    buffer = (char *) mr_malloc(sizeof(char) * (length + 1));
    115117
    116118    if (buffer == NULL) {
     
    139141
    140142/*release all memory and prepare to the next possiable config file*/
    141 void mr_conf_close() {
     143void mr_conf_close(void) {
    142144    /* if not opened => error */
    143145    if (!mr_conf_check_int_flag(MRCONF_INTFLAG_OPEN)) {
     
    233235    mr_asprintf(&q, p);
    234236
     237    if (*p != '"') {
     238        mr_conf_error_msg(MRCONF_STRING_QUOTE, "");
     239        return (NULL);
     240    }
     241    p++;
     242
    235243    /* trunk at first \n */
    236244    r = index(q,'\n');
     245    r--;
     246    if (*r != '"') {
     247        mr_conf_error_msg(MRCONF_STRING_QUOTE, "");
     248        return (NULL);
     249    }
     250    r--;
    237251
    238252    size = r-q+1;
    239253    /*copy filtered data to the buffer */
    240     ret = (char *) malloc(sizeof(char) * (size));
     254    ret = (char *) mr_malloc(sizeof(char) * (size));
    241255    if (ret == NULL) {
    242256        mr_conf_error_msg(MRCONF_ALLOC_FAILED, "");
     
    249263    }
    250264
    251     ret[i] = (char) 0;      /*and set its length */
     265    ret[i] = (char) 0;      /* and set its length */
    252266    mr_free(q);
    253267
     
    278292    }
    279293    /* k is new buffer length now */
    280     tmp_buf = (char *) malloc(sizeof(char) * (k + 1));
     294    tmp_buf = (char *) mr_malloc(sizeof(char) * (k + 1));
    281295    if (tmp_buf == NULL) {
    282296        mr_conf_error_msg(MRCONF_ALLOC_FAILED, "");
     
    371385            break;
    372386
     387        case MRCONF_STRING_QUOTE:
     388            mr_msg(0,"%s %s\n", MRCONF_STR_ERROR, MRCONF_STR_STRING_QUOTE);
     389            break;
     390
    373391        default:
    374392            mr_msg(1,"%s %s\n", MRCONF_STR_ERROR, MRCONF_STR_DEFAULT_ERROR);
  • trunk/mondo/src/lib/mr_err.c

    r900 r1074  
    99 * Provided under the GPLv2
    1010 */
     11
     12#ifndef _GNU_SOURCE
     13#define _GNU_SOURCE
     14#endif
    1115
    1216#include <stdio.h>
     
    3640
    3741void mr_log_exit(int errorcode, const char *message) {
    38     mr_msg(0,message);
     42    mr_msg(0, message);
    3943    mr_exit(errorcode, message);
    4044}
  • trunk/mondo/src/lib/mr_mem.c

    r929 r1074  
    1010 */
    1111
     12#ifndef _GNU_SOURCE
     13#define _GNU_SOURCE
     14#endif
     15
    1216#include <stdio.h>
    1317#include <stdlib.h>
    14 #include <stdarg.h>
    1518
    1619#include "mr_err.h"
     
    5255}
    5356
    54 
    55 /* encapsulation function for vasprintf */
    56 void mr_vasprintf(char **strp, const char *fmt, va_list ap) {
    57 
    58     int res = 0;
    59 
    60     res = vasprintf(strp, fmt, ap);
    61     if (res == -1) {
    62         mr_log_exit(-1,"Unable to alloc memory in mr_vasprintf\nExiting...");
    63     }
    64 }
    65 
    6657/* encapsulation function for asprintf */
    6758void mr_asprintf(char **strp, const char *fmt, ...) {
     
    7061    va_list args;
    7162
    72     va_start(args, fmt);
    73     res = asprintf(strp, fmt, args);
     63    va_start(args,fmt);
     64    res = vasprintf(strp, fmt, args);
    7465    if (res == -1) {
    7566        mr_log_exit(-1,"Unable to alloc memory in mr_asprintf\nExiting...");
  • trunk/mondo/src/lib/mr_msg.c

    r900 r1074  
    1010 */
    1111
     12#ifndef _GNU_SOURCE
     13#define _GNU_SOURCE
     14#endif
    1215#include <stdio.h>
    1316#include <stdarg.h>
     17#include <stdlib.h>
    1418
    1519static int mr_loglevel = 0;
    1620static char *mr_logfile = NULL;
    1721
     22/*
     23 * This function is in the lowest part of the tree
     24 * It should not depend on any other function of the mr lib
     25 */
     26
     27/* Cleanup function for messages */
     28void mr_msg_close(void) {
     29    free(mr_logfile);
     30    mr_logfile = NULL;
     31    mr_loglevel = 0;
     32}
     33
    1834/* Initialization function for messages */
    19 void mr_msg_init(void) {
     35void mr_msg_init(const char *configfile, int loglevel) {
     36    FILE *fout = NULL;
     37    int res = 0;
    2038
     39    asprintf(&mr_logfile,configfile);
     40    if ((fout = fopen(mr_logfile, "w")) == NULL) {
     41        fprintf(stderr,"Unable to write to %s\n",mr_logfile);
     42        fprintf(stderr,"Logging desactivated\n");
     43        mr_msg_close();
     44    }
     45    if ((res = fclose(fout)) != 0) {
     46        fprintf(stderr,"Unable to close %s\n",mr_logfile);
     47    }
     48    mr_loglevel = loglevel;
    2149}
    2250
    2351/*
    2452 * Function that log a message. Not called directly
    25  * but through macros in mr_msg.h
     53 * but through other functions
    2654 */
    27 void _mr_msg(int debug, const char *file, const char *function, int line, const char *fmt, ...) {
     55void mr_msg(int debug, const char *fmt, ...) {
    2856
    29     va_list args;
    3057    int i = 0;
    3158    int res = 0;
    3259    FILE *fout = NULL;
     60    va_list args;
     61
     62    if (mr_logfile == NULL) {
     63        return;
     64    }
    3365
    3466    if (debug <= mr_loglevel) {
    35         va_start(args, fmt);
    36         if (!(fout = fopen(mr_logfile, "a"))) {
     67        if ((fout = fopen(mr_logfile, "a")) == NULL) {
    3768            fprintf(stderr,"Unable to append to %s\n",mr_logfile);
    3869            return;
     
    4374            for (i = 1; i < debug; i++)
    4475                fprintf(fout, "  ");
    45             fprintf(fout, "%s->%s#%d: ", file, function, line);
     76            fprintf(fout, "%s->%s#%d: ", __FILE__, __FUNCTION__, __LINE__);
    4677        }
    47         vfprintf(fout, fmt, args);
     78        va_start(args,fmt);
     79        if (vfprintf(fout, fmt, args) < 0) {
     80            fprintf(stderr,"Unable to print to %s\n",mr_logfile);
     81        }
     82        va_end(args);
    4883
    49         va_end(args);
    50         fprintf(fout, "\n");
    5184        if ((res = fclose(fout)) != 0) {
    5285            fprintf(stderr,"Unable to close %s\n",mr_logfile);
  • trunk/mondo/src/lib/mr_str.c

    r969 r1074  
    88#include <stdio.h>
    99#include <string.h>
     10
     11#include "mr_mem.h"
    1012 
    1113/**
     
    3537    strptr += pos2;
    3638    pos1 = strcspn(strptr, delims);
    37     token = malloc(sizeof(*token) * (pos1 + 1));
     39    token = (char *)mr_malloc(sizeof(*token) * (pos1 + 1));
    3840    strncpy(token, strptr, pos1);
    3941    token[pos1] = '\0';
     
    8082    inptr = instr;
    8183
    82     retstr = (char *) malloc(strlen(inptr) + cnt + 1);
     84    retstr = (char *) mr_malloc(strlen(inptr) + cnt + 1);
    8385    retptr = retstr;
    8486
Note: See TracChangeset for help on using the changeset viewer.