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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "apr_thread_proc.h"
19 #include "apr_errno.h"
20 #include "apr_general.h"
22 #include "apr_strings.h"
24 #if APR_HAS_OTHER_CHILD
26 /* XXX I'm sure there has to be a better way to do this ... */
28 #define EXTENSION ".exe"
30 #define EXTENSION ".nlm"
35 static char reasonstr[256];
37 static void ocmaint(int reason, void *data, int status)
40 case APR_OC_REASON_DEATH:
41 apr_cpystrn(reasonstr, "APR_OC_REASON_DEATH",
42 strlen("APR_OC_REASON_DEATH") + 1);
44 case APR_OC_REASON_LOST:
45 apr_cpystrn(reasonstr, "APR_OC_REASON_LOST",
46 strlen("APR_OC_REASON_LOST") + 1);
48 case APR_OC_REASON_UNWRITABLE:
49 apr_cpystrn(reasonstr, "APR_OC_REASON_UNWRITEABLE",
50 strlen("APR_OC_REASON_UNWRITEABLE") + 1);
52 case APR_OC_REASON_RESTART:
53 apr_cpystrn(reasonstr, "APR_OC_REASON_RESTART",
54 strlen("APR_OC_REASON_RESTART") + 1);
63 /* It would be great if we could stress this stuff more, and make the test
66 static void test_child_kill(CuTest *tc)
68 apr_file_t *std = NULL;
70 apr_procattr_t *procattr = NULL;
74 args[0] = apr_pstrdup(p, "occhild" EXTENSION);
75 args[1] = apr_pstrdup(p, "-X");
78 rv = apr_procattr_create(&procattr, p);
79 CuAssertIntEquals(tc, APR_SUCCESS, rv);
81 rv = apr_procattr_io_set(procattr, APR_FULL_BLOCK, APR_NO_PIPE,
83 CuAssertIntEquals(tc, APR_SUCCESS, rv);
85 rv = apr_proc_create(&newproc, "./occhild" EXTENSION, args, NULL, procattr, p);
86 CuAssertIntEquals(tc, APR_SUCCESS, rv);
87 CuAssertPtrNotNull(tc, newproc.in);
88 CuAssertPtrEquals(tc, NULL, newproc.out);
89 CuAssertPtrEquals(tc, NULL, newproc.err);
93 apr_proc_other_child_register(&newproc, ocmaint, NULL, std, p);
95 apr_sleep(apr_time_from_sec(1));
96 rv = apr_proc_kill(&newproc, SIGKILL);
97 CuAssertIntEquals(tc, APR_SUCCESS, rv);
99 /* allow time for things to settle... */
100 apr_sleep(apr_time_from_sec(3));
102 apr_proc_other_child_check();
103 CuAssertStrEquals(tc, "APR_OC_REASON_DEATH", reasonstr);
107 static void oc_not_impl(CuTest *tc)
109 CuNotImpl(tc, "Other child logic not implemented on this platform");
113 CuSuite *testoc(void)
115 CuSuite *suite = CuSuiteNew("Other Child");
117 #if !APR_HAS_OTHER_CHILD
118 SUITE_ADD_TEST(suite, oc_not_impl);
121 SUITE_ADD_TEST(suite, test_child_kill);