1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 /**
27 * \file KMSAgentFatalState.cpp
28 */
29 #include <stdio.h>
30 #include <string.h>
31
32 #include "SYSCommon.h"
33 #include "KMSAgentStringUtilities.h"
34 #include "KMSAuditLogger.h"
35
36 #define MAX_TIME_STAMP_LENGTH 30
37
38 #ifndef METAWARE
39 /**
40 * append the state of the application in the <KMSAgentAuditLogger> log file.
41 */
process_fatal_application_state(const char * sFile,const char * sFunction,int iLine,const char * sAdditionalText)42 void process_fatal_application_state(const char* sFile,
43 const char* sFunction,
44 int iLine,
45 const char* sAdditionalText)
46 {
47
48 // File format: <date/time>,<operation>,<retention>,<audit id>,<network adddress>,<message>
49 char sFileLogEntry[MAX_LOG_FILE_LINE_LENGTH];
50 char sTimeStamp[MAX_TIME_STAMP_LENGTH];
51 char sLine[20];
52
53 GetCurrentDateTimeISO8601UTC(sTimeStamp, MAX_TIME_STAMP_LENGTH);
54 Int64ToUTF8(sLine, iLine, false, false);
55
56 strncpy(sFileLogEntry, "A fatal application error has occurred. Date: ", sizeof(sFileLogEntry));
57
58 sFileLogEntry[sizeof(sFileLogEntry)-1] = '\0';
59
60 strncat(sFileLogEntry, sTimeStamp, MAX_LOG_FILE_LINE_LENGTH - strlen(sFileLogEntry));
61
62 strncat(sFileLogEntry, " File: ", MAX_LOG_FILE_LINE_LENGTH - strlen(sFileLogEntry));
63
64 strncat(sFileLogEntry, sFile, MAX_LOG_FILE_LINE_LENGTH - strlen(sFileLogEntry));
65
66 strncat(sFileLogEntry, " Function: ", MAX_LOG_FILE_LINE_LENGTH - strlen(sFileLogEntry));
67
68 strncat(sFileLogEntry, sFunction, MAX_LOG_FILE_LINE_LENGTH - strlen(sFileLogEntry));
69
70 strncat(sFileLogEntry, " Line: ", MAX_LOG_FILE_LINE_LENGTH - strlen(sFileLogEntry));
71
72 strncat(sFileLogEntry, sLine, MAX_LOG_FILE_LINE_LENGTH - strlen(sFileLogEntry));
73
74 LogToFile( 0, sFileLogEntry );
75
76 exit( -1 );
77 }
78
79 #endif
80