socsvn commit: r256595 - in soc2013/dpl/head/lib/libzcap: . test zlibworker

dpl at FreeBSD.org dpl at FreeBSD.org
Mon Aug 26 19:24:34 UTC 2013


Author: dpl
Date: Mon Aug 26 19:24:33 2013
New Revision: 256595
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256595

Log:
  Update.
  

Modified:
  soc2013/dpl/head/lib/libzcap/Makefile
  soc2013/dpl/head/lib/libzcap/capsicum.c
  soc2013/dpl/head/lib/libzcap/commands.c
  soc2013/dpl/head/lib/libzcap/test/zcaplibtest.c
  soc2013/dpl/head/lib/libzcap/zlibworker/Makefile
  soc2013/dpl/head/lib/libzcap/zlibworker/commands.c
  soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c

Modified: soc2013/dpl/head/lib/libzcap/Makefile
==============================================================================
--- soc2013/dpl/head/lib/libzcap/Makefile	Mon Aug 26 18:53:19 2013	(r256594)
+++ soc2013/dpl/head/lib/libzcap/Makefile	Mon Aug 26 19:24:33 2013	(r256595)
@@ -2,8 +2,8 @@
 # $FreeBSD: head/lib/libz/Makefile 232263 2012-02-28 18:30:18Z dim $
 #
 
-#TODEL
-CFLAGS+= -Wall -g -fno-color-diagnostics
+#XXX
+CFLAGS+= -Wall -g -O0 -fno-color-diagnostics
 
 LIB=		zcap
 SHLIBDIR?=	/lib
@@ -15,21 +15,21 @@
 
 CLEANFILES+=	example.o example foo.gz minigzip.o minigzip
 
-SRCS+=		capsicum.c
-SRCS+=		commands.c
-SRCS+=		adler32.c
-SRCS+=		compress.c
-SRCS+=		crc32.c
-SRCS+=		deflate.c
-SRCS+=		gzclose.c
-SRCS+=		gzlib.c
-SRCS+=		gzread.c
-SRCS+=		gzwrite.c
-SRCS+=		infback.c
-SRCS+=		inflate.c
-SRCS+=		uncompr.c
-SRCS+=		zopen.c
-SRCS+=		zutil.c
+SRCS+= capsicum.c
+SRCS+= commands.c
+SRCS+= adler32.c
+SRCS+= compress.c
+SRCS+= crc32.c
+SRCS+= deflate.c
+SRCS+= gzclose.c
+SRCS+= gzlib.c
+SRCS+= gzread.c
+SRCS+= gzwrite.c
+SRCS+= infback.c
+SRCS+= inflate.c
+SRCS+= uncompr.c
+SRCS+= zopen.c
+SRCS+= zutil.c
 
 SUBDIR= zlibworker
 

Modified: soc2013/dpl/head/lib/libzcap/capsicum.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/capsicum.c	Mon Aug 26 18:53:19 2013	(r256594)
+++ soc2013/dpl/head/lib/libzcap/capsicum.c	Mon Aug 26 19:24:33 2013	(r256595)
@@ -4,6 +4,7 @@
 #include <nv.h>
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <sys/ioctl.h>
 
 #include <signal.h>
 #include <stdlib.h>
@@ -18,6 +19,7 @@
 
 int startChild(void);
 void killChild(void);
+void suicide(int signal);
 nvlist_t * sendCommand(nvlist_t *nvl);
 
 int
@@ -27,10 +29,11 @@
 		perror("zcaplib: socketpair()");
 
 	if( (pid = fork()) == 0 ){
-		cap_rights_limit(STDIN_FILENO, CAP_WRITE);
-		cap_rights_limit(STDOUT_FILENO, CAP_READ);
+		cap_rights_limit(STDIN_FILENO, CAP_READ);
+		cap_rights_limit(STDOUT_FILENO, CAP_WRITE|CAP_FSTAT|CAP_IOCTL);
 		cap_rights_limit(STDERR_FILENO, CAP_WRITE);
-		//cap_rights_limit(3, CAP_WRITE|CAP_READ|CAP_EVENT);
+		dup2(sv[0], 3);
+		cap_rights_limit(3, CAP_WRITE|CAP_READ|CAP_POLL_EVENT);
 		closefrom(4);
 
 		/* open and execl() listener */
@@ -39,12 +42,13 @@
 			exit (-1);
 		}
 	
-		if ( execl("/usr/libexec/zlibworker", "zlibworker", NULL) <0 ) {
+		if ( execl("/usr/libexec/zlibworker", "zlibworker", NULL) < 0) {
 			perror("zcaplib: execl:");
 			exit (-1);
 		}
 		exit(0);
 	} else {
+		signal(SIGCHLD, suicide);
 		atexit(killChild);
 	}
 
