Apache HTTPD
nt_eventlog.c
Go to the documentation of this file.
1/* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "httpd.h"
18#include "http_log.h"
19#include "mpm_winnt.h"
20#include "apr_strings.h"
21#include "apr_lib.h"
22#include "apr_portable.h"
23#include "ap_regkey.h"
24
25static const char *display_name = NULL;
28
30{
33 char errbuf[256];
34 char *errmsg = errbuf;
35 const char *errarg[9];
38 apr_status_t rv;
40
42 apr_pool_tag(p, "service_stderr_thread");
43
44 errarg[0] = "The Apache service named";
45 errarg[1] = display_name;
46 errarg[2] = "reported the following error:\r\n>>>";
47 errarg[3] = errbuf;
48 errarg[4] = NULL;
49 errarg[5] = NULL;
50 errarg[6] = NULL;
51 errarg[7] = NULL;
52 errarg[8] = NULL;
53
54 /* What are we going to do in here, bail on the user? not. */
56 "SYSTEM\\CurrentControlSet\\Services\\"
57 "EventLog\\Application\\Apache Service",
59 == APR_SUCCESS)
60 {
63
64 /* The stock message file */
65 ap_regkey_value_set(regkey, "EventMessageFile",
66 "%SystemRoot%\\System32\\netmsg.dll",
68
69 ap_regkey_value_raw_set(regkey, "TypesSupported", &dwData,
70 sizeof(dwData), REG_DWORD, p);
72 }
73
74 hEventSource = RegisterEventSourceW(NULL, L"Apache Service");
75
77
78 while (ReadFile(hPipeRead, errmsg, 1, &errres, NULL) && (errres == 1))
79 {
80 if ((errmsg > errbuf) || !apr_isspace(*errmsg))
81 {
82 ++errmsg;
83 if ((*(errmsg - 1) == '\n')
84 || (errmsg >= errbuf + sizeof(errbuf) - 1))
85 {
86 while ((errmsg > errbuf) && apr_isspace(*(errmsg - 1))) {
87 --errmsg;
88 }
89 *errmsg = '\0';
90
91 /* Generic message: '%1 %2 %3 %4 %5 %6 %7 %8 %9'
92 * The event code in netmsg.dll is 3299
93 */
95 3299, NULL, 9, 0, errarg, NULL);
96 errmsg = errbuf;
97 }
98 }
99 }
100
102 apr_snprintf(errbuf, sizeof(errbuf),
103 "Win32 error %lu reading stderr pipe stream\r\n",
104 GetLastError());
105
107 3299, NULL, 9, 0, errarg, NULL);
108 }
109
115 return 0;
116}
117
118
131
132
134{
141
143
144 /* Create a pipe to send stderr messages to the system error log.
145 *
146 * _dup2() duplicates the write handle inheritable for us.
147 */
148 sa.nLength = sizeof(sa);
149 sa.lpSecurityDescriptor = NULL;
150 sa.bInheritHandle = FALSE;
153
158
160
162 == APR_SUCCESS)
164 == APR_SUCCESS))
166
167 /* The code above _will_ corrupt the StdHandle...
168 * and we must do so anyways. We set this up only
169 * after we initialized the posix stderr API.
170 */
172}
const ap_regex_t char * errbuf
Definition ap_regex.h:198
APR-style Win32 Registry Manipulation.
#define FALSE
Definition abts.h:35
#define SetEvent(h)
#define CreatePipe(ph1, ph2, sd, d)
#define RegisterEventSourceW(s1, s2)
#define GetStdHandle(d)
#define CreateThread(sd, d1, fn, pv, d2, pd3)
#define DeregisterEventSource(h)
#define CloseHandle(h)
#define WaitForSingleObject(h, d)
APR general purpose library routines.
APR Portability Routines.
APR Strings library.
void ap_open_stderr_log(apr_pool_t *p)
Definition log.c:243
DWORD stack_res_flag
void mpm_nt_eventlog_stderr_open(const char *argv0, apr_pool_t *p)
void mpm_nt_eventlog_stderr_flush(void)
#define ap_assert(exp)
Definition httpd.h:2271
apr_size_t size
#define apr_isspace(c)
Definition apr_lib.h:225
#define APR_SUCCESS
Definition apr_errno.h:225
int apr_status_t
Definition apr_errno.h:44
#define APR_READ
Definition apr_file_io.h:93
#define APR_WRITE
Definition apr_file_io.h:94
#define APR_CREATE
Definition apr_file_io.h:95
apr_sockaddr_t * sa
Apache Logging library.
HTTP Daemon routines.
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
WinNT MPM specific.
static const char * display_name
Definition nt_eventlog.c:25
static HANDLE stderr_ready
Definition nt_eventlog.c:27
static HANDLE stderr_thread
Definition nt_eventlog.c:26
static DWORD WINAPI service_stderr_thread(LPVOID hPipe)
Definition nt_eventlog.c:29
typedef HANDLE(WINAPI *apr_winapi_fpt_CreateToolhelp32Snapshot)(DWORD dwFlags
typedef DWORD(WINAPI *apr_winapi_fpt_GetCompressedFileSizeA)(IN LPCSTR lpFileName