1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #include <cstring>
20 #include <stdlib.h> // for abort
21 #include <ts/ts.h>  // for debug
22 
23 // debug messages viewable by setting 'proxy.config.diags.debug.tags'
24 // in 'records.config'
25 
26 // debug messages during one-time initialization
27 static const char DEBUG_TAG[] = "TSEmergency_test";
28 
29 // plugin registration info
30 static char plugin_name[]   = "TSEmergency_test";
31 static char vendor_name[]   = "apache";
32 static char support_email[] = "duke8253@apache.org";
33 
34 static int
test_handler(TSCont contp,TSEvent event,void * edata)35 test_handler(TSCont contp, TSEvent event, void *edata)
36 {
37   TSDebug(DEBUG_TAG, "failed to shutdown");
38   return 0;
39 }
40 
41 static int
LifecycleHookTracer(TSCont contp,TSEvent event,void * edata)42 LifecycleHookTracer(TSCont contp, TSEvent event, void *edata)
43 {
44   if (event == TS_EVENT_LIFECYCLE_TASK_THREADS_READY) {
45     TSCont contp = TSContCreate(test_handler, TSMutexCreate());
46     TSContScheduleOnPool(contp, 500, TS_THREAD_POOL_NET);
47     TSEmergency("testing emergency shutdown");
48   }
49   return 0;
50 }
51 
52 void
TSPluginInit(int argc,const char * argv[])53 TSPluginInit(int argc, const char *argv[])
54 {
55   TSPluginRegistrationInfo info;
56 
57   info.plugin_name   = plugin_name;
58   info.vendor_name   = vendor_name;
59   info.support_email = support_email;
60 
61   if (TSPluginRegister(&info) != TS_SUCCESS) {
62     TSEmergency("[%s] plugin registration failed", plugin_name);
63   }
64 
65   TSLifecycleHookAdd(TS_LIFECYCLE_TASK_THREADS_READY_HOOK, TSContCreate(LifecycleHookTracer, TSMutexCreate()));
66 }
67