2 * Copyright (c) 2001-2002 International Business Machines Corp.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
9 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
10 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
11 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
12 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
13 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
14 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
15 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
16 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
17 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
18 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 #include "org_openafs_jafs_Process.h"
25 #include <afs_bosAdmin.h>
27 ///// definitions in Internal.c ////////////////////
29 extern jclass processCls
;
30 extern jfieldID process_nameField
;
31 extern jfieldID process_typeField
;
32 extern jfieldID process_stateField
;
33 extern jfieldID process_goalField
;
34 extern jfieldID process_startTimeField
;
35 extern jfieldID process_numberStartsField
;
36 extern jfieldID process_exitTimeField
;
37 extern jfieldID process_exitErrorTimeField
;
38 extern jfieldID process_errorCodeField
;
39 extern jfieldID process_errorSignalField
;
40 extern jfieldID process_stateOkField
;
41 extern jfieldID process_stateTooManyErrorsField
;
42 extern jfieldID process_stateBadFileAccessField
;
44 //////////////////////////////////////////////////////////////////
47 * Retrieve the information for the specified process and populate the
50 * env the Java environment
51 * serverHandle the bos handle of the server on which the process resides
52 * processName the name of the process for which to get the info
53 * process the Process object to populate with the info
55 void getProcessInfoChar( JNIEnv
*env
, void *serverHandle
,
56 const char *processName
, jobject process
) {
59 bos_ProcessType_t type
;
60 bos_ProcessInfo_t infoEntry
;
61 bos_ProcessExecutionState_t state
;
64 // get class fields if need be
65 if( processCls
== 0 ) {
66 internal_getProcessClass( env
, process
);
69 if( !bos_ProcessInfoGet( serverHandle
, processName
, &type
,
70 &infoEntry
, &ast
) ) {
71 throwAFSException( env
, ast
);
77 case BOS_PROCESS_SIMPLE
:
78 (*env
)->SetIntField(env
, process
, process_typeField
,
79 org_openafs_jafs_Process_SIMPLE_PROCESS
);
82 (*env
)->SetIntField(env
, process
, process_typeField
,
83 org_openafs_jafs_Process_FS_PROCESS
);
85 case BOS_PROCESS_CRON
:
86 (*env
)->SetIntField(env
, process
, process_typeField
,
87 org_openafs_jafs_Process_CRON_PROCESS
);
90 throwAFSException( env
, type
);
95 switch( infoEntry
.processGoal
) {
96 case BOS_PROCESS_STOPPED
:
97 (*env
)->SetIntField(env
, process
, process_goalField
,
98 org_openafs_jafs_Process_STOPPED
);
100 case BOS_PROCESS_RUNNING
:
101 (*env
)->SetIntField(env
, process
, process_goalField
,
102 org_openafs_jafs_Process_RUNNING
);
104 case BOS_PROCESS_STOPPING
:
105 (*env
)->SetIntField(env
, process
, process_goalField
,
106 org_openafs_jafs_Process_STOPPING
);
108 case BOS_PROCESS_STARTING
:
109 (*env
)->SetIntField(env
, process
, process_goalField
,
110 org_openafs_jafs_Process_STARTING
);
113 throwAFSException( env
, infoEntry
.processGoal
);
117 // set state variable
118 auxStatus
= malloc( sizeof(char)*BOS_MAX_NAME_LEN
);
120 throwAFSException( env
, JAFSADMNOMEM
);
123 if( !bos_ProcessExecutionStateGet( (void *) serverHandle
, processName
,
124 &state
, auxStatus
, &ast
) ) {
126 throwAFSException( env
, ast
);
131 case BOS_PROCESS_STOPPED
:
132 (*env
)->SetIntField(env
, process
, process_stateField
,
133 org_openafs_jafs_Process_STOPPED
);
135 case BOS_PROCESS_RUNNING
:
136 (*env
)->SetIntField(env
, process
, process_stateField
,
137 org_openafs_jafs_Process_RUNNING
);
139 case BOS_PROCESS_STOPPING
:
140 (*env
)->SetIntField(env
, process
, process_stateField
,
141 org_openafs_jafs_Process_STOPPING
);
143 case BOS_PROCESS_STARTING
:
144 (*env
)->SetIntField(env
, process
, process_stateField
,
145 org_openafs_jafs_Process_STARTING
);
148 throwAFSException( env
, state
);
153 (*env
)->SetLongField(env
, process
, process_startTimeField
,
154 infoEntry
.processStartTime
);
155 (*env
)->SetLongField(env
, process
, process_numberStartsField
,
156 infoEntry
.numberProcessStarts
);
157 (*env
)->SetLongField(env
, process
, process_exitTimeField
,
158 infoEntry
.processExitTime
);
159 (*env
)->SetLongField(env
, process
, process_exitErrorTimeField
,
160 infoEntry
.processExitErrorTime
);
161 (*env
)->SetLongField(env
, process
, process_errorCodeField
,
162 infoEntry
.processErrorCode
);
163 (*env
)->SetLongField(env
, process
, process_errorSignalField
,
164 infoEntry
.processErrorSignal
);
166 // set stateOk to true if no core dump
167 if( infoEntry
.state
& BOS_PROCESS_CORE_DUMPED
) {
168 (*env
)->SetBooleanField(env
, process
, process_stateOkField
, FALSE
);
170 (*env
)->SetBooleanField(env
, process
, process_stateOkField
, TRUE
);
173 // set stateTooManyErrors
174 if( infoEntry
.state
& BOS_PROCESS_TOO_MANY_ERRORS
) {
175 (*env
)->SetBooleanField(env
, process
,
176 process_stateTooManyErrorsField
, TRUE
);
178 (*env
)->SetBooleanField(env
, process
,
179 process_stateTooManyErrorsField
, FALSE
);
182 // set stateBadFileAccess
183 if( infoEntry
.state
& BOS_PROCESS_BAD_FILE_ACCESS
) {
184 (*env
)->SetBooleanField(env
, process
,
185 process_stateBadFileAccessField
, TRUE
);
187 (*env
)->SetBooleanField(env
, process
,
188 process_stateBadFileAccessField
, FALSE
);
194 * Fills in the information fields of the provided Process.
196 * env the Java environment
197 * cls the current Java class
198 * cellHandle the handle of the cell to which the process belongs
199 * jname the instance name of the process for which to get
201 * process the Process object in which to fill
204 JNIEXPORT
void JNICALL
205 Java_org_openafs_jafs_Process_getProcessInfo (JNIEnv
*env
, jclass cls
,
212 if( jname
!= NULL
) {
213 name
= (*env
)->GetStringUTFChars(env
, jname
, 0);
215 throwAFSException( env
, JAFSADMNOMEM
);
222 getProcessInfoChar( env
, (void *) serverHandle
, name
, process
);
224 // set name in case blank object
226 if( processCls
== 0 ) {
227 internal_getProcessClass( env
, process
);
229 (*env
)->SetObjectField(env
, process
, process_nameField
, jname
);
230 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
236 * Creates a process on a server.
238 * env the Java environment
239 * cls the current Java class
240 * serverHandle the bos handle of the server to which the key will
242 * jname the instance name to give the process. See AFS
243 * documentation for a standard list of instance names
244 * jtype the type of process this will be.
245 * Acceptable values are:
246 * org_openafs_jafs_Process_SIMPLE_PROCESS
247 * org_openafs_jafs_Process_FS_PROCESS
248 * org_openafs_jafs_Process_CRON_PROCESS
249 * jpath the execution path process to create
250 * jcronTime a String representing the time a cron process is to
251 * be run. Acceptable formats are:
252 * for daily restarts: "23:10" or "11:10 pm"
253 * for weekly restarts: "sunday 11:10pm" or
255 * Can be null for non-cron processes.
256 * jnotifier the execution path to a notifier program that should
257 * be called when the process terminates. Can be
260 JNIEXPORT
void JNICALL
261 Java_org_openafs_jafs_Process_create (JNIEnv
*env
, jclass cls
,
262 jlong serverHandle
, jstring jname
,
263 jint jtype
, jstring jpath
,
268 bos_ProcessType_t type
;
271 const char *cronTime
;
272 const char *notifier
;
274 if( jname
!= NULL
) {
275 name
= (*env
)->GetStringUTFChars(env
, jname
, 0);
277 throwAFSException( env
, JAFSADMNOMEM
);
284 if( jpath
!= NULL
) {
285 path
= (*env
)->GetStringUTFChars(env
, jpath
, 0);
288 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
290 throwAFSException( env
, JAFSADMNOMEM
);
298 case org_openafs_jafs_Process_SIMPLE_PROCESS
:
299 type
= BOS_PROCESS_SIMPLE
;
301 case org_openafs_jafs_Process_FS_PROCESS
:
302 type
= BOS_PROCESS_FS
;
304 case org_openafs_jafs_Process_CRON_PROCESS
:
305 type
= BOS_PROCESS_CRON
;
309 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
312 (*env
)->ReleaseStringUTFChars(env
, jpath
, path
);
314 throwAFSException( env
, jtype
);
318 if( jcronTime
!= NULL
) {
319 cronTime
= (*env
)->GetStringUTFChars(env
, jcronTime
, 0);
322 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
325 (*env
)->ReleaseStringUTFChars(env
, jpath
, path
);
327 throwAFSException( env
, JAFSADMNOMEM
);
334 if( jnotifier
!= NULL
) {
335 notifier
= (*env
)->GetStringUTFChars(env
, jnotifier
, 0);
338 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
341 (*env
)->ReleaseStringUTFChars(env
, jpath
, path
);
343 if( cronTime
!= NULL
) {
344 (*env
)->ReleaseStringUTFChars(env
, jcronTime
, cronTime
);
346 throwAFSException( env
, JAFSADMNOMEM
);
353 if( !bos_ProcessCreate( (void *) serverHandle
, name
, type
, path
,
354 cronTime
, notifier
, &ast
) ) {
356 if( cronTime
!= NULL
) {
357 (*env
)->ReleaseStringUTFChars(env
, jcronTime
, cronTime
);
359 if( notifier
!= NULL
) {
360 (*env
)->ReleaseStringUTFChars(env
, jnotifier
, notifier
);
363 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
366 (*env
)->ReleaseStringUTFChars(env
, jpath
, path
);
368 throwAFSException( env
, ast
);
374 if( cronTime
!= NULL
) {
375 (*env
)->ReleaseStringUTFChars(env
, jcronTime
, cronTime
);
377 if( notifier
!= NULL
) {
378 (*env
)->ReleaseStringUTFChars(env
, jnotifier
, notifier
);
381 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
384 (*env
)->ReleaseStringUTFChars(env
, jpath
, path
);
390 * Removes a process from a server.
392 * env the Java environment
393 * cls the current Java class
394 * serverHandle the bos handle of the server to which the process
396 * jname the name of the process to remove
398 JNIEXPORT
void JNICALL
399 Java_org_openafs_jafs_Process_delete (JNIEnv
*env
, jclass cls
,
400 jlong serverHandle
, jstring jname
) {
405 if( jname
!= NULL
) {
406 name
= (*env
)->GetStringUTFChars(env
, jname
, 0);
408 throwAFSException( env
, JAFSADMNOMEM
);
415 if( !bos_ProcessDelete( (void *) serverHandle
, name
, &ast
) ) {
417 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
419 throwAFSException( env
, ast
);
424 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
432 * env the Java environment
433 * cls the current Java class
434 * serverHandle the bos handle of the server to which the process
436 * jname the name of the process to stop
438 JNIEXPORT
void JNICALL
439 Java_org_openafs_jafs_Process_stop (JNIEnv
*env
, jclass cls
,
440 jlong serverHandle
, jstring jname
) {
445 if( jname
!= NULL
) {
446 name
= (*env
)->GetStringUTFChars(env
, jname
, 0);
448 throwAFSException( env
, JAFSADMNOMEM
);
455 if( !bos_ProcessExecutionStateSet( (void *) serverHandle
, name
,
456 BOS_PROCESS_STOPPED
, &ast
) ) {
458 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
460 throwAFSException( env
, ast
);
465 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
471 * Start this process.
473 * env the Java environment
474 * cls the current Java class
475 * serverHandle the bos handle of the server to which the process
477 * jname the name of the process to start
479 JNIEXPORT
void JNICALL
480 Java_org_openafs_jafs_Process_start (JNIEnv
*env
, jclass cls
,
481 jlong serverHandle
, jstring jname
) {
486 if( jname
!= NULL
) {
487 name
= (*env
)->GetStringUTFChars(env
, jname
, 0);
489 throwAFSException( env
, JAFSADMNOMEM
);
496 if( !bos_ProcessExecutionStateSet( (void *) serverHandle
, name
,
497 BOS_PROCESS_RUNNING
, &ast
) ) {
499 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
501 throwAFSException( env
, ast
);
506 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
512 * Retart this process.
514 * env the Java environment
515 * cls the current Java class
516 * serverHandle the bos handle of the server to which the process
518 * jname the name of the process to restart
520 JNIEXPORT
void JNICALL
521 Java_org_openafs_jafs_Process_restart (JNIEnv
*env
, jclass cls
,
522 jlong serverHandle
, jstring jname
) {
527 if( jname
!= NULL
) {
528 name
= (*env
)->GetStringUTFChars(env
, jname
, 0);
530 throwAFSException( env
, JAFSADMNOMEM
);
537 if( !bos_ProcessRestart( (void *) serverHandle
, name
, &ast
) ) {
539 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
541 throwAFSException( env
, ast
);
546 (*env
)->ReleaseStringUTFChars(env
, jname
, name
);
551 // reclaim global memory being used by this portion
552 JNIEXPORT
void JNICALL
553 Java_org_openafs_jafs_Process_reclaimProcessMemory (JNIEnv
*env
,
557 (*env
)->DeleteGlobalRef(env
, processCls
);