- Timestamp:
- Feb 13, 2016, 2:57:55 AM (9 years ago)
- Location:
- branches/3.2/mondo/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mondo/src/include/mr_msg.h
r2208 r3509 16 16 /* functions (public methods) */ 17 17 18 #define mr_msg( x,y,args...) {mr_msg_int(x,__LINE__,__FILE__,y,## args);}19 extern void mr_msg_init(const char * configfile, int loglevel);18 #define mr_msg(lvl,fmt,args...) {mr_msg_int(lvl,__LINE__,__FILE__,__FUNCTION__,fmt,## args);} 19 extern void mr_msg_init(const char *logfile, int loglevel); 20 20 extern void mr_msg_close(void); 21 21 extern void mr_msg_loglevel(int loglevel); … … 23 23 /* Internal function bringing debuging info 24 24 * called indirectly through macros */ 25 extern inline void mr_msg_int(int debug, int line, const char *file, const char *fmt, ...);25 extern inline void mr_msg_int(int debug, int line, const char *file, const char *function, const char *fmt, ...); 26 26 27 27 #endif /* MR_MSG_H */ -
branches/3.2/mondo/src/include/mr_sys.h
r3498 r3509 14 14 #include <stdarg.h> 15 15 #include <stdio.h> 16 17 /* functions (public methods) */ 18 19 #define mr_system(y,args...) mr_system_int(__LINE__,__FILE__,y,## args) 16 #include "mr_msg.h" 20 17 21 18 /* Internal function bringing debuging info … … 23 20 extern inline int mr_system_int(int line, char *file, const char *fmt, ...); 24 21 22 /* functions (public methods) */ 23 #define mr_system(y,args...) mr_system_int(__LINE__,__FILE__,y,## args) 24 25 /* Global variables */ 26 27 extern int mr_loglevel; 28 extern char *mr_logfile; 29 25 30 #endif /* MR_SYS_H */ -
branches/3.2/mondo/src/lib/mr_conf.c
r3294 r3509 409 409 switch (error_code) { 410 410 case MRCONF_BAD_FILE: 411 mr_msg_int(1,line,file," %s (%s) %s %s", MRCONF_STR_ERROR, mr_conf_filename, MRCONF_STR_BAD_FILE,411 mr_msg_int(1,line,file,"mr_conf_error_msg_int","%s (%s) %s %s", MRCONF_STR_ERROR, mr_conf_filename, MRCONF_STR_BAD_FILE, 412 412 add_line); 413 413 break; 414 414 415 415 case MRCONF_READING_FAILED: 416 mr_msg_int(1,line,file," %s (%s) %s", MRCONF_STR_ERROR, mr_conf_filename, MRCONF_STR_READING_FAILED);416 mr_msg_int(1,line,file,"mr_conf_error_msg_int","%s (%s) %s", MRCONF_STR_ERROR, mr_conf_filename, MRCONF_STR_READING_FAILED); 417 417 break; 418 418 419 419 case MRCONF_FIELD_NOT_FOUND: 420 mr_msg_int(1,line,file," %s (%s) %s \"%s\"", MRCONF_STR_WARNING, mr_conf_filename, MRCONF_STR_FIELD_NOT_FOUND, add_line);420 mr_msg_int(1,line,file,"mr_conf_error_msg_int","%s (%s) %s \"%s\"", MRCONF_STR_WARNING, mr_conf_filename, MRCONF_STR_FIELD_NOT_FOUND, add_line); 421 421 break; 422 422 423 423 case MRCONF_FIELD_NO_VALUE: 424 mr_msg_int(1,line,file," %s (%s) %s \"%s\"", MRCONF_STR_ERROR, mr_conf_filename, MRCONF_STR_FIELD_NO_VALUE, add_line);425 mr_msg_int(1,line,file," %s (%s) %s", MRCONF_STR_WARNING, mr_conf_filename, MRCONF_STR_IGNORE);424 mr_msg_int(1,line,file,"mr_conf_error_msg_int","%s (%s) %s \"%s\"", MRCONF_STR_ERROR, mr_conf_filename, MRCONF_STR_FIELD_NO_VALUE, add_line); 425 mr_msg_int(1,line,file,"mr_conf_error_msg_int","%s (%s) %s", MRCONF_STR_WARNING, mr_conf_filename, MRCONF_STR_IGNORE); 426 426 break; 427 427 428 428 case MRCONF_CLOSE_BUT_NOT_OPEN: 429 mr_msg_int(1,line,file," %s (%s) %s", MRCONF_STR_WARNING, mr_conf_filename, MRCONF_STR_CLOSE_BUT_NOT_OPEN);429 mr_msg_int(1,line,file,"mr_conf_error_msg_int","%s (%s) %s", MRCONF_STR_WARNING, mr_conf_filename, MRCONF_STR_CLOSE_BUT_NOT_OPEN); 430 430 break; 431 431 432 432 case MRCONF_CALL_BUT_NOT_OPEN: 433 mr_msg_int(1,line,file," %s (%s) %s", MRCONF_STR_WARNING, mr_conf_filename, MRCONF_STR_CALL_BUT_NOT_OPEN);433 mr_msg_int(1,line,file,"mr_conf_error_msg_int","%s (%s) %s", MRCONF_STR_WARNING, mr_conf_filename, MRCONF_STR_CALL_BUT_NOT_OPEN); 434 434 break; 435 435 436 436 case MRCONF_OPEN_OPENED: 437 mr_msg_int(1,line,file," %s (%s) %s", MRCONF_STR_ERROR, mr_conf_filename, MRCONF_STR_OPEN_OPENED);437 mr_msg_int(1,line,file,"mr_conf_error_msg_int","%s (%s) %s", MRCONF_STR_ERROR, mr_conf_filename, MRCONF_STR_OPEN_OPENED); 438 438 break; 439 439 440 440 case MRCONF_STRING_QUOTE: 441 mr_msg_int(1,line,file," %s: %s (%s) %s", add_line, MRCONF_STR_ERROR, mr_conf_filename, MRCONF_STR_STRING_QUOTE);441 mr_msg_int(1,line,file,"mr_conf_error_msg_int","%s: %s (%s) %s", add_line, MRCONF_STR_ERROR, mr_conf_filename, MRCONF_STR_STRING_QUOTE); 442 442 break; 443 443 444 444 case MRCONF_STRING_ENDQUOTE: 445 mr_msg_int(1,line,file," %s: %s (%s) %s", add_line, MRCONF_STR_ERROR, mr_conf_filename, MRCONF_STR_STRING_ENDQUOTE);445 mr_msg_int(1,line,file,"mr_conf_error_msg_int","%s: %s (%s) %s", add_line, MRCONF_STR_ERROR, mr_conf_filename, MRCONF_STR_STRING_ENDQUOTE); 446 446 break; 447 447 448 448 default: 449 mr_msg_int(1,line,file," %s (%s) %s", MRCONF_STR_ERROR, mr_conf_filename, MRCONF_STR_DEFAULT_ERROR);450 break; 451 } 452 } 453 } 449 mr_msg_int(1,line,file,"mr_conf_error_msg_int","%s (%s) %s", MRCONF_STR_ERROR, mr_conf_filename, MRCONF_STR_DEFAULT_ERROR); 450 break; 451 } 452 } 453 } -
branches/3.2/mondo/src/lib/mr_file.c
r1136 r3509 23 23 24 24 if ((fd = fopen(path, mode)) == NULL) { 25 mr_msg_int(1,line,file," Unable to open %s",path);25 mr_msg_int(1,line,file,"mr_fopen_int","Unable to open %s",path); 26 26 mr_exit(-1,"Exiting"); 27 27 } … … 34 34 35 35 if (fd == NULL) { 36 mr_msg_int(1,line,file," fd is NULL.\nShould NOT happen.");36 mr_msg_int(1,line,file,"mr_fprintf_int","fd is NULL.\nShould NOT happen."); 37 37 mr_exit(-1,"Exiting"); 38 38 } 39 39 va_start(args,fmt); 40 40 if (vfprintf(fd, fmt, args) < 0) { 41 mr_msg_int(1,line,file," Unable to print to fd");41 mr_msg_int(1,line,file,"mr_fprintf_int","Unable to print to fd"); 42 42 mr_exit(-1,"Exiting"); 43 43 } … … 48 48 49 49 if (fd == NULL) { 50 mr_msg_int(1,line,file," fd is NULL.\nShould NOT happen.");50 mr_msg_int(1,line,file,"mr_fclose_int","fd is NULL.\nShould NOT happen."); 51 51 mr_exit(-1,"Exiting"); 52 52 } 53 53 if (*fd == NULL) { 54 mr_msg_int(1,line,file," File descriptor is NULL.\nShould NOT happen.");54 mr_msg_int(1,line,file,"mr_fclose_int","File descriptor is NULL.\nShould NOT happen."); 55 55 mr_exit(-1,"Exiting"); 56 56 } 57 57 if (fclose(*fd) < 0) { 58 mr_msg_int(1,line,file," Unable to close File Descriptor");58 mr_msg_int(1,line,file,"mr_fclose_int","Unable to close File Descriptor"); 59 59 } 60 60 *fd = NULL; … … 64 64 65 65 if (mkdir(pathname,mode) != 0) { 66 mr_msg_int(1,line,file," Unable to create directory %s",pathname);66 mr_msg_int(1,line,file,"mr_mkdir_int","Unable to create directory %s",pathname); 67 67 mr_exit(-1,"Exiting"); 68 68 } -
branches/3.2/mondo/src/lib/mr_mem.c
r3294 r3509 36 36 *allocated = NULL; 37 37 } else { 38 mr_msg_int(8,line,file," Attempt to free NULL pointer");38 mr_msg_int(8,line,file,"mr_asprintf","Attempt to free NULL pointer"); 39 39 } 40 40 } … … 47 47 ret = malloc(size); 48 48 if (ret == NULL) { 49 mr_msg_int(1,line,file," Unable to alloc memory in mr_malloc\nExiting...");49 mr_msg_int(1,line,file,"mr_asprintf","Unable to alloc memory in mr_malloc\nExiting..."); 50 50 mr_exit(-1,"Unable to alloc memory in mr_malloc"); 51 51 } … … 62 62 res = vasprintf(strp, fmt, args); 63 63 if (res == -1) { 64 mr_msg_int(1,line,file," Unable to alloc memory in mr_asprintf\nExiting...");64 mr_msg_int(1,line,file,"mr_asprintf","Unable to alloc memory in mr_asprintf\nExiting..."); 65 65 mr_exit(-1,"Unable to alloc memory in mr_asprintf"); 66 66 } … … 76 76 if (*lineptr != NULL) { 77 77 /* free a variable which should be already free */ 78 mr_msg_int(1,line,file,"mr_getline_ found a non freed variable here");78 mr_msg_int(1,line,file,"mr_getline_int","mr_getline_ found a non freed variable here"); 79 79 mr_free_int((void **)lineptr,line,file); 80 80 } 81 81 ret = getline(lineptr,&n,fd); 82 82 if ((ret == -1) && (! feof(fd))) { 83 mr_msg_int(1,line,file," Unable to alloc memory in mr_getline\nExiting...");83 mr_msg_int(1,line,file,"mr_getline_int","Unable to alloc memory in mr_getline\nExiting..."); 84 84 mr_exit(-1,"Unable to alloc memory in mr_getline"); 85 85 } … … 109 109 110 110 if (name == NULL) { 111 mr_msg_int(1,line,file," Unable to setenv a NULL variable\nExiting...");111 mr_msg_int(1,line,file,"mr_setenv_int","Unable to setenv a NULL variable\nExiting..."); 112 112 mr_exit(-1, "Unable to setenv a NULL variable"); 113 113 } 114 114 if (value == NULL) { 115 mr_msg_int(1,line,file," Unable to affect NULL to %s\nExiting...", name);115 mr_msg_int(1,line,file,"mr_setenv_int","Unable to affect NULL to %s\nExiting...", name); 116 116 mr_exit(-1, "Unable to affect a NULL variable"); 117 117 } 118 118 if (setenv(name, value, 1) != 0) { 119 mr_msg_int(1,line,file," Unable to put %s in environment", name);119 mr_msg_int(1,line,file,"mr_setenv_int","Unable to put %s in environment", name); 120 120 mr_exit(-1,"Unable to put in environment"); 121 121 } … … 136 136 } 137 137 if (in == NULL) { 138 mr_msg_int(1,line,file," Unable to add to NULL pointer\nExiting...");138 mr_msg_int(1,line,file,"mr_strcat_int","Unable to add to NULL pointer\nExiting..."); 139 139 mr_exit(-1, "Unable to add to a NULL pointer"); 140 140 } … … 143 143 res = vasprintf(in, fmt, args); 144 144 if (res == -1) { 145 mr_msg_int(1,line,file," Unable to alloc memory in mr_strcat\nExiting...");145 mr_msg_int(1,line,file,"mr_strcat_int","Unable to alloc memory in mr_strcat\nExiting..."); 146 146 mr_exit(-1,"Unable to alloc memory in mr_strcat"); 147 147 } … … 151 151 res = vasprintf(in, fmt2, args); 152 152 if (res == -1) { 153 mr_msg_int(1,line,file," Unable to alloc memory in mr_strcat\nExiting...");153 mr_msg_int(1,line,file,"mr_strcat_int","Unable to alloc memory in mr_strcat\nExiting..."); 154 154 mr_exit(-1,"Unable to alloc memory in mr_strcat"); 155 155 } -
branches/3.2/mondo/src/lib/mr_msg.c
r2209 r3509 19 19 static int mr_loglevel = 0; 20 20 static char *mr_logfile = NULL; 21 static FILE *mr_flog = NULL; 21 22 22 23 /* … … 24 25 * It should not depend on any other function of the mr lib 25 26 */ 26 27 /* Cleanup function for messages */28 void mr_msg_close(void) {29 free(mr_logfile);30 mr_logfile = NULL;31 mr_loglevel = 0;32 }33 27 34 28 /* Function allowing to change loglevel after init */ … … 38 32 } 39 33 34 /* Cleanup function for messages */ 35 void mr_msg_close(void) { 36 37 int res = 0; 38 if ((res = fclose(mr_flog)) != 0) { 39 fprintf(stderr,"Unable to close %s\n",mr_logfile); 40 } 41 free(mr_logfile); 42 43 mr_logfile = NULL; 44 mr_loglevel = 0; 45 mr_flog = NULL; 46 return; 47 } 48 40 49 /* Initialization function for messages */ 41 50 void mr_msg_init(const char *logfile, int loglevel) { 42 FILE *fout = NULL;43 int res = 0;44 45 51 if (asprintf(&mr_logfile, "%s", logfile) == -1) { 46 52 fprintf(stderr,"Unable to alloc memory\n"); … … 48 54 mr_msg_close(); 49 55 } 50 if ((fout = fopen(mr_logfile, "w")) == NULL) { 51 fprintf(stderr,"Unable to write to %s\n",mr_logfile); 52 fprintf(stderr,"Logging desactivated\n"); 53 mr_msg_close(); 54 } 55 if ((res = fclose(fout)) != 0) { 56 fprintf(stderr,"Unable to close %s\n",mr_logfile); 56 if (fopen(mr_logfile, "r") == NULL) { 57 /* log file doesn't exist yet, so creating it */ 58 if ((mr_flog = fopen(mr_logfile, "w")) == NULL) { 59 fprintf(stderr,"Unable to write to %s\n",mr_logfile); 60 fprintf(stderr,"Logging desactivated\n"); 61 mr_msg_close(); 62 } 63 } else { 64 /* If it exists try to append to it */ 65 if ((mr_flog = fopen(mr_logfile, "a")) == NULL) { 66 fprintf(stderr,"Unable to write to %s\n",mr_logfile); 67 fprintf(stderr,"Logging desactivated\n"); 68 mr_msg_close(); 69 } 57 70 } 58 71 mr_msg_loglevel(loglevel); … … 63 76 * but through other functions 64 77 * fmt needs to be just before ... 65 * debugshould be >0 to have file and line printed (real debug)78 * level should be >0 to have file and line printed (real debug) 66 79 * If =0 it's an informative log message 67 80 */ 68 void mr_msg_int(int debug, int line, const char *file, const char *fmt, ...) {81 void mr_msg_int(int level, int line, const char *file, char *function, const char *fmt, ...) { 69 82 70 int i = 0;71 int res = 0;72 FILE *fout = NULL;73 83 va_list args; 74 84 75 if ( mr_logfile == NULL) {85 if ((mr_logfile == NULL) || (mr_flog == NULL)) { 76 86 return; 77 87 } 78 88 79 if (debug <= mr_loglevel) { 80 if ((fout = fopen(mr_logfile, "a")) == NULL) { 81 fprintf(stderr,"Unable to append to %s\n",mr_logfile); 82 return; 83 } 84 85 // add 2 spaces to distinguish log levels 86 if (debug > 0) { 87 for (i = 1; i < debug; i++) 88 fprintf(fout, " "); 89 fprintf(fout, "%s #%d: ", file, line); 89 if (level <= mr_loglevel) { 90 if (level > 0) { 91 fprintf(mr_flog, "DBG%d: ", level); 92 fprintf(mr_flog, "%s->%s#%d: ", file, function, line); 93 } else { 94 fprintf(mr_flog, "INFO: "); 90 95 } 91 96 va_start(args,fmt); 92 if (vfprintf( fout, fmt, args) < 0) {97 if (vfprintf(mr_flog, fmt, args) < 0) { 93 98 fprintf(stderr,"Unable to print to %s\n",mr_logfile); 94 99 } 95 fprintf( fout,"\n");100 fprintf(mr_flog,"\n"); 96 101 va_end(args); 97 102 98 if ((res = fclose(fout)) != 0) {99 fprintf(stderr,"Unable to close %s\n",mr_logfile);100 }101 103 } 104 return; 102 105 } 106 -
branches/3.2/mondo/src/lib/mr_sys.c
r3498 r3509 36 36 res = vasprintf(&cmd, fmt, args); 37 37 if (res == -1) { 38 mr_msg_int(1,line,file," Unable to alloc memory in mr_asprintf\nExiting...");39 mr_exit(-1,"Unable to alloc memory in mr_ asprintf");38 mr_msg_int(1,line,file,"mr_system_int","Unable to alloc memory in mr_system_int\nExiting..."); 39 mr_exit(-1,"Unable to alloc memory in mr_system_int"); 40 40 } 41 41 /* … … 43 43 */ 44 44 res = system(cmd); 45 if (res < 0 ) { 46 mr_msg(4, "Unable to execute %s",cmd); 47 } 45 48 mr_free(cmd); 46 49 va_end(args); -
branches/3.2/mondo/src/mondoarchive/mondoarchive.c
r3478 r3509 322 322 } 323 323 324 /* setup log level for new log system as well */ 325 mr_msg_init(MONDO_LOGFILE,g_loglevel); 326 324 327 if (pre_param_configuration()) { 325 328 fatal_error("Pre-param initialization phase failed. Please review the error messages above, make the specified changes, then try again. Exiting..."); … … 448 451 printf("See %s for details of backup run.\n", MONDO_LOGFILE); 449 452 } 453 mr_msg_close(); 450 454 finish(retval); 451 455 -
branches/3.2/mondo/src/mondorestore/mondorestore.c
r3472 r3509 2805 2805 } 2806 2806 2807 /* setup log level for new log system as well */ 2808 mr_msg_init(MONDO_LOGFILE,g_loglevel); 2809 2807 2810 // Handle params here first 2808 2811 handle_incoming_parameters(argc,argv); … … 3004 3007 unlink("/tmp/filelist.full.gz"); 3005 3008 3009 mr_msg_close(); 3006 3010 exit(retval); 3007 3011 }
Note:
See TracChangeset
for help on using the changeset viewer.