[Opensrf-commits] r1277 - in trunk: include/opensrf src src/c-apps src/libopensrf

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Mar 10 09:44:04 EDT 2008


Author: miker
Date: 2008-03-10 09:10:59 -0400 (Mon, 10 Mar 2008)
New Revision: 1277

Added:
   trunk/src/c-apps/timejson.c
Modified:
   trunk/include/opensrf/utils.h
   trunk/src/Makefile
   trunk/src/c-apps/Makefile
   trunk/src/libopensrf/socket_bundle.c
Log:
Parially, a patch from Scott McKellar:

1. In socket_open_unix_server() and socket_open_unix_client(), I added
checks to make sure that the path parameter doesn't point to aomething
too big to fit into the receiving buffer of the struct sockaddr_un.

2. In _socket_handle_client_data() I add a terminal nul to the data
received by recv().


Also, reversing the semantics and default of NDEBUG per.  To turn on debugging
code, set DEBUG to 1 durring the build:

 $ DEBUG=1 make clean all



Modified: trunk/include/opensrf/utils.h
===================================================================
--- trunk/include/opensrf/utils.h	2008-03-10 12:04:57 UTC (rev 1276)
+++ trunk/include/opensrf/utils.h	2008-03-10 13:10:59 UTC (rev 1277)
@@ -41,7 +41,7 @@
 		memset( ptr, 0, size );\
 	} while(0)
 
-#ifndef NDEBUG
+#ifdef NDEBUG
 // The original ... replace with noop once no more errors occur in NDEBUG mode
 #define osrf_clearbuf( s, n ) memset( s, 0, n )
 #else

Modified: trunk/src/Makefile
===================================================================
--- trunk/src/Makefile	2008-03-10 12:04:57 UTC (rev 1276)
+++ trunk/src/Makefile	2008-03-10 13:10:59 UTC (rev 1277)
@@ -12,6 +12,10 @@
 export LDFLAGS	+= -Wl,-rpath=$(LIBDIR) -L $(TMPDIR) -L .
 export CFLAGS	+= -D_LARGEFILE64_SOURCE -pipe -g -Wall -O2 -fPIC -I ../../include/ -I$(LIBXML2_HEADERS) -I$(APACHE2_HEADERS) -I$(APR_HEADERS) 
 
+ifneq ($(DEBUG), 1)
+export CGLAGS += -DNDEBUG
+endif
+
 ifeq ($(OSRF_LEGACY_JSON), 1)
 export LDLIBS += -lobjson
 endif

Modified: trunk/src/c-apps/Makefile
===================================================================
--- trunk/src/c-apps/Makefile	2008-03-10 12:04:57 UTC (rev 1276)
+++ trunk/src/c-apps/Makefile	2008-03-10 13:10:59 UTC (rev 1277)
@@ -1,12 +1,16 @@
 LDLIBS += -lopensrf
 CFLAGS += -D_LARGEFILE64_SOURCE -DOSRF_LOG_PARAMS
 
-all:	osrf_math.so osrf_dbmath.so osrf_version.so
+all:	osrf_math.so osrf_dbmath.so osrf_version.so timejson
 
+timejson.o: timejson.c
 osrf_math.o: osrf_math.c
 osrf_dbmath.o: osrf_dbmath.c
 osrf_version.o: osrf_version.c
 
+timejson: timejson.o
+	$(CC) -shared -W1 $(LDLIBS) $(LDFLAGS) timejson.o -o $(TMPDIR)/timejson
+
 osrf_math.so: osrf_math.o
 	$(CC) -shared -W1 $(LDLIBS) $(LDFLAGS) osrf_math.o -o $(TMPDIR)/osrf_math.so
 

