Commit f54c89ab0ea9bc93c1199f946cedf20a81e5baee

Authored by Perry Werneck
1 parent f8a828b9

Moving event source to global to avoid segfault when writing logs before

session creation.
@@ -432,7 +432,7 @@ dnl --------------------------------------------------------------------------- @@ -432,7 +432,7 @@ dnl ---------------------------------------------------------------------------
432 432
433 AC_ARG_WITH([libname], [AS_HELP_STRING([--with-libname], [Setup library name])], [ app_cv_libname="$withval" ],[ app_cv_libname="3270" ]) 433 AC_ARG_WITH([libname], [AS_HELP_STRING([--with-libname], [Setup library name])], [ app_cv_libname="$withval" ],[ app_cv_libname="3270" ])
434 434
435 -AC_DEFINE(LIB3270_NAME,$app_cv_libname) 435 +AC_DEFINE_UNQUOTED(LIB3270_NAME,$app_cv_libname)
436 AC_SUBST(LIB3270_NAME,$app_cv_libname) 436 AC_SUBST(LIB3270_NAME,$app_cv_libname)
437 437
438 AC_ARG_WITH([sdk-version], [AS_HELP_STRING([--with-sdk-version], [Setup library version for SDK])], [ app_cv_sdkversion="$withval" ],[ app_cv_sdkversion=$VERSION ]) 438 AC_ARG_WITH([sdk-version], [AS_HELP_STRING([--with-sdk-version], [Setup library version for SDK])], [ app_cv_sdkversion="$withval" ],[ app_cv_sdkversion=$VERSION ])
src/include/config.h.in
@@ -35,6 +35,7 @@ @@ -35,6 +35,7 @@
35 #undef PACKAGE_NAME 35 #undef PACKAGE_NAME
36 #undef PACKAGE_VERSION 36 #undef PACKAGE_VERSION
37 #undef PACKAGE_RELEASE 37 #undef PACKAGE_RELEASE
  38 + #undef LIB3270_NAME
38 39
39 /* Default settings */ 40 /* Default settings */
40 41
src/lib3270/init.c
@@ -63,6 +63,11 @@ @@ -63,6 +63,11 @@
63 63
64 /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ 64 /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/
65 65
  66 +#ifdef _WIN32
  67 +/// @brief Windows Event Log Handler.
  68 +HANDLE hEventLog = 0;
  69 +#endif // _WIN32
  70 +
66 /** 71 /**
67 * @brief Parse an stty control-character specification; a cheap, non-complaining implementation. 72 * @brief Parse an stty control-character specification; a cheap, non-complaining implementation.
68 */ 73 */
@@ -128,10 +133,13 @@ BOOL WINAPI DllMain(HANDLE GNUC_UNUSED(hinst), DWORD dwcallpurpose, LPVOID GNUC_ @@ -128,10 +133,13 @@ BOOL WINAPI DllMain(HANDLE GNUC_UNUSED(hinst), DWORD dwcallpurpose, LPVOID GNUC_
128 case DLL_PROCESS_ATTACH: 133 case DLL_PROCESS_ATTACH:
129 get_version_info(); 134 get_version_info();
130 lib3270_loaded(); 135 lib3270_loaded();
  136 + hEventLog = RegisterEventSource(NULL, LIB3270_STRINGIZE_VALUE_OF(LIB3270_NAME));
131 break; 137 break;
132 138
133 case DLL_PROCESS_DETACH: 139 case DLL_PROCESS_DETACH:
134 lib3270_unloaded(); 140 lib3270_unloaded();
  141 + DeregisterEventSource(hEventLog);
  142 + hEventLog = 0;
135 break; 143 break;
136 144
137 } 145 }
src/lib3270/private.h
@@ -674,11 +674,6 @@ struct _h3270 @@ -674,11 +674,6 @@ struct _h3270
674 struct lib3270_state_callback * last[LIB3270_STATE_USER]; 674 struct lib3270_state_callback * last[LIB3270_STATE_USER];
675 } st; 675 } st;
676 676
677 -#ifdef _WIN32  
678 - /// @brief Windows Event Log Handler.  
679 - HANDLE hEventLog;  
680 -#endif // _WIN32  
681 -  
682 }; 677 };
683 678
684 #define SELECTION_LEFT 0x01 679 #define SELECTION_LEFT 0x01
@@ -691,6 +686,11 @@ struct _h3270 @@ -691,6 +686,11 @@ struct _h3270
691 686
692 #define SELECTION_ACTIVE 0x80 687 #define SELECTION_ACTIVE 0x80
693 688
  689 +#ifdef _WIN32
  690 +/// @brief Windows Event Log Handler.
  691 +LIB3270_INTERNAL HANDLE hEventLog;
  692 +#endif // _WIN32
  693 +
