Author: jfrederic.clere(a)jboss.com
Date: 2007-09-30 11:03:08 -0400 (Sun, 30 Sep 2007)
New Revision: 1063
Modified:
trunk/sight/native/os/solaris/main.c
trunk/sight/native/os/solaris/process.c
trunk/sight/native/os/solaris/volume.c
Log:
Arrange process and port volume to solaris.
Modified: trunk/sight/native/os/solaris/main.c
===================================================================
--- trunk/sight/native/os/solaris/main.c 2007-09-29 06:48:13 UTC (rev 1062)
+++ trunk/sight/native/os/solaris/main.c 2007-09-30 15:03:08 UTC (rev 1063)
@@ -78,13 +78,7 @@
int fd;
apr_status_t rc;
- /* check directory */
- sprintf(pname, "/proc/%d", pid);
- if ((rc = apr_stat(&i, pname,
- APR_FINFO_MIN | APR_FINFO_OWNER,
- pool)) != APR_SUCCESS) {
- return rc;
- }
+ /* Don't check directory on Solaris */
sprintf(pname, "/proc/%d/psinfo", pid);
/* XXX: use APR */
if ((fd = open(pname, O_RDONLY)) < 0) {
Modified: trunk/sight/native/os/solaris/process.c
===================================================================
--- trunk/sight/native/os/solaris/process.c 2007-09-29 06:48:13 UTC (rev 1062)
+++ trunk/sight/native/os/solaris/process.c 2007-09-30 15:03:08 UTC (rev 1063)
@@ -307,97 +307,6 @@
}
SET_IFIELD_S(0001, thiz, psinfo.pr_fname);
- /* to read the arguments and the environment we must read /proc/pid/as */
- sprintf(pname, "/proc/%d/as", pid);
- if ((fd = open(pname, O_RDONLY))<0)
- return apr_get_os_error();
- sa = (char **) malloc(sizeof(char *) * (psinfo.pr_argc + 1));
- if (lseek(fd, psinfo.pr_argv, SEEK_SET) == -1) {
- close(fd);
- free(sa);
- return apr_get_os_error();
- }
- if (read(fd, sa, sizeof(char *) * (psinfo.pr_argc + 1)) < 0) {
- close(fd);
- free(sa);
- return apr_get_os_error();
- }
-
- arr = sight_new_cc_array(_E, SIGHT_CC_STRING, psinfo.pr_argc);
- pname[SIGHT_STYPE_LEN] = '\0';
- for (n = 0; n < psinfo.pr_argc; n++) {
- jstring s;
- if (lseek(fd, sa[n], SEEK_SET) != -1) {
- if (read(fd, pname, SIGHT_STYPE_LEN) > 0) {
- s = (*_E)->NewStringUTF((_E), pname);
- if (s) {
- (*_E)->SetObjectArrayElement(_E, arr, n, s);
- (*_E)->DeleteLocalRef(_E, s);
- }
- continue;
- }
- }
- s = (*_E)->NewStringUTF((_E), "");
- if (s) {
- (*_E)->SetObjectArrayElement(_E, arr, n, s);
- (*_E)->DeleteLocalRef(_E, s);
- }
- }
-
- SET_IFIELD_O(0003, thiz, arr);
- free(sa);
-
- /* process environment like arguments */
- if (lseek(fd, psinfo.pr_envp, SEEK_SET) == -1) {
- close(fd);
- return apr_get_os_error();
- }
- /* count the environment variables */
- p = (char *)1;
- count = 0;
- while (p) {
- if (read(fd, &p, sizeof(char *)) < 0) {
- close(fd);
- return apr_get_os_error();
- }
- count++;
- }
- sa = (char **) malloc(sizeof(char *) * (count));
- if (lseek(fd, psinfo.pr_envp, SEEK_SET) == -1) {
- close(fd);
- free(sa);
- return apr_get_os_error();
- }
- if (read(fd, sa, sizeof(char *) * (count)) < 0) {
- close(fd);
- free(sa);
- return apr_get_os_error();
- }
- arr = sight_new_cc_array(_E, SIGHT_CC_STRING, count-1);
- pname[SIGHT_STYPE_LEN] = '\0';
- for (n = 0; n < count-1; n++) {
- jstring s;
- if (lseek(fd, sa[n], SEEK_SET) != -1) {
- if (read(fd, pname, SIGHT_STYPE_LEN) > 0) {
- s = (*_E)->NewStringUTF((_E), pname);
- if (s) {
- (*_E)->SetObjectArrayElement(_E, arr, n, s);
- (*_E)->DeleteLocalRef(_E, s);
- }
- continue;
- }
- }
- s = (*_E)->NewStringUTF((_E), "");
- if (s) {
- (*_E)->SetObjectArrayElement(_E, arr, n, s);
- (*_E)->DeleteLocalRef(_E, s);
- }
- }
-
- SET_IFIELD_O(0004, thiz, arr);
- free(sa);
- close(fd);
-
SET_IFIELD_I(0000, thiz, psinfo.pr_ppid);
SET_IFIELD_S(0002, thiz, psinfo.pr_fname); /* XXX: trucate ? */
@@ -427,6 +336,135 @@
SET_IFIELD_J(0014, thiz, psinfo.pr_time.tv_sec * 1000 +
psinfo.pr_time.tv_nsec/1000);
/* XXX: SET_IFIELD_J(0015, thiz, TCK2MS(utime)); */
+ /* to read the arguments and the environment we must read /proc/pid/as */
+ sprintf(pname, "/proc/%d/as", pid);
+ if ((fd = open(pname, O_RDONLY))<0){
+ rc = apr_get_os_error();
+ if (rc != APR_EACCES)
+ return rc;
+ }
+ if ( rc == APR_SUCCESS) {
+ sa = (char **) malloc(sizeof(char *) * (psinfo.pr_argc + 1));
+ if (lseek(fd, psinfo.pr_argv, SEEK_SET) == -1) {
+ close(fd);
+ free(sa);
+ return apr_get_os_error();
+ }
+ if (read(fd, sa, sizeof(char *) * (psinfo.pr_argc + 1)) < 0) {
+ close(fd);
+ free(sa);
+ return apr_get_os_error();
+ }
+
+ arr = sight_new_cc_array(_E, SIGHT_CC_STRING, psinfo.pr_argc);
+ pname[SIGHT_STYPE_LEN] = '\0';
+ for (n = 0; n < psinfo.pr_argc; n++) {
+ jstring s;
+ if (lseek(fd, sa[n], SEEK_SET) != -1) {
+ if (read(fd, pname, SIGHT_STYPE_LEN) > 0) {
+ s = (*_E)->NewStringUTF((_E), pname);
+ if (s) {
+ (*_E)->SetObjectArrayElement(_E, arr, n, s);
+ (*_E)->DeleteLocalRef(_E, s);
+ }
+ continue;
+ }
+ }
+ s = (*_E)->NewStringUTF((_E), "");
+ if (s) {
+ (*_E)->SetObjectArrayElement(_E, arr, n, s);
+ (*_E)->DeleteLocalRef(_E, s);
+ }
+ }
+
+ SET_IFIELD_O(0003, thiz, arr);
+ free(sa);
+
+ /* process environment like arguments */
+ if (lseek(fd, psinfo.pr_envp, SEEK_SET) == -1) {
+ close(fd);
+ return apr_get_os_error();
+ }
+ /* count the environment variables */
+ p = (char *)1;
+ count = 0;
+ while (p) {
+ if (read(fd, &p, sizeof(char *)) < 0) {
+ close(fd);
+ return apr_get_os_error();
+ }
+ count++;
+ }
+ sa = (char **) malloc(sizeof(char *) * (count));
+ if (lseek(fd, psinfo.pr_envp, SEEK_SET) == -1) {
+ close(fd);
+ free(sa);
+ return apr_get_os_error();
+ }
+ if (read(fd, sa, sizeof(char *) * (count)) < 0) {
+ close(fd);
+ free(sa);
+ return apr_get_os_error();
+ }
+ arr = sight_new_cc_array(_E, SIGHT_CC_STRING, count-1);
+ pname[SIGHT_STYPE_LEN] = '\0';
+ for (n = 0; n < count-1; n++) {
+ jstring s;
+ if (lseek(fd, sa[n], SEEK_SET) != -1) {
+ if (read(fd, pname, SIGHT_STYPE_LEN) > 0) {
+ s = (*_E)->NewStringUTF((_E), pname);
+ if (s) {
+ (*_E)->SetObjectArrayElement(_E, arr, n, s);
+ (*_E)->DeleteLocalRef(_E, s);
+ }
+ continue;
+ }
+ }
+ s = (*_E)->NewStringUTF((_E), "");
+ if (s) {
+ (*_E)->SetObjectArrayElement(_E, arr, n, s);
+ (*_E)->DeleteLocalRef(_E, s);
+ }
+ }
+
+ SET_IFIELD_O(0004, thiz, arr);
+ free(sa);
+ close(fd);
+ } else {
+ /* Use the psinfo */
+ char pr_name[PRARGSZ];
+ int k = 0;
+ int j = 0;
+ count = 0;
+ int l = 0;
+ while (k<PRARGSZ && psinfo.pr_psargs[k] != '\0') {
+ if (psinfo.pr_psargs[k] == ' ')
+ count++;
+ k++;
+ }
+
+ arr = sight_new_cc_array(_E, SIGHT_CC_STRING, count + 1);
+ for (k=0; k<count+1;k++) {
+ jstring s;
+ while (j<PRARGSZ && psinfo.pr_psargs[j] != '\0') {
+ if (psinfo.pr_psargs[j] == ' ')
+ break;
+ j++;
+ }
+ memset(pr_name, '\0', sizeof(pr_name));
+ memcpy(pr_name, &psinfo.pr_psargs[l], j-l);
+ j++;
+ l = j;
+ s = (*_E)->NewStringUTF((_E), pr_name);
+ if (s) {
+ (*_E)->SetObjectArrayElement(_E, arr, k, s);
+ (*_E)->DeleteLocalRef(_E, s);
+ }
+
+ }
+ SET_IFIELD_O(0003, thiz, arr);
+ }
+
/* get user, group and creation time (pr_start?) */
sprintf(pname, "/proc/%d", pid);
if ((rc = apr_stat(&i, pname,
Modified: trunk/sight/native/os/solaris/volume.c
===================================================================
--- trunk/sight/native/os/solaris/volume.c 2007-09-29 06:48:13 UTC (rev 1062)
+++ trunk/sight/native/os/solaris/volume.c 2007-09-30 15:03:08 UTC (rev 1063)
@@ -32,10 +32,13 @@
#define SIGHT_WANT_LATE_DLL
#include "sight_private.h"
-#include <mntent.h>
+#include <sys/mnttab.h>
#include <sys/statfs.h>
#include <sys/statvfs.h>
+#include <sys/stat.h>
+#include <sys/swap.h>
+
/*
* Network adapter implementation
*/
@@ -144,21 +147,34 @@
sight_unload_class(_E, &_clazzn);
}
-#define PROC_SWAPS_FS "/proc/swaps"
+extern apr_pool_t *sight_temp_pool;
typedef struct volume_enum_t {
+ apr_pool_t *pool;
+ int mounts_idx;
int num_mounts;
- FILE *fp;
- sight_arr_t *swaps;
+ struct sight_mnttab *ent;
int swap_idx;
+ int num_swap;
+ swaptbl_t * swap_table;
} volume_enum_t;
+#define MAXSTRSIZE 80
+#define MNTOPT_RW "write"
+#define MNTOPT_RO "read only"
+#define MNTOPT_SUID "setuid"
+
+struct sight_mnttab {
+ struct mnttab ent;
+ struct sight_mnttab *next;
+};
+
/* Initialize volume enumeration */
SIGHT_EXPORT_DECLARE(jlong, Volume, enum0)(SIGHT_STDARGS,
jlong pool)
{
volume_enum_t *e;
- char buf[SIGHT_MBUFFER_SIZ];
+ apr_status_t rc;
UNREFERENCED_O;
if (!(e = (volume_enum_t *)sight_calloc(_E,
@@ -166,46 +182,82 @@
THROW_FMARK))) {
return 0;
}
+ if ((rc = sight_create_pool(&e->pool, sight_temp_pool)) != APR_SUCCESS) {
+ throwAprMemoryException(_E, THROW_FMARK, rc);
+ return 0;
+ }
return P2J(e);
}
SIGHT_EXPORT_DECLARE(jint, Volume, enum1)(SIGHT_STDARGS,
jlong handle)
{
- struct mntent ent;
- char buf[SIGHT_MBUFFER_SIZ];
+ struct sight_mnttab *ent;
+ struct sight_mnttab *previous;
+ char *buf;
+ int i;
+ apr_status_t rc;
+ struct mnttab mp;
volume_enum_t *e = J2P(handle, volume_enum_t *);
+ FILE *fp = fopen(MNTTAB, "r");
UNREFERENCED_O;
if (!e)
return 0;
- if (!(e->fp = setmntent(MOUNTED, "r"))) {
+ if (fp == NULL) {
throwAprException(_E, apr_get_os_error());
return 0;
- } else {
- e->num_mounts = 0;
- while (getmntent_r(e->fp, &ent, buf, SIGHT_MBUFFER_LEN)) {
- e->num_mounts++;
- }
- endmntent(e->fp);
- e->fp = setmntent(MOUNTED, "r");
- /* Now read the swaps */
- if ((e->swaps = sight_arr_rload(PROC_SWAPS_FS))) {
- if (e->swaps->siz) {
- e->num_mounts += (e->swaps->siz - 1);
- e->swap_idx = 1;
- }
- }
- return e->num_mounts;
}
+ e->num_mounts = 0;
+ ent = (struct sight_mnttab *) apr_palloc(e->pool, sizeof(struct sight_mnttab));
+ ent->next = NULL;
+ e->ent = ent;
+ previous = ent;
+ while (getmntent(fp, &mp) == 0) {
+ ent->ent.mnt_special = apr_pstrdup(e->pool, mp.mnt_special);
+ ent->ent.mnt_mountp = apr_pstrdup(e->pool, mp.mnt_mountp);
+ ent->ent.mnt_fstype = apr_pstrdup(e->pool, mp.mnt_fstype);
+ ent->ent.mnt_mntopts = apr_pstrdup(e->pool, mp.mnt_mntopts);
+ ent->ent.mnt_time = apr_pstrdup(e->pool, mp.mnt_time);
+
+ e->num_mounts++;
+ previous = ent;
+ ent->next = (struct sight_mnttab *) apr_palloc(e->pool, sizeof(struct
sight_mnttab));
+ ent = ent->next;
+ ent->next = NULL;
+ }
+ fclose(fp);
+ free(previous->next);
+ previous->next = NULL;
+
+ ent = e->ent;
+ while (ent != NULL) {
+ ent = ent->next;
+ }
+
+ /* process swap */
+ e->num_swap = swapctl(SC_GETNSWP, 0);
+ e->num_mounts = e->num_mounts + e->num_swap;
+ e->swap_table = malloc(sizeof(swapent_t) * e->num_swap + sizeof(int));
+ buf = malloc(MAXSTRSIZE * e->num_swap);
+ for (i = 0; i < e->num_swap; i++) {
+ e->swap_table->swt_ent[i].ste_path = buf + (i * MAXSTRSIZE);
+ }
+ e->swap_table->swt_n = e->num_swap;
+ swapctl(SC_LIST, e->swap_table);
+
+ e->swap_idx = 0;
+ e->mounts_idx = 0;
+
+ return e->num_mounts;
}
SIGHT_EXPORT_DECLARE(void, Volume, enum2)(SIGHT_STDARGS,
jobject thiz,
jlong handle)
{
- struct mntent ent;
+ struct mnttab ent;
struct statvfs sv;
char buf[SIGHT_MBUFFER_SIZ];
volume_enum_t *e = J2P(handle, volume_enum_t *);
@@ -214,46 +266,48 @@
if (!e || !thiz)
return;
- if (e->swaps && e->swap_idx < e->swaps->siz) {
- char path[256];
- char type[32];
- unsigned long size, used;
- int priority;
+ if (e->swap_idx < e->num_swap) {
+ int size = getpagesize();
- if (sscanf(e->swaps->arr[e->swap_idx],
- "%250s %30s %lu %lu %d",
- path, type, &size, &used, &priority) == 5) {
- SET_IFIELD_S(0000, thiz, path);
- SET_IFIELD_S(0001, thiz, type);
- SET_IFIELD_S(0002, thiz, "swap");
- CALL_METHOD1(0000, thiz, SIGHT_FS_SWAP);
- CALL_METHOD1(0001, thiz, SIGHT_READ_WRITE_VOLUME);
- CALL_METHOD1(0002, thiz, SIGHT_DRIVE_SWAP);
- SET_IFIELD_J(0005, thiz, size - used);
- SET_IFIELD_J(0006, thiz, size);
- SET_IFIELD_J(0007, thiz, size - used);
- }
+ SET_IFIELD_S(0000, thiz, e->swap_table->swt_ent[e->swap_idx].ste_path);
+ SET_IFIELD_S(0001, thiz, "partition");
+ SET_IFIELD_S(0002, thiz, "swap");
+ CALL_METHOD1(0000, thiz, SIGHT_FS_SWAP);
+ CALL_METHOD1(0001, thiz, SIGHT_READ_WRITE_VOLUME);
+ CALL_METHOD1(0002, thiz, SIGHT_DRIVE_SWAP);
+ SET_IFIELD_J(0005, thiz, (jlong)
e->swap_table->swt_ent[e->swap_idx].ste_pages * (jlong) size);
+ SET_IFIELD_J(0006, thiz, (jlong)
e->swap_table->swt_ent[e->swap_idx].ste_length * (jlong) size);
+ SET_IFIELD_J(0007, thiz, (jlong)
e->swap_table->swt_ent[e->swap_idx].ste_free * (jlong) size);
e->swap_idx++;
return;
}
- if (getmntent_r(e->fp, &ent, buf, SIGHT_MBUFFER_LEN)) {
+ if (e->mounts_idx < e->num_mounts) {
+ struct sight_mnttab *ent;
+ int i;
int flags = 0;
- int dtype = sight_get_fs_type(ent.mnt_type);
- SET_IFIELD_S(0000, thiz, ent.mnt_fsname);
- SET_IFIELD_S(0002, thiz, ent.mnt_dir);
+ int dtype;
+ ent = e->ent;
+ for (i=1; i<e->mounts_idx; i++) {
+ ent = ent->next;
+ }
+ e->mounts_idx++;
+ dtype = sight_get_fs_type(ent->ent.mnt_fstype);
+ SET_IFIELD_S(0000, thiz, ent->ent.mnt_special);
+ SET_IFIELD_S(0001, thiz, ent->ent.mnt_fstype);
+ SET_IFIELD_S(0002, thiz, ent->ent.mnt_mountp);
CALL_METHOD1(0000, thiz, dtype);
- if (!statvfs(ent.mnt_dir, &sv)) {
+ if (!statvfs(ent->ent.mnt_mountp, &sv)) {
SET_IFIELD_I(0004, thiz, sv.f_bsize);
- SET_IFIELD_J(0005, thiz, sv.f_frsize * sv.f_bavail);
- SET_IFIELD_J(0006, thiz, sv.f_frsize * sv.f_blocks);
- SET_IFIELD_J(0007, thiz, sv.f_frsize * sv.f_bfree);
+ SET_IFIELD_J(0005, thiz, (jlong) sv.f_frsize * (jlong) sv.f_bavail);
+ SET_IFIELD_J(0006, thiz, (jlong) sv.f_frsize * (jlong) sv.f_blocks);
+ SET_IFIELD_J(0007, thiz, (jlong) sv.f_frsize * (jlong) sv.f_bfree);
}
- if (hasmntopt(&ent, MNTOPT_RW))
+ if (hasmntopt(&ent->ent, MNTOPT_RW))
flags |= SIGHT_READ_WRITE_VOLUME;
- if (hasmntopt(&ent, MNTOPT_RO))
+ if (hasmntopt(&ent->ent, MNTOPT_RO))
flags |= SIGHT_READ_ONLY_VOLUME;
- if (hasmntopt(&ent, MNTOPT_SUID))
+ if (hasmntopt(&ent->ent, MNTOPT_SUID))
flags |= SIGHT_SUID_VOLUME;
CALL_METHOD1(0001, thiz, flags);
switch (dtype) {
@@ -304,10 +358,7 @@
UNREFERENCED_STDARGS;
if (e) {
- if (e->fp)
- endmntent(e->fp);
- if (e->swaps)
- sight_arr_free(e->swaps);
+ apr_pool_destroy(e->pool);
free(e);
}
}