src/jdk.jdwp.agent/share/native/libjdwp/log_messages.c
author rkennke
Fri, 12 Oct 2018 16:25:24 +0200
changeset 52107 0c1e44da019c
parent 48235 8db54e2c453b
child 53979 70c7c4db9c9a
child 56230 489867818774
permissions -rw-r--r--
8212053: A few more missing object equals barriers Reviewed-by: shade, zgu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
48235
8db54e2c453b 8192978: Missing checks and small fixes in jdwp library
clanger
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <time.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <errno.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "proc_md.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "log_messages.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#ifdef JDWP_LOGGING
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#define MAXLEN_INTEGER          20
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#define MAXLEN_FILENAME         256
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#define MAXLEN_TIMESTAMP        80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
#define MAXLEN_LOCATION         (MAXLEN_FILENAME+MAXLEN_INTEGER+16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
#define MAXLEN_MESSAGE          256
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
#define MAXLEN_EXEC             (MAXLEN_FILENAME*2+MAXLEN_INTEGER+16)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
static MUTEX_T my_mutex = MUTEX_INIT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/* Static variables (should be protected with mutex) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
static int logging;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
static FILE * log_file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
static char logging_filename[MAXLEN_FILENAME+1+6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
static char location_stamp[MAXLEN_LOCATION+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
static PID_T processPid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
static int open_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/* Ascii id of current native thread. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
get_time_stamp(char *tbuf, size_t ltbuf)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
{
23566
760a74c1b589 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents: 5506
diff changeset
    59
    char timestamp_prefix[MAXLEN_TIMESTAMP+1];
760a74c1b589 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents: 5506
diff changeset
    60
    char timestamp_postfix[MAXLEN_TIMESTAMP+1];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    unsigned millisecs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    time_t t = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    GETMILLSECS(millisecs);
23566
760a74c1b589 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents: 5506
diff changeset
    65
    if ( time(&t) == (time_t)(-1) ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        t = 0;
23566
760a74c1b589 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents: 5506
diff changeset
    67
    }
760a74c1b589 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents: 5506
diff changeset
    68
    /* Break this up so that the format strings are string literals
760a74c1b589 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents: 5506
diff changeset
    69
       and we avoid a compiler warning. */
760a74c1b589 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents: 5506
diff changeset
    70
    (void)strftime(timestamp_prefix, sizeof(timestamp_prefix),
760a74c1b589 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents: 5506
diff changeset
    71
                "%d.%m.%Y %T", localtime(&t));
760a74c1b589 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents: 5506
diff changeset
    72
    (void)strftime(timestamp_postfix, sizeof(timestamp_postfix),
760a74c1b589 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents: 5506
diff changeset
    73
                "%Z", localtime(&t));
760a74c1b589 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents: 5506
diff changeset
    74
    (void)snprintf(tbuf, ltbuf,
760a74c1b589 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents: 5506
diff changeset
    75
                   "%s.%.3d %s", timestamp_prefix,
760a74c1b589 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents: 5506
diff changeset
    76
                   (int)(millisecs), timestamp_postfix);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