694 /* Library internal calls */ 694 /* Library internal calls */
695 LIB3270_INTERNAL int key_ACharacter(H3270 *hSession, unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped); 695 LIB3270_INTERNAL int key_ACharacter(H3270 *hSession, unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped);
696 LIB3270_INTERNAL int cursor_move(H3270 *session, int baddr); 696 LIB3270_INTERNAL int cursor_move(H3270 *session, int baddr);
src/lib3270/session.c
@@ -151,11 +151,6 @@ void lib3270_session_free(H3270 *h) @@ -151,11 +151,6 @@ void lib3270_session_free(H3270 *h)
151 lib3270_free(ip); 151 lib3270_free(ip);
152 } 152 }
153 153
154 -#ifdef _WIN32  
155 - DeregisterEventSource(h->hEventLog);  
156 - h->hEventLog = 0;  
157 -#endif // _WIN32  
158 -  
159 trace("Releasing session %p",h); 154 trace("Releasing session %p",h);
160 lib3270_free(h); 155 lib3270_free(h);
161 156
@@ -413,10 +408,6 @@ H3270 * lib3270_session_new(const char *model) @@ -413,10 +408,6 @@ H3270 * lib3270_session_new(const char *model)
413 ft_init(hSession); 408 ft_init(hSession);
414 #endif 409 #endif
415 410
416 -#ifdef _WIN32  
417 - hSession->hEventLog = RegisterEventSource(NULL, PACKAGE_NAME);  
418 -#endif // _WIN32  
419 -  
420 trace("%s finished",__FUNCTION__); 411 trace("%s finished",__FUNCTION__);
421 412
422 errno = 0; 413 errno = 0;
src/lib3270/windows/log.c
@@ -41,7 +41,7 @@ @@ -41,7 +41,7 @@
41 41
42 /*---[ Implement ]------------------------------------------------------------------------------------------*/ 42 /*---[ Implement ]------------------------------------------------------------------------------------------*/
43 43
44 - void default_log_writer(H3270 *session, const char *module, int rc, const char *fmt, va_list arg_ptr) 44 + void default_log_writer(H3270 GNUC_UNUSED(*session), const char *module, int rc, const char *fmt, va_list arg_ptr)
45 { 45 {
46 char username[UNLEN + 1]; 46 char username[UNLEN + 1];
47 DWORD szName = sizeof(username); 47 DWORD szName = sizeof(username);
@@ -60,19 +60,17 @@ @@ -60,19 +60,17 @@
60 msg 60 msg
61 }; 61 };
62 62
63 - if(session->hEventLog) {  
64 - ReportEvent(  
65 - session->hEventLog,  
66 - (rc == 0 ? EVENTLOG_INFORMATION_TYPE : EVENTLOG_ERROR_TYPE),  
67 - 1,  
68 - 0,  
69 - NULL,  
70 - 3,  
71 - 0,  
72 - outMsg,  
73 - NULL  
74 - );  
75 - } 63 + ReportEvent(
  64 + hEventLog,
  65 + (rc == 0 ? EVENTLOG_INFORMATION_TYPE : EVENTLOG_ERROR_TYPE),
  66 + 1,
  67 + 0,
  68 + NULL,
  69 + 3,
  70 + 0,
  71 + outMsg,
  72 + NULL
  73 + );
76 74
77 } 75 }
78 76