@@ -56,12 +60,15 @@
 {
 	nvlist_t *new;
 	if( nvlist_send(sv[1], nvl) != 0 ) 
-		err(1, "zcaplib: nvlist_send()");
+		err(1, "zcaplib: nvlist_send() Went wrong");
 	if ((new = nvlist_recv(sv[1])) == NULL) 
-		err(1, "nvlist_recv(): nvl is NULL");
+		err(1, "nvlist_recv(): nvlist_t is NULL");
 	return (new);
 }
 
 void killChild(void) {
 	kill(pid, SIGKILL);
+}
+void suicide(int signal) {
+	kill(getpid(), SIGKILL);
 }
\ No newline at end of file

Modified: soc2013/dpl/head/lib/libzcap/commands.c
==============================================================================
--- soc2013/dpl/head/lib/libzcap/commands.c	Mon Aug 26 18:53:19 2013	(r256594)
+++ soc2013/dpl/head/lib/libzcap/commands.c	Mon Aug 26 19:24:33 2013	(r256595)
@@ -7,11 +7,14 @@
 #include "capsicum.h"
 
 #include <string.h>
+#include <err.h>
 
 
 void checkChild(void);
+void initializeCommand(void);
 void destroy(void);
 
+
 /* Basic functions */
 int zcapcmd_deflateInit(z_streamp strm, int level, int method, int windowBits,
 						int memLevel, int strategy, const char * version,
@@ -87,7 +90,7 @@
 nvlist_t *nvl, *args, *result;
 size_t gzfilesize = sizeof(struct gzFile_s);
 size_t gzheadersize = sizeof(struct gz_header_s);
-size_t z_streamsize = sizeof(z_stream);
+size_t zstreamsize = sizeof(z_stream);
 
 
 void
@@ -97,6 +100,14 @@
 }
 
 void
+initializeCommand() {
+	checkChild();
+
+	if( (args = nvlist_create(0)) == NULL || (nvl = nvlist_create(0)) == NULL )
+		err(1, "zcaplib: nvlist_create");
+}
+
+void
 destroy(void) {
 	nvlist_destroy(args);
 	nvlist_destroy(nvl);
@@ -109,16 +120,11 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
-	/* No worries here */
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	/* No worries here, strm state will be saved on zlibworker */
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_number(args, "level", level);
 	nvlist_add_number(args, "method", method);
 	nvlist_add_number(args, "windowBits", windowBits);
@@ -137,8 +143,8 @@
 	   buffers, and sync: next_in, avail_in, total_in, next_out,
 	   avail_out, total_out. */
 	/* Supposing there's already space reserved for z_stream */
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	char *msg = nvlist_take_string(result, "msg");
 	memcpy(strm->msg, msg, strlen(msg)+1);
 	destroy();
@@ -150,23 +156,18 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
 	/* Supposing there's already space reserved for z_stream */
-	memcpy(strm, newstrm, z_streamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -177,23 +178,16 @@
 {
 	uLong ret;
 	
-	checkChild();
-
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
-	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	initializeCommand();
+	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEEND);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	/* Supposing there's already space reserved for z_stream */
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -204,16 +198,11 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
-	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
+	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEINIT);
 	/* No worries here */
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_number(args, "windowBits", windowBits);
 	nvlist_add_string(args, "version", version);
 	nvlist_add_number(args, "stream_size", stream_size);
@@ -222,8 +211,8 @@
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	char *msg = nvlist_take_string(result, "msg");
 	memcpy(strm->msg, msg, strlen(msg)+1);
 	destroy();
@@ -235,23 +224,18 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
 	/* Supposing there's already space reserved for z_stream */
-	memcpy(strm, newstrm, z_streamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -261,22 +245,17 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEINIT);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -289,13 +268,8 @@
 	/* XXX */
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATESETDICTIONARY);
 	nvlist_add_binary(args, "dictionary", *dictionary, dictLength);
 	nvlist_add_number(args, "dictLength", dictLength);
@@ -304,8 +278,8 @@
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -315,24 +289,19 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATECOPY);
-	nvlist_add_binary(args, "dest", (void *)dest, z_streamsize);
-	nvlist_add_binary(args, "source", (void *)source, z_streamsize);
+	nvlist_add_binary(args, "dest", (void *)dest, zstreamsize);
+	nvlist_add_binary(args, "source", (void *)source, zstreamsize);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	/* The two z_streamp are now copied at the worker. */
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(dest, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(dest, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -342,23 +311,18 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATERESET);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
 	/* Save the reseted strm. */
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	char *msg = nvlist_take_string(result, "msg");
 	memcpy(strm->msg, msg, strlen(msg)+1);
 	destroy();
@@ -370,15 +334,10 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEPARAMS);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_number(args, "level", level);
 	nvlist_add_number(args, "strategy", strategy);
 	nvlist_add_nvlist(nvl, "args", args);
@@ -387,8 +346,8 @@
 
 	ret = nvlist_take_number(result, "result");
 	/* Overwrite the old streamp */
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -399,15 +358,10 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATETUNE);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_number(args, "good_length", good_length);
 	nvlist_add_number(args, "max_lazy", max_lazy);
 	nvlist_add_number(args, "nice_length", nice_length);
