1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #define INCL_DOS 25 #include <os2.h> 26 27 #include "precompiled_sal.hxx" 28 #include "sal/config.h" 29 30 #include "osl/process.h" 31 #include "sal/main.h" 32 #include "sal/types.h" 33 34 // for exception logging 35 #include <stdio.h> 36 #include <string.h> 37 #include <setjmp.h> 38 #include "helpers/except.h" 39 40 extern "C" { 41 42 /*----------------------------------------------------------------------------*/ 43 44 static CHAR szOOoExe[CCHMAXPATH]; 45 46 static FILE* APIENTRY _oslExceptOpenLogFile(VOID) 47 { 48 FILE *file; 49 DATETIME DT; 50 PPIB pib; 51 PSZ slash; 52 53 // get executable fullpath 54 DosGetInfoBlocks(NULL, &pib); 55 DosQueryModuleName(pib->pib_hmte, sizeof(szOOoExe), szOOoExe); 56 // truncate to exe name 57 slash = (PSZ)strrchr( szOOoExe, '.'); 58 *slash = '\0'; 59 // make log path 60 strcat( szOOoExe, ".log"); 61 62 file = fopen( szOOoExe, "a"); 63 if (!file) { // e.g. readonly drive 64 // try again, usually C exist and is writable 65 file = fopen( "c:\\OOo.log", "a"); 66 } 67 if (file) { 68 DosGetDateTime(&DT); 69 fprintf(file, "\nTrap message -- Date: %04d-%02d-%02d, Time: %02d:%02d:%02d\n", 70 DT.year, DT.month, DT.day, 71 DT.hours, DT.minutes, DT.seconds); 72 fprintf(file, "-------------------------------------------------------\n" 73 "\nAn internal error occurred (Built " __DATE__ "-" __TIME__ ").\n"); 74 75 } 76 77 // ok, return handle 78 return (file); 79 } 80 81 /*----------------------------------------------------------------------------*/ 82 83 static EXCEPTSTRUCT g_excptstruct = {0}; 84 85 void SAL_CALL sal_detail_initialize(int argc, char ** argv) 86 { 87 APIRET rc = -1; 88 89 #if OSL_DEBUG_LEVEL == 0 90 excRegisterHooks(_oslExceptOpenLogFile, NULL, NULL, FALSE); 91 92 g_excptstruct.RegRec2.pfnHandler = (PFN)excHandlerLoud; 93 g_excptstruct.arc = DosSetExceptionHandler( 94 (PEXCEPTIONREGISTRATIONRECORD)&(g_excptstruct.RegRec2)); 95 96 if (g_excptstruct.arc) 97 if (G_pfnExcHookError) 98 G_pfnExcHookError(__FILE__, __LINE__, __FUNCTION__, g_excptstruct.arc); 99 else 100 DosBeep(1000, 1000); 101 g_excptstruct.ulExcpt = setjmp(g_excptstruct.RegRec2.jmpThread); 102 #endif 103 104 osl_setCommandArgs(argc, argv); 105 } 106 107 void SAL_CALL sal_detail_deinitialize() 108 { 109 APIRET rc = -1; 110 111 #if OSL_DEBUG_LEVEL == 0 112 rc = DosUnsetExceptionHandler((PEXCEPTIONREGISTRATIONRECORD)&(g_excptstruct.RegRec2)); 113 #endif 114 } 115 116 } 117