Author: jfrederic.clere(a)jboss.com
Date: 2007-10-17 16:30:12 -0400 (Wed, 17 Oct 2007)
New Revision: 1130
Modified:
trunk/sight/native/os/solaris/process.c
Log:
Arrange handling of special process (argc=0 and envn=0).
Modified: trunk/sight/native/os/solaris/process.c
===================================================================
--- trunk/sight/native/os/solaris/process.c 2007-10-17 16:27:07 UTC (rev 1129)
+++ trunk/sight/native/os/solaris/process.c 2007-10-17 20:30:12 UTC (rev 1130)
@@ -345,90 +345,99 @@
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();
- }
+ if (psinfo.pr_argc !=0) {
+ 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, (off_t) sa[n], SEEK_SET) != -1) {
- if (read(fd, pname, SIGHT_STYPE_LEN) > 0) {
- s = CSTR_TO_JSTRING(pname);
- if (s) {
- (*_E)->SetObjectArrayElement(_E, arr, n, s);
- (*_E)->DeleteLocalRef(_E, s);
+ 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, (off_t) sa[n], SEEK_SET) != -1) {
+ if (read(fd, pname, SIGHT_STYPE_LEN) > 0) {
+ s = CSTR_TO_JSTRING(pname);
+ if (s) {
+ (*_E)->SetObjectArrayElement(_E, arr, n, s);
+ (*_E)->DeleteLocalRef(_E, s);
+ }
+ continue;
}
- continue;
}
+ s = CSTR_TO_JSTRING("");
+ if (s) {
+ (*_E)->SetObjectArrayElement(_E, arr, n, s);
+ (*_E)->DeleteLocalRef(_E, s);
+ }
}
- s = CSTR_TO_JSTRING("");
- if (s) {
- (*_E)->SetObjectArrayElement(_E, arr, n, s);
- (*_E)->DeleteLocalRef(_E, s);
- }
+
+ SET_IFIELD_O(0003, thiz, arr);
+ free(sa);
}
-
- 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) {
+ if (psinfo.pr_envp !=0) {
+ if (lseek(fd, psinfo.pr_envp, SEEK_SET) == -1) {
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, (off_t) sa[n], SEEK_SET) != -1) {
- if (read(fd, pname, SIGHT_STYPE_LEN) > 0) {
- s = CSTR_TO_JSTRING(pname);
- if (s) {
- (*_E)->SetObjectArrayElement(_E, arr, n, s);
- (*_E)->DeleteLocalRef(_E, s);
+ /* 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();
+ }
+ } else
+ count = 1; /* no argumentts */
+
+ /* The last argument is NULL */
+ if (count-1 != 0) {
+ 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, (off_t) sa[n], SEEK_SET) != -1) {
+ if (read(fd, pname, SIGHT_STYPE_LEN) > 0) {
+ s = CSTR_TO_JSTRING(pname);
+ if (s) {
+ (*_E)->SetObjectArrayElement(_E, arr, n, s);
+ (*_E)->DeleteLocalRef(_E, s);
+ }
+ continue;
}
- continue;
}
+ s = CSTR_TO_JSTRING("");
+ if (s) {
+ (*_E)->SetObjectArrayElement(_E, arr, n, s);
+ (*_E)->DeleteLocalRef(_E, s);
+ }
}
- s = CSTR_TO_JSTRING("");
- if (s) {
- (*_E)->SetObjectArrayElement(_E, arr, n, s);
- (*_E)->DeleteLocalRef(_E, s);
- }
- }
- SET_IFIELD_O(0004, thiz, arr);
+ SET_IFIELD_O(0004, thiz, arr);
+ }
free(sa);
close(fd);
} else {