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 "ap_mpm.h"
20
21#include <netware.h>
22#include <nks/netware.h>
23#include <nks/vm.h>
24
25void ap_down_server_cb(void *, void *);
26void ap_dummy_cb(void *, void *);
27void ap_cb_destroy(void *);
28
29int nlmUnloadSignaled(int wait);
30event_handle_t eh;
31Warn_t ref;
32Report_t dum;
33
34AP_DECLARE(apr_status_t) ap_os_create_privileged_process(
35    const request_rec *r,
36    apr_proc_t *newproc, const char *progname,
37    const char * const *args,
38    const char * const *env,
39    apr_procattr_t *attr, apr_pool_t *p)
40{
41    return apr_proc_create(newproc, progname, args, env, attr, p);
42}
43
44int _NonAppCheckUnload(void)
45{
46    return nlmUnloadSignaled(1);
47}
48
49/* down server event callback */
50void ap_down_server_cb(void *a, void *b)
51{
52    nlmUnloadSignaled(0);
53    return;
54}
55
56/* Required place holder event callback */
57void ap_dummy_cb(void *a, void *b)
58{
59    return;
60}
61
62/* destroy callback resources */
63void ap_cb_destroy(void *a)
64{
65    /* cleanup down event notification */
66    UnRegisterEventNotification(eh);
67    NX_UNWRAP_INTERFACE(ref);
68    NX_UNWRAP_INTERFACE(dum);
69}
70
71int _NonAppStart
72(
73    void        *NLMHandle,
74    void        *errorScreen,
75    const char  *cmdLine,
76    const char  *loadDirPath,
77    size_t      uninitializedDataLength,
78    void        *NLMFileHandle,
79    int         (*readRoutineP)( int conn, void *fileHandle, size_t offset,
80                    size_t nbytes, size_t *bytesRead, void *buffer ),
81    size_t      customDataOffset,
82    size_t      customDataSize,
83    int         messageCount,
84    const char  **messages
85)
86{
87#pragma unused(cmdLine)
88#pragma unused(loadDirPath)
89#pragma unused(uninitializedDataLength)
90#pragma unused(NLMFileHandle)
91#pragma unused(readRoutineP)
92#pragma unused(customDataOffset)
93#pragma unused(customDataSize)
94#pragma unused(messageCount)
95#pragma unused(messages)
96
97    /* register for down server event */
98    rtag_t rt = AllocateResourceTag(NLMHandle, "Apache2 Down Server Callback",
99                                    EventSignature);
100
101    NX_WRAP_INTERFACE((void *)ap_down_server_cb, 2, (void **)&ref);
102    NX_WRAP_INTERFACE((void *)ap_dummy_cb, 2, (void **)&dum);
103    eh = RegisterForEventNotification(rt, EVENT_DOWN_SERVER,
104                                      EVENT_PRIORITY_APPLICATION,
105                                      ref, dum, NULL);
106
107    /* clean-up */
108    NXVmRegisterExitHandler(ap_cb_destroy, NULL);
109
110    return 0;
111}
112
113