Added: trunk/src/c-apps/timejson.c
===================================================================
--- trunk/src/c-apps/timejson.c	                        (rev 0)
+++ trunk/src/c-apps/timejson.c	2008-03-10 13:10:59 UTC (rev 1277)
@@ -0,0 +1,80 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <malloc.h>
+#include "opensrf/utils.h"
+#include "opensrf/osrf_json.h"
+
+struct timeval diff_timeval( const struct timeval * begin,
+	const struct timeval * end );
+
+static const char sample_json[] =
+	"{\"menu\": {\"id\": \"file\", \"value\": \"File\","
+	"\"popup\": { \"menuitem\": [ {\"value\": \"New\", "
+	"\"onclick\": \"CreateNewDoc()\"},"
+	"{\"value\": \"Open\", \"onclick\": \"OpenDoc()\"}, "
+	"{\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}]}}}";
+
+int main( void ) {
+	int rc = 0;
+
+	struct timezone tz = { 240, 1 };
+	struct timeval begin_timeval;
+	struct timeval end_timeval;
+
+	gettimeofday( &begin_timeval, &tz );
+
+	long i;
+	jsonObject * pObj = NULL;
+
+	for( i = 10000000; i; --i )
+	{
+//		pObj = jsonParseString( sample_json );
+		pObj = jsonNewObject( NULL );
+		jsonObject * p1 = jsonNewObject( NULL );
+		jsonObject * p2 = jsonNewObject( NULL );
+		jsonObjectFree( p1 );
+		jsonObjectFree( p2 );
+		jsonObjectFree( pObj );
+	}
+
+	jsonObjectFreeUnused();
+	
+	gettimeofday( &end_timeval, &tz );
+
+	struct timeval elapsed = diff_timeval( &begin_timeval, &end_timeval );
+
+	printf( "Elapsed time: %ld seconds, %ld microseconds\n",
+			(long) elapsed.tv_sec, (long) elapsed.tv_usec );
+
+	struct rlimit rlim;
+	if( getrlimit( RLIMIT_DATA, &rlim ) )
+		printf( "Error calling getrlimit\n" );
+	else
+		printf( "Address space: %lu\n", (unsigned long) rlim.rlim_cur );
+
+	malloc_stats();
+
+	return rc;
+}
+
+struct timeval diff_timeval( const struct timeval * begin, const struct timeval * end )
+{
+	struct timeval diff;
+
+	diff.tv_sec = end->tv_sec - begin->tv_sec;
+	diff.tv_usec = end->tv_usec - begin->tv_usec;
+
+	if( diff.tv_usec < 0 )
+	{
+		diff.tv_usec += 1000000;
+		--diff.tv_sec;
+	}
+
+	return diff;
+
+}

Modified: trunk/src/libopensrf/socket_bundle.c
===================================================================
--- trunk/src/libopensrf/socket_bundle.c	2008-03-10 12:04:57 UTC (rev 1276)
+++ trunk/src/libopensrf/socket_bundle.c	2008-03-10 13:10:59 UTC (rev 1277)
@@ -136,6 +136,13 @@
 	int sock_fd;
 	struct sockaddr_un server_addr;
 
+	if(strlen(path) > sizeof(server_addr.sun_path) - 1)
+	{
+		osrfLogWarning( OSRF_LOG_MARK, "socket_open_unix_server(): path too long: %s",
+			path );
+		return -1;
+	}
+
 	errno = 0;
 	sock_fd = socket(AF_UNIX, SOCK_STREAM, 0);
 	if(sock_fd < 0){
@@ -336,6 +343,13 @@
 	int sock_fd, len;
    struct sockaddr_un usock;
 
+   if(strlen(sock_path) > sizeof(usock.sun_path) - 1)
+   {
+	   osrfLogWarning( OSRF_LOG_MARK, "socket_open_unix_client(): path too long: %s",
+		   sock_path );
+	   return -1;
+   }
+
    errno = 0;
    if( (sock_fd = socket( AF_UNIX, SOCK_STREAM, 0 )) < 0 ) {
 	   osrfLogWarning(  OSRF_LOG_MARK, "socket_open_unix_client(): Cannot create UNIX socket: %s", strerror( errno ) );
@@ -713,6 +727,7 @@
 	osrfLogInternal( OSRF_LOG_MARK, "%ld : Received data at %f\n", (long) getpid(), get_timestamp_millis());
 
 	while( (read_bytes = recv(sock_fd, buf, RBUFSIZE-1, 0) ) > 0 ) {
+		buf[read_bytes] = '\0';
 		osrfLogInternal( OSRF_LOG_MARK, "Socket %d Read %d bytes and data: %s", sock_fd, read_bytes, buf);
 		if(mgr->data_received)
 			mgr->data_received(mgr->blob, mgr, sock_fd, buf, node->parent_id);



More information about the opensrf-commits mailing list