Author: mladen.turk(a)jboss.com
Date: 2007-10-03 02:32:40 -0400 (Wed, 03 Oct 2007)
New Revision: 1075
Modified:
trunk/sight/native/os/linux/scm.c
Log:
Seal Linux service JNI calls
Modified: trunk/sight/native/os/linux/scm.c
===================================================================
--- trunk/sight/native/os/linux/scm.c 2007-10-03 06:19:24 UTC (rev 1074)
+++ trunk/sight/native/os/linux/scm.c 2007-10-03 06:32:40 UTC (rev 1075)
@@ -56,7 +56,7 @@
NULL,
0
}
-};
+};
static void scm_cleanup(int mode, sight_object_t *no)
{
@@ -79,6 +79,7 @@
DIR *sd = NULL;
scm_instance_t *si;
sight_object_t *no = J2P(instance, sight_object_t *);
+ apr_status_t rv;
UNREFERENCED_O;
UNREFERENCED(database);
@@ -87,65 +88,69 @@
if (!no || !no->pool) {
return APR_EINVAL;
}
- if (no->native)
- scm_cleanup(0, no);
- if (!(si = (scm_instance_t *)sight_calloc(_E,
- sizeof(scm_instance_t),
- THROW_FMARK))) {
- return apr_get_os_error();
- }
- no->native = si;
- while (scm_paths[i].flavor) {
- char sname[PATH_MAX];
- struct stat sb;
- if ((sd = opendir(scm_paths[i].idpath))) {
- sprintf(sname, scm_paths[i].rlpath, scm_paths[i].rlevel);
- /* Check default run level path */
- if (stat(sname, &sb) < 0) {
- closedir(sd);
- sd = NULL;
- continue;
- }
- si->flavor = scm_paths[i].flavor;
- si->idpath = scm_paths[i].idpath;
- si->rlpath = scm_paths[i].rlpath;
- si->what = scm_paths[i].rlevel;
- if (!(si->services = sight_arr_new(16))) {
- apr_status_t rv = apr_get_os_error();
- closedir(sd);
- scm_cleanup(0, no);
- return rv;
- }
- break;
+ SIGHT_LOCAL_TRY(no) {
+ if (no->native)
+ scm_cleanup(0, no);
+ if (!(si = (scm_instance_t *)sight_calloc(_E,
+ sizeof(scm_instance_t),
+ THROW_FMARK))) {
+ SIGHT_LOCAL_BRK(no);
+ return apr_get_os_error();
}
- i++;
- }
- if (sd) {
- struct dirent *sent, sbuf;
- while (!readdir_r(sd, &sbuf, &sent)) {
+ no->native = si;
+ while (scm_paths[i].flavor) {
char sname[PATH_MAX];
struct stat sb;
- if (!sent)
+ if ((sd = opendir(scm_paths[i].idpath))) {
+ sprintf(sname, scm_paths[i].rlpath, scm_paths[i].rlevel);
+ /* Check default run level path */
+ if (stat(sname, &sb) < 0) {
+ closedir(sd);
+ sd = NULL;
+ continue;
+ }
+ si->flavor = scm_paths[i].flavor;
+ si->idpath = scm_paths[i].idpath;
+ si->rlpath = scm_paths[i].rlpath;
+ si->what = scm_paths[i].rlevel;
+ if (!(si->services = sight_arr_new(16))) {
+ rv = apr_get_os_error();
+ closedir(sd);
+ scm_cleanup(0, no);
+ SIGHT_LOCAL_BRK(no);
+ return rv;
+ }
break;
- strcpy(sname, si->idpath);
- strcat(sname, sent->d_name);
- if (stat(sname, &sb) < 0)
- continue;
- if (!S_ISREG(sb.st_mode))
- continue;
- if (!(sb.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
- continue;
- sight_arr_add(si->services, sent->d_name);
+ }
+ i++;
}
- closedir(sd);
- no->clean = scm_cleanup;
- return APR_SUCCESS;
- }
- else {
- apr_status_t rv = apr_get_os_error();
- scm_cleanup(0, no);
- return rv;
- }
+ if (sd) {
+ struct dirent *sent, sbuf;
+ while (!readdir_r(sd, &sbuf, &sent)) {
+ char sname[PATH_MAX];
+ struct stat sb;
+ if (!sent)
+ break;
+ strcpy(sname, si->idpath);
+ strcat(sname, sent->d_name);
+ if (stat(sname, &sb) < 0)
+ continue;
+ if (!S_ISREG(sb.st_mode))
+ continue;
+ if (!(sb.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
+ continue;
+ sight_arr_add(si->services, sent->d_name);
+ }
+ closedir(sd);
+ no->clean = scm_cleanup;
+ rv = APR_SUCCESS;
+ }
+ else {
+ rv = apr_get_os_error();
+ scm_cleanup(0, no);
+ }
+ } SIGHT_LOCAL_END(no);
+ return rv;
}
SIGHT_EXPORT_DECLARE(void, ServiceControlManager, close0)(SIGHT_STDARGS,
@@ -175,37 +180,39 @@
if (!no || !no->pool || !no->native) {
return NULL;
}
- if (drivers) {
- /* There are no drivers on linux ?
- * Perhaps we should have here the kernel modules
- */
- return NULL;
- }
- si = (scm_instance_t *)no->native;
- if (what > 0)
- si->what = what;
- if (si->services && si->services->siz) {
- jint i;
- /* TODO: Calculate size according to the flags */
- cnt = si->services->siz;
- ea = sight_new_cc_array(_E, SIGHT_CC_STRING, cnt);
- if (!ea || (*_E)->ExceptionCheck(_E)) {
- ea = NULL;
- goto cleanup;
+ SIGHT_LOCAL_TRY(no) {
+ if (drivers) {
+ /* There are no drivers on linux ?
+ * Perhaps we should have here the kernel modules
+ */
+ SIGHT_LOCAL_BRK(no);
+ return NULL;
}
- for (i = 0; i < cnt; i++) {
- jstring s = (*_E)->NewStringUTF(_E, si->services->arr[i]);
- if (s)
- (*_E)->SetObjectArrayElement(_E, ea, idx++, s);
- else
- break;
- if ((*_E)->ExceptionCheck(_E)) {
- ea = NULL;
- break;
+ si = (scm_instance_t *)no->native;
+ if (what > 0)
+ si->what = what;
+ if (si->services && si->services->siz) {
+ jint i;
+ /* TODO: Calculate size according to the flags */
+ cnt = si->services->siz;
+ ea = sight_new_cc_array(_E, SIGHT_CC_STRING, cnt);
+ if (!ea || (*_E)->ExceptionCheck(_E)) {
+ SIGHT_LOCAL_BRK(no);
+ return NULL;
}
- (*_E)->DeleteLocalRef(_E, s);
- }
- }
-cleanup:
+ for (i = 0; i < cnt; i++) {
+ jstring s = (*_E)->NewStringUTF(_E, si->services->arr[i]);
+ if (s)
+ (*_E)->SetObjectArrayElement(_E, ea, idx++, s);
+ else
+ break;
+ if ((*_E)->ExceptionCheck(_E)) {
+ ea = NULL;
+ break;
+ }
+ (*_E)->DeleteLocalRef(_E, s);
+ }
+ }
+ } SIGHT_LOCAL_END(no);
return ea;
}