@@ -417,8 +371,8 @@
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -428,23 +382,18 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEBOUND);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_number(args, "sourceLen", sourceLen);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -454,15 +403,10 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEPENDING);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	/* Will get malloc()ed at the worker. */
 	nvlist_add_number(args, "pending", *pending);
 	nvlist_add_number(args, "bits", *bits);
@@ -471,8 +415,8 @@
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -482,15 +426,10 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATEPRIME);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_number(args, "bits", bits);
 	nvlist_add_number(args, "value", value);
 	nvlist_add_nvlist(nvl, "args", args);
@@ -498,8 +437,8 @@
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -511,15 +450,10 @@
 	/* What happens with header->extra??? */
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_DEFLATESETHEADER);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_binary(args, "head", (void*)head, gzheadersize);
 	nvlist_add_string(nvl, "name", head->name);
 	nvlist_add_string(nvl, "comment", head->comment);
@@ -528,8 +462,8 @@
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -540,22 +474,17 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESETDICTIONARY);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -566,22 +495,17 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEGETDICTIONARY);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -591,22 +515,17 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATESYNC);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -616,24 +535,19 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATECOPY);
-	nvlist_add_binary(args, "dest", (void *)dest, z_streamsize);
-	nvlist_add_binary(args, "source", (void *)source, z_streamsize);
+	nvlist_add_binary(args, "dest", (void *)dest, zstreamsize);
+	nvlist_add_binary(args, "source", (void *)source, zstreamsize);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	/* The two z_streamp are now copied at the worker. */
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(dest, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(dest, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -643,22 +557,17 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATERESET);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	char *msg = nvlist_take_string(result, "msg");
 	memcpy(strm->msg, msg, strlen(msg)+1);
 	destroy();
@@ -670,23 +579,18 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATERESET2);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_number(nvl, "windowBits", windowBits);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	char *msg = nvlist_take_string(result, "msg");
 	memcpy(strm->msg, msg, strlen(msg)+1);
 	destroy();
@@ -698,15 +602,10 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEPRIME);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_number(args, "bits", bits);
 	nvlist_add_number(args, "value", value);
 	nvlist_add_nvlist(nvl, "args", args);
@@ -714,8 +613,8 @@
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -725,22 +624,17 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEMARK);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -751,23 +645,18 @@
 	/* XXX: Beware of gz_headerp extra */
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEGETHEADER);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_binary(args, "head", (void *)head, gzheadersize);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	gz_headerp newhead = nvlist_take_binary(result, "newhead", gzheadersize);
 	head->done = newhead->done;
 	destroy();
@@ -781,24 +670,19 @@
 	/* window has to be a pointer to at least a 32kb buffer */
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEBACKINIT);
 	/* No worries here */
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_number(args, "windowBits", windowBits);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	char *msg = nvlist_take_string(result, "msg");
 	memcpy(strm->msg, msg, strlen(msg)+1);
 	destroy();
@@ -811,22 +695,17 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEBACK);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -836,22 +715,17 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_INFLATEBACKEND);
-	nvlist_add_binary(args, "strm", (void *)strm, z_streamsize);
+	nvlist_add_binary(args, "strm", (void *)strm, zstreamsize);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
 
 	ret = nvlist_take_number(result, "result");
-	z_stream *newstrm = nvlist_take_binary(result, "newstrm", z_streamsize);
-	memcpy(strm, newstrm, z_streamsize);
+	z_stream *newstrm = nvlist_take_binary(result, "newstrm", &zstreamsize);
+	memcpy(strm, newstrm, zstreamsize);
 	destroy();
 	return(ret);
 }
@@ -861,13 +735,8 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_ZLIBCOMPILEFLAGS);
 	nvlist_add_nvlist(nvl, "args", args);
 
@@ -884,19 +753,13 @@
 {
 	uLong ret;
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_COMPRESSBOUND);
 	nvlist_add_number(args, "sourceLen", sourceLen);
 	nvlist_add_nvlist(nvl, "args", args);
 
 	result = sendCommand(nvl);
-
 	ret = nvlist_take_number(result, "result");
 	destroy();
 	return(ret);
@@ -907,13 +770,8 @@
 zcapcmd_gzopen(const char *path, int fd, const char *mode)
 {
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return (NULL);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZOPEN);
 	nvlist_add_string(args, "path", path);
 	nvlist_move_descriptor(args, "fd", fd);
@@ -934,13 +792,8 @@
 zcapcmd_gzbuffer(gzFile file, unsigned size)
 {
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}
 	nvlist_add_number(nvl, "command", ZCAPCMD_GZBUFFER);
 	nvlist_add_binary(args, "file", file, gzfilesize);
 	nvlist_add_number(args, "size", size);
@@ -957,13 +810,8 @@
 zcapcmd_gzsetparams(gzFile file, int level, int strategy)
 {
 	
-	checkChild();
+	initializeCommand();
 
-	if( (args = nvlist_create(0)) == NULL ||
-		(nvl = nvlist_create(0)) == NULL ) {
-		perror("zcaplib: nvlist_create");
-		return(0);
-	}

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***


More information about the svn-soc-all mailing list