src/share/back/log_messages.c

Print this page
rev 9508 : 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
Reviewed-by:


  39 #define MAXLEN_FILENAME         256
  40 #define MAXLEN_TIMESTAMP        80
  41 #define MAXLEN_LOCATION         (MAXLEN_FILENAME+MAXLEN_INTEGER+16)
  42 #define MAXLEN_MESSAGE          256
  43 #define MAXLEN_EXEC             (MAXLEN_FILENAME*2+MAXLEN_INTEGER+16)
  44 
  45 static MUTEX_T my_mutex = MUTEX_INIT;
  46 
  47 /* Static variables (should be protected with mutex) */
  48 static int logging;
  49 static FILE * log_file;
  50 static char logging_filename[MAXLEN_FILENAME+1+6];
  51 static char location_stamp[MAXLEN_LOCATION+1];
  52 static PID_T processPid;
  53 static int open_count;
  54 
  55 /* Ascii id of current native thread. */
  56 static void
  57 get_time_stamp(char *tbuf, size_t ltbuf)
  58 {
  59     char format[MAXLEN_TIMESTAMP+1];

  60     unsigned millisecs = 0;
  61     time_t t = 0;
  62 
  63     GETMILLSECS(millisecs);
  64     if ( time(&t) == (time_t)(-1) )
  65         t = 0;
  66     (void)strftime(format, sizeof(format),
  67                 /* Break this string up for SCCS's sake */
  68                 "%" "d.%" "m.%" "Y %" "T.%%.3d %" "Z", localtime(&t));
  69     (void)snprintf(tbuf, ltbuf, format, (int)(millisecs));



  70 }
  71 
  72 /* Get basename of filename */
  73 static const char *
  74 file_basename(const char *file)
  75 {
  76     char *p1;
  77     char *p2;
  78 
  79     if ( file==NULL )
  80         return "unknown";
  81     p1 = strrchr(file, '\\');
  82     p2 = strrchr(file, '/');
  83     p1 = ((p1 > p2) ? p1 : p2);
  84     if (p1 != NULL) {
  85         file = p1 + 1;
  86     }
  87     return file;
  88 }
  89 


 158             log_file = fopen(logging_filename, "w");
 159             if ( log_file!=NULL ) {
 160                 (void)setvbuf(log_file, NULL, _IOLBF, BUFSIZ);
 161             } else {
 162                 logging = 0;
 163             }
 164         }
 165 
 166         if ( log_file != NULL ) {
 167 
 168             /* Get the rest of the needed information */
 169             tid = GET_THREAD_ID();
 170             level = "FINEST"; /* FIXUP? */
 171             product = "J2SE1.5"; /* FIXUP? */
 172             module = "jdwp"; /* FIXUP? */
 173             messageID = ""; /* FIXUP: Unique message string ID? */
 174             (void)snprintf(optional, sizeof(optional),
 175                         "LOC=%s;PID=%d;THR=t@%d",
 176                         location_stamp,
 177                         (int)processPid,
 178                         (int)tid);
 179 
 180             /* Construct message string. */
 181             va_start(ap, format);
 182             (void)vsnprintf(message, sizeof(message), format, ap);
 183             va_end(ap);
 184 
 185             get_time_stamp(datetime, sizeof(datetime));
 186 
 187             /* Send out standard logging format message */
 188             standard_logging_format(log_file,
 189                 datetime,
 190                 level,
 191                 product,
 192                 module,
 193                 optional,
 194                 messageID,
 195                 message);
 196         }
 197         location_stamp[0] = 0;
 198     }




  39 #define MAXLEN_FILENAME         256
  40 #define MAXLEN_TIMESTAMP        80
  41 #define MAXLEN_LOCATION         (MAXLEN_FILENAME+MAXLEN_INTEGER+16)
  42 #define MAXLEN_MESSAGE          256
  43 #define MAXLEN_EXEC             (MAXLEN_FILENAME*2+MAXLEN_INTEGER+16)
  44 
  45 static MUTEX_T my_mutex = MUTEX_INIT;
  46 
  47 /* Static variables (should be protected with mutex) */
  48 static int logging;
  49 static FILE * log_file;
  50 static char logging_filename[MAXLEN_FILENAME+1+6];
  51 static char location_stamp[MAXLEN_LOCATION+1];
  52 static PID_T processPid;
  53 static int open_count;
  54 
  55 /* Ascii id of current native thread. */
  56 static void
  57 get_time_stamp(char *tbuf, size_t ltbuf)
  58 {
  59     char timestamp_prefix[MAXLEN_TIMESTAMP+1];
  60     char timestamp_postfix[MAXLEN_TIMESTAMP+1];
  61     unsigned millisecs = 0;
  62     time_t t = 0;
  63 
  64     GETMILLSECS(millisecs);
  65     if ( time(&t) == (time_t)(-1) )
  66         t = 0;
  67     (void)strftime(timestamp_prefix, sizeof(timestamp_prefix),
  68                 /* Break this string up for SCCS's sake */
  69                 "%" "d.%" "m.%" "Y %" "T", localtime(&t));
  70     (void)strftime(timestamp_postfix, sizeof(timestamp_postfix),
  71                 /* Break this string up for SCCS's sake */
  72                 "%" "Z", localtime(&t));
  73     (void)snprintf(tbuf, ltbuf, "%s.%.3d %s", timestamp_prefix, (int)(millisecs), timestamp_postfix);
  74 }
  75 
  76 /* Get basename of filename */
  77 static const char *
  78 file_basename(const char *file)
  79 {
  80     char *p1;
  81     char *p2;
  82 
  83     if ( file==NULL )
  84         return "unknown";
  85     p1 = strrchr(file, '\\');
  86     p2 = strrchr(file, '/');
  87     p1 = ((p1 > p2) ? p1 : p2);
  88     if (p1 != NULL) {
  89         file = p1 + 1;
  90     }
  91     return file;
  92 }
  93 


 162             log_file = fopen(logging_filename, "w");
 163             if ( log_file!=NULL ) {
 164                 (void)setvbuf(log_file, NULL, _IOLBF, BUFSIZ);
 165             } else {
 166                 logging = 0;
 167             }
 168         }
 169 
 170         if ( log_file != NULL ) {
 171 
 172             /* Get the rest of the needed information */
 173             tid = GET_THREAD_ID();
 174             level = "FINEST"; /* FIXUP? */
 175             product = "J2SE1.5"; /* FIXUP? */
 176             module = "jdwp"; /* FIXUP? */
 177             messageID = ""; /* FIXUP: Unique message string ID? */
 178             (void)snprintf(optional, sizeof(optional),
 179                         "LOC=%s;PID=%d;THR=t@%d",
 180                         location_stamp,
 181                         (int)processPid,
 182                         (int)(intptr_t)tid);
 183 
 184             /* Construct message string. */
 185             va_start(ap, format);
 186             (void)vsnprintf(message, sizeof(message), format, ap);
 187             va_end(ap);
 188 
 189             get_time_stamp(datetime, sizeof(datetime));
 190 
 191             /* Send out standard logging format message */
 192             standard_logging_format(log_file,
 193                 datetime,
 194                 level,
 195                 product,
 196                 module,
 197                 optional,
 198                 messageID,
 199                 message);
 200         }
 201         location_stamp[0] = 0;
 202     }