/* Get basename of filename */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
static const char *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
file_basename(const char *file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    char *p1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    char *p2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    if ( file==NULL )
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return "unknown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    p1 = strrchr(file, '\\');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    p2 = strrchr(file, '/');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    p1 = ((p1 > p2) ? p1 : p2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    if (p1 != NULL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        file = p1 + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    return file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
/* Fill in the exact source location of the LOG entry. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
fill_location_stamp(const char *flavor, const char *file, int line)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    (void)snprintf(location_stamp, sizeof(location_stamp),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                    "%s:\"%s\":%d;",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                    flavor, file_basename(file), line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    location_stamp[sizeof(location_stamp)-1] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
/* Begin a log entry. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
log_message_begin(const char *flavor, const char *file, int line)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    MUTEX_LOCK(my_mutex); /* Unlocked in log_message_end() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    if ( logging ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        location_stamp[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        fill_location_stamp(flavor, file, line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
/* Standard Logging Format Entry */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
static void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
standard_logging_format(FILE *fp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        const char *datetime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        const char *level,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        const char *product,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        const char *module,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        const char *optional,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        const char *messageID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        const char *message)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    const char *format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /* "[#|Date&Time&Zone|LogLevel|ProductName|ModuleID|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *     OptionalKey1=Value1;OptionalKeyN=ValueN|MessageID:MessageText|#]\n"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    format="[#|%s|%s|%s|%s|%s|%s:%s|#]\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    print_message(fp, "", "", format,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            datetime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            level,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            product,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            module,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            optional,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            messageID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
/* End a log entry */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
log_message_end(const char *format, ...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    if ( logging ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        va_list ap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        THREAD_T tid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        char datetime[MAXLEN_TIMESTAMP+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        const char *level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        const char *product;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        const char *module;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        char optional[MAXLEN_INTEGER+6+MAXLEN_INTEGER+6+MAXLEN_LOCATION+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        const char *messageID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        char message[MAXLEN_MESSAGE+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        /* Grab the location, start file if needed, and clear the lock */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if ( log_file == NULL && open_count == 0 && logging_filename[0] != 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            open_count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            log_file = fopen(logging_filename, "w");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            if ( log_file!=NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                (void)setvbuf(log_file, NULL, _IOLBF, BUFSIZ);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                logging = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        if ( log_file != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            /* Get the rest of the needed information */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            tid = GET_THREAD_ID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            level = "FINEST"; /* FIXUP? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            product = "J2SE1.5"; /* FIXUP? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            module = "jdwp"; /* FIXUP? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            messageID = ""; /* FIXUP: Unique message string ID? */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            (void)snprintf(optional, sizeof(optional),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                        "LOC=%s;PID=%d;THR=t@%d",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                        location_stamp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                        (int)processPid,
23566
760a74c1b589 8037825: Fix warnings and enable "warnings as errors" in serviceability native libraries
sla
parents: 5506
diff changeset
   185
                        (int)(intptr_t)tid);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            /* Construct message string. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            va_start(ap, format);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            (void)vsnprintf(message, sizeof(message), format, ap);
48235
8db54e2c453b 8192978: Missing checks and small fixes in jdwp library
clanger
parents: 47216
diff changeset
   190
            message[sizeof(message) - 1] = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            va_end(ap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            get_time_stamp(datetime, sizeof(datetime));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            /* Send out standard logging format message */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            standard_logging_format(log_file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                datetime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                level,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                product,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                module,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                optional,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                messageID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        location_stamp[0] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    MUTEX_UNLOCK(my_mutex); /* Locked in log_message_begin() */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
/* Set up the logging with the name of a logging file. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
void
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
setup_logging(const char *filename, unsigned flags)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
#ifdef JDWP_LOGGING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    FILE *fp = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    /* Turn off logging */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    logging = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    gdata->log_flags = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    /* Just return if not doing logging */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    if ( filename==NULL || flags==0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /* Create potential filename for logging */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    processPid = GETPID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    (void)snprintf(logging_filename, sizeof(logging_filename),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                    "%s.%d", filename, (int)processPid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    /* Turn on logging (do this last) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    logging = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    gdata->log_flags = flags;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
/* Finish up logging, flush output to the logfile. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
void
26223
3830bfd8440a 8049226: com/sun/jdi/OptionTest.java test times out again
dsamersoff
parents: 25859
diff changeset
   241
finish_logging()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
#ifdef JDWP_LOGGING
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    MUTEX_LOCK(my_mutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    if ( logging ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        logging = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if ( log_file != NULL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            (void)fflush(log_file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            (void)fclose(log_file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            log_file = NULL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    MUTEX_UNLOCK(my_mutex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
}