Commit f54c89ab0ea9bc93c1199f946cedf20a81e5baee
1 parent
f8a828b9
Exists in
master
and in
3 other branches
Moving event source to global to avoid segfault when writing logs before
session creation.
Showing
6 changed files
with
27 additions
and
29 deletions
Show diff stats
configure.ac
... | ... | @@ -432,7 +432,7 @@ dnl --------------------------------------------------------------------------- |
432 | 432 | |
433 | 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 | 436 | AC_SUBST(LIB3270_NAME,$app_cv_libname) |
437 | 437 | |
438 | 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
src/lib3270/init.c
... | ... | @@ -63,6 +63,11 @@ |
63 | 63 | |
64 | 64 | /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ |
65 | 65 | |
66 | +#ifdef _WIN32 | |
67 | +/// @brief Windows Event Log Handler. | |
68 | +HANDLE hEventLog = 0; | |
69 | +#endif // _WIN32 | |
70 | + | |
66 | 71 | /** |
67 | 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 | 133 | case DLL_PROCESS_ATTACH: |
129 | 134 | get_version_info(); |
130 | 135 | lib3270_loaded(); |
136 | + hEventLog = RegisterEventSource(NULL, LIB3270_STRINGIZE_VALUE_OF(LIB3270_NAME)); | |
131 | 137 | break; |
132 | 138 | |
133 | 139 | case DLL_PROCESS_DETACH: |
134 | 140 | lib3270_unloaded(); |
141 | + DeregisterEventSource(hEventLog); | |
142 | + hEventLog = 0; | |
135 | 143 | break; |
136 | 144 | |
137 | 145 | } | ... | ... |
src/lib3270/private.h
... | ... | @@ -674,11 +674,6 @@ struct _h3270 |
674 | 674 | struct lib3270_state_callback * last[LIB3270_STATE_USER]; |
675 | 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 | 679 | #define SELECTION_LEFT 0x01 |
... | ... | @@ -691,6 +686,11 @@ struct _h3270 |
691 | 686 | |
692 | 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 | 694 | /* Library internal calls */ |
695 | 695 | LIB3270_INTERNAL int key_ACharacter(H3270 *hSession, unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped); |
696 | 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 | 151 | lib3270_free(ip); |
152 | 152 | } |
153 | 153 | |
154 | -#ifdef _WIN32 | |
155 | - DeregisterEventSource(h->hEventLog); | |
156 | - h->hEventLog = 0; | |
157 | -#endif // _WIN32 | |
158 | - | |
159 | 154 | trace("Releasing session %p",h); |
160 | 155 | lib3270_free(h); |
161 | 156 | |
... | ... | @@ -413,10 +408,6 @@ H3270 * lib3270_session_new(const char *model) |
413 | 408 | ft_init(hSession); |
414 | 409 | #endif |
415 | 410 | |
416 | -#ifdef _WIN32 | |
417 | - hSession->hEventLog = RegisterEventSource(NULL, PACKAGE_NAME); | |
418 | -#endif // _WIN32 | |
419 | - | |
420 | 411 | trace("%s finished",__FUNCTION__); |
421 | 412 | |
422 | 413 | errno = 0; | ... | ... |
src/lib3270/windows/log.c
... | ... | @@ -41,7 +41,7 @@ |
41 | 41 | |
42 | 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 | 46 | char username[UNLEN + 1]; |
47 | 47 | DWORD szName = sizeof(username); |
... | ... | @@ -60,19 +60,17 @@ |
60 | 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 | ... | ... |