JBoss Native SVN: r963 - trunk/sight/native/share.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-03 02:43:20 -0400 (Mon, 03 Sep 2007)
New Revision: 963
Modified:
trunk/sight/native/share/hash.c
Log:
Result from trim is NULL for empty strings
Modified: trunk/sight/native/share/hash.c
===================================================================
--- trunk/sight/native/share/hash.c 2007-09-03 06:38:58 UTC (rev 962)
+++ trunk/sight/native/share/hash.c 2007-09-03 06:43:20 UTC (rev 963)
@@ -208,19 +208,15 @@
char *val = NULL;
char *key = NULL;
pline = sight_trim(&line[0]);
- if (*pline && *pline != '#') {
+ if (pline && *pline != '#') {
if ((first = strchr(pline, sep)) != NULL) {
*first++ = '\0';
key = sight_rtrim(pline);
val = sight_ltrim(first);
}
- if (key && *key) {
- key = apr_pstrdup(ctx, key);
- if (val && *val)
- val = apr_pstrdup(ctx, val);
- else
- val = NULL;
- apr_table_addn(t, key, val);
+ if (key) {
+ /* We can have NULL values for valid keys */
+ apr_table_add(t, key, val);
}
}
}
17 years, 3 months
JBoss Native SVN: r962 - trunk/sight/native/share.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-03 02:38:58 -0400 (Mon, 03 Sep 2007)
New Revision: 962
Modified:
trunk/sight/native/share/jnu.c
Log:
Make trim functions return NULL for empty trimmed strings.
Modified: trunk/sight/native/share/jnu.c
===================================================================
--- trunk/sight/native/share/jnu.c 2007-09-03 06:37:05 UTC (rev 961)
+++ trunk/sight/native/share/jnu.c 2007-09-03 06:38:58 UTC (rev 962)
@@ -121,20 +121,30 @@
size_t i;
/* check for empty strings */
if (!s || !*s)
- return s;
- for (i = strlen(s) - 1; i >= 0 && apr_isspace(s[i]); i--)
+ return NULL;
+ for (i = strlen(s) - 1; i >= 0 && (apr_iscntrl(s[i]) ||
+ apr_isspace(s[i])); i--)
;
s[i + 1] = '\0';
- return s;
+ if (!s[0])
+ return NULL;
+ else
+ return s;
}
char *sight_ltrim(char *s)
{
size_t i;
+ /* check for empty strings */
+ if (!s || !*s)
+ return NULL;
for (i = 0; s[i] != '\0' && apr_isspace(s[i]); i++)
;
- return s + i;
+ if (!s[i])
+ return NULL;
+ else
+ return s + i;
}
char *sight_trim(char *s)
@@ -142,14 +152,21 @@
size_t i;
/* check for empty strings */
if (!s || !*s)
- return s;
- for (i = strlen(s) - 1; i >= 0 && apr_isspace(s[i]); i--)
+ return NULL;
+ for (i = strlen(s) - 1; i >= 0 && (apr_iscntrl(s[i]) ||
+ apr_isspace(s[i])); i--)
;
s[i + 1] = '\0';
+ /* Don't check if the sting is empty */
+ if (!s[0])
+ return NULL;
for (i = 0; s[i] != '\0' && apr_isspace(s[i]); i++)
;
- return s + i;
+ if (!s[i])
+ return NULL;
+ else
+ return s + i;
}
@@ -157,9 +174,9 @@
{
size_t i;
/* check for empty strings */
- if (!(i = strlen(s)))
+ if (!s || !(i = strlen(s)))
return 0;
- if (s[i-1] == chr)
+ if (s[i - 1] == chr)
return -1;
else
return 0;
@@ -207,8 +224,10 @@
if ((b = malloc(rd))) {
rd = fread(b, 1, rd - 2, f);
- if (rd > 0) {
- for (i = rd - 1; i >= 0 && apr_isspace(b[i]); i--)
+ if (rd > 0) {
+ /* Remove all trailing zero and space characters */
+ for (rd = i - 1; i >= 0 && (apr_iscntrl(b[i]) ||
+ apr_isspace(b[i])); i--)
;
b[i + 1] = '\0';
b[i + 2] = '\0';
@@ -547,12 +566,12 @@
* Copy the input (bytewise) array into a wordwise array.
* Find the longest run of 0x00's in src[] for :: shorthanding.
*/
- next_src = src;
- src_end = src + IN6ADDRSZ;
+ next_src = src;
+ src_end = src + IN6ADDRSZ;
next_dest = words;
best.base = -1;
- cur.base = -1;
- cur.len = best.len = 0; /* silence gcc4 warning */
+ cur.base = -1;
+ cur.len = best.len = 0; /* silence gcc4 warning */
i = 0;
do {
unsigned int next_word = (unsigned int)*next_src++;
@@ -760,7 +779,7 @@
while (fgets(&buf[0], 8192, file)) {
char *pline = sight_trim(&buf[0]);
/* Skip empty lines */
- if (*pline) {
+ if (pline) {
if (sight_arr_add(array, pline))
break;
}
@@ -787,7 +806,7 @@
while (fgets(&buf[0], 8192, file)) {
char *pline = sight_trim(&buf[0]);
/* Skip empty lines */
- if (*pline) {
+ if (pline) {
/* Skip comments */
int ic = 0;
size_t ci;
17 years, 3 months
JBoss Native SVN: r961 - trunk/build/unix.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-03 02:37:05 -0400 (Mon, 03 Sep 2007)
New Revision: 961
Modified:
trunk/build/unix/package.list
Log:
Downgrade APR to 1.2.8 because 1.2.9 is broken. We'll use 1.2.10 when released
Modified: trunk/build/unix/package.list
===================================================================
--- trunk/build/unix/package.list 2007-09-01 07:54:45 UTC (rev 960)
+++ trunk/build/unix/package.list 2007-09-03 06:37:05 UTC (rev 961)
@@ -1,4 +1,4 @@
# list of the packages
# add new versions of package after existing ones.
-jboss-native|2.0.2|1.2.9|1.2.8|0.9.8e|TOMCAT_NATIVE_1_1_11
-jboss-sight|1.0.0|1.2.9|1.2.8||trunk
+jboss-native|2.0.2|1.2.8|1.2.8|0.9.8e|TOMCAT_NATIVE_1_1_11
+jboss-sight|1.0.0|1.2.8|1.2.8||trunk
17 years, 3 months
JBoss Native SVN: r960 - trunk/sight/native/os/windows.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-01 03:54:45 -0400 (Sat, 01 Sep 2007)
New Revision: 960
Modified:
trunk/sight/native/os/windows/console.c
Log:
Fix param usage
Modified: trunk/sight/native/os/windows/console.c
===================================================================
--- trunk/sight/native/os/windows/console.c 2007-09-01 07:46:21 UTC (rev 959)
+++ trunk/sight/native/os/windows/console.c 2007-09-01 07:54:45 UTC (rev 960)
@@ -57,7 +57,7 @@
SIGHT_EXPORT_DECLARE(jlong, Console, alloc0)(SIGHT_STDARGS)
{
sight_nt_console_t *con;
- UNREFERENCED_STDARGS;
+ UNREFERENCED_O;
if (!(con = (sight_nt_console_t *)calloc(1, sizeof(sight_nt_console_t)))) {
throwAprMemoryException(_E, THROW_FMARK,
17 years, 3 months
JBoss Native SVN: r959 - trunk/sight/native/os/linux.
by jbossnative-commits@lists.jboss.org
Author: mladen.turk(a)jboss.com
Date: 2007-09-01 03:46:21 -0400 (Sat, 01 Sep 2007)
New Revision: 959
Modified:
trunk/sight/native/os/linux/console.c
trunk/sight/native/os/linux/module.c
Log:
Implement Console and Module for linux platform
Modified: trunk/sight/native/os/linux/console.c
===================================================================
--- trunk/sight/native/os/linux/console.c 2007-08-30 09:22:15 UTC (rev 958)
+++ trunk/sight/native/os/linux/console.c 2007-09-01 07:46:21 UTC (rev 959)
@@ -192,8 +192,42 @@
TTY_STRUCT ttyo;
TTY_STRUCT ttyn;
int is_a_tty;
+ int echo_char;
} sight_console_t;
+/* Internal functions to read a string without echoing */
+static void read_till_nl(FILE *in)
+{
+#define SIZE 4
+ char buf[SIZE+1];
+
+ do {
+ fgets(buf, SIZE, in);
+ } while (strchr(buf, '\n') == NULL);
+}
+
+static int echo_console(sight_console_t *con, jboolean on)
+{
+
+#ifdef TTY_FLAGS
+ memcpy(&(con->ttyn), &(con->ttyo), sizeof(con->ttyo));
+ if (on) {
+ con->ttyn.TTY_FLAGS |= ECHO;
+ }
+ else {
+ con->ttyn.TTY_FLAGS &= ~ECHO;
+ }
+#endif
+
+#if defined(TTY_set)
+ if (con->is_a_tty && (TTY_set(fileno(con->coni), &(con->ttyn)) == -1)) {
+ return errno;
+ }
+#endif
+ return 0;
+}
+
+
SIGHT_EXPORT_DECLARE(jlong, Console, alloc0)(SIGHT_STDARGS)
{
sight_console_t *con;
@@ -216,12 +250,12 @@
if (!con)
return;
con->is_a_tty = 1;
- if ((con->coni = fopen(DEV_TTY,"r")) == NULL)
- con->coni = stdin;
- if ((con->cono = fopen(DEV_TTY,"r")) == NULL)
- con->cono = stdout;
+ if ((con->coni = fopen(DEV_TTY, "r")) == NULL)
+ con->coni = stdin;
+ if ((con->cono = fopen(DEV_TTY, "w")) == NULL)
+ con->cono = stdout;
- if (TTY_get(fileno(con->coni), &con->ttyo) == -1) {
+ if (TTY_get(fileno(con->coni), &con->ttyo) == -1) {
#ifdef ENOTTY
if (errno == ENOTTY)
con->is_a_tty = 0;
@@ -248,7 +282,7 @@
{
UNREFERENCED_STDARGS;
UNREFERENCED(pid);
- return APR_ENOTIMPL;
+ return APR_SUCCESS;
}
SIGHT_EXPORT_DECLARE(void, Console, close0)(SIGHT_STDARGS,
@@ -260,9 +294,22 @@
if (!con)
return;
- if (con->coni != stdin)
+ if (con->coni && con->echo_char) {
+
+#ifdef TTY_FLAGS
+ memcpy(&(con->ttyn), &(con->ttyo), sizeof(con->ttyo));
+ con->ttyn.TTY_FLAGS |= ECHO;
+#endif
+
+#if defined(TTY_set)
+ if (con->is_a_tty && (TTY_set(fileno(con->coni), &(con->ttyn)) == -1)) {
+ /* TODO: Do we need throw on error here? */
+ }
+#endif
+ }
+ if (con->coni && con->coni != stdin)
fclose(con->coni);
- if (con->cono != stdout)
+ if (con->cono && con->cono != stdout)
fclose(con->cono);
free(con);
}
@@ -274,20 +321,10 @@
sight_console_t *con = J2P(instance, sight_console_t *);
UNREFERENCED_STDARGS;
-#ifdef TTY_FLAGS
- memcpy(&(con->ttyn), &(con->ttyo), sizeof(con->ttyo));
if (on)
- con->ttyn.TTY_FLAGS |= ECHO;
+ con->echo_char = 0;
else
- con->ttyn.TTY_FLAGS &= ~ECHO;
-#endif
-
-#if defined(TTY_set)
- if (con->is_a_tty && (TTY_set(fileno(con->coni), &(con->ttyn)) == -1)) {
- return;
- }
-#endif
-
+ con->echo_char = '*';
}
SIGHT_EXPORT_DECLARE(void, Console, stitle0)(SIGHT_STDARGS,
@@ -307,6 +344,7 @@
{
UNREFERENCED_STDARGS;
+ kill(getpid(), SIGQUIT);
}
@@ -314,16 +352,89 @@
jlong instance)
{
sight_console_t *con = J2P(instance, sight_console_t *);
- UNREFERENCED_STDARGS;
- return NULL;
+ static int ps;
+ char buff[SIGHT_HBUFFER_SIZ];
+ char *p;
+ jstring rv = NULL;
+
+ UNREFERENCED_O;
+ if (!con) {
+ return NULL;
+ }
+
+ fflush(stdout);
+ ps = 0;
+ pushsig();
+ ps = 1;
+ if (con->echo_char && echo_console(con, JNI_FALSE))
+ goto cleanup;
+ ps = 2;
+ p = fgets(buff, SIGHT_HBUFFER_LEN, con->coni);
+ if (!p)
+ goto cleanup;
+
+ if (feof(con->coni)) {
+ goto cleanup;
+ }
+ if (ferror(con->coni)) {
+ throwAprIOException(_E, apr_get_os_error());
+ goto cleanup;
+ }
+ if ((p = (char *)strchr(buff, '\n')) != NULL)
+ *p = '\0';
+ else
+ read_till_nl(con->coni);
+
+ rv = CSTR_TO_JSTRING(buff);
+
+cleanup:
+ if (intr_signal == SIGINT) {
+
+ /* TODO: Throw some exception */
+ }
+ if (ps >= 2 && con->echo_char)
+ echo_console(con, JNI_TRUE);
+ if (ps >= 1)
+ popsig();
+ return rv;
}
SIGHT_EXPORT_DECLARE(jint, Console, getc0)(SIGHT_STDARGS,
jlong instance)
{
sight_console_t *con = J2P(instance, sight_console_t *);
- UNREFERENCED_STDARGS;
- return -1;
+ int ch;
+ static int ps;
+ UNREFERENCED_O;
+ if (!con) {
+ return -1;
+ }
+
+ ps = 0;
+ pushsig();
+ ps = 1;
+ if (con->echo_char && echo_console(con, JNI_FALSE))
+ goto cleanup;
+ ps = 2;
+
+ ch = fgetc(con->coni);
+ if (ch == -1) {
+ if (ferror(con->coni)) {
+ throwAprIOException(_E, apr_get_os_error());
+ }
+ }
+
+ if (intr_signal == SIGINT) {
+ /* TODO: Throw some exception */
+ ch = -1;
+ }
+
+cleanup:
+ if (ps >= 2 && con->echo_char)
+ echo_console(con, JNI_TRUE);
+ if (ps >= 1)
+ popsig();
+ return ch;
}
SIGHT_EXPORT_DECLARE(void, Console, putc0)(SIGHT_STDARGS,
@@ -366,7 +477,7 @@
{
UNREFERENCED_STDARGS;
UNREFERENCED(instance);
- return APR_ENOTIMPL;
+ return APR_SUCCESS;
}
SIGHT_EXPORT_DECLARE(void, Console, ddisable0)(SIGHT_STDARGS,
Modified: trunk/sight/native/os/linux/module.c
===================================================================
--- trunk/sight/native/os/linux/module.c 2007-08-30 09:22:15 UTC (rev 958)
+++ trunk/sight/native/os/linux/module.c 2007-09-01 07:46:21 UTC (rev 959)
@@ -107,7 +107,64 @@
SIGHT_EXPORT_DECLARE(jobjectArray, Module, enum0)(SIGHT_STDARGS,
jint pid)
{
- UNREFERENCED_STDARGS;
- UNREFERENCED(pid);
- return NULL;
+ char spath[SIGHT_SBUFFER_SIZ];
+ jsize j, i = 0, nmods = 0;
+ jobjectArray mods = NULL;
+ sight_arr_t *amods;
+
+ UNREFERENCED_O;
+ if (pid < 0)
+ strcpy(spath, "/proc/self/maps");
+ else
+ sprintf(spath, "/proc/%d/maps", pid);
+ if (!(amods = sight_arr_rload(spath))) {
+ throwAprIOException(_E, apr_get_os_error());
+ goto cleanup;
+ }
+ for (j = 0; j < amods->siz; j++) {
+ if (strchr(amods->arr.ca[j], '/'))
+ nmods++;
+ }
+
+ mods = (*_E)->NewObjectArray(_E, nmods, _clazzn.a, NULL);
+ if (!mods || (*_E)->ExceptionCheck(_E)) {
+ goto cleanup;
+ }
+ for (j = 0; j < amods->siz; j++) {
+ jobject m;
+ char *bp = NULL;
+ char *bn = NULL;
+ char *p;
+ unsigned long long b, o;
+ if ((bp = strchr(amods->arr.ca[j], '/'))) {
+ if ((bn = strrchr(bp, '/')))
+ bn++;
+ }
+ else
+ continue;
+ m = new_module_class(_E, _O, pid, i);
+ if (!m || (*_E)->ExceptionCheck(_E)) {
+ mods = NULL;
+ goto cleanup;
+ }
+ SET_IFIELD_S(0000, m, bn);
+ SET_IFIELD_S(0001, m, bp);
+ b = strtoull(amods->arr.ca[j], &p, 16);
+ if (p && *p == '-')
+ o = strtoull(p + 1, NULL, 16) - b;
+ else
+ o = 0;
+ SET_IFIELD_J(0002, m, b);
+ SET_IFIELD_J(0003, m, o);
+
+ (*_E)->SetObjectArrayElement(_E, mods, i++, m);
+ (*_E)->DeleteLocalRef(_E, m);
+ if (i > nmods)
+ break;
+ }
+
+cleanup:
+ if (amods)
+ sight_arr_free(amods);
+ return mods;
}
17 years, 3 months