Date: Tue, 20 Aug 2013 12:23:34 GMT From: dpl@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r256193 - in soc2013/dpl/head/lib/libzcap: . zlibworker Message-ID: <201308201223.r7KCNY0Y026598@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: dpl Date: Tue Aug 20 12:23:34 2013 New Revision: 256193 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=256193 Log: Made slight advances. Modified: soc2013/dpl/head/lib/libzcap/capsicum.c soc2013/dpl/head/lib/libzcap/commands.h soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c Modified: soc2013/dpl/head/lib/libzcap/capsicum.c ============================================================================== --- soc2013/dpl/head/lib/libzcap/capsicum.c Tue Aug 20 11:06:56 2013 (r256192) +++ soc2013/dpl/head/lib/libzcap/capsicum.c Tue Aug 20 12:23:34 2013 (r256193) @@ -9,6 +9,7 @@ #include <stdlib.h> #include <unistd.h> #include <stdio.h> +#include <err.h> #define SUM 0 @@ -23,30 +24,27 @@ startChild(void) { if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) < 0 ) - perror("zcaplib: socketpair"); + perror("zcaplib: socketpair()"); if( (pid = fork()) == 0 ){ cap_rights_limit(STDIN_FILENO, CAP_WRITE); cap_rights_limit(STDOUT_FILENO, CAP_READ); cap_rights_limit(STDERR_FILENO, CAP_WRITE); + //cap_rights_limit(3, CAP_WRITE|CAP_READ|CAP_EVENT); + closefrom(4); - close(sv[0]); - dup2(sv[1] , 3); /* 3 is now the socket */ - close(4); - /* open and execl() listener */ if (access("/usr/libexec/zlibworker", X_OK) < 0) { - perror("zcaplib: zlibworker:"); + perror("zcaplib: access():"); exit (-1); } if ( execl("/usr/libexec/zlibworker", "zlibworker", NULL) <0 ) { - perror("zcaplib: zlibworker:"); + perror("zcaplib: execl:"); exit (-1); } exit(0); } else { - close(sv[1]); atexit(killChild); } @@ -56,16 +54,11 @@ nvlist_t * sendCommand( nvlist_t *nvl ) { - if( nvlist_send(sv[0], nvl) != 0 ) { - perror("zcaplib: nvlist_send()"); - return NULL; - } + if( nvlist_send(sv[1], nvl) != 0 ) + err(1, "zcaplib: nvlist_send()"); - /* recv results */ - if ((nvl = nvlist_recv(sv[0])) == NULL) { - perror("zcaplib: nvlist_recv()"); - return NULL; - } + if ((nvl = nvlist_recv(sv[1])) == NULL) + err(1, "nvlist_recv(): nvl is NULL"); return (nvl); } Modified: soc2013/dpl/head/lib/libzcap/commands.h ============================================================================== --- soc2013/dpl/head/lib/libzcap/commands.h Tue Aug 20 11:06:56 2013 (r256192) +++ soc2013/dpl/head/lib/libzcap/commands.h Tue Aug 20 12:23:34 2013 (r256193) @@ -47,35 +47,35 @@ #define ZCAPCMD_ZLIBCOMPILEFLAGS 28 /* utility functions */ -#define ZCAPCMD_COMPRESSBOUND 30 +#define ZCAPCMD_COMPRESSBOUND 29 /* gzip file access functions */ -#define ZCAPCMD_GZOPEN 32 -#define ZCAPCMD_GZBUFFER 34 -#define ZCAPCMD_GZSETPARAMS 35 -#define ZCAPCMD_GZREAD 36 -#define ZCAPCMD_GZWRITE 37 -#define ZCAPCMD_GZPRINTF 38 -#define ZCAPCMD_GZPUTS 39 -#define ZCAPCMD_GZGETS 49 -#define ZCAPCMD_GZPUTC 50 -#define ZCAPCMD_GZGETC 51 -#define ZCAPCMD_GZUNGETC 52 -#define ZCAPCMD_GZFLUSH 53 -#define ZCAPCMD_GZSEEK 54 -#define ZCAPCMD_GZREWIND 55 -#define ZCAPCMD_GZTELL 56 -#define ZCAPCMD_GZOFFSET 57 -#define ZCAPCMD_GZEOF 58 -#define ZCAPCMD_GZDIRECT 59 -#define ZCAPCMD_GZCLOSE 60 -#define ZCAPCMD_GZCLOSE_R 61 -#define ZCAPCMD_GZCLOSE_W 62 -#define ZCAPCMD_GZERROR 63 -#define ZCAPCMD_GZCLEARERR 64 +#define ZCAPCMD_GZOPEN 30 +#define ZCAPCMD_GZBUFFER 31 +#define ZCAPCMD_GZSETPARAMS 32 +#define ZCAPCMD_GZREAD 33 +#define ZCAPCMD_GZWRITE 34 +#define ZCAPCMD_GZPRINTF 35 +#define ZCAPCMD_GZPUTS 36 +#define ZCAPCMD_GZGETS 46 +#define ZCAPCMD_GZPUTC 47 +#define ZCAPCMD_GZGETC 48 +#define ZCAPCMD_GZUNGETC 49 +#define ZCAPCMD_GZFLUSH 50 +#define ZCAPCMD_GZSEEK 51 +#define ZCAPCMD_GZREWIND 52 +#define ZCAPCMD_GZTELL 53 +#define ZCAPCMD_GZOFFSET 54 +#define ZCAPCMD_GZEOF 55 +#define ZCAPCMD_GZDIRECT 56 +#define ZCAPCMD_GZCLOSE 57 +#define ZCAPCMD_GZCLOSE_R 58 +#define ZCAPCMD_GZCLOSE_W 59 +#define ZCAPCMD_GZERROR 60 +#define ZCAPCMD_GZCLEARERR 61 /* checksum functions */ -#define ZCAPCMD_ADLER32 65 -#define ZCAPCMD_ADLER32_COMBINE 66 -#define ZCAPCMD_CRC32 67 -#define ZCAPCMD_CRC32_COMBINE 68 +#define ZCAPCMD_ADLER32 62 +#define ZCAPCMD_ADLER32_COMBINE 63 +#define ZCAPCMD_CRC32 64 +#define ZCAPCMD_CRC32_COMBINE 65 Modified: soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c ============================================================================== --- soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c Tue Aug 20 11:06:56 2013 (r256192) +++ soc2013/dpl/head/lib/libzcap/zlibworker/zlibworker.c Tue Aug 20 12:23:34 2013 (r256193) @@ -5,7 +5,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <assert.h> +#include <err.h> #include "../commands.h" /* Basic functions */ @@ -79,32 +79,23 @@ /* Sandbox the process */ cap_enter(); - if ((data = calloc(5*1024, 1)) == NULL) { - perror("malloc"); - abort(); - } + if ((data = calloc(5*1024, 1)) == NULL) + err(1, "malloc\n"); - while(1) { - if ((result = nvlist_create(0)) == NULL) { - fprintf(stderr, "zlibworker: Can't create result.\n"); - exit(1); - } + if ((result = nvlist_create(0)) == NULL) + err(1, "Can't create result.\n"); + //fprintf(stderr, "DEBUG: zlibworker waiting command\n"); if ((nvl = nvlist_recv(3)) != NULL) { - if (!nvlist_exists(nvl, "command")) { - fprintf(stderr, "zlibworker: No command.\n"); - exit(1); - } - if (!nvlist_exists(nvl, "args")) { - fprintf(stderr, "zlibworker: args doesn't exist\n"); - exit(1); - } - } else { - fprintf(stderr, "zlibworker: nvl is NULL\n"); - exit(1); - } + if (!nvlist_exists(nvl, "command")) + err(1, "No command.\n"); + if (!nvlist_exists(nvl, "args")) + err(1, "args doesn't exist\n"); + } else err(1, "nvl is NULL\n"); + + //fprintf(stderr, "DEBUG: zlibworker got command\n"); // Switch for "command" // Get args, and call the real lib. switch( nvlist_take_number(nvl, "command") ){ @@ -235,10 +226,10 @@ case (ZCAPCMD_GZSEEK): zcapcmd_gzseek(nvl, result); break; - /* - * All this commands have gzFile as argument, - * and return an int (or void, in the last case). - */ + /* + * All this commands have gzFile as argument, + * and return an int (or void, in the last case). + */ case (ZCAPCMD_GZGETC): case (ZCAPCMD_GZREWIND): case (ZCAPCMD_GZTELL): @@ -268,18 +259,16 @@ zcapcmd_crc32_combine(nvl, result); break; default: - perror("zlibworker: unknown command"); - exit(1); + err(1, "Wrong command"); break; } - if( nvlist_send(3, result) != 0 ) { - perror("zlibworker: Couldn't send response\n"); - exit(1); - } + //fprintf(stderr, "DEBUG: zlibworker responding\n"); + if( nvlist_send(3, result) != 0 ) + err(1, "Couldn't send response\n"); - if (zero) - memset(data, 0, 5*1024); + nvlist_destroy(nvl); + if (zero) memset(data, 0, 5*1024); } return (0);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308201223.r7KCNY0Y026598>