trinidad_init_services 1.1.3 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. data/.gitignore +5 -0
  2. data/Gemfile +3 -0
  3. data/History.txt +6 -0
  4. data/README.md +95 -0
  5. data/Rakefile +9 -58
  6. data/bin/trinidad_init_service +3 -4
  7. data/init.d/trinidad.erb +33 -12
  8. data/jsvc-unix-src/CHANGES.txt +62 -0
  9. data/jsvc-unix-src/INSTALL.txt +81 -0
  10. data/jsvc-unix-src/Makedefs.in +32 -0
  11. data/jsvc-unix-src/Makefile.in +42 -0
  12. data/jsvc-unix-src/configure +4417 -0
  13. data/jsvc-unix-src/configure.in +141 -0
  14. data/jsvc-unix-src/man/README +20 -0
  15. data/jsvc-unix-src/man/fetch.sh +36 -0
  16. data/jsvc-unix-src/man/jsvc.1.xml +214 -0
  17. data/jsvc-unix-src/native/.indent.pro +7 -0
  18. data/jsvc-unix-src/native/Makefile.in +46 -0
  19. data/jsvc-unix-src/native/arguments.c +476 -0
  20. data/jsvc-unix-src/native/arguments.h +94 -0
  21. data/jsvc-unix-src/native/debug.c +87 -0
  22. data/jsvc-unix-src/native/debug.h +65 -0
  23. data/jsvc-unix-src/native/dso-dlfcn.c +62 -0
  24. data/jsvc-unix-src/native/dso-dyld.c +153 -0
  25. data/jsvc-unix-src/native/dso.h +38 -0
  26. data/jsvc-unix-src/native/help.c +106 -0
  27. data/jsvc-unix-src/native/help.h +24 -0
  28. data/jsvc-unix-src/native/home.c +265 -0
  29. data/jsvc-unix-src/native/home.h +47 -0
  30. data/jsvc-unix-src/native/java.c +608 -0
  31. data/jsvc-unix-src/native/java.h +35 -0
  32. data/jsvc-unix-src/native/jsvc-unix.c +1267 -0
  33. data/jsvc-unix-src/native/jsvc.h +55 -0
  34. data/jsvc-unix-src/native/location.c +151 -0
  35. data/jsvc-unix-src/native/location.h +29 -0
  36. data/jsvc-unix-src/native/locks.c +52 -0
  37. data/jsvc-unix-src/native/locks.h +40 -0
  38. data/jsvc-unix-src/native/replace.c +121 -0
  39. data/jsvc-unix-src/native/replace.h +39 -0
  40. data/jsvc-unix-src/native/signals.c +105 -0
  41. data/jsvc-unix-src/native/signals.h +34 -0
  42. data/jsvc-unix-src/native/version.h +63 -0
  43. data/jsvc-unix-src/support/apfunctions.m4 +110 -0
  44. data/jsvc-unix-src/support/apjava.m4 +94 -0
  45. data/jsvc-unix-src/support/apsupport.m4 +155 -0
  46. data/jsvc-unix-src/support/buildconf.sh +33 -0
  47. data/jsvc-unix-src/support/config.guess +1371 -0
  48. data/jsvc-unix-src/support/config.sub +1760 -0
  49. data/jsvc-unix-src/support/install.sh +128 -0
  50. data/jsvc-unix-src/support/mkdist.sh +104 -0
  51. data/lib/trinidad/daemon.rb +31 -0
  52. data/lib/trinidad_init_services.rb +2 -30
  53. data/lib/trinidad_init_services/configuration.rb +91 -14
  54. data/lib/trinidad_init_services/version.rb +5 -0
  55. data/spec/spec_helper.rb +5 -6
  56. data/spec/trinidad_daemon_spec.rb +0 -1
  57. data/spec/trinidad_init_services/configuration_spec.rb +34 -1
  58. data/trinidad_init_services.gemspec +14 -51
  59. metadata +146 -87
  60. data/README +0 -63
  61. data/trinidad-libs/jsvc_linux +0 -0
@@ -0,0 +1,608 @@
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
+ /* @version $Id: java.c 1196468 2011-11-02 06:24:11Z mturk $ */
18
+ #include "jsvc.h"
19
+
20
+ #ifdef OS_CYGWIN
21
+ typedef long long __int64;
22
+ #endif
23
+ #include <unistd.h>
24
+ #include <jni.h>
25
+
26
+ #ifdef CHARSET_EBCDIC
27
+ #ifdef OSD_POSIX
28
+ #include <ascii_ebcdic.h>
29
+ #define jsvc_xlate_to_ascii(b) _e2a(b)
30
+ #define jsvc_xlate_from_ascii(b) _a2e(b)
31
+ #endif
32
+ #else
33
+ #define jsvc_xlate_to_ascii(b) /* NOOP */
34
+ #define jsvc_xlate_from_ascii(b) /* NOOP */
35
+ #endif
36
+
37
+ static JavaVM *jvm = NULL;
38
+ static JNIEnv *env = NULL;
39
+ static jclass cls = NULL;
40
+
41
+ #define FALSE 0
42
+ #define TRUE !FALSE
43
+
44
+ static void shutdown(JNIEnv *env, jobject source, jboolean reload)
45
+ {
46
+ log_debug("Shutdown requested (reload is %d)", reload);
47
+ if (reload == TRUE)
48
+ main_reload();
49
+ else
50
+ main_shutdown();
51
+ }
52
+
53
+ static void failed(JNIEnv *env, jobject source, jstring message)
54
+ {
55
+ if (message) {
56
+ const char *msg = (*env)->GetStringUTFChars(env, message, NULL);
57
+ log_error("Failed %s", msg ? msg : "(null)");
58
+ if (msg)
59
+ (*env)->ReleaseStringUTFChars(env, message, msg);
60
+ }
61
+ else
62
+ log_error("Failed requested");
63
+ main_shutdown();
64
+ }
65
+
66
+ /* Automatically restart when the JVM crashes */
67
+ static void java_abort123(void)
68
+ {
69
+ exit(123);
70
+ }
71
+
72
+ char *java_library(arg_data *args, home_data *data)
73
+ {
74
+ char *libf = NULL;
75
+
76
+ /* Did we find ANY virtual machine? */
77
+ if (data->jnum == 0) {
78
+ log_error("Cannot find any VM in Java Home %s", data->path);
79
+ return NULL;
80
+ }
81
+
82
+ /* Select the VM */
83
+ if (args->name == NULL) {
84
+ libf = data->jvms[0]->libr;
85
+ log_debug("Using default JVM in %s", libf);
86
+ }
87
+ else {
88
+ int x;
89
+ for (x = 0; x < data->jnum; x++) {
90
+ if (data->jvms[x]->name == NULL)
91
+ continue;
92
+ if (strcmp(args->name, data->jvms[x]->name) == 0) {
93
+ libf = data->jvms[x]->libr;
94
+ log_debug("Using specific JVM in %s", libf);
95
+ break;
96
+ }
97
+ }
98
+ if (libf == NULL) {
99
+ log_error("Invalid JVM name specified %s", args->name);
100
+ return NULL;
101
+ }
102
+ }
103
+ return libf;
104
+ }
105
+
106
+ typedef jint (*jvm_create_t)(JavaVM **, JNIEnv **, JavaVMInitArgs *);
107
+
108
+ bool java_signal(void)
109
+ {
110
+ jmethodID method;
111
+ jboolean ret;
112
+ char start[] = "signal";
113
+ char startparams[] = "()Z";
114
+
115
+ jsvc_xlate_to_ascii(start);
116
+ jsvc_xlate_to_ascii(startparams);
117
+ method = (*env)->GetStaticMethodID(env, cls, start, startparams);
118
+ if (method == NULL) {
119
+ (*env)->ExceptionClear(env);
120
+ log_error("Cannot find DaemonLoader \"signal\" method");
121
+ return false;
122
+ }
123
+
124
+ ret = (*env)->CallStaticBooleanMethod(env, cls, method);
125
+ /* Clear any pending exception
126
+ * so we can continue calling native methods
127
+ */
128
+ (*env)->ExceptionClear(env);
129
+ log_debug("Daemon signal method returned %s", ret ? "true" : "false");
130
+ return ret;
131
+ }
132
+
133
+ /* Initialize the JVM and its environment, loading libraries and all */
134
+ bool java_init(arg_data *args, home_data *data)
135
+ {
136
+ #ifdef OS_DARWIN
137
+ dso_handle apph = NULL;
138
+ char appf[1024];
139
+ struct stat sb;
140
+ #endif /* ifdef OS_DARWIN */
141
+ jvm_create_t symb = NULL;
142
+ JNINativeMethod nativemethods[2];
143
+ JavaVMOption *opt = NULL;
144
+ dso_handle libh = NULL;
145
+ JavaVMInitArgs arg;
146
+ char *libf = NULL;
147
+ jint ret;
148
+ int x;
149
+ char loaderclass[] = LOADER;
150
+ char shutdownmethod[] = "shutdown";
151
+ char shutdownparams[] = "(Z)V";
152
+ char failedmethod[] = "failed";
153
+ char failedparams[] = "(Ljava/lang/String;)V";
154
+ char daemonprocid[64];
155
+ /* Decide WHAT virtual machine we need to use */
156
+ libf = java_library(args, data);
157
+ if (libf == NULL) {
158
+ log_error("Cannot locate JVM library file");
159
+ return false;
160
+ }
161
+
162
+ /* Initialize the DSO library */
163
+ if (dso_init() != true) {
164
+ log_error("Cannot initialize the dynamic library loader");
165
+ return false;
166
+ }
167
+
168
+ /* Load the JVM library */
169
+ #if !defined(OSD_POSIX)
170
+ libh = dso_link(libf);
171
+ if (libh == NULL) {
172
+ log_error("Cannot dynamically link to %s", libf);
173
+ log_error("%s", dso_error());
174
+ return false;
175
+ }
176
+ log_debug("JVM library %s loaded", libf);
177
+ #endif
178
+
179
+ #ifdef OS_DARWIN
180
+ /*
181
+ MacOS/X actually has two libraries, one with the REAL vm, and one for
182
+ the VM startup.
183
+ before JVM 1.4.1 The first one (libappshell.dyld) contains CreateVM
184
+ JVM 1.4.1 through 1.5.* The library name is libjvm_compat.dylib
185
+ starting with JVM 1.6 on OS X 10.6 the library name is libverify.dylib.
186
+ */
187
+ if (replace(appf, 1024, "$JAVA_HOME/../Libraries/libappshell.dylib",
188
+ "$JAVA_HOME", data->path) != 0) {
189
+ log_error("Cannot replace values in loader library");
190
+ return false;
191
+ }
192
+ if (stat(appf, &sb)) {
193
+ if (replace(appf, 1024, "$JAVA_HOME/../Libraries/libjvm_compat.dylib",
194
+ "$JAVA_HOME", data->path) != 0) {
195
+ log_error("Cannot replace values in loader library");
196
+ return false;
197
+ }
198
+ }
199
+ if (stat(appf, &sb)) {
200
+ if (replace(appf, 1024, "$JAVA_HOME/../Libraries/libverify.dylib",
201
+ "$JAVA_HOME", data->path) != 0) {
202
+ log_error("Cannot replace values in loader library");
203
+ return false;
204
+ }
205
+ }
206
+ apph = dso_link(appf);
207
+ if (apph == NULL) {
208
+ log_error("Cannot load required shell library %s", appf);
209
+ return false;
210
+ }
211
+ log_debug("Shell library %s loaded", appf);
212
+ #endif /* ifdef OS_DARWIN */
213
+ #if defined(OSD_POSIX)
214
+ /* BS2000 does not allow to call JNI_CreateJavaVM indirectly */
215
+ #else
216
+ symb = (jvm_create_t)dso_symbol(libh, "JNI_CreateJavaVM");
217
+ if (symb == NULL) {
218
+ #ifdef OS_DARWIN
219
+ symb = (jvm_create_t)dso_symbol(apph, "JNI_CreateJavaVM");
220
+ if (symb == NULL) {
221
+ #endif /* ifdef OS_DARWIN */
222
+ log_error("Cannot find JVM library entry point");
223
+ return false;
224
+ #ifdef OS_DARWIN
225
+ }
226
+ #endif /* ifdef OS_DARWIN */
227
+ }
228
+ log_debug("JVM library entry point found (0x%08X)", symb);
229
+ #endif
230
+
231
+ /* Prepare the VM initialization arguments */
232
+
233
+ /*
234
+ * Mac OS X Java will load JVM 1.3.1 instead of 1.4.2 if JNI_VERSION_1_2
235
+ * is specified. So use JNI_VERSION_1_4 if we can.
236
+ */
237
+ #if defined(JNI_VERSION_1_4)
238
+ arg.version = JNI_VERSION_1_4;
239
+ #else
240
+ arg.version = JNI_VERSION_1_2;
241
+ #endif
242
+ #if defined(OSD_POSIX)
243
+ if (JNI_GetDefaultJavaVMInitArgs(&arg) < 0) {
244
+ log_error("Cannot init default JVM default args");
245
+ return false;
246
+ }
247
+ #endif
248
+ arg.ignoreUnrecognized = FALSE;
249
+ arg.nOptions = args->onum + 4; /* pid, ppid and abort */
250
+ opt = (JavaVMOption *) malloc(arg.nOptions * sizeof(JavaVMOption));
251
+ for (x = 0; x < args->onum; x++) {
252
+ opt[x].optionString = strdup(args->opts[x]);
253
+ jsvc_xlate_to_ascii(opt[x].optionString);
254
+ opt[x].extraInfo = NULL;
255
+ }
256
+ /* Add our daemon process id */
257
+ snprintf(daemonprocid, sizeof(daemonprocid),
258
+ "-Dcommons.daemon.process.id=%d", (int)getpid());
259
+ opt[x].optionString = strdup(daemonprocid);
260
+ jsvc_xlate_to_ascii(opt[x].optionString);
261
+ opt[x++].extraInfo = NULL;
262
+ snprintf(daemonprocid, sizeof(daemonprocid),
263
+ "-Dcommons.daemon.process.parent=%d", (int)getppid());
264
+ opt[x].optionString = strdup(daemonprocid);
265
+ jsvc_xlate_to_ascii(opt[x].optionString);
266
+ opt[x++].extraInfo = NULL;
267
+ snprintf(daemonprocid, sizeof(daemonprocid),
268
+ "-Dcommons.daemon.version=%s", JSVC_VERSION_STRING);
269
+ opt[x].optionString = strdup(daemonprocid);
270
+ jsvc_xlate_to_ascii(opt[x].optionString);
271
+ opt[x++].extraInfo = NULL;
272
+ opt[x].optionString = strdup("abort");
273
+ jsvc_xlate_to_ascii(opt[x].optionString);
274
+ opt[x].extraInfo = (void *)java_abort123;
275
+ arg.options = opt;
276
+
277
+ /* Do some debugging */
278
+ if (log_debug_flag == true) {
279
+ log_debug("+-- DUMPING JAVA VM CREATION ARGUMENTS -----------------");
280
+ log_debug("| Version: %#08x", arg.version);
281
+ log_debug("| Ignore Unrecognized Arguments: %s",
282
+ arg.ignoreUnrecognized == TRUE ? "True" : "False");
283
+ log_debug("| Extra options: %d", args->onum);
284
+
285
+ for (x = 0; x < args->onum; x++) {
286
+ jsvc_xlate_from_ascii(opt[x].optionString);
287
+ log_debug("| \"%s\" (0x%08x)", opt[x].optionString,
288
+ opt[x].extraInfo);
289
+ jsvc_xlate_to_ascii(opt[x].optionString);
290
+ }
291
+ log_debug("+-------------------------------------------------------");
292
+ log_debug("| Internal options: %d", arg.nOptions - args->onum);
293
+
294
+ for (; x < arg.nOptions; x++) {
295
+ jsvc_xlate_from_ascii(opt[x].optionString);
296
+ log_debug("| \"%s\" (0x%08x)", opt[x].optionString,
297
+ opt[x].extraInfo);
298
+ jsvc_xlate_to_ascii(opt[x].optionString);
299
+ }
300
+ log_debug("+-------------------------------------------------------");
301
+ }
302
+
303
+ /* And finally create the Java VM */
304
+ #if defined(OSD_POSIX)
305
+ ret = JNI_CreateJavaVM(&jvm, &env, &arg);
306
+ #else
307
+ ret = (*symb) (&jvm, &env, &arg);
308
+ #endif
309
+ if (ret < 0) {
310
+ log_error("Cannot create Java VM");
311
+ return false;
312
+ }
313
+ log_debug("Java VM created successfully");
314
+
315
+ jsvc_xlate_to_ascii(loaderclass);
316
+ cls = (*env)->FindClass(env, loaderclass);
317
+ jsvc_xlate_from_ascii(loaderclass);
318
+ if (cls == NULL) {
319
+ log_error("Cannot find daemon loader %s", loaderclass);
320
+ return false;
321
+ }
322
+ log_debug("Class %s found", loaderclass);
323
+
324
+ jsvc_xlate_to_ascii(shutdownmethod);
325
+ nativemethods[0].name = shutdownmethod;
326
+ jsvc_xlate_to_ascii(shutdownparams);
327
+ nativemethods[0].signature = shutdownparams;
328
+ nativemethods[0].fnPtr = (void *)shutdown;
329
+ jsvc_xlate_to_ascii(failedmethod);
330
+ nativemethods[1].name = failedmethod;
331
+ jsvc_xlate_to_ascii(failedparams);
332
+ nativemethods[1].signature = failedparams;
333
+ nativemethods[1].fnPtr = (void *)failed;
334
+
335
+ if ((*env)->RegisterNatives(env, cls, nativemethods, 2) != 0) {
336
+ log_error("Cannot register native methods");
337
+ return false;
338
+ }
339
+ log_debug("Native methods registered");
340
+
341
+ return true;
342
+ }
343
+
344
+ /* Destroy the Java VM */
345
+ bool JVM_destroy(int exit)
346
+ {
347
+ jclass system = NULL;
348
+ jmethodID method;
349
+ char System[] = "java/lang/System";
350
+ char exitclass[] = "exit";
351
+ char exitparams[] = "(I)V";
352
+
353
+ jsvc_xlate_to_ascii(System);
354
+ system = (*env)->FindClass(env, System);
355
+ jsvc_xlate_from_ascii(System);
356
+ if (system == NULL) {
357
+ log_error("Cannot find class %s", System);
358
+ return false;
359
+ }
360
+
361
+ jsvc_xlate_to_ascii(exitclass);
362
+ jsvc_xlate_to_ascii(exitparams);
363
+ method = (*env)->GetStaticMethodID(env, system, exitclass, exitparams);
364
+ if (method == NULL) {
365
+ log_error("Cannot find \"System.exit(int)\" entry point");
366
+ return false;
367
+ }
368
+
369
+ log_debug("Calling System.exit(%d)", exit);
370
+ (*env)->CallStaticVoidMethod(env, system, method, (jint) exit);
371
+
372
+ /* We shouldn't get here, but just in case... */
373
+ log_debug("Destroying the Java VM");
374
+ if ((*jvm)->DestroyJavaVM(jvm) != 0)
375
+ return false;
376
+ log_debug("Java VM destroyed");
377
+ return true;
378
+ }
379
+
380
+ /* Call the load method in our DaemonLoader class */
381
+ bool java_load(arg_data *args)
382
+ {
383
+ jclass stringClass = NULL;
384
+ jstring className = NULL;
385
+ jstring currentArgument = NULL;
386
+ jobjectArray stringArray = NULL;
387
+ jmethodID method = NULL;
388
+ jboolean ret = FALSE;
389
+ int x;
390
+ char lang[] = "java/lang/String";
391
+ char load[] = "load";
392
+ char loadparams[] = "(Ljava/lang/String;[Ljava/lang/String;)Z";
393
+
394
+ jsvc_xlate_to_ascii(args->clas);
395
+ className = (*env)->NewStringUTF(env, args->clas);
396
+ jsvc_xlate_from_ascii(args->clas);
397
+ if (className == NULL) {
398
+ log_error("Cannot create string for class name");
399
+ return false;
400
+ }
401
+
402
+ jsvc_xlate_to_ascii(lang);
403
+ stringClass = (*env)->FindClass(env, lang);
404
+ if (stringClass == NULL) {
405
+ log_error("Cannot find class java/lang/String");
406
+ return false;
407
+ }
408
+
409
+ stringArray = (*env)->NewObjectArray(env, args->anum, stringClass, NULL);
410
+ if (stringArray == NULL) {
411
+ log_error("Cannot create arguments array");
412
+ return false;
413
+ }
414
+
415
+ for (x = 0; x < args->anum; x++) {
416
+ jsvc_xlate_to_ascii(args->args[x]);
417
+ currentArgument = (*env)->NewStringUTF(env, args->args[x]);
418
+ if (currentArgument == NULL) {
419
+ jsvc_xlate_from_ascii(args->args[x]);
420
+ log_error("Cannot create string for argument %s", args->args[x]);
421
+ return false;
422
+ }
423
+ (*env)->SetObjectArrayElement(env, stringArray, x, currentArgument);
424
+ }
425
+
426
+ jsvc_xlate_to_ascii(load);
427
+ jsvc_xlate_to_ascii(loadparams);
428
+ method = (*env)->GetStaticMethodID(env, cls, load, loadparams);
429
+ if (method == NULL) {
430
+ log_error("Cannot find Daemon Loader \"load\" entry point");
431
+ return false;
432
+ }
433
+
434
+ log_debug("Daemon loading...");
435
+ ret = (*env)->CallStaticBooleanMethod(env, cls, method, className,
436
+ stringArray);
437
+ if (ret == FALSE) {
438
+ log_error("Cannot load daemon");
439
+ return false;
440
+ }
441
+
442
+ log_debug("Daemon loaded successfully");
443
+ return true;
444
+ }
445
+
446
+ /* Call the start method in our daemon loader */
447
+ bool java_start(void)
448
+ {
449
+ jmethodID method;
450
+ jboolean ret;
451
+ char start[] = "start";
452
+ char startparams[] = "()Z";
453
+
454
+ jsvc_xlate_to_ascii(start);
455
+ jsvc_xlate_to_ascii(startparams);
456
+ method = (*env)->GetStaticMethodID(env, cls, start, startparams);
457
+ if (method == NULL) {
458
+ log_error("Cannot find Daemon Loader \"start\" entry point");
459
+ return false;
460
+ }
461
+
462
+ ret = (*env)->CallStaticBooleanMethod(env, cls, method);
463
+ if (ret == FALSE) {
464
+ log_error("Cannot start daemon");
465
+ return false;
466
+ }
467
+
468
+ log_debug("Daemon started successfully");
469
+ return true;
470
+ }
471
+
472
+ /*
473
+ * call the java sleep to prevent problems with threads
474
+ */
475
+ void java_sleep(int wait)
476
+ {
477
+ jclass clsThread;
478
+ jmethodID method;
479
+ char jsleep[] = "sleep";
480
+ char jsleepparams[] = "(J)V";
481
+ char jthread[] = "java/lang/Thread";
482
+
483
+ jsvc_xlate_to_ascii(jsleep);
484
+ jsvc_xlate_to_ascii(jsleepparams);
485
+ jsvc_xlate_to_ascii(jthread);
486
+
487
+ clsThread = (*env)->FindClass(env, jthread);
488
+ if (clsThread == NULL) {
489
+ log_error("Cannot find java/lang/Thread class");
490
+ return;
491
+ }
492
+ method = (*env)->GetStaticMethodID(env, clsThread, jsleep, jsleepparams);
493
+ if (method == NULL) {
494
+ log_error("Cannot found the sleep entry point");
495
+ return;
496
+ }
497
+
498
+ (*env)->CallStaticVoidMethod(env, clsThread, method, (jlong) wait * 1000);
499
+ }
500
+
501
+ /* Call the stop method in our daemon loader */
502
+ bool java_stop(void)
503
+ {
504
+ jmethodID method;
505
+ jboolean ret;
506
+ char stop[] = "stop";
507
+ char stopparams[] = "()Z";
508
+
509
+ jsvc_xlate_to_ascii(stop);
510
+ jsvc_xlate_to_ascii(stopparams);
511
+ method = (*env)->GetStaticMethodID(env, cls, stop, stopparams);
512
+ if (method == NULL) {
513
+ log_error("Cannot found Daemon Loader \"stop\" entry point");
514
+ return false;
515
+ }
516
+
517
+ ret = (*env)->CallStaticBooleanMethod(env, cls, method);
518
+ if (ret == FALSE) {
519
+ log_error("Cannot stop daemon");
520
+ return false;
521
+ }
522
+
523
+ log_debug("Daemon stopped successfully");
524
+ return true;
525
+ }
526
+
527
+ /* Call the version method in our daemon loader */
528
+ bool java_version(void)
529
+ {
530
+ jmethodID method;
531
+ char version[] = "version";
532
+ char versionparams[] = "()V";
533
+
534
+ jsvc_xlate_to_ascii(version);
535
+ jsvc_xlate_to_ascii(versionparams);
536
+ method = (*env)->GetStaticMethodID(env, cls, version, versionparams);
537
+ if (method == NULL) {
538
+ log_error("Cannot found Daemon Loader \"version\" entry point");
539
+ return false;
540
+ }
541
+
542
+ (*env)->CallStaticVoidMethod(env, cls, method);
543
+ return true;
544
+ }
545
+
546
+ /* Call the check method in our DaemonLoader class */
547
+ bool java_check(arg_data *args)
548
+ {
549
+ jstring className = NULL;
550
+ jmethodID method = NULL;
551
+ jboolean ret = FALSE;
552
+ char check[] = "check";
553
+ char checkparams[] = "(Ljava/lang/String;)Z";
554
+
555
+ log_debug("Checking daemon");
556
+
557
+ jsvc_xlate_to_ascii(args->clas);
558
+ className = (*env)->NewStringUTF(env, args->clas);
559
+ jsvc_xlate_from_ascii(args->clas);
560
+ if (className == NULL) {
561
+ log_error("Cannot create string for class name");
562
+ return false;
563
+ }
564
+
565
+ jsvc_xlate_to_ascii(check);
566
+ jsvc_xlate_to_ascii(checkparams);
567
+ method = (*env)->GetStaticMethodID(env, cls, check, checkparams);
568
+ if (method == NULL) {
569
+ log_error("Cannot found Daemon Loader \"check\" entry point");
570
+ return false;
571
+ }
572
+
573
+ ret = (*env)->CallStaticBooleanMethod(env, cls, method, className);
574
+ if (ret == FALSE) {
575
+ log_error("An error was detected checking the %s daemon", args->clas);
576
+ return false;
577
+ }
578
+
579
+ log_debug("Daemon checked successfully");
580
+ return true;
581
+ }
582
+
583
+ /* Call the destroy method in our daemon loader */
584
+ bool java_destroy(void)
585
+ {
586
+ jmethodID method;
587
+ jboolean ret;
588
+ char destroy[] = "destroy";
589
+ char destroyparams[] = "()Z";
590
+
591
+ jsvc_xlate_to_ascii(destroy);
592
+ jsvc_xlate_to_ascii(destroyparams);
593
+ method = (*env)->GetStaticMethodID(env, cls, destroy, destroyparams);
594
+ if (method == NULL) {
595
+ log_error("Cannot found Daemon Loader \"destroy\" entry point");
596
+ return false;
597
+ }
598
+
599
+ ret = (*env)->CallStaticBooleanMethod(env, cls, method);
600
+ if (ret == FALSE) {
601
+ log_error("Cannot destroy daemon");
602
+ return false;
603
+ }
604
+
605
+ log_debug("Daemon destroyed successfully");
606
+ return true;
607
+ }